From 215f966daa9ff9d8098aa2936a503780ebe8dc0c Mon Sep 17 00:00:00 2001 From: Steven H Johnson <shjohnson.pi@gmail.com> Date: Fri, 8 Jul 2016 19:09:57 -0400 Subject: [PATCH] Allow selecting specific section of map. Allow url hashes in nav nodes. --- htmleditor/admin.py | 3 +- .../0030_navigationnode_url_hash.py | 20 +++++++++++ htmleditor/models.py | 8 +++++ usta/templates/usta/main_menu.html | 8 ++--- usta/templates/usta/map.html | 33 +++++++++++++++---- 5 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 htmleditor/migrations/0030_navigationnode_url_hash.py diff --git a/htmleditor/admin.py b/htmleditor/admin.py index 7d16048..b90e84f 100644 --- a/htmleditor/admin.py +++ b/htmleditor/admin.py @@ -111,7 +111,8 @@ class NavigationNodeAdmin(SortableAdmin): fieldsets = ( (None, { 'fields': ( - 'name', 'parent', 'document', 'show_title', 'view', 'icon') + 'name', 'parent', 'document', 'show_title', 'view', 'url_hash', + 'icon') }), ('Advanced', { 'classes': ('collapse',), diff --git a/htmleditor/migrations/0030_navigationnode_url_hash.py b/htmleditor/migrations/0030_navigationnode_url_hash.py new file mode 100644 index 0000000..f2301c1 --- /dev/null +++ b/htmleditor/migrations/0030_navigationnode_url_hash.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.1 on 2016-07-08 23:08 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('htmleditor', '0029_document_content'), + ] + + operations = [ + migrations.AddField( + model_name='navigationnode', + name='url_hash', + field=models.CharField(blank=True, default='', help_text='The fragment identifier, appended to the url. <kbd>Example: 123 -> /my_url/#123</kbd><br>For Map Locations: <kbd>All-map</kbd>, <kbd>Tournament_Site-map</kbd>, <kbd>Practice_Court-map</kbd>, <kbd>Parking-map</kbd>, <kbd>Hotel-map</kbd>, and <kbd>Hospital-map</kbd>.', max_length=100, verbose_name='hash'), + ), + ] diff --git a/htmleditor/models.py b/htmleditor/models.py index a3c4d07..cc83b44 100644 --- a/htmleditor/models.py +++ b/htmleditor/models.py @@ -247,6 +247,14 @@ class NavigationNode(SortableMixin): view = models.CharField( max_length=MAX_LENGTH, choices=VIEW_CHOICES, blank=True, default="", help_text="This overrides document and any tab documents if set.") + url_hash = models.CharField( + max_length=MAX_LENGTH, blank=True, default="", verbose_name="hash", + help_text="The fragment identifier, appended to the url. " + + "<kbd>Example: 123 -> /my_url/#123</kbd><br>" + + "For Map Locations: <kbd>All-map</kbd>, " + + "<kbd>Tournament_Site-map</kbd>, <kbd>Practice_Court-map</kbd>, " + + "<kbd>Parking-map</kbd>, <kbd>Hotel-map</kbd>, and " + + "<kbd>Hospital-map</kbd>.") slug = models.SlugField() icon = models.ForeignKey('Image', models.SET_NULL, blank=True, null=True) diff --git a/usta/templates/usta/main_menu.html b/usta/templates/usta/main_menu.html index 498f72e..6b94bb9 100644 --- a/usta/templates/usta/main_menu.html +++ b/usta/templates/usta/main_menu.html @@ -9,10 +9,10 @@ {# Hide links to alumni reunion form, if disabled #} {% if not SiteSettings.show_reunion_form and child.view == "usta:alumni_reunion_form" %} {% else %} - <li class="nav-sublink"><a href="{% url child.view %}">{{ child.name }}</a></li> + <li class="nav-sublink"><a href="{% url child.view %}{% if child.url_hash %}#{{ child.url_hash|urlencode }}{% endif %}">{{ child.name }}</a></li> {% endif %} {% elif child.path %} - <li class="nav-sublink"><a href="{% url 'htmleditor:view' child.path %}">{{ child.name }}</a></li> + <li class="nav-sublink"><a href="{% url 'htmleditor:view' child.path %}{% if child.url_hash %}#{{ child.url_hash|urlencode }}{% endif %}">{{ child.name }}</a></li> {% endif %} {% endif %} {% endfor %} @@ -24,12 +24,12 @@ {% if not SiteSettings.show_reunion_form and parent.view == "usta:alumni_reunion_form" %} {% else %} <li class="nav-link"> - <a href="{% url parent.view %}">{% if parent.icon %}<img alt="{{ parent.icon.alt_text }}" src="{{ parent.icon.url }}">{% endif %}{{ parent.name }}</a> + <a href="{% url parent.view %}{% if parent.url_hash %}#{{ parent.url_hash|urlencode }}{% endif %}">{% if parent.icon %}<img alt="{{ parent.icon.alt_text }}" src="{{ parent.icon.url }}">{% endif %}{{ parent.name }}</a> </li> {% endif %} {% elif parent.path %} <li class="nav-link"> - <a href="{% url 'htmleditor:view' parent.path %}">{% if parent.icon %}<img alt="{{ parent.icon.alt_text }}" src="{{ parent.icon.url }}">{% endif %}{{ parent.name }}</a> + <a href="{% url 'htmleditor:view' parent.path %}{% if parent.url_hash %}#{{ parent.url_hash|urlencode }}{% endif %}">{% if parent.icon %}<img alt="{{ parent.icon.alt_text }}" src="{{ parent.icon.url }}">{% endif %}{{ parent.name }}</a> </li> {% endif %} {% endif %} diff --git a/usta/templates/usta/map.html b/usta/templates/usta/map.html index 66dc047..b8eef5f 100644 --- a/usta/templates/usta/map.html +++ b/usta/templates/usta/map.html @@ -11,7 +11,7 @@ {% block main %} <h1>Map Locations</h1> -<div id="map"></div> +<div id="map">Note: Javascript is disabled. Unable to load map.</div> <div id="map-checkbox-wrapper"> {% for category, places in locations.items %} {% if places.0 %}{# If there are any items of this category #} @@ -149,6 +149,7 @@ function onMapButtonClick(checkbox, list) { var table = document.getElementById(checkbox.value); //console.log("Table: ", table); if (checkbox.checked) { + window.location.replace("#" + checkbox.value + "-map"); setMap(list, map); if (table != null) { table.style.display = "block"; @@ -260,11 +261,31 @@ function initMap() { // Insert helpful text for checkboxes. $("#map-checkbox-wrapper").append("<p class='map-helper-text'>Click on a checkbox to show the corresponding map info and tables. Click again to hide the corresponding map info and tables.</p>"); - // Uncheck all checkboxes except Tournament site, initially. - $("#Practice_Court-checkbox").click(); - $("#Parking-checkbox").click(); - $("#Hotel-checkbox").click(); - $("#Hospital-checkbox").click(); + // Hide options if not 'all-map' + if (window.location.hash != "#All-map") { + // Uncheck all checkboxes + $("#Tournament_Site-checkbox").click(); + $("#Practice_Court-checkbox").click(); + $("#Parking-checkbox").click(); + $("#Hotel-checkbox").click(); + $("#Hospital-checkbox").click(); + + // If url set, show proper one, otherwise show Tournament Site + if (window.location.hash == "#Tournament_Site-map") { + $("#Tournament_Site-checkbox").click(); + } else if (window.location.hash == "#Practice_Court-map") { + $("#Practice_Court-checkbox").click(); + } else if (window.location.hash == "#Parking-map") { + $("#Parking-checkbox").click(); + } else if (window.location.hash == "#Hotel-map") { + $("#Hotel-checkbox").click(); + } else if (window.location.hash == "#Hospital-map") { + $("#Hospital-checkbox").click(); + } else { + // default + $("#Tournament_Site-checkbox").click(); + } + } } </script> <script src="https://maps.googleapis.com/maps/api/js?key={{ GOOGLE_API_KEY }}&signed_in=true&callback=initMap" async defer></script> -- GitLab