diff options
| author | Nim <etienne.loks@peacefrogs.net> | 2012-02-19 04:09:06 +0100 |
|---|---|---|
| committer | Nim <etienne.loks@peacefrogs.net> | 2012-02-19 04:09:06 +0100 |
| commit | b8c357a488da55ec263373e8e831381375904abe (patch) | |
| tree | a7bea4dedb582e14293a4765d6aee16ba03b6618 | |
| parent | d619212928d82def5aa826aa1d02e5b24510811f (diff) | |
| download | Chimère-b8c357a488da55ec263373e8e831381375904abe.tar.bz2 Chimère-b8c357a488da55ec263373e8e831381375904abe.zip | |
Many fixes on chimere jquery JS
| -rw-r--r-- | chimere/static/chimere/img/minus.png (renamed from example_project/static/icons/minus.png) | bin | 259 -> 259 bytes | |||
| -rw-r--r-- | chimere/static/chimere/img/plus.png (renamed from example_project/static/icons/plus.png) | bin | 275 -> 275 bytes | |||
| -rw-r--r-- | chimere/static/chimere/img/zoom.png (renamed from example_project/static/icons/zoom.png) | bin | 655 -> 655 bytes | |||
| -rw-r--r-- | chimere/static/chimere/js/jquery.chimere.js | 89 | ||||
| -rwxr-xr-x | example_project/static/icons/marker.png | bin | 0 -> 606 bytes |
5 files changed, 50 insertions, 39 deletions
diff --git a/example_project/static/icons/minus.png b/chimere/static/chimere/img/minus.png Binary files differindex a95822f..a95822f 100644 --- a/example_project/static/icons/minus.png +++ b/chimere/static/chimere/img/minus.png diff --git a/example_project/static/icons/plus.png b/chimere/static/chimere/img/plus.png Binary files differindex 404a24a..404a24a 100644 --- a/example_project/static/icons/plus.png +++ b/chimere/static/chimere/img/plus.png diff --git a/example_project/static/icons/zoom.png b/chimere/static/chimere/img/zoom.png Binary files differindex 3a53680..3a53680 100644 --- a/example_project/static/icons/zoom.png +++ b/chimere/static/chimere/img/zoom.png diff --git a/chimere/static/chimere/js/jquery.chimere.js b/chimere/static/chimere/js/jquery.chimere.js index d6bf310..fdac708 100644 --- a/chimere/static/chimere/js/jquery.chimere.js +++ b/chimere/static/chimere/js/jquery.chimere.js @@ -81,7 +81,6 @@ See the file COPYING for details. /* Manage parameters */ settings = $.extend({}, defaults); if ( options ) $.extend(settings, options); - var clicked = false; // TODO : remove this var map_element = $(this).get(0); var map_options = { controls: settings.controls, @@ -167,7 +166,9 @@ See the file COPYING for details. */ loadGeoObjects: function () { helpers.retrieve_checked_categories(); - var uri = extra_url + "getGeoObjects/" + settings.checked_categories.join('_'); + var ids = settings.checked_categories.join('_'); + if (!ids) ids = '0'; + var uri = extra_url + "getGeoObjects/" + ids; if (settings.display_submited) uri += "/A_S"; $.ajax({url: uri, dataType: "json", @@ -181,6 +182,9 @@ See the file COPYING for details. methods.addRoute(feature); } } + }, + error: function (data) { + settings.layerMarkers.clearMarkers(); } }); }, @@ -215,36 +219,49 @@ See the file COPYING for details. var val = category_element.is(":checked") ? true : false; category_element.parent().find("li input").attr("checked", val); } + var _toggle_categories = function (category_element) {} + var _toggle_categories = function (subcategory_element) { + var parent = subcategory_element.parent().parent().parent(); + var master_check = parent.find("> input"); + if (parent.find('.subcategories input[type=checkbox]').length == + parent.find('.subcategories input[type=checkbox]:checked').length){ + master_check.attr('checked', 'checked'); + } else { + master_check.removeAttr('checked'); + } + }; var _init_categories = function () { /* * Add event listener in categories DOM elements */ - $('#categories #ul_categories > li input').bind("click", function () { + $('#categories #ul_categories > li > input').bind("click", function () { _toggle_subcategories($(this));methods.loadGeoObjects();}); + $('.subcategories li input').bind("click", function () { + methods.loadGeoObjects();_toggle_categories($(this));}); + $('#display_submited_check').bind("click", function () { + methods.loadGeoObjects();}); // Zoom to category $(".zoom_to_category").bind("click", function (e) {var id = this.id.substr(this.id.lastIndexOf("_")+1); helpers.zoom_to_category(id);}); $(".zoom_to_subcategory").bind("click", function (e) {var id = this.id.substr(this.id.lastIndexOf("_")+1); helpers.zoom_to_subcategories([id]);}); $(".toggle_category").bind("click", function (e) {var id = this.id.substr(this.id.lastIndexOf("_")+1); methods.toggle_category(id); }); } var _reCheckCategories = function (){ - /* recheck categories when a redraw occurs */ + /* recheck categories on init or when a redraw occurs */ if (!settings.checked_categories){ return; } - inputs = window.document.forms["frm_categories"]; - for (var i = 0; i < inputs.length; i++) { - input = inputs[i]; - cat_id = input.name.split('_').pop(); - if (settings.checked_categories.indexOf(parseInt(cat_id)) != -1){ - input.checked = true; - } - if (input.id == 'display_submited' && settings.display_submited == true){ - input.checked = true; + $('#frm_categories .subcategories input:checkbox').each(function(index){ + cat_id = $(this).attr('id').split('_').pop(); + if (settings.checked_categories.indexOf(parseInt(cat_id)) != -1) { + $(this).attr("checked", "checked"); + _toggle_categories($(this)); } + }); + if (settings.display_submited == true){ + $('#display_submited_check').attr("checked", "checked"); } } }, - /* * Put a marker on the map */ @@ -295,10 +312,9 @@ See the file COPYING for details. else { // Default popup - if (clicked) { + if (feature.popup && feature.popup.visible()) { if (settings.current_popup == feature.popup) { feature.popup.hide(); - clicked = false; if (!settings.simple){ $('#detail').hide(); } @@ -309,7 +325,6 @@ See the file COPYING for details. } } else { _popup(); - clicked = true; methods.display_feature_detail(feature.pk); } } @@ -330,7 +345,6 @@ See the file COPYING for details. /* show the item when designed in the permalink */ if (settings.display_feature == feature.pk){ _popup(feature); - clicked = true; methods.display_feature_detail(feature.pk); settings.map.setCenter(feature.lonlat, 17); updateCategories(); @@ -418,13 +432,13 @@ See the file COPYING for details. // Close all categories $("#categories ul.subcategories").hide(); // Put a minus image - $("#categories img.toggle_category").attr("src", STATIC_URL + "chimere/img/minus.png"); + $("#categories img.toggle_category").attr("src", STATIC_URL + "chimere/img/plus.png"); if (!was_visible) { // Show the subcategories $("#maincategory_" + id).toggle(); // Put a plus image - $("#maincategory_img_" + id).attr("src", STATIC_URL + "chimere/img/plus.png"); + $("#maincategory_img_" + id).attr("src", STATIC_URL + "chimere/img/minus.png"); settings.current_category = id; } } @@ -464,25 +478,20 @@ See the file COPYING for details. /* * Retrieve checked_categories, and store it in settings */ - inputs = window.document.forms["frm_categories"]; - // Otherwise at first launch, the HTML is not ready - if (inputs.length > 0 ) - { - settings.checked_categories = []; - settings.display_submited = false; - for (var i = 0; i < inputs.length; i++) { - input = inputs[i]; - // 'category_'.length : 9 - if (input.checked - && input.name.substring(9, 0) == 'category_'){ - id = input.name.substring(9, input.name.length); - settings.checked_categories.push(id); - } - if (input.checked && input.name == 'display_submited'){ - settings.display_submited = true; - } + var initialized = false; + $('#frm_categories .subcategories input:checkbox').each(function(index){ + if (!initialized){ + initialized = true; + settings.checked_categories = []; + settings.display_submited = false; } - settings.permalink.updateLink(); + if ($(this).attr('checked') == 'checked'){ + cat_id = $(this).attr('id').split('_').pop(); + settings.checked_categories.push(cat_id); + } + }); + if(initialized && $('#display_submited_check').attr("checked") == "checked"){ + settings.display_submited = true; } }, zoom_to: function (bounds) { @@ -490,7 +499,9 @@ See the file COPYING for details. }, zoom_to_subcategories: function (ids) { // TODO add markers and check the subcategory, if not yet checked/displayed - var uri = extra_url + "getGeoObjects/" + ids.join('_'); + var ids = ids.join('_'); + if (!ids) ids = '0'; + var uri = extra_url + "getGeoObjects/" + ids; if (settings.display_submited) uri += "/A_S"; $.ajax({url: uri, dataType: "json", diff --git a/example_project/static/icons/marker.png b/example_project/static/icons/marker.png Binary files differnew file mode 100755 index 0000000..ccd1913 --- /dev/null +++ b/example_project/static/icons/marker.png |
