diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000000..30d6fcc1e36d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,37 @@ +# http://editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true +end_of_line = lf +charset = utf-8 + +# Use 2 spaces for the HTML files +[*.html] +indent_size = 2 + +# The JSON files contain newlines inconsistently +[*.json] +indent_size = 2 +insert_final_newline = ignore + +[**/admin/js/vendor/**] +indent_style = ignore +indent_size = ignore + +# Minified JavaScript files shouldn't be changed +[**.min.js] +indent_style = ignore +insert_final_newline = ignore + +# Makefiles always use tabs for indentation +[Makefile] +indent_style = tab + +# Batch files use tabs for indentation +[*.bat] +indent_style = tab diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000000..cb0447577ba7 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +**/{*.min,jquery}.js +django/contrib/gis/templates/**/*.js +node_modules/**.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 000000000000..4d8f385896ca --- /dev/null +++ b/.eslintrc @@ -0,0 +1,51 @@ +{ + "rules": { + "camelcase": [1, {"properties": "always"}], + "comma-spacing": [1, {"before": false, "after": true}], + "dot-notation": [1, {"allowKeywords": true}], + "curly": [1, "all"], + "indent": [ + 2, + 4 + ], + "key-spacing": [1, { + "beforeColon": false, + "afterColon": true + }], + "new-cap": [1, {"newIsCap": true, "capIsNew": true}], + "no-alert": [0], + "no-eval": [1], + "no-extend-native": [2, {"exceptions": ["Date", "String"]}], + "no-multi-spaces": [1], + "no-octal-escape": [1], + "no-underscore-dangle": [1], + "no-unused-vars": [2, {"vars": "local", "args": "none"}], + "no-script-url": [1], + "no-shadow": [1, {"hoist": "functions"}], + "quotes": [ + 1, + "single" + ], + "linebreak-style": [ + 2, + "unix" + ], + "semi": [ + 2, + "always" + ], + "space-before-blocks": [2, "always"], + "space-before-function-paren": [1, {"anonymous": "always", "named": "never"}], + "space-infix-ops": [ + 1, + {"int32Hint": false} + ], + "strict": [1, "function"] + }, + "env": { + "browser": true + }, + "globals": { + "django": false + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5f1338f23221..e873831f50d7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ MANIFEST dist/ docs/_build/ docs/locale/ +node_modules/ tests/coverage_html/ tests/.coverage build/ diff --git a/django/contrib/admin/static/admin/js/SelectBox.js b/django/contrib/admin/static/admin/js/SelectBox.js index db3206ccf528..bbd30a2c58b3 100644 --- a/django/contrib/admin/static/admin/js/SelectBox.js +++ b/django/contrib/admin/static/admin/js/SelectBox.js @@ -1,9 +1,10 @@ +/*eslint no-cond-assign:1*/ var SelectBox = { - cache: new Object(), + cache: {}, init: function(id) { var box = document.getElementById(id); var node; - SelectBox.cache[id] = new Array(); + SelectBox.cache[id] = []; var cache = SelectBox.cache[id]; for (var i = 0; (node = box.options[i]); i++) { cache.push({value: node.value, text: node.text, displayed: 1}); @@ -31,7 +32,7 @@ var SelectBox = { for (var i = 0; (node = SelectBox.cache[id][i]); i++) { node.displayed = 1; for (var j = 0; (token = tokens[j]); j++) { - if (node.text.toLowerCase().indexOf(token) == -1) { + if (node.text.toLowerCase().indexOf(token) === -1) { node.displayed = 0; } } @@ -41,13 +42,13 @@ var SelectBox = { delete_from_cache: function(id, value) { var node, delete_index = null; for (var i = 0; (node = SelectBox.cache[id][i]); i++) { - if (node.value == value) { + if (node.value === value) { delete_index = i; break; } } var j = SelectBox.cache[id].length - 1; - for (var i = delete_index; i < j; i++) { + for (i = delete_index; i < j; i++) { SelectBox.cache[id][i] = SelectBox.cache[id][i+1]; } SelectBox.cache[id].length--; @@ -59,7 +60,7 @@ var SelectBox = { // Check if an item is contained in the cache var node; for (var i = 0; (node = SelectBox.cache[id][i]); i++) { - if (node.value == value) { + if (node.value === value) { return true; } } @@ -67,7 +68,6 @@ var SelectBox = { }, move: function(from, to) { var from_box = document.getElementById(from); - var to_box = document.getElementById(to); var option; for (var i = 0; (option = from_box.options[i]); i++) { if (option.selected && SelectBox.cache_contains(from, option.value)) { @@ -80,7 +80,6 @@ var SelectBox = { }, move_all: function(from, to) { var from_box = document.getElementById(from); - var to_box = document.getElementById(to); var option; for (var i = 0; (option = from_box.options[i]); i++) { if (SelectBox.cache_contains(from, option.value)) { @@ -111,4 +110,4 @@ var SelectBox = { box.options[i].selected = 'selected'; } } -} +}; diff --git a/django/contrib/admin/static/admin/js/SelectFilter2.js b/django/contrib/admin/static/admin/js/SelectFilter2.js index 8f417dd9df80..f8aba12fd682 100644 --- a/django/contrib/admin/static/admin/js/SelectFilter2.js +++ b/django/contrib/admin/static/admin/js/SelectFilter2.js @@ -1,196 +1,197 @@ +/*global SelectBox, addEvent, gettext, interpolate, quickElement, SelectFilter*/ /* SelectFilter2 - Turns a multiple-select box into a filter interface. Requires core.js, SelectBox.js and addevent.js. */ (function($) { -function findForm(node) { - // returns the node of the form containing the given node - if (node.tagName.toLowerCase() != 'form') { - return findForm(node.parentNode); - } - return node; -} - -window.SelectFilter = { - init: function(field_id, field_name, is_stacked) { - if (field_id.match(/__prefix__/)){ - // Don't initialize on empty forms. - return; - } - var from_box = document.getElementById(field_id); - from_box.id += '_from'; // change its ID - from_box.className = 'filtered'; - - var ps = from_box.parentNode.getElementsByTagName('p'); - for (var i=0; i, because it just gets in the way. - from_box.parentNode.removeChild(ps[i]); - } else if (ps[i].className.indexOf("help") != -1) { - // Move help text up to the top so it isn't below the select - // boxes or wrapped off on the side to the right of the add - // button: - from_box.parentNode.insertBefore(ps[i], from_box.parentNode.firstChild); - } + function findForm(node) { + // returns the node of the form containing the given node + if (node.tagName.toLowerCase() !== 'form') { + return findForm(node.parentNode); } + return node; + } - //
or
- var selector_div = quickElement('div', from_box.parentNode); - selector_div.className = is_stacked ? 'selector stacked' : 'selector'; - - //
- var selector_available = quickElement('div', selector_div); - selector_available.className = 'selector-available'; - var title_available = quickElement('h2', selector_available, interpolate(gettext('Available %s') + ' ', [field_name])); - quickElement( - 'span', title_available, '', - 'class', 'help help-tooltip help-icon', - 'title', interpolate( - gettext( - 'This is the list of available %s. You may choose some by ' + - 'selecting them in the box below and then clicking the ' + - '"Choose" arrow between the two boxes.' - ), - [field_name] - ) - ); - - var filter_p = quickElement('p', selector_available, '', 'id', field_id + '_filter'); - filter_p.className = 'selector-filter'; - - var search_filter_label = quickElement('label', filter_p, '', 'for', field_id + "_input"); - - var search_selector_img = quickElement( - 'span', search_filter_label, '', - 'class', 'help-tooltip search-label-icon', - 'title', interpolate(gettext("Type into this box to filter down the list of available %s."), [field_name]) - ); - - filter_p.appendChild(document.createTextNode(' ')); - - var filter_input = quickElement('input', filter_p, '', 'type', 'text', 'placeholder', gettext("Filter")); - filter_input.id = field_id + '_input'; - - selector_available.appendChild(from_box); - var choose_all = quickElement('a', selector_available, gettext('Choose all'), 'title', interpolate(gettext('Click to choose all %s at once.'), [field_name]), 'href', 'javascript:void(0);', 'id', field_id + '_add_all_link'); - choose_all.className = 'selector-chooseall'; - - //
    - var selector_chooser = quickElement('ul', selector_div); - selector_chooser.className = 'selector-chooser'; - var add_link = quickElement('a', quickElement('li', selector_chooser), gettext('Choose'), 'title', gettext('Choose'), 'href', 'javascript:void(0);', 'id', field_id + '_add_link'); - add_link.className = 'selector-add'; - var remove_link = quickElement('a', quickElement('li', selector_chooser), gettext('Remove'), 'title', gettext('Remove'), 'href', 'javascript:void(0);', 'id', field_id + '_remove_link'); - remove_link.className = 'selector-remove'; - - //
    - var selector_chosen = quickElement('div', selector_div); - selector_chosen.className = 'selector-chosen'; - var title_chosen = quickElement('h2', selector_chosen, interpolate(gettext('Chosen %s') + ' ', [field_name])); - quickElement( - 'span', title_chosen, '', - 'class', 'help help-tooltip help-icon', - 'title', interpolate( - gettext( - 'This is the list of chosen %s. You may remove some by ' + - 'selecting them in the box below and then clicking the ' + - '"Remove" arrow between the two boxes.' - ), - [field_name] - ) - ); - - var to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', 'multiple', 'size', from_box.size, 'name', from_box.getAttribute('name')); - to_box.className = 'filtered'; - var clear_all = quickElement('a', selector_chosen, gettext('Remove all'), 'title', interpolate(gettext('Click to remove all chosen %s at once.'), [field_name]), 'href', 'javascript:void(0);', 'id', field_id + '_remove_all_link'); - clear_all.className = 'selector-clearall'; - - from_box.setAttribute('name', from_box.getAttribute('name') + '_old'); - - // Set up the JavaScript event handlers for the select box filter interface - addEvent(choose_all, 'click', function() { SelectBox.move_all(field_id + '_from', field_id + '_to'); SelectFilter.refresh_icons(field_id); }); - addEvent(add_link, 'click', function() { SelectBox.move(field_id + '_from', field_id + '_to'); SelectFilter.refresh_icons(field_id); }); - addEvent(remove_link, 'click', function() { SelectBox.move(field_id + '_to', field_id + '_from'); SelectFilter.refresh_icons(field_id); }); - addEvent(clear_all, 'click', function() { SelectBox.move_all(field_id + '_to', field_id + '_from'); SelectFilter.refresh_icons(field_id); }); - addEvent(filter_input, 'keypress', function(e) { SelectFilter.filter_key_press(e, field_id); }); - addEvent(filter_input, 'keyup', function(e) { SelectFilter.filter_key_up(e, field_id); }); - addEvent(filter_input, 'keydown', function(e) { SelectFilter.filter_key_down(e, field_id); }); - addEvent(from_box, 'change', function(e) { SelectFilter.refresh_icons(field_id) }); - addEvent(to_box, 'change', function(e) { SelectFilter.refresh_icons(field_id) }); - addEvent(from_box, 'dblclick', function() { SelectBox.move(field_id + '_from', field_id + '_to'); SelectFilter.refresh_icons(field_id); }); - addEvent(to_box, 'dblclick', function() { SelectBox.move(field_id + '_to', field_id + '_from'); SelectFilter.refresh_icons(field_id); }); - addEvent(findForm(from_box), 'submit', function() { SelectBox.select_all(field_id + '_to'); }); - SelectBox.init(field_id + '_from'); - SelectBox.init(field_id + '_to'); - // Move selected from_box options to to_box - SelectBox.move(field_id + '_from', field_id + '_to'); - - if (!is_stacked) { - // In horizontal mode, give the same height to the two boxes. - var j_from_box = $(from_box); - var j_to_box = $(to_box); - var resize_filters = function() { j_to_box.height($(filter_p).outerHeight() + j_from_box.outerHeight()); } - if (j_from_box.outerHeight() > 0) { - resize_filters(); // This fieldset is already open. Resize now. - } else { - // This fieldset is probably collapsed. Wait for its 'show' event. - j_to_box.closest('fieldset').one('show.fieldset', resize_filters); + window.SelectFilter = { + init: function(field_id, field_name, is_stacked) { + if (field_id.match(/__prefix__/)) { + // Don't initialize on empty forms. + return; + } + var from_box = document.getElementById(field_id); + from_box.id += '_from'; // change its ID + from_box.className = 'filtered'; + + var ps = from_box.parentNode.getElementsByTagName('p'); + for (var i=0; i, because it just gets in the way. + from_box.parentNode.removeChild(ps[i]); + } else if (ps[i].className.indexOf("help") !== -1) { + // Move help text up to the top so it isn't below the select + // boxes or wrapped off on the side to the right of the add + // button: + from_box.parentNode.insertBefore(ps[i], from_box.parentNode.firstChild); + } } - } - // Initial icon refresh - SelectFilter.refresh_icons(field_id); - }, - refresh_icons: function(field_id) { - var from = $('#' + field_id + '_from'); - var to = $('#' + field_id + '_to'); - var is_from_selected = from.find('option:selected').length > 0; - var is_to_selected = to.find('option:selected').length > 0; - // Active if at least one item is selected - $('#' + field_id + '_add_link').toggleClass('active', is_from_selected); - $('#' + field_id + '_remove_link').toggleClass('active', is_to_selected); - // Active if the corresponding box isn't empty - $('#' + field_id + '_add_all_link').toggleClass('active', from.find('option').length > 0); - $('#' + field_id + '_remove_all_link').toggleClass('active', to.find('option').length > 0); - }, - filter_key_press: function(event, field_id) { - var from = document.getElementById(field_id + '_from'); - // don't submit form if user pressed Enter - if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) { - from.selectedIndex = 0; - SelectBox.move(field_id + '_from', field_id + '_to'); - from.selectedIndex = 0; - event.preventDefault() - return false; - } - }, - filter_key_up: function(event, field_id) { - var from = document.getElementById(field_id + '_from'); - var temp = from.selectedIndex; - SelectBox.filter(field_id + '_from', document.getElementById(field_id + '_input').value); - from.selectedIndex = temp; - return true; - }, - filter_key_down: function(event, field_id) { - var from = document.getElementById(field_id + '_from'); - // right arrow -- move across - if ((event.which && event.which == 39) || (event.keyCode && event.keyCode == 39)) { - var old_index = from.selectedIndex; + //
    or
    + var selector_div = quickElement('div', from_box.parentNode); + selector_div.className = is_stacked ? 'selector stacked' : 'selector'; + + //
    + var selector_available = quickElement('div', selector_div); + selector_available.className = 'selector-available'; + var title_available = quickElement('h2', selector_available, interpolate(gettext('Available %s') + ' ', [field_name])); + quickElement( + 'span', title_available, '', + 'class', 'help help-tooltip help-icon', + 'title', interpolate( + gettext( + 'This is the list of available %s. You may choose some by ' + + 'selecting them in the box below and then clicking the ' + + '"Choose" arrow between the two boxes.' + ), + [field_name] + ) + ); + + var filter_p = quickElement('p', selector_available, '', 'id', field_id + '_filter'); + filter_p.className = 'selector-filter'; + + var search_filter_label = quickElement('label', filter_p, '', 'for', field_id + '_input'); + + quickElement( + 'span', search_filter_label, '', + 'class', 'help-tooltip search-label-icon', + 'title', interpolate(gettext("Type into this box to filter down the list of available %s."), [field_name]) + ); + + filter_p.appendChild(document.createTextNode(' ')); + + var filter_input = quickElement('input', filter_p, '', 'type', 'text', 'placeholder', gettext("Filter")); + filter_input.id = field_id + '_input'; + + selector_available.appendChild(from_box); + var choose_all = quickElement('a', selector_available, gettext('Choose all'), 'title', interpolate(gettext('Click to choose all %s at once.'), [field_name]), 'href', 'javascript:void(0);', 'id', field_id + '_add_all_link'); + choose_all.className = 'selector-chooseall'; + + //
      + var selector_chooser = quickElement('ul', selector_div); + selector_chooser.className = 'selector-chooser'; + var add_link = quickElement('a', quickElement('li', selector_chooser), gettext('Choose'), 'title', gettext('Choose'), 'href', 'javascript:void(0);', 'id', field_id + '_add_link'); + add_link.className = 'selector-add'; + var remove_link = quickElement('a', quickElement('li', selector_chooser), gettext('Remove'), 'title', gettext('Remove'), 'href', 'javascript:void(0);', 'id', field_id + '_remove_link'); + remove_link.className = 'selector-remove'; + + //
      + var selector_chosen = quickElement('div', selector_div); + selector_chosen.className = 'selector-chosen'; + var title_chosen = quickElement('h2', selector_chosen, interpolate(gettext('Chosen %s') + ' ', [field_name])); + quickElement( + 'span', title_chosen, '', + 'class', 'help help-tooltip help-icon', + 'title', interpolate( + gettext( + 'This is the list of chosen %s. You may remove some by ' + + 'selecting them in the box below and then clicking the ' + + '"Remove" arrow between the two boxes.' + ), + [field_name] + ) + ); + + var to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', 'multiple', 'size', from_box.size, 'name', from_box.getAttribute('name')); + to_box.className = 'filtered'; + var clear_all = quickElement('a', selector_chosen, gettext('Remove all'), 'title', interpolate(gettext('Click to remove all chosen %s at once.'), [field_name]), 'href', 'javascript:void(0);', 'id', field_id + '_remove_all_link'); + clear_all.className = 'selector-clearall'; + + from_box.setAttribute('name', from_box.getAttribute('name') + '_old'); + + // Set up the JavaScript event handlers for the select box filter interface + addEvent(choose_all, 'click', function() { SelectBox.move_all(field_id + '_from', field_id + '_to'); SelectFilter.refresh_icons(field_id); }); + addEvent(add_link, 'click', function() { SelectBox.move(field_id + '_from', field_id + '_to'); SelectFilter.refresh_icons(field_id); }); + addEvent(remove_link, 'click', function() { SelectBox.move(field_id + '_to', field_id + '_from'); SelectFilter.refresh_icons(field_id); }); + addEvent(clear_all, 'click', function() { SelectBox.move_all(field_id + '_to', field_id + '_from'); SelectFilter.refresh_icons(field_id); }); + addEvent(filter_input, 'keypress', function(e) { SelectFilter.filter_key_press(e, field_id); }); + addEvent(filter_input, 'keyup', function(e) { SelectFilter.filter_key_up(e, field_id); }); + addEvent(filter_input, 'keydown', function(e) { SelectFilter.filter_key_down(e, field_id); }); + addEvent(from_box, 'change', function(e) { SelectFilter.refresh_icons(field_id); }); + addEvent(to_box, 'change', function(e) { SelectFilter.refresh_icons(field_id); }); + addEvent(from_box, 'dblclick', function() { SelectBox.move(field_id + '_from', field_id + '_to'); SelectFilter.refresh_icons(field_id); }); + addEvent(to_box, 'dblclick', function() { SelectBox.move(field_id + '_to', field_id + '_from'); SelectFilter.refresh_icons(field_id); }); + addEvent(findForm(from_box), 'submit', function() { SelectBox.select_all(field_id + '_to'); }); + SelectBox.init(field_id + '_from'); + SelectBox.init(field_id + '_to'); + // Move selected from_box options to to_box SelectBox.move(field_id + '_from', field_id + '_to'); - from.selectedIndex = (old_index == from.length) ? from.length - 1 : old_index; - return false; - } - // down arrow -- wrap around - if ((event.which && event.which == 40) || (event.keyCode && event.keyCode == 40)) { - from.selectedIndex = (from.length == from.selectedIndex + 1) ? 0 : from.selectedIndex + 1; - } - // up arrow -- wrap around - if ((event.which && event.which == 38) || (event.keyCode && event.keyCode == 38)) { - from.selectedIndex = (from.selectedIndex == 0) ? from.length - 1 : from.selectedIndex - 1; + + if (!is_stacked) { + // In horizontal mode, give the same height to the two boxes. + var j_from_box = $(from_box); + var j_to_box = $(to_box); + var resize_filters = function() { j_to_box.height($(filter_p).outerHeight() + j_from_box.outerHeight()); }; + if (j_from_box.outerHeight() > 0) { + resize_filters(); // This fieldset is already open. Resize now. + } else { + // This fieldset is probably collapsed. Wait for its 'show' event. + j_to_box.closest('fieldset').one('show.fieldset', resize_filters); + } + } + + // Initial icon refresh + SelectFilter.refresh_icons(field_id); + }, + refresh_icons: function(field_id) { + var from = $('#' + field_id + '_from'); + var to = $('#' + field_id + '_to'); + var is_from_selected = from.find('option:selected').length > 0; + var is_to_selected = to.find('option:selected').length > 0; + // Active if at least one item is selected + $('#' + field_id + '_add_link').toggleClass('active', is_from_selected); + $('#' + field_id + '_remove_link').toggleClass('active', is_to_selected); + // Active if the corresponding box isn't empty + $('#' + field_id + '_add_all_link').toggleClass('active', from.find('option').length > 0); + $('#' + field_id + '_remove_all_link').toggleClass('active', to.find('option').length > 0); + }, + filter_key_press: function(event, field_id) { + var from = document.getElementById(field_id + '_from'); + // don't submit form if user pressed Enter + if ((event.which && event.which === 13) || (event.keyCode && event.keyCode === 13)) { + from.selectedIndex = 0; + SelectBox.move(field_id + '_from', field_id + '_to'); + from.selectedIndex = 0; + event.preventDefault(); + return false; + } + }, + filter_key_up: function(event, field_id) { + var from = document.getElementById(field_id + '_from'); + var temp = from.selectedIndex; + SelectBox.filter(field_id + '_from', document.getElementById(field_id + '_input').value); + from.selectedIndex = temp; + return true; + }, + filter_key_down: function(event, field_id) { + var from = document.getElementById(field_id + '_from'); + // right arrow -- move across + if ((event.which && event.which === 39) || (event.keyCode && event.keyCode === 39)) { + var old_index = from.selectedIndex; + SelectBox.move(field_id + '_from', field_id + '_to'); + from.selectedIndex = (old_index === from.length) ? from.length - 1 : old_index; + return false; + } + // down arrow -- wrap around + if ((event.which && event.which === 40) || (event.keyCode && event.keyCode === 40)) { + from.selectedIndex = (from.length === from.selectedIndex + 1) ? 0 : from.selectedIndex + 1; + } + // up arrow -- wrap around + if ((event.which && event.which === 38) || (event.keyCode && event.keyCode === 38)) { + from.selectedIndex = (from.selectedIndex === 0) ? from.length - 1 : from.selectedIndex - 1; + } + return true; } - return true; - } -} + }; })(django.jQuery); diff --git a/django/contrib/admin/static/admin/js/actions.js b/django/contrib/admin/static/admin/js/actions.js index 58f572f252a7..e899000ab393 100644 --- a/django/contrib/admin/static/admin/js/actions.js +++ b/django/contrib/admin/static/admin/js/actions.js @@ -1,144 +1,145 @@ +/*global _actions_icnt, gettext, interpolate, ngettext*/ (function($) { - var lastChecked; + var lastChecked; - $.fn.actions = function(opts) { - var options = $.extend({}, $.fn.actions.defaults, opts); - var actionCheckboxes = $(this); - var list_editable_changed = false; - var checker = function(checked) { - if (checked) { - showQuestion(); - } else { - reset(); - } - $(actionCheckboxes).prop("checked", checked) - .parent().parent().toggleClass(options.selectedClass, checked); - }, - updateCounter = function() { - var sel = $(actionCheckboxes).filter(":checked").length; - // _actions_icnt is defined in the generated HTML - // and contains the total amount of objects in the queryset - $(options.counterContainer).html(interpolate( - ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel), { - sel: sel, - cnt: _actions_icnt - }, true)); - $(options.allToggle).prop("checked", function() { - var value; - if (sel == actionCheckboxes.length) { - value = true; - showQuestion(); - } else { - value = false; - clearAcross(); - } - return value; - }); - }, - showQuestion = function() { - $(options.acrossClears).hide(); - $(options.acrossQuestions).show(); - $(options.allContainer).hide(); - }, - showClear = function() { - $(options.acrossClears).show(); - $(options.acrossQuestions).hide(); - $(options.actionContainer).toggleClass(options.selectedClass); - $(options.allContainer).show(); - $(options.counterContainer).hide(); - }, - reset = function() { - $(options.acrossClears).hide(); - $(options.acrossQuestions).hide(); - $(options.allContainer).hide(); - $(options.counterContainer).show(); - }, - clearAcross = function() { - reset(); - $(options.acrossInput).val(0); - $(options.actionContainer).removeClass(options.selectedClass); - }; - // Show counter by default - $(options.counterContainer).show(); - // Check state of checkboxes and reinit state if needed - $(this).filter(":checked").each(function(i) { - $(this).parent().parent().toggleClass(options.selectedClass); - updateCounter(); - if ($(options.acrossInput).val() == 1) { - showClear(); - } - }); - $(options.allToggle).show().click(function() { - checker($(this).prop("checked")); - updateCounter(); - }); - $("a", options.acrossQuestions).click(function(event) { - event.preventDefault(); - $(options.acrossInput).val(1); - showClear(); - }); - $("a", options.acrossClears).click(function(event) { - event.preventDefault(); - $(options.allToggle).prop("checked", false); - clearAcross(); - checker(0); - updateCounter(); - }); - lastChecked = null; - $(actionCheckboxes).click(function(event) { - if (!event) { event = window.event; } - var target = event.target ? event.target : event.srcElement; - if (lastChecked && $.data(lastChecked) != $.data(target) && event.shiftKey === true) { - var inrange = false; - $(lastChecked).prop("checked", target.checked) - .parent().parent().toggleClass(options.selectedClass, target.checked); - $(actionCheckboxes).each(function() { - if ($.data(this) == $.data(lastChecked) || $.data(this) == $.data(target)) { - inrange = (inrange) ? false : true; - } - if (inrange) { - $(this).prop("checked", target.checked) - .parent().parent().toggleClass(options.selectedClass, target.checked); - } - }); - } - $(target).parent().parent().toggleClass(options.selectedClass, target.checked); - lastChecked = target; - updateCounter(); - }); - $('form#changelist-form table#result_list tr').find('td:gt(0) :input').change(function() { - list_editable_changed = true; - }); - $('form#changelist-form button[name="index"]').click(function(event) { - if (list_editable_changed) { - return confirm(gettext("You have unsaved changes on individual editable fields. If you run an action, your unsaved changes will be lost.")); - } - }); - $('form#changelist-form input[name="_save"]').click(function(event) { - var action_changed = false; - $('select option:selected', options.actionContainer).each(function() { - if ($(this).val()) { - action_changed = true; - } - }); - if (action_changed) { - if (list_editable_changed) { - return confirm(gettext("You have selected an action, but you haven't saved your changes to individual fields yet. Please click OK to save. You'll need to re-run the action.")); - } else { - return confirm(gettext("You have selected an action, and you haven't made any changes on individual fields. You're probably looking for the Go button rather than the Save button.")); - } - } - }); - }; - /* Setup plugin defaults */ - $.fn.actions.defaults = { - actionContainer: "div.actions", - counterContainer: "span.action-counter", - allContainer: "div.actions span.all", - acrossInput: "div.actions input.select-across", - acrossQuestions: "div.actions span.question", - acrossClears: "div.actions span.clear", - allToggle: "#action-toggle", - selectedClass: "selected" - }; + $.fn.actions = function(opts) { + var options = $.extend({}, $.fn.actions.defaults, opts); + var actionCheckboxes = $(this); + var list_editable_changed = false; + var showQuestion = function() { + $(options.acrossClears).hide(); + $(options.acrossQuestions).show(); + $(options.allContainer).hide(); + }, + showClear = function() { + $(options.acrossClears).show(); + $(options.acrossQuestions).hide(); + $(options.actionContainer).toggleClass(options.selectedClass); + $(options.allContainer).show(); + $(options.counterContainer).hide(); + }, + reset = function() { + $(options.acrossClears).hide(); + $(options.acrossQuestions).hide(); + $(options.allContainer).hide(); + $(options.counterContainer).show(); + }, + clearAcross = function() { + reset(); + $(options.acrossInput).val(0); + $(options.actionContainer).removeClass(options.selectedClass); + }, + checker = function(checked) { + if (checked) { + showQuestion(); + } else { + reset(); + } + $(actionCheckboxes).prop("checked", checked) + .parent().parent().toggleClass(options.selectedClass, checked); + }, + updateCounter = function() { + var sel = $(actionCheckboxes).filter(":checked").length; + // _actions_icnt is defined in the generated HTML + // and contains the total amount of objects in the queryset + $(options.counterContainer).html(interpolate( + ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel), { + sel: sel, + cnt: _actions_icnt + }, true)); + $(options.allToggle).prop("checked", function() { + var value; + if (sel === actionCheckboxes.length) { + value = true; + showQuestion(); + } else { + value = false; + clearAcross(); + } + return value; + }); + }; + // Show counter by default + $(options.counterContainer).show(); + // Check state of checkboxes and reinit state if needed + $(this).filter(":checked").each(function(i) { + $(this).parent().parent().toggleClass(options.selectedClass); + updateCounter(); + if ($(options.acrossInput).val() === 1) { + showClear(); + } + }); + $(options.allToggle).show().click(function() { + checker($(this).prop("checked")); + updateCounter(); + }); + $("a", options.acrossQuestions).click(function(event) { + event.preventDefault(); + $(options.acrossInput).val(1); + showClear(); + }); + $("a", options.acrossClears).click(function(event) { + event.preventDefault(); + $(options.allToggle).prop("checked", false); + clearAcross(); + checker(0); + updateCounter(); + }); + lastChecked = null; + $(actionCheckboxes).click(function(event) { + if (!event) { event = window.event; } + var target = event.target ? event.target : event.srcElement; + if (lastChecked && $.data(lastChecked) !== $.data(target) && event.shiftKey === true) { + var inrange = false; + $(lastChecked).prop("checked", target.checked) + .parent().parent().toggleClass(options.selectedClass, target.checked); + $(actionCheckboxes).each(function() { + if ($.data(this) === $.data(lastChecked) || $.data(this) === $.data(target)) { + inrange = (inrange) ? false : true; + } + if (inrange) { + $(this).prop("checked", target.checked) + .parent().parent().toggleClass(options.selectedClass, target.checked); + } + }); + } + $(target).parent().parent().toggleClass(options.selectedClass, target.checked); + lastChecked = target; + updateCounter(); + }); + $('form#changelist-form table#result_list tr').find('td:gt(0) :input').change(function() { + list_editable_changed = true; + }); + $('form#changelist-form button[name="index"]').click(function(event) { + if (list_editable_changed) { + return confirm(gettext("You have unsaved changes on individual editable fields. If you run an action, your unsaved changes will be lost.")); + } + }); + $('form#changelist-form input[name="_save"]').click(function(event) { + var action_changed = false; + $('select option:selected', options.actionContainer).each(function() { + if ($(this).val()) { + action_changed = true; + } + }); + if (action_changed) { + if (list_editable_changed) { + return confirm(gettext("You have selected an action, but you haven't saved your changes to individual fields yet. Please click OK to save. You'll need to re-run the action.")); + } else { + return confirm(gettext("You have selected an action, and you haven't made any changes on individual fields. You're probably looking for the Go button rather than the Save button.")); + } + } + }); + }; + /* Setup plugin defaults */ + $.fn.actions.defaults = { + actionContainer: "div.actions", + counterContainer: "span.action-counter", + allContainer: "div.actions span.all", + acrossInput: "div.actions input.select-across", + acrossQuestions: "div.actions span.question", + acrossClears: "div.actions span.clear", + allToggle: "#action-toggle", + selectedClass: "selected" + }; })(django.jQuery); diff --git a/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js b/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js index 9b25b9df36e9..987ee9004f4e 100644 --- a/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js +++ b/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js @@ -1,3 +1,4 @@ +/*global addEvent, Calendar, cancelEventPropagation, findPosX, findPosY, getStyle, get_format, gettext, interpolate, ngettext, quickElement, removeEvent*/ // Inserts shortcut buttons after all of the following: // // @@ -17,20 +18,20 @@ var DateTimeShortcuts = { timezoneWarningClass: 'timezonewarning', // class of the warning for timezone mismatch timezoneOffset: 0, init: function() { - if (window.__admin_utc_offset__ != undefined) { + if (window.__admin_utc_offset__ !== undefined) { var serverOffset = window.__admin_utc_offset__; var localOffset = new Date().getTimezoneOffset() * -60; DateTimeShortcuts.timezoneOffset = localOffset - serverOffset; } var inputs = document.getElementsByTagName('input'); - for (i=0; i')) - .append($warning) + .append($warning); }, // Add clock widget to a given field addClock: function(inp) { @@ -150,7 +151,7 @@ var DateTimeShortcuts = { cancel_p.className = 'calendar-cancel'; quickElement('a', cancel_p, gettext('Cancel'), 'href', 'javascript:DateTimeShortcuts.dismissClock(' + num + ');'); django.jQuery(document).bind('keyup', function(event) { - if (event.which == 27) { + if (event.which === 27) { // ESC key closes popup DateTimeShortcuts.dismissClock(num); event.preventDefault(); @@ -158,12 +159,12 @@ var DateTimeShortcuts = { }); }, openClock: function(num) { - var clock_box = document.getElementById(DateTimeShortcuts.clockDivName+num) - var clock_link = document.getElementById(DateTimeShortcuts.clockLinkName+num) + var clock_box = document.getElementById(DateTimeShortcuts.clockDivName+num); + var clock_link = document.getElementById(DateTimeShortcuts.clockLinkName+num); // Recalculate the clockbox position // is it left-to-right or right-to-left layout ? - if (getStyle(document.body,'direction')!='rtl') { + if (getStyle(document.body,'direction')!=='rtl') { clock_box.style.left = findPosX(clock_link) + 17 + 'px'; } else { @@ -180,20 +181,20 @@ var DateTimeShortcuts = { addEvent(document, 'click', DateTimeShortcuts.dismissClockFunc[num]); }, dismissClock: function(num) { - document.getElementById(DateTimeShortcuts.clockDivName + num).style.display = 'none'; - removeEvent(document, 'click', DateTimeShortcuts.dismissClockFunc[num]); + document.getElementById(DateTimeShortcuts.clockDivName + num).style.display = 'none'; + removeEvent(document, 'click', DateTimeShortcuts.dismissClockFunc[num]); }, handleClockQuicklink: function(num, val) { - var d; - if (val == -1) { - d = DateTimeShortcuts.now(); - } - else { - d = new Date(1970, 1, 1, val, 0, 0, 0) - } - DateTimeShortcuts.clockInputs[num].value = d.strftime(get_format('TIME_INPUT_FORMATS')[0]); - DateTimeShortcuts.clockInputs[num].focus(); - DateTimeShortcuts.dismissClock(num); + var d; + if (val === -1) { + d = DateTimeShortcuts.now(); + } + else { + d = new Date(1970, 1, 1, val, 0, 0, 0); + } + DateTimeShortcuts.clockInputs[num].value = d.strftime(get_format('TIME_INPUT_FORMATS')[0]); + DateTimeShortcuts.clockInputs[num].focus(); + DateTimeShortcuts.dismissClock(num); }, // Add calendar widget to a given field. addCalendar: function(inp) { @@ -274,7 +275,7 @@ var DateTimeShortcuts = { cancel_p.className = 'calendar-cancel'; quickElement('a', cancel_p, gettext('Cancel'), 'href', 'javascript:DateTimeShortcuts.dismissCalendar(' + num + ');'); django.jQuery(document).bind('keyup', function(event) { - if (event.which == 27) { + if (event.which === 27) { // ESC key closes popup DateTimeShortcuts.dismissCalendar(num); event.preventDefault(); @@ -282,8 +283,8 @@ var DateTimeShortcuts = { }); }, openCalendar: function(num) { - var cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1+num) - var cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName+num) + var cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1+num); + var cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName+num); var inp = DateTimeShortcuts.calendarInputs[num]; // Determine if the current value in the input has a valid date. @@ -293,7 +294,7 @@ var DateTimeShortcuts = { var selected = inp.value.strptime(format); var year = selected.getFullYear(); var month = selected.getMonth() + 1; - var re = /\d{4}/ + var re = /\d{4}/; if (re.test(year.toString()) && month >= 1 && month <= 12) { DateTimeShortcuts.calendars[num].drawDate(month, year, selected); } @@ -301,7 +302,7 @@ var DateTimeShortcuts = { // Recalculate the clockbox position // is it left-to-right or right-to-left layout ? - if (getStyle(document.body,'direction')!='rtl') { + if (getStyle(document.body,'direction')!=='rtl') { cal_box.style.left = findPosX(cal_link) + 17 + 'px'; } else { @@ -345,12 +346,12 @@ var DateTimeShortcuts = { ").style.display='none';}"].join(''); }, handleCalendarQuickLink: function(num, offset) { - var d = DateTimeShortcuts.now(); - d.setDate(d.getDate() + offset) - DateTimeShortcuts.calendarInputs[num].value = d.strftime(get_format('DATE_INPUT_FORMATS')[0]); - DateTimeShortcuts.calendarInputs[num].focus(); - DateTimeShortcuts.dismissCalendar(num); + var d = DateTimeShortcuts.now(); + d.setDate(d.getDate() + offset); + DateTimeShortcuts.calendarInputs[num].value = d.strftime(get_format('DATE_INPUT_FORMATS')[0]); + DateTimeShortcuts.calendarInputs[num].focus(); + DateTimeShortcuts.dismissCalendar(num); } -} +}; addEvent(window, 'load', DateTimeShortcuts.init); diff --git a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js index 4a577c418755..e8b8dd789033 100644 --- a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js +++ b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js @@ -1,3 +1,4 @@ +/*global SelectBox, interpolate*/ // Handles related-objects functionality: lookup link for raw_id_fields // and Add Another links. @@ -32,7 +33,7 @@ function showAdminPopup(triggeringLink, name_regexp, add_popup) { name = id_to_windowname(name); var href = triggeringLink.href; if (add_popup) { - if (href.indexOf('?') == -1) { + if (href.indexOf('?') === -1) { href += '?_popup=1'; } else { href += '&_popup=1'; @@ -50,7 +51,7 @@ function showRelatedObjectLookupPopup(triggeringLink) { function dismissRelatedLookupPopup(win, chosenId) { var name = windowname_to_id(win.name); var elem = document.getElementById(name); - if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { + if (elem.className.indexOf('vManyToManyRawIdAdminField') !== -1 && elem.value) { elem.value += ',' + chosenId; } else { document.getElementById(name).value = chosenId; @@ -86,10 +87,10 @@ function dismissAddRelatedObjectPopup(win, newId, newRepr) { var elem = document.getElementById(name); if (elem) { var elemName = elem.nodeName.toUpperCase(); - if (elemName == 'SELECT') { + if (elemName === 'SELECT') { elem.options[elem.options.length] = new Option(newRepr, newId, true, true); - } else if (elemName == 'INPUT') { - if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { + } else if (elemName === 'INPUT') { + if (elem.className.indexOf('vManyToManyRawIdAdminField') !== -1 && elem.value) { elem.value += ',' + newId; } else { elem.value = newId; @@ -113,13 +114,13 @@ function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) { var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]); var selects = django.jQuery(selectsSelector); selects.find('option').each(function() { - if (this.value == objId) { + if (this.value === objId) { this.innerHTML = newRepr; this.value = newId; } }); win.close(); -}; +} function dismissDeleteRelatedObjectPopup(win, objId) { objId = html_unescape(objId); @@ -127,13 +128,13 @@ function dismissDeleteRelatedObjectPopup(win, objId) { var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]); var selects = django.jQuery(selectsSelector); selects.find('option').each(function() { - if (this.value == objId) { + if (this.value === objId) { django.jQuery(this).remove(); } }).trigger('change'); win.close(); -}; +} // Kept for backward compatibility -showAddAnotherPopup = showRelatedObjectPopup; -dismissAddAnotherPopup = dismissAddRelatedObjectPopup; +var showAddAnotherPopup = showRelatedObjectPopup; +var dismissAddAnotherPopup = dismissAddRelatedObjectPopup; diff --git a/django/contrib/admin/static/admin/js/calendar.js b/django/contrib/admin/static/admin/js/calendar.js index 458eece92fb8..deaac8ec20f4 100644 --- a/django/contrib/admin/static/admin/js/calendar.js +++ b/django/contrib/admin/static/admin/js/calendar.js @@ -1,3 +1,4 @@ +/*global gettext, get_format, quickElement, removeChildren*/ /* calendar.js - Calendar functions by Adrian Holovaty depends on core.js for utility functions like removeChildren or quickElement @@ -9,17 +10,17 @@ var CalendarNamespace = { daysOfWeek: gettext('S M T W T F S').split(' '), firstDayOfWeek: parseInt(get_format('FIRST_DAY_OF_WEEK')), isLeapYear: function(year) { - return (((year % 4)==0) && ((year % 100)!=0) || ((year % 400)==0)); + return (((year % 4)===0) && ((year % 100)!==0) || ((year % 400)===0)); }, getDaysInMonth: function(month,year) { var days; - if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12) { + if (month===1 || month===3 || month===5 || month===7 || month===8 || month===10 || month===12) { days = 31; } - else if (month==4 || month==6 || month==9 || month==11) { + else if (month===4 || month===6 || month===9 || month===11) { days = 30; } - else if (month==2 && CalendarNamespace.isLeapYear(year)) { + else if (month===2 && CalendarNamespace.isLeapYear(year)) { days = 29; } else { @@ -46,8 +47,8 @@ var CalendarNamespace = { // The day variable above will be 1 instead of 2 in, say, US Pacific time // zone. var isSelectedMonth = false; - if (typeof selected != 'undefined') { - isSelectedMonth = (selected.getUTCFullYear() == year && (selected.getUTCMonth()+1) == month); + if (typeof selected !== 'undefined') { + isSelectedMonth = (selected.getUTCFullYear() === year && (selected.getUTCMonth()+1) === month); } month = parseInt(month); @@ -67,28 +68,30 @@ var CalendarNamespace = { var startingPos = new Date(year, month-1, 1 - CalendarNamespace.firstDayOfWeek).getDay(); var days = CalendarNamespace.getDaysInMonth(month, year); + var _cell; + // Draw blanks before first of month tableRow = quickElement('tr', tableBody); - for (var i = 0; i < startingPos; i++) { - var _cell = quickElement('td', tableRow, ' '); + for (i = 0; i < startingPos; i++) { + _cell = quickElement('td', tableRow, ' '); _cell.className = "nonday"; } // Draw days of month var currentDay = 1; - for (var i = startingPos; currentDay <= days; i++) { - if (i%7 == 0 && currentDay != 1) { + for (i = startingPos; currentDay <= days; i++) { + if (i%7 === 0 && currentDay !== 1) { tableRow = quickElement('tr', tableBody); } - if ((currentDay==todayDay) && (month==todayMonth) && (year==todayYear)) { + if ((currentDay===todayDay) && (month===todayMonth) && (year===todayYear)) { todayClass='today'; } else { todayClass=''; } // use UTC function; see above for explanation. - if (isSelectedMonth && currentDay == selected.getUTCDate()) { - if (todayClass != '') todayClass += " "; + if (isSelectedMonth && currentDay === selected.getUTCDate()) { + if (todayClass !== '') todayClass += " "; todayClass += "selected"; } @@ -100,13 +103,13 @@ var CalendarNamespace = { // Draw blanks after end of month (optional, but makes for valid code) while (tableRow.childNodes.length < 7) { - var _cell = quickElement('td', tableRow, ' '); + _cell = quickElement('td', tableRow, ' '); _cell.className = "nonday"; } calDiv.appendChild(calTable); } -} +}; // Calendar -- A calendar instance function Calendar(div_id, callback, selected) { @@ -120,7 +123,7 @@ function Calendar(div_id, callback, selected) { this.today = new Date(); this.currentMonth = this.today.getMonth() + 1; this.currentYear = this.today.getFullYear(); - if (typeof selected != 'undefined') { + if (typeof selected !== 'undefined') { this.selected = selected; } } @@ -139,7 +142,7 @@ Calendar.prototype = { this.drawCurrent(); }, drawPreviousMonth: function() { - if (this.currentMonth == 1) { + if (this.currentMonth === 1) { this.currentMonth = 12; this.currentYear--; } @@ -149,7 +152,7 @@ Calendar.prototype = { this.drawCurrent(); }, drawNextMonth: function() { - if (this.currentMonth == 12) { + if (this.currentMonth === 12) { this.currentMonth = 1; this.currentYear++; } @@ -166,4 +169,4 @@ Calendar.prototype = { this.currentYear++; this.drawCurrent(); } -} +}; diff --git a/django/contrib/admin/static/admin/js/collapse.js b/django/contrib/admin/static/admin/js/collapse.js index 3b1f31bd23d7..b11fcd68f3fb 100644 --- a/django/contrib/admin/static/admin/js/collapse.js +++ b/django/contrib/admin/static/admin/js/collapse.js @@ -1,24 +1,25 @@ +/*global gettext*/ (function($) { - $(document).ready(function() { - // Add anchor tag for Show/Hide link - $("fieldset.collapse").each(function(i, elem) { - // Don't hide if fields in this fieldset have errors - if ($(elem).find("div.errors").length == 0) { - $(elem).addClass("collapsed").find("h2").first().append(' (' + gettext("Show") + - ')'); - } - }); - // Add toggle to anchor tag - $("fieldset.collapse a.collapse-toggle").click(function(ev) { - if ($(this).closest("fieldset").hasClass("collapsed")) { - // Show - $(this).text(gettext("Hide")).closest("fieldset").removeClass("collapsed").trigger("show.fieldset", [$(this).attr("id")]); - } else { - // Hide - $(this).text(gettext("Show")).closest("fieldset").addClass("collapsed").trigger("hide.fieldset", [$(this).attr("id")]); - } - return false; - }); - }); + $(document).ready(function() { + // Add anchor tag for Show/Hide link + $("fieldset.collapse").each(function(i, elem) { + // Don't hide if fields in this fieldset have errors + if ($(elem).find("div.errors").length === 0) { + $(elem).addClass("collapsed").find("h2").first().append(' (' + gettext("Show") + + ')'); + } + }); + // Add toggle to anchor tag + $("fieldset.collapse a.collapse-toggle").click(function(ev) { + if ($(this).closest("fieldset").hasClass("collapsed")) { + // Show + $(this).text(gettext("Hide")).closest("fieldset").removeClass("collapsed").trigger("show.fieldset", [$(this).attr("id")]); + } else { + // Hide + $(this).text(gettext("Show")).closest("fieldset").addClass("collapsed").trigger("hide.fieldset", [$(this).attr("id")]); + } + return false; + }); + }); })(django.jQuery); diff --git a/django/contrib/admin/static/admin/js/collapse.min.js b/django/contrib/admin/static/admin/js/collapse.min.js index 0a8c20ea4482..6251d916668f 100644 --- a/django/contrib/admin/static/admin/js/collapse.min.js +++ b/django/contrib/admin/static/admin/js/collapse.min.js @@ -1,2 +1,2 @@ -(function(a){a(document).ready(function(){a("fieldset.collapse").each(function(c,b){a(b).find("div.errors").length==0&&a(b).addClass("collapsed").find("h2").first().append(' ('+gettext("Show")+")")});a("fieldset.collapse a.collapse-toggle").click(function(){a(this).closest("fieldset").hasClass("collapsed")?a(this).text(gettext("Hide")).closest("fieldset").removeClass("collapsed").trigger("show.fieldset",[a(this).attr("id")]):a(this).text(gettext("Show")).closest("fieldset").addClass("collapsed").trigger("hide.fieldset", -[a(this).attr("id")]);return false})})})(django.jQuery); +(function(a){a(document).ready(function(){a("fieldset.collapse").each(function(b,c){0===a(c).find("div.errors").length&&a(c).addClass("collapsed").find("h2").first().append(' ('+gettext("Show")+")")});a("fieldset.collapse a.collapse-toggle").click(function(b){a(this).closest("fieldset").hasClass("collapsed")?a(this).text(gettext("Hide")).closest("fieldset").removeClass("collapsed").trigger("show.fieldset",[a(this).attr("id")]):a(this).text(gettext("Show")).closest("fieldset").addClass("collapsed").trigger("hide.fieldset", +[a(this).attr("id")]);return!1})})})(django.jQuery); diff --git a/django/contrib/admin/static/admin/js/core.js b/django/contrib/admin/static/admin/js/core.js index 2c096aac6dbd..7702c66194c1 100644 --- a/django/contrib/admin/static/admin/js/core.js +++ b/django/contrib/admin/static/admin/js/core.js @@ -74,8 +74,8 @@ var xmlhttp; @else xmlhttp = false; @end @*/ -if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { - xmlhttp = new XMLHttpRequest(); +if (!xmlhttp && typeof XMLHttpRequest !== 'undefined') { + xmlhttp = new XMLHttpRequest(); } // ---------------------------------------------------------------------------- @@ -90,7 +90,7 @@ function findPosX(obj) { obj = obj.offsetParent; } // IE offsetParent does not include the top-level - if (isIE && obj.parentElement){ + if (isIE && obj.parentElement) { curleft += obj.offsetLeft - obj.scrollLeft; } } else if (obj.x) { @@ -107,7 +107,7 @@ function findPosY(obj) { obj = obj.offsetParent; } // IE offsetParent does not include the top-level - if (isIE && obj.parentElement){ + if (isIE && obj.parentElement) { curtop += obj.offsetTop - obj.scrollTop; } } else if (obj.y) { @@ -121,46 +121,46 @@ function findPosY(obj) { // ---------------------------------------------------------------------------- Date.prototype.getTwelveHours = function() { - hours = this.getHours(); - if (hours == 0) { + var hours = this.getHours(); + if (hours === 0) { return 12; } else { - return hours <= 12 ? hours : hours-12 + return hours <= 12 ? hours : hours-12; } -} +}; Date.prototype.getTwoDigitMonth = function() { return (this.getMonth() < 9) ? '0' + (this.getMonth()+1) : (this.getMonth()+1); -} +}; Date.prototype.getTwoDigitDate = function() { return (this.getDate() < 10) ? '0' + this.getDate() : this.getDate(); -} +}; Date.prototype.getTwoDigitTwelveHour = function() { return (this.getTwelveHours() < 10) ? '0' + this.getTwelveHours() : this.getTwelveHours(); -} +}; Date.prototype.getTwoDigitHour = function() { return (this.getHours() < 10) ? '0' + this.getHours() : this.getHours(); -} +}; Date.prototype.getTwoDigitMinute = function() { return (this.getMinutes() < 10) ? '0' + this.getMinutes() : this.getMinutes(); -} +}; Date.prototype.getTwoDigitSecond = function() { return (this.getSeconds() < 10) ? '0' + this.getSeconds() : this.getSeconds(); -} +}; Date.prototype.getHourMinute = function() { return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute(); -} +}; Date.prototype.getHourMinuteSecond = function() { return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute() + ':' + this.getTwoDigitSecond(); -} +}; Date.prototype.strftime = function(format) { var fields = { @@ -191,7 +191,7 @@ Date.prototype.strftime = function(format) { ++i; } return result; -} +}; // ---------------------------------------------------------------------------- // String object extensions @@ -202,42 +202,43 @@ String.prototype.pad_left = function(pad_length, pad_string) { new_string = pad_string + new_string; } return new_string; -} +}; String.prototype.strptime = function(format) { var split_format = format.split(/[.\-/]/); var date = this.split(/[.\-/]/); var i = 0; + var day, month, year; while (i < split_format.length) { switch (split_format[i]) { case "%d": - var day = date[i]; + day = date[i]; break; case "%m": - var month = date[i] - 1; + month = date[i] - 1; break; case "%Y": - var year = date[i]; + year = date[i]; break; case "%y": - var year = date[i]; + year = date[i]; break; } ++i; - }; + } return new Date(year, month, day); -} +}; // ---------------------------------------------------------------------------- // Get the computed style for and element // ---------------------------------------------------------------------------- -function getStyle(oElm, strCssRule){ +function getStyle(oElm, strCssRule) { var strValue = ""; - if(document.defaultView && document.defaultView.getComputedStyle){ + if(document.defaultView && document.defaultView.getComputedStyle) { strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule); } - else if(oElm.currentStyle){ - strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ + else if(oElm.currentStyle) { + strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1) { return p1.toUpperCase(); }); strValue = oElm.currentStyle[strCssRule]; diff --git a/django/contrib/admin/static/admin/js/inlines.js b/django/contrib/admin/static/admin/js/inlines.js index 6f127365e668..e977fc9fa59d 100644 --- a/django/contrib/admin/static/admin/js/inlines.js +++ b/django/contrib/admin/static/admin/js/inlines.js @@ -1,3 +1,4 @@ +/*global DateTimeShortcuts, SelectFilter*/ /** * Django admin inlines * @@ -15,258 +16,260 @@ * See: http://www.opensource.org/licenses/bsd-license.php */ (function($) { - $.fn.formset = function(opts) { - var options = $.extend({}, $.fn.formset.defaults, opts); - var $this = $(this); - var $parent = $this.parent(); - var updateElementIndex = function(el, prefix, ndx) { - var id_regex = new RegExp("(" + prefix + "-(\\d+|__prefix__))"); - var replacement = prefix + "-" + ndx; - if ($(el).prop("for")) { - $(el).prop("for", $(el).prop("for").replace(id_regex, replacement)); - } - if (el.id) { - el.id = el.id.replace(id_regex, replacement); - } - if (el.name) { - el.name = el.name.replace(id_regex, replacement); - } - }; - var totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS").prop("autocomplete", "off"); - var nextIndex = parseInt(totalForms.val(), 10); - var maxForms = $("#id_" + options.prefix + "-MAX_NUM_FORMS").prop("autocomplete", "off"); - // only show the add button if we are allowed to add more items, + $.fn.formset = function(opts) { + var options = $.extend({}, $.fn.formset.defaults, opts); + var $this = $(this); + var $parent = $this.parent(); + var updateElementIndex = function(el, prefix, ndx) { + var id_regex = new RegExp("(" + prefix + "-(\\d+|__prefix__))"); + var replacement = prefix + "-" + ndx; + if ($(el).prop("for")) { + $(el).prop("for", $(el).prop("for").replace(id_regex, replacement)); + } + if (el.id) { + el.id = el.id.replace(id_regex, replacement); + } + if (el.name) { + el.name = el.name.replace(id_regex, replacement); + } + }; + var totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS").prop("autocomplete", "off"); + var nextIndex = parseInt(totalForms.val(), 10); + var maxForms = $("#id_" + options.prefix + "-MAX_NUM_FORMS").prop("autocomplete", "off"); + // only show the add button if we are allowed to add more items, // note that max_num = None translates to a blank string. - var showAddButton = maxForms.val() === '' || (maxForms.val()-totalForms.val()) > 0; - $this.each(function(i) { - $(this).not("." + options.emptyCssClass).addClass(options.formCssClass); - }); - if ($this.length && showAddButton) { - var addButton; - if ($this.prop("tagName") == "TR") { - // If forms are laid out as table rows, insert the - // "add" button in a new table row: - var numCols = this.eq(-1).children().length; - $parent.append('' + options.addText + ""); - addButton = $parent.find("tr:last a"); - } else { - // Otherwise, insert it immediately after the last form: - $this.filter(":last").after('"); - addButton = $this.filter(":last").next().find("a"); - } - addButton.click(function(e) { - e.preventDefault(); - var totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS"); - var template = $("#" + options.prefix + "-empty"); - var row = template.clone(true); - row.removeClass(options.emptyCssClass) - .addClass(options.formCssClass) - .attr("id", options.prefix + "-" + nextIndex); - if (row.is("tr")) { - // If the forms are laid out in table rows, insert - // the remove button into the last table cell: - row.children(":last").append('"); - } else if (row.is("ul") || row.is("ol")) { - // If they're laid out as an ordered/unordered list, - // insert an
    • after the last list item: - row.append('
    • ' + options.deleteText + "
    • "); - } else { - // Otherwise, just insert the remove button as the - // last child element of the form's container: - row.children(":first").append('' + options.deleteText + ""); - } - row.find("*").each(function() { - updateElementIndex(this, options.prefix, totalForms.val()); + var showAddButton = maxForms.val() === '' || (maxForms.val()-totalForms.val()) > 0; + $this.each(function(i) { + $(this).not("." + options.emptyCssClass).addClass(options.formCssClass); }); - // Insert the new form when it has been fully edited - row.insertBefore($(template)); - // Update number of total forms - $(totalForms).val(parseInt(totalForms.val(), 10) + 1); - nextIndex += 1; - // Hide add button in case we've hit the max, except we want to add infinitely - if ((maxForms.val() !== '') && (maxForms.val()-totalForms.val()) <= 0) { - addButton.parent().hide(); - } - // The delete button of each row triggers a bunch of other things - row.find("a." + options.deleteCssClass).click(function(e) { - e.preventDefault(); - // Remove the parent form containing this button: - var row = $(this).parents("." + options.formCssClass); - row.remove(); - nextIndex -= 1; - // If a post-delete callback was provided, call it with the deleted form: - if (options.removed) { - options.removed(row); - } - // Update the TOTAL_FORMS form count. - var forms = $("." + options.formCssClass); - $("#id_" + options.prefix + "-TOTAL_FORMS").val(forms.length); - // Show add button again once we drop below max - if ((maxForms.val() === '') || (maxForms.val()-forms.length) > 0) { - addButton.parent().show(); - } - // Also, update names and ids for all remaining form controls - // so they remain in sequence: - for (var i=0, formCount=forms.length; i' + options.addText + ""); + addButton = $parent.find("tr:last a"); + } else { + // Otherwise, insert it immediately after the last form: + $this.filter(":last").after('"); + addButton = $this.filter(":last").next().find("a"); + } + addButton.click(function(e) { + e.preventDefault(); + var totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS"); + var template = $("#" + options.prefix + "-empty"); + var row = template.clone(true); + row.removeClass(options.emptyCssClass) + .addClass(options.formCssClass) + .attr("id", options.prefix + "-" + nextIndex); + if (row.is("tr")) { + // If the forms are laid out in table rows, insert + // the remove button into the last table cell: + row.children(":last").append('"); + } else if (row.is("ul") || row.is("ol")) { + // If they're laid out as an ordered/unordered list, + // insert an
    • after the last list item: + row.append('
    • ' + options.deleteText + "
    • "); + } else { + // Otherwise, just insert the remove button as the + // last child element of the form's container: + row.children(":first").append('' + options.deleteText + ""); + } + row.find("*").each(function() { + updateElementIndex(this, options.prefix, totalForms.val()); + }); + // Insert the new form when it has been fully edited + row.insertBefore($(template)); + // Update number of total forms + $(totalForms).val(parseInt(totalForms.val(), 10) + 1); + nextIndex += 1; + // Hide add button in case we've hit the max, except we want to add infinitely + if ((maxForms.val() !== '') && (maxForms.val()-totalForms.val()) <= 0) { + addButton.parent().hide(); + } + // The delete button of each row triggers a bunch of other things + row.find("a." + options.deleteCssClass).click(function(e) { + e.preventDefault(); + // Remove the parent form containing this button: + var row = $(this).parents("." + options.formCssClass); + row.remove(); + nextIndex -= 1; + // If a post-delete callback was provided, call it with the deleted form: + if (options.removed) { + options.removed(row); + } + // Update the TOTAL_FORMS form count. + var forms = $("." + options.formCssClass); + $("#id_" + options.prefix + "-TOTAL_FORMS").val(forms.length); + // Show add button again once we drop below max + if ((maxForms.val() === '') || (maxForms.val()-forms.length) > 0) { + addButton.parent().show(); + } + // Also, update names and ids for all remaining form controls + // so they remain in sequence: + var i, formCount; + var updateElementCallback = function() { + updateElementIndex(this, options.prefix, i); + }; + for (i=0, formCount=forms.length; i'+a.addText+""),h=b.find("tr:last a")):(d.filter(":last").after('"),h=d.filter(":last").next().find("a"));h.click(function(b){b.preventDefault();var d=c("#id_"+a.prefix+ -"-TOTAL_FORMS");b=c("#"+a.prefix+"-empty");var g=b.clone(!0);g.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+l);g.is("tr")?g.children(":last").append('"):g.is("ul")||g.is("ol")?g.append('
    • '+a.deleteText+"
    • "):g.children(":first").append(''+a.deleteText+ -"");g.find("*").each(function(){k(this,a.prefix,d.val())});g.insertBefore(c(b));c(d).val(parseInt(d.val(),10)+1);l+=1;""!==f.val()&&0>=f.val()-d.val()&&h.parent().hide();g.find("a."+a.deleteCssClass).click(function(b){b.preventDefault();b=c(this).parents("."+a.formCssClass);b.remove();--l;a.removed&&a.removed(b);b=c("."+a.formCssClass);c("#id_"+a.prefix+"-TOTAL_FORMS").val(b.length);(""===f.val()||0'+a.addText+""),h=b.find("tr:last a")):(d.filter(":last").after('"),h=d.filter(":last").next().find("a"));h.click(function(b){b.preventDefault();var d=c("#id_"+a.prefix+ +"-TOTAL_FORMS");b=c("#"+a.prefix+"-empty");var e=b.clone(!0);e.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+l);e.is("tr")?e.children(":last").append('"):e.is("ul")||e.is("ol")?e.append('
    • '+a.deleteText+"
    • "):e.children(":first").append(''+a.deleteText+ +"");e.find("*").each(function(){k(this,a.prefix,d.val())});e.insertBefore(c(b));c(d).val(parseInt(d.val(),10)+1);l+=1;""!==g.val()&&0>=g.val()-d.val()&&h.parent().hide();e.find("a."+a.deleteCssClass).click(function(b){b.preventDefault();b=c(this).parents("."+a.formCssClass);b.remove();--l;a.removed&&a.removed(b);b=c("."+a.formCssClass);c("#id_"+a.prefix+"-TOTAL_FORMS").val(b.length);(""===g.val()||00&&f.push(c.val())});a.val(URLify(f.join(" "),g))}};a.data("_changed",false);a.change(function(){a.data("_changed",true)});a.val()||b(e.join(",")).keyup(d).change(d).focus(d)})}})(django.jQuery); +(function(c){c.fn.prepopulate=function(e,f){return this.each(function(){var a=c(this),b=function(){if(!a.data("_changed")){var b=[];c.each(e,function(a,d){d=c(d);0 1) { - old_feats = [this.layers.vector.features[0]]; + var old_feats = [this.layers.vector.features[0]]; this.layers.vector.removeFeatures(old_feats); this.layers.vector.destroyFeatures(old_feats); } @@ -306,7 +308,7 @@ MapWidget.prototype.add_wkt = function(event) { MapWidget.prototype.modify_wkt = function(event) { if (this.options.is_collection) { - if (this.options.geom_name == 'MultiPoint') { + if (this.options.geom_name === 'MultiPoint') { this.add_wkt(event); return; } else { @@ -359,13 +361,13 @@ MapWidget.prototype.getControls = function(layer) { this.controls = [new OpenLayers.Control.Navigation()]; if (!this.options.modifiable && layer.features.length) return; - if (this.options.geom_name.indexOf('LineString') >= 0 || this.options.geom_name == 'GeometryCollection' || this.options.geom_name == 'Unknown') { + if (this.options.geom_name.indexOf('LineString') >= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') { this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'})); } - if (this.options.geom_name.indexOf('Polygon') >= 0 || this.options.geom_name == 'GeometryCollection' || this.options.geom_name == 'Unknown') { + if (this.options.geom_name.indexOf('Polygon') >= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') { this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'})); } - if (this.options.geom_name.indexOf('Point') >= 0 || this.options.geom_name == 'GeometryCollection' || this.options.geom_name == 'Unknown') { + if (this.options.geom_name.indexOf('Point') >= 0 || this.options.geom_name === 'GeometryCollection' || this.options.geom_name === 'Unknown') { this.controls.push(new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'})); } if (this.options.modifiable) { diff --git a/django/contrib/gis/templates/gis/admin/openlayers.js b/django/contrib/gis/templates/gis/admin/openlayers.js index 4425fee27e64..dd00bfd70a75 100644 --- a/django/contrib/gis/templates/gis/admin/openlayers.js +++ b/django/contrib/gis/templates/gis/admin/openlayers.js @@ -12,98 +12,98 @@ OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp {{ module }}.is_point = {{ is_point|yesno:"true,false" }}; {% endblock %} {{ module }}.get_ewkt = function(feat){ - return 'SRID={{ srid|unlocalize }};' + {{ module }}.wkt_f.write(feat); + return 'SRID={{ srid|unlocalize }};' + {{ module }}.wkt_f.write(feat); }; {{ module }}.read_wkt = function(wkt){ - // OpenLayers cannot handle EWKT -- we make sure to strip it out. - // EWKT is only exposed to OL if there's a validation error in the admin. - var match = {{ module }}.re.exec(wkt); - if (match){wkt = match[1];} - return {{ module }}.wkt_f.read(wkt); + // OpenLayers cannot handle EWKT -- we make sure to strip it out. + // EWKT is only exposed to OL if there's a validation error in the admin. + var match = {{ module }}.re.exec(wkt); + if (match){wkt = match[1];} + return {{ module }}.wkt_f.read(wkt); }; {{ module }}.write_wkt = function(feat){ - if ({{ module }}.is_collection){ {{ module }}.num_geom = feat.geometry.components.length;} - else { {{ module }}.num_geom = 1;} - document.getElementById('{{ id }}').value = {{ module }}.get_ewkt(feat); + if ({{ module }}.is_collection){ {{ module }}.num_geom = feat.geometry.components.length;} + else { {{ module }}.num_geom = 1;} + document.getElementById('{{ id }}').value = {{ module }}.get_ewkt(feat); }; {{ module }}.add_wkt = function(event){ - // This function will sync the contents of the `vector` layer with the - // WKT in the text field. - if ({{ module }}.is_collection){ - var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); - for (var i = 0; i < {{ module }}.layers.vector.features.length; i++){ - feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]); - } - {{ module }}.write_wkt(feat); - } else { - // Make sure to remove any previously added features. - if ({{ module }}.layers.vector.features.length > 1){ - old_feats = [{{ module }}.layers.vector.features[0]]; - {{ module }}.layers.vector.removeFeatures(old_feats); - {{ module }}.layers.vector.destroyFeatures(old_feats); + // This function will sync the contents of the `vector` layer with the + // WKT in the text field. + if ({{ module }}.is_collection){ + var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); + for (var i = 0; i < {{ module }}.layers.vector.features.length; i++){ + feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]); + } + {{ module }}.write_wkt(feat); + } else { + // Make sure to remove any previously added features. + if ({{ module }}.layers.vector.features.length > 1){ + old_feats = [{{ module }}.layers.vector.features[0]]; + {{ module }}.layers.vector.removeFeatures(old_feats); + {{ module }}.layers.vector.destroyFeatures(old_feats); + } + {{ module }}.write_wkt(event.feature); } - {{ module }}.write_wkt(event.feature); - } }; {{ module }}.modify_wkt = function(event){ - if ({{ module }}.is_collection){ - if ({{ module }}.is_point){ - {{ module }}.add_wkt(event); - return; + if ({{ module }}.is_collection){ + if ({{ module }}.is_point){ + {{ module }}.add_wkt(event); + return; + } else { + // When modifying the selected components are added to the + // vector layer so we only increment to the `num_geom` value. + var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); + for (var i = 0; i < {{ module }}.num_geom; i++){ + feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]); + } + {{ module }}.write_wkt(feat); + } } else { - // When modifying the selected components are added to the - // vector layer so we only increment to the `num_geom` value. - var feat = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.{{ geom_type }}()); - for (var i = 0; i < {{ module }}.num_geom; i++){ - feat.geometry.addComponents([{{ module }}.layers.vector.features[i].geometry]); - } - {{ module }}.write_wkt(feat); + {{ module }}.write_wkt(event.feature); } - } else { - {{ module }}.write_wkt(event.feature); - } }; // Function to clear vector features and purge wkt from div {{ module }}.deleteFeatures = function(){ - {{ module }}.layers.vector.removeFeatures({{ module }}.layers.vector.features); - {{ module }}.layers.vector.destroyFeatures(); + {{ module }}.layers.vector.removeFeatures({{ module }}.layers.vector.features); + {{ module }}.layers.vector.destroyFeatures(); }; {{ module }}.clearFeatures = function (){ - {{ module }}.deleteFeatures(); - document.getElementById('{{ id }}').value = ''; - {% localize off %} - {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }}); - {% endlocalize %} + {{ module }}.deleteFeatures(); + document.getElementById('{{ id }}').value = ''; + {% localize off %} + {{ module }}.map.setCenter(new OpenLayers.LonLat({{ default_lon }}, {{ default_lat }}), {{ default_zoom }}); + {% endlocalize %} }; // Add Select control {{ module }}.addSelectControl = function(){ - var select = new OpenLayers.Control.SelectFeature({{ module }}.layers.vector, {'toggle' : true, 'clickout' : true}); - {{ module }}.map.addControl(select); - select.activate(); + var select = new OpenLayers.Control.SelectFeature({{ module }}.layers.vector, {'toggle' : true, 'clickout' : true}); + {{ module }}.map.addControl(select); + select.activate(); }; {{ module }}.enableDrawing = function(){ - {{ module }}.map.getControlsByClass('OpenLayers.Control.DrawFeature')[0].activate(); + {{ module }}.map.getControlsByClass('OpenLayers.Control.DrawFeature')[0].activate(); }; {{ module }}.enableEditing = function(){ - {{ module }}.map.getControlsByClass('OpenLayers.Control.ModifyFeature')[0].activate(); + {{ module }}.map.getControlsByClass('OpenLayers.Control.ModifyFeature')[0].activate(); }; // Create an array of controls based on geometry type {{ module }}.getControls = function(lyr){ - {{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'}); - {{ module }}.controls = [new OpenLayers.Control.Navigation()]; - if (!{{ module }}.modifiable && lyr.features.length) return; - if ({{ module }}.is_linestring || {{ module }}.is_generic){ - {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'})); - } - if ({{ module }}.is_polygon || {{ module }}.is_generic){ - {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'})); - } - if ({{ module }}.is_point || {{ module }}.is_generic){ - {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'})); - } - if ({{ module }}.modifiable){ - {{ module }}.controls.push(new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'})); - } + {{ module }}.panel = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'}); + {{ module }}.controls = [new OpenLayers.Control.Navigation()]; + if (!{{ module }}.modifiable && lyr.features.length) return; + if ({{ module }}.is_linestring || {{ module }}.is_generic){ + {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Path, {'displayClass': 'olControlDrawFeaturePath'})); + } + if ({{ module }}.is_polygon || {{ module }}.is_generic){ + {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Polygon, {'displayClass': 'olControlDrawFeaturePolygon'})); + } + if ({{ module }}.is_point || {{ module }}.is_generic){ + {{ module }}.controls.push(new OpenLayers.Control.DrawFeature(lyr, OpenLayers.Handler.Point, {'displayClass': 'olControlDrawFeaturePoint'})); + } + if ({{ module }}.modifiable){ + {{ module }}.controls.push(new OpenLayers.Control.ModifyFeature(lyr, {'displayClass': 'olControlModifyFeature'})); + } }; {{ module }}.init = function(){ {% block map_options %}// The options hash, w/ zoom, resolution, and projection settings. @@ -124,28 +124,28 @@ OpenLayers.Projection.addTransform("EPSG:4326", "EPSG:3857", OpenLayers.Layer.Sp // Read WKT from the text field. var wkt = document.getElementById('{{ id }}').value; if (wkt){ - // After reading into geometry, immediately write back to - // WKT