Fixed #31493 -- Replaced var with const and let keywords in JavaScript.
The eslint configuration and the admin script compress.py have been updated for ES6. The unused fallback of globals.django in jquery.init.js was removed. It is always included before jsi18n-mocks.test.js and it always sets the global value.
This commit is contained in:
parent
0dafadadb9
commit
5d37cc703b
@ -16,8 +16,10 @@
|
|||||||
"no-unused-vars": ["error", {"vars": "local", "args": "none"}],
|
"no-unused-vars": ["error", {"vars": "local", "args": "none"}],
|
||||||
"no-script-url": ["error"],
|
"no-script-url": ["error"],
|
||||||
"no-shadow": ["error", {"hoist": "functions"}],
|
"no-shadow": ["error", {"hoist": "functions"}],
|
||||||
|
"no-var": ["error"],
|
||||||
"quotes": ["off", "single"],
|
"quotes": ["off", "single"],
|
||||||
"linebreak-style": ["error", "unix"],
|
"linebreak-style": ["error", "unix"],
|
||||||
|
"prefer-const": ["error"],
|
||||||
"semi": ["error", "always"],
|
"semi": ["error", "always"],
|
||||||
"space-before-blocks": ["error", "always"],
|
"space-before-blocks": ["error", "always"],
|
||||||
"space-before-function-paren": ["error", {"anonymous": "never", "named": "never"}],
|
"space-before-function-paren": ["error", {"anonymous": "never", "named": "never"}],
|
||||||
@ -25,7 +27,8 @@
|
|||||||
"strict": ["warn", "function"]
|
"strict": ["warn", "function"]
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true
|
"browser": true,
|
||||||
|
"es6": true
|
||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
"django": false
|
"django": false
|
||||||
|
@ -36,6 +36,7 @@ and Java version 7 or later."""
|
|||||||
cmd.append('-q')
|
cmd.append('-q')
|
||||||
cmd.extend([
|
cmd.extend([
|
||||||
'google-closure-compiler',
|
'google-closure-compiler',
|
||||||
|
'--language_out=ECMASCRIPT_2015',
|
||||||
'--rewrite_polyfills=false',
|
'--rewrite_polyfills=false',
|
||||||
'--js', str(to_compress),
|
'--js', str(to_compress),
|
||||||
'--js_output_file', str(to_compress_min),
|
'--js_output_file', str(to_compress_min),
|
||||||
|
@ -1,29 +1,27 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var SelectBox = {
|
const SelectBox = {
|
||||||
cache: {},
|
cache: {},
|
||||||
init: function(id) {
|
init: function(id) {
|
||||||
var box = document.getElementById(id);
|
const box = document.getElementById(id);
|
||||||
var node;
|
|
||||||
SelectBox.cache[id] = [];
|
SelectBox.cache[id] = [];
|
||||||
var cache = SelectBox.cache[id];
|
const cache = SelectBox.cache[id];
|
||||||
var boxOptions = box.options;
|
const boxOptions = box.options;
|
||||||
var boxOptionsLength = boxOptions.length;
|
const boxOptionsLength = boxOptions.length;
|
||||||
for (var i = 0, j = boxOptionsLength; i < j; i++) {
|
for (let i = 0, j = boxOptionsLength; i < j; i++) {
|
||||||
node = boxOptions[i];
|
const node = boxOptions[i];
|
||||||
cache.push({value: node.value, text: node.text, displayed: 1});
|
cache.push({value: node.value, text: node.text, displayed: 1});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
redisplay: function(id) {
|
redisplay: function(id) {
|
||||||
// Repopulate HTML select box from cache
|
// Repopulate HTML select box from cache
|
||||||
var box = document.getElementById(id);
|
const box = document.getElementById(id);
|
||||||
var node;
|
|
||||||
box.innerHTML = '';
|
box.innerHTML = '';
|
||||||
var cache = SelectBox.cache[id];
|
const cache = SelectBox.cache[id];
|
||||||
for (var i = 0, j = cache.length; i < j; i++) {
|
for (let i = 0, j = cache.length; i < j; i++) {
|
||||||
node = cache[i];
|
const node = cache[i];
|
||||||
if (node.displayed) {
|
if (node.displayed) {
|
||||||
var new_option = new Option(node.text, node.value, false, false);
|
const new_option = new Option(node.text, node.value, false, false);
|
||||||
// Shows a tooltip when hovering over the option
|
// Shows a tooltip when hovering over the option
|
||||||
new_option.title = node.text;
|
new_option.title = node.text;
|
||||||
box.appendChild(new_option);
|
box.appendChild(new_option);
|
||||||
@ -33,16 +31,15 @@
|
|||||||
filter: function(id, text) {
|
filter: function(id, text) {
|
||||||
// Redisplay the HTML select box, displaying only the choices containing ALL
|
// Redisplay the HTML select box, displaying only the choices containing ALL
|
||||||
// the words in text. (It's an AND search.)
|
// the words in text. (It's an AND search.)
|
||||||
var tokens = text.toLowerCase().split(/\s+/);
|
const tokens = text.toLowerCase().split(/\s+/);
|
||||||
var node, token;
|
const cache = SelectBox.cache[id];
|
||||||
var cache = SelectBox.cache[id];
|
for (let i = 0, j = cache.length; i < j; i++) {
|
||||||
for (var i = 0, j = cache.length; i < j; i++) {
|
const node = cache[i];
|
||||||
node = cache[i];
|
|
||||||
node.displayed = 1;
|
node.displayed = 1;
|
||||||
var node_text = node.text.toLowerCase();
|
const node_text = node.text.toLowerCase();
|
||||||
var numTokens = tokens.length;
|
const numTokens = tokens.length;
|
||||||
for (var k = 0; k < numTokens; k++) {
|
for (let k = 0; k < numTokens; k++) {
|
||||||
token = tokens[k];
|
const token = tokens[k];
|
||||||
if (node_text.indexOf(token) === -1) {
|
if (node_text.indexOf(token) === -1) {
|
||||||
node.displayed = 0;
|
node.displayed = 0;
|
||||||
break; // Once the first token isn't found we're done
|
break; // Once the first token isn't found we're done
|
||||||
@ -52,10 +49,10 @@
|
|||||||
SelectBox.redisplay(id);
|
SelectBox.redisplay(id);
|
||||||
},
|
},
|
||||||
delete_from_cache: function(id, value) {
|
delete_from_cache: function(id, value) {
|
||||||
var node, delete_index = null;
|
let delete_index = null;
|
||||||
var cache = SelectBox.cache[id];
|
const cache = SelectBox.cache[id];
|
||||||
for (var i = 0, j = cache.length; i < j; i++) {
|
for (let i = 0, j = cache.length; i < j; i++) {
|
||||||
node = cache[i];
|
const node = cache[i];
|
||||||
if (node.value === value) {
|
if (node.value === value) {
|
||||||
delete_index = i;
|
delete_index = i;
|
||||||
break;
|
break;
|
||||||
@ -68,10 +65,9 @@
|
|||||||
},
|
},
|
||||||
cache_contains: function(id, value) {
|
cache_contains: function(id, value) {
|
||||||
// Check if an item is contained in the cache
|
// Check if an item is contained in the cache
|
||||||
var node;
|
const cache = SelectBox.cache[id];
|
||||||
var cache = SelectBox.cache[id];
|
for (let i = 0, j = cache.length; i < j; i++) {
|
||||||
for (var i = 0, j = cache.length; i < j; i++) {
|
const node = cache[i];
|
||||||
node = cache[i];
|
|
||||||
if (node.value === value) {
|
if (node.value === value) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -79,13 +75,12 @@
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
move: function(from, to) {
|
move: function(from, to) {
|
||||||
var from_box = document.getElementById(from);
|
const from_box = document.getElementById(from);
|
||||||
var option;
|
const boxOptions = from_box.options;
|
||||||
var boxOptions = from_box.options;
|
const boxOptionsLength = boxOptions.length;
|
||||||
var boxOptionsLength = boxOptions.length;
|
for (let i = 0, j = boxOptionsLength; i < j; i++) {
|
||||||
for (var i = 0, j = boxOptionsLength; i < j; i++) {
|
const option = boxOptions[i];
|
||||||
option = boxOptions[i];
|
const option_value = option.value;
|
||||||
var option_value = option.value;
|
|
||||||
if (option.selected && SelectBox.cache_contains(from, option_value)) {
|
if (option.selected && SelectBox.cache_contains(from, option_value)) {
|
||||||
SelectBox.add_to_cache(to, {value: option_value, text: option.text, displayed: 1});
|
SelectBox.add_to_cache(to, {value: option_value, text: option.text, displayed: 1});
|
||||||
SelectBox.delete_from_cache(from, option_value);
|
SelectBox.delete_from_cache(from, option_value);
|
||||||
@ -95,13 +90,12 @@
|
|||||||
SelectBox.redisplay(to);
|
SelectBox.redisplay(to);
|
||||||
},
|
},
|
||||||
move_all: function(from, to) {
|
move_all: function(from, to) {
|
||||||
var from_box = document.getElementById(from);
|
const from_box = document.getElementById(from);
|
||||||
var option;
|
const boxOptions = from_box.options;
|
||||||
var boxOptions = from_box.options;
|
const boxOptionsLength = boxOptions.length;
|
||||||
var boxOptionsLength = boxOptions.length;
|
for (let i = 0, j = boxOptionsLength; i < j; i++) {
|
||||||
for (var i = 0, j = boxOptionsLength; i < j; i++) {
|
const option = boxOptions[i];
|
||||||
option = boxOptions[i];
|
const option_value = option.value;
|
||||||
var option_value = option.value;
|
|
||||||
if (SelectBox.cache_contains(from, option_value)) {
|
if (SelectBox.cache_contains(from, option_value)) {
|
||||||
SelectBox.add_to_cache(to, {value: option_value, text: option.text, displayed: 1});
|
SelectBox.add_to_cache(to, {value: option_value, text: option.text, displayed: 1});
|
||||||
SelectBox.delete_from_cache(from, option_value);
|
SelectBox.delete_from_cache(from, option_value);
|
||||||
@ -124,10 +118,10 @@
|
|||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
select_all: function(id) {
|
select_all: function(id) {
|
||||||
var box = document.getElementById(id);
|
const box = document.getElementById(id);
|
||||||
var boxOptions = box.options;
|
const boxOptions = box.options;
|
||||||
var boxOptionsLength = boxOptions.length;
|
const boxOptionsLength = boxOptions.length;
|
||||||
for (var i = 0; i < boxOptionsLength; i++) {
|
for (let i = 0; i < boxOptionsLength; i++) {
|
||||||
boxOptions[i].selected = 'selected';
|
boxOptions[i].selected = 'selected';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,12 @@ Requires core.js and SelectBox.js.
|
|||||||
// Don't initialize on empty forms.
|
// Don't initialize on empty forms.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var from_box = document.getElementById(field_id);
|
const from_box = document.getElementById(field_id);
|
||||||
from_box.id += '_from'; // change its ID
|
from_box.id += '_from'; // change its ID
|
||||||
from_box.className = 'filtered';
|
from_box.className = 'filtered';
|
||||||
|
|
||||||
var ps = from_box.parentNode.getElementsByTagName('p');
|
const ps = from_box.parentNode.getElementsByTagName('p');
|
||||||
for (var i = 0; i < ps.length; i++) {
|
for (let i = 0; i < ps.length; i++) {
|
||||||
if (ps[i].classList.contains("info")) {
|
if (ps[i].classList.contains("info")) {
|
||||||
// Remove <p class="info">, because it just gets in the way.
|
// Remove <p class="info">, because it just gets in the way.
|
||||||
from_box.parentNode.removeChild(ps[i]);
|
from_box.parentNode.removeChild(ps[i]);
|
||||||
@ -30,13 +30,13 @@ Requires core.js and SelectBox.js.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// <div class="selector"> or <div class="selector stacked">
|
// <div class="selector"> or <div class="selector stacked">
|
||||||
var selector_div = quickElement('div', from_box.parentNode);
|
const selector_div = quickElement('div', from_box.parentNode);
|
||||||
selector_div.className = is_stacked ? 'selector stacked' : 'selector';
|
selector_div.className = is_stacked ? 'selector stacked' : 'selector';
|
||||||
|
|
||||||
// <div class="selector-available">
|
// <div class="selector-available">
|
||||||
var selector_available = quickElement('div', selector_div);
|
const selector_available = quickElement('div', selector_div);
|
||||||
selector_available.className = 'selector-available';
|
selector_available.className = 'selector-available';
|
||||||
var title_available = quickElement('h2', selector_available, interpolate(gettext('Available %s') + ' ', [field_name]));
|
const title_available = quickElement('h2', selector_available, interpolate(gettext('Available %s') + ' ', [field_name]));
|
||||||
quickElement(
|
quickElement(
|
||||||
'span', title_available, '',
|
'span', title_available, '',
|
||||||
'class', 'help help-tooltip help-icon',
|
'class', 'help help-tooltip help-icon',
|
||||||
@ -50,10 +50,10 @@ Requires core.js and SelectBox.js.
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
var filter_p = quickElement('p', selector_available, '', 'id', field_id + '_filter');
|
const filter_p = quickElement('p', selector_available, '', 'id', field_id + '_filter');
|
||||||
filter_p.className = 'selector-filter';
|
filter_p.className = 'selector-filter';
|
||||||
|
|
||||||
var search_filter_label = quickElement('label', filter_p, '', 'for', field_id + '_input');
|
const search_filter_label = quickElement('label', filter_p, '', 'for', field_id + '_input');
|
||||||
|
|
||||||
quickElement(
|
quickElement(
|
||||||
'span', search_filter_label, '',
|
'span', search_filter_label, '',
|
||||||
@ -63,25 +63,25 @@ Requires core.js and SelectBox.js.
|
|||||||
|
|
||||||
filter_p.appendChild(document.createTextNode(' '));
|
filter_p.appendChild(document.createTextNode(' '));
|
||||||
|
|
||||||
var filter_input = quickElement('input', filter_p, '', 'type', 'text', 'placeholder', gettext("Filter"));
|
const filter_input = quickElement('input', filter_p, '', 'type', 'text', 'placeholder', gettext("Filter"));
|
||||||
filter_input.id = field_id + '_input';
|
filter_input.id = field_id + '_input';
|
||||||
|
|
||||||
selector_available.appendChild(from_box);
|
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', '#', 'id', field_id + '_add_all_link');
|
const choose_all = quickElement('a', selector_available, gettext('Choose all'), 'title', interpolate(gettext('Click to choose all %s at once.'), [field_name]), 'href', '#', 'id', field_id + '_add_all_link');
|
||||||
choose_all.className = 'selector-chooseall';
|
choose_all.className = 'selector-chooseall';
|
||||||
|
|
||||||
// <ul class="selector-chooser">
|
// <ul class="selector-chooser">
|
||||||
var selector_chooser = quickElement('ul', selector_div);
|
const selector_chooser = quickElement('ul', selector_div);
|
||||||
selector_chooser.className = 'selector-chooser';
|
selector_chooser.className = 'selector-chooser';
|
||||||
var add_link = quickElement('a', quickElement('li', selector_chooser), gettext('Choose'), 'title', gettext('Choose'), 'href', '#', 'id', field_id + '_add_link');
|
const add_link = quickElement('a', quickElement('li', selector_chooser), gettext('Choose'), 'title', gettext('Choose'), 'href', '#', 'id', field_id + '_add_link');
|
||||||
add_link.className = 'selector-add';
|
add_link.className = 'selector-add';
|
||||||
var remove_link = quickElement('a', quickElement('li', selector_chooser), gettext('Remove'), 'title', gettext('Remove'), 'href', '#', 'id', field_id + '_remove_link');
|
const remove_link = quickElement('a', quickElement('li', selector_chooser), gettext('Remove'), 'title', gettext('Remove'), 'href', '#', 'id', field_id + '_remove_link');
|
||||||
remove_link.className = 'selector-remove';
|
remove_link.className = 'selector-remove';
|
||||||
|
|
||||||
// <div class="selector-chosen">
|
// <div class="selector-chosen">
|
||||||
var selector_chosen = quickElement('div', selector_div);
|
const selector_chosen = quickElement('div', selector_div);
|
||||||
selector_chosen.className = 'selector-chosen';
|
selector_chosen.className = 'selector-chosen';
|
||||||
var title_chosen = quickElement('h2', selector_chosen, interpolate(gettext('Chosen %s') + ' ', [field_name]));
|
const title_chosen = quickElement('h2', selector_chosen, interpolate(gettext('Chosen %s') + ' ', [field_name]));
|
||||||
quickElement(
|
quickElement(
|
||||||
'span', title_chosen, '',
|
'span', title_chosen, '',
|
||||||
'class', 'help help-tooltip help-icon',
|
'class', 'help help-tooltip help-icon',
|
||||||
@ -95,15 +95,15 @@ Requires core.js and SelectBox.js.
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
var to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', '', 'size', from_box.size, 'name', from_box.name);
|
const to_box = quickElement('select', selector_chosen, '', 'id', field_id + '_to', 'multiple', '', 'size', from_box.size, 'name', from_box.name);
|
||||||
to_box.className = 'filtered';
|
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', '#', 'id', field_id + '_remove_all_link');
|
const clear_all = quickElement('a', selector_chosen, gettext('Remove all'), 'title', interpolate(gettext('Click to remove all chosen %s at once.'), [field_name]), 'href', '#', 'id', field_id + '_remove_all_link');
|
||||||
clear_all.className = 'selector-clearall';
|
clear_all.className = 'selector-clearall';
|
||||||
|
|
||||||
from_box.name = from_box.name + '_old';
|
from_box.name = from_box.name + '_old';
|
||||||
|
|
||||||
// Set up the JavaScript event handlers for the select box filter interface
|
// Set up the JavaScript event handlers for the select box filter interface
|
||||||
var move_selection = function(e, elem, move_func, from, to) {
|
const move_selection = function(e, elem, move_func, from, to) {
|
||||||
if (elem.classList.contains('active')) {
|
if (elem.classList.contains('active')) {
|
||||||
move_func(from, to);
|
move_func(from, to);
|
||||||
SelectFilter.refresh_icons(field_id);
|
SelectFilter.refresh_icons(field_id);
|
||||||
@ -156,11 +156,11 @@ Requires core.js and SelectBox.js.
|
|||||||
|
|
||||||
if (!is_stacked) {
|
if (!is_stacked) {
|
||||||
// In horizontal mode, give the same height to the two boxes.
|
// In horizontal mode, give the same height to the two boxes.
|
||||||
var j_from_box = document.getElementById(field_id + '_from');
|
const j_from_box = document.getElementById(field_id + '_from');
|
||||||
var j_to_box = document.getElementById(field_id + '_to');
|
const j_to_box = document.getElementById(field_id + '_to');
|
||||||
var height = filter_p.offsetHeight + j_from_box.offsetHeight;
|
let height = filter_p.offsetHeight + j_from_box.offsetHeight;
|
||||||
|
|
||||||
var j_to_box_style = window.getComputedStyle(j_to_box);
|
const j_to_box_style = window.getComputedStyle(j_to_box);
|
||||||
if (j_to_box_style.getPropertyValue('box-sizing') === 'border-box') {
|
if (j_to_box_style.getPropertyValue('box-sizing') === 'border-box') {
|
||||||
// Add the padding and border to the final height.
|
// Add the padding and border to the final height.
|
||||||
height += parseInt(j_to_box_style.getPropertyValue('padding-top'), 10)
|
height += parseInt(j_to_box_style.getPropertyValue('padding-top'), 10)
|
||||||
@ -176,16 +176,15 @@ Requires core.js and SelectBox.js.
|
|||||||
SelectFilter.refresh_icons(field_id);
|
SelectFilter.refresh_icons(field_id);
|
||||||
},
|
},
|
||||||
any_selected: function(field) {
|
any_selected: function(field) {
|
||||||
var any_selected = false;
|
|
||||||
// Temporarily add the required attribute and check validity.
|
// Temporarily add the required attribute and check validity.
|
||||||
field.required = true;
|
field.required = true;
|
||||||
any_selected = field.checkValidity();
|
const any_selected = field.checkValidity();
|
||||||
field.required = false;
|
field.required = false;
|
||||||
return any_selected;
|
return any_selected;
|
||||||
},
|
},
|
||||||
refresh_icons: function(field_id) {
|
refresh_icons: function(field_id) {
|
||||||
var from = document.getElementById(field_id + '_from');
|
const from = document.getElementById(field_id + '_from');
|
||||||
var to = document.getElementById(field_id + '_to');
|
const to = document.getElementById(field_id + '_to');
|
||||||
// Active if at least one item is selected
|
// Active if at least one item is selected
|
||||||
document.getElementById(field_id + '_add_link').classList.toggle('active', SelectFilter.any_selected(from));
|
document.getElementById(field_id + '_add_link').classList.toggle('active', SelectFilter.any_selected(from));
|
||||||
document.getElementById(field_id + '_remove_link').classList.toggle('active', SelectFilter.any_selected(to));
|
document.getElementById(field_id + '_remove_link').classList.toggle('active', SelectFilter.any_selected(to));
|
||||||
@ -194,7 +193,7 @@ Requires core.js and SelectBox.js.
|
|||||||
document.getElementById(field_id + '_remove_all_link').classList.toggle('active', to.querySelector('option'));
|
document.getElementById(field_id + '_remove_all_link').classList.toggle('active', to.querySelector('option'));
|
||||||
},
|
},
|
||||||
filter_key_press: function(event, field_id) {
|
filter_key_press: function(event, field_id) {
|
||||||
var from = document.getElementById(field_id + '_from');
|
const from = document.getElementById(field_id + '_from');
|
||||||
// don't submit form if user pressed Enter
|
// don't submit form if user pressed Enter
|
||||||
if ((event.which && event.which === 13) || (event.keyCode && event.keyCode === 13)) {
|
if ((event.which && event.which === 13) || (event.keyCode && event.keyCode === 13)) {
|
||||||
from.selectedIndex = 0;
|
from.selectedIndex = 0;
|
||||||
@ -204,16 +203,16 @@ Requires core.js and SelectBox.js.
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
filter_key_up: function(event, field_id) {
|
filter_key_up: function(event, field_id) {
|
||||||
var from = document.getElementById(field_id + '_from');
|
const from = document.getElementById(field_id + '_from');
|
||||||
var temp = from.selectedIndex;
|
const temp = from.selectedIndex;
|
||||||
SelectBox.filter(field_id + '_from', document.getElementById(field_id + '_input').value);
|
SelectBox.filter(field_id + '_from', document.getElementById(field_id + '_input').value);
|
||||||
from.selectedIndex = temp;
|
from.selectedIndex = temp;
|
||||||
},
|
},
|
||||||
filter_key_down: function(event, field_id) {
|
filter_key_down: function(event, field_id) {
|
||||||
var from = document.getElementById(field_id + '_from');
|
const from = document.getElementById(field_id + '_from');
|
||||||
// right arrow -- move across
|
// right arrow -- move across
|
||||||
if ((event.which && event.which === 39) || (event.keyCode && event.keyCode === 39)) {
|
if ((event.which && event.which === 39) || (event.keyCode && event.keyCode === 39)) {
|
||||||
var old_index = from.selectedIndex;
|
const old_index = from.selectedIndex;
|
||||||
SelectBox.move(field_id + '_from', field_id + '_to');
|
SelectBox.move(field_id + '_from', field_id + '_to');
|
||||||
from.selectedIndex = (old_index === from.length) ? from.length - 1 : old_index;
|
from.selectedIndex = (old_index === from.length) ? from.length - 1 : old_index;
|
||||||
return;
|
return;
|
||||||
@ -231,7 +230,7 @@ Requires core.js and SelectBox.js.
|
|||||||
|
|
||||||
window.addEventListener('load', function(e) {
|
window.addEventListener('load', function(e) {
|
||||||
document.querySelectorAll('select.selectfilter, select.selectfilterstacked').forEach(function(el) {
|
document.querySelectorAll('select.selectfilter, select.selectfilterstacked').forEach(function(el) {
|
||||||
var data = el.dataset;
|
const data = el.dataset;
|
||||||
SelectFilter.init(el.id, data.fieldName, parseInt(data.isStacked, 10));
|
SelectFilter.init(el.id, data.fieldName, parseInt(data.isStacked, 10));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
/*global gettext, interpolate, ngettext*/
|
/*global gettext, interpolate, ngettext*/
|
||||||
(function($) {
|
(function($) {
|
||||||
'use strict';
|
'use strict';
|
||||||
var lastChecked;
|
let lastChecked;
|
||||||
|
|
||||||
$.fn.actions = function(opts) {
|
$.fn.actions = function(opts) {
|
||||||
var options = $.extend({}, $.fn.actions.defaults, opts);
|
const options = $.extend({}, $.fn.actions.defaults, opts);
|
||||||
var actionCheckboxes = $(this);
|
const actionCheckboxes = $(this);
|
||||||
var list_editable_changed = false;
|
let list_editable_changed = false;
|
||||||
var showQuestion = function() {
|
const showQuestion = function() {
|
||||||
$(options.acrossClears).hide();
|
$(options.acrossClears).hide();
|
||||||
$(options.acrossQuestions).show();
|
$(options.acrossQuestions).show();
|
||||||
$(options.allContainer).hide();
|
$(options.allContainer).hide();
|
||||||
@ -40,17 +40,17 @@
|
|||||||
.parent().parent().toggleClass(options.selectedClass, checked);
|
.parent().parent().toggleClass(options.selectedClass, checked);
|
||||||
},
|
},
|
||||||
updateCounter = function() {
|
updateCounter = function() {
|
||||||
var sel = $(actionCheckboxes).filter(":checked").length;
|
const sel = $(actionCheckboxes).filter(":checked").length;
|
||||||
// data-actions-icnt is defined in the generated HTML
|
// data-actions-icnt is defined in the generated HTML
|
||||||
// and contains the total amount of objects in the queryset
|
// and contains the total amount of objects in the queryset
|
||||||
var actions_icnt = $('.action-counter').data('actionsIcnt');
|
const actions_icnt = $('.action-counter').data('actionsIcnt');
|
||||||
$(options.counterContainer).html(interpolate(
|
$(options.counterContainer).html(interpolate(
|
||||||
ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel), {
|
ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel), {
|
||||||
sel: sel,
|
sel: sel,
|
||||||
cnt: actions_icnt
|
cnt: actions_icnt
|
||||||
}, true));
|
}, true));
|
||||||
$(options.allToggle).prop("checked", function() {
|
$(options.allToggle).prop("checked", function() {
|
||||||
var value;
|
let value;
|
||||||
if (sel === actionCheckboxes.length) {
|
if (sel === actionCheckboxes.length) {
|
||||||
value = true;
|
value = true;
|
||||||
showQuestion();
|
showQuestion();
|
||||||
@ -90,9 +90,9 @@
|
|||||||
lastChecked = null;
|
lastChecked = null;
|
||||||
$(actionCheckboxes).on('click', function(event) {
|
$(actionCheckboxes).on('click', function(event) {
|
||||||
if (!event) { event = window.event; }
|
if (!event) { event = window.event; }
|
||||||
var target = event.target ? event.target : event.srcElement;
|
const target = event.target ? event.target : event.srcElement;
|
||||||
if (lastChecked && $.data(lastChecked) !== $.data(target) && event.shiftKey === true) {
|
if (lastChecked && $.data(lastChecked) !== $.data(target) && event.shiftKey === true) {
|
||||||
var inrange = false;
|
let inrange = false;
|
||||||
$(lastChecked).prop("checked", target.checked)
|
$(lastChecked).prop("checked", target.checked)
|
||||||
.parent().parent().toggleClass(options.selectedClass, target.checked);
|
.parent().parent().toggleClass(options.selectedClass, target.checked);
|
||||||
$(actionCheckboxes).each(function() {
|
$(actionCheckboxes).each(function() {
|
||||||
@ -118,7 +118,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('form#changelist-form input[name="_save"]').on('click', function(event) {
|
$('form#changelist-form input[name="_save"]').on('click', function(event) {
|
||||||
var action_changed = false;
|
let action_changed = false;
|
||||||
$('select option:selected', options.actionContainer).each(function() {
|
$('select option:selected', options.actionContainer).each(function() {
|
||||||
if ($(this).val()) {
|
if ($(this).val()) {
|
||||||
action_changed = true;
|
action_changed = true;
|
||||||
@ -145,7 +145,7 @@
|
|||||||
selectedClass: "selected"
|
selectedClass: "selected"
|
||||||
};
|
};
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var $actionsEls = $('tr input.action-select');
|
const $actionsEls = $('tr input.action-select');
|
||||||
if ($actionsEls.length > 0) {
|
if ($actionsEls.length > 0) {
|
||||||
$actionsEls.actions();
|
$actionsEls.actions();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
// <input type="text" class="vTimeField">
|
// <input type="text" class="vTimeField">
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var DateTimeShortcuts = {
|
const DateTimeShortcuts = {
|
||||||
calendars: [],
|
calendars: [],
|
||||||
calendarInputs: [],
|
calendarInputs: [],
|
||||||
clockInputs: [],
|
clockInputs: [],
|
||||||
@ -28,16 +28,16 @@
|
|||||||
timezoneWarningClass: 'timezonewarning', // class of the warning for timezone mismatch
|
timezoneWarningClass: 'timezonewarning', // class of the warning for timezone mismatch
|
||||||
timezoneOffset: 0,
|
timezoneOffset: 0,
|
||||||
init: function() {
|
init: function() {
|
||||||
var body = document.getElementsByTagName('body')[0];
|
const body = document.getElementsByTagName('body')[0];
|
||||||
var serverOffset = body.dataset.adminUtcOffset;
|
const serverOffset = body.dataset.adminUtcOffset;
|
||||||
if (serverOffset) {
|
if (serverOffset) {
|
||||||
var localOffset = new Date().getTimezoneOffset() * -60;
|
const localOffset = new Date().getTimezoneOffset() * -60;
|
||||||
DateTimeShortcuts.timezoneOffset = localOffset - serverOffset;
|
DateTimeShortcuts.timezoneOffset = localOffset - serverOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
var inputs = document.getElementsByTagName('input');
|
const inputs = document.getElementsByTagName('input');
|
||||||
for (var i = 0; i < inputs.length; i++) {
|
for (let i = 0; i < inputs.length; i++) {
|
||||||
var inp = inputs[i];
|
const inp = inputs[i];
|
||||||
if (inp.type === 'text' && inp.classList.contains('vTimeField')) {
|
if (inp.type === 'text' && inp.classList.contains('vTimeField')) {
|
||||||
DateTimeShortcuts.addClock(inp);
|
DateTimeShortcuts.addClock(inp);
|
||||||
DateTimeShortcuts.addTimezoneWarning(inp);
|
DateTimeShortcuts.addTimezoneWarning(inp);
|
||||||
@ -50,11 +50,11 @@
|
|||||||
},
|
},
|
||||||
// Return the current time while accounting for the server timezone.
|
// Return the current time while accounting for the server timezone.
|
||||||
now: function() {
|
now: function() {
|
||||||
var body = document.getElementsByTagName('body')[0];
|
const body = document.getElementsByTagName('body')[0];
|
||||||
var serverOffset = body.dataset.adminUtcOffset;
|
const serverOffset = body.dataset.adminUtcOffset;
|
||||||
if (serverOffset) {
|
if (serverOffset) {
|
||||||
var localNow = new Date();
|
const localNow = new Date();
|
||||||
var localOffset = localNow.getTimezoneOffset() * -60;
|
const localOffset = localNow.getTimezoneOffset() * -60;
|
||||||
localNow.setTime(localNow.getTime() + 1000 * (serverOffset - localOffset));
|
localNow.setTime(localNow.getTime() + 1000 * (serverOffset - localOffset));
|
||||||
return localNow;
|
return localNow;
|
||||||
} else {
|
} else {
|
||||||
@ -63,8 +63,8 @@
|
|||||||
},
|
},
|
||||||
// Add a warning when the time zone in the browser and backend do not match.
|
// Add a warning when the time zone in the browser and backend do not match.
|
||||||
addTimezoneWarning: function(inp) {
|
addTimezoneWarning: function(inp) {
|
||||||
var warningClass = DateTimeShortcuts.timezoneWarningClass;
|
const warningClass = DateTimeShortcuts.timezoneWarningClass;
|
||||||
var timezoneOffset = DateTimeShortcuts.timezoneOffset / 3600;
|
let timezoneOffset = DateTimeShortcuts.timezoneOffset / 3600;
|
||||||
|
|
||||||
// Only warn if there is a time zone mismatch.
|
// Only warn if there is a time zone mismatch.
|
||||||
if (!timezoneOffset) {
|
if (!timezoneOffset) {
|
||||||
@ -76,7 +76,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var message;
|
let message;
|
||||||
if (timezoneOffset > 0) {
|
if (timezoneOffset > 0) {
|
||||||
message = ngettext(
|
message = ngettext(
|
||||||
'Note: You are %s hour ahead of server time.',
|
'Note: You are %s hour ahead of server time.',
|
||||||
@ -94,7 +94,7 @@
|
|||||||
}
|
}
|
||||||
message = interpolate(message, [timezoneOffset]);
|
message = interpolate(message, [timezoneOffset]);
|
||||||
|
|
||||||
var warning = document.createElement('span');
|
const warning = document.createElement('span');
|
||||||
warning.className = warningClass;
|
warning.className = warningClass;
|
||||||
warning.textContent = message;
|
warning.textContent = message;
|
||||||
inp.parentNode.appendChild(document.createElement('br'));
|
inp.parentNode.appendChild(document.createElement('br'));
|
||||||
@ -102,22 +102,22 @@
|
|||||||
},
|
},
|
||||||
// Add clock widget to a given field
|
// Add clock widget to a given field
|
||||||
addClock: function(inp) {
|
addClock: function(inp) {
|
||||||
var num = DateTimeShortcuts.clockInputs.length;
|
const num = DateTimeShortcuts.clockInputs.length;
|
||||||
DateTimeShortcuts.clockInputs[num] = inp;
|
DateTimeShortcuts.clockInputs[num] = inp;
|
||||||
DateTimeShortcuts.dismissClockFunc[num] = function() { DateTimeShortcuts.dismissClock(num); return true; };
|
DateTimeShortcuts.dismissClockFunc[num] = function() { DateTimeShortcuts.dismissClock(num); return true; };
|
||||||
|
|
||||||
// Shortcut links (clock icon and "Now" link)
|
// Shortcut links (clock icon and "Now" link)
|
||||||
var shortcuts_span = document.createElement('span');
|
const shortcuts_span = document.createElement('span');
|
||||||
shortcuts_span.className = DateTimeShortcuts.shortCutsClass;
|
shortcuts_span.className = DateTimeShortcuts.shortCutsClass;
|
||||||
inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling);
|
inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling);
|
||||||
var now_link = document.createElement('a');
|
const now_link = document.createElement('a');
|
||||||
now_link.href = "#";
|
now_link.href = "#";
|
||||||
now_link.textContent = gettext('Now');
|
now_link.textContent = gettext('Now');
|
||||||
now_link.addEventListener('click', function(e) {
|
now_link.addEventListener('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
DateTimeShortcuts.handleClockQuicklink(num, -1);
|
DateTimeShortcuts.handleClockQuicklink(num, -1);
|
||||||
});
|
});
|
||||||
var clock_link = document.createElement('a');
|
const clock_link = document.createElement('a');
|
||||||
clock_link.href = '#';
|
clock_link.href = '#';
|
||||||
clock_link.id = DateTimeShortcuts.clockLinkName + num;
|
clock_link.id = DateTimeShortcuts.clockLinkName + num;
|
||||||
clock_link.addEventListener('click', function(e) {
|
clock_link.addEventListener('click', function(e) {
|
||||||
@ -152,7 +152,7 @@
|
|||||||
// <p class="calendar-cancel"><a href="#">Cancel</a></p>
|
// <p class="calendar-cancel"><a href="#">Cancel</a></p>
|
||||||
// </div>
|
// </div>
|
||||||
|
|
||||||
var clock_box = document.createElement('div');
|
const clock_box = document.createElement('div');
|
||||||
clock_box.style.display = 'none';
|
clock_box.style.display = 'none';
|
||||||
clock_box.style.position = 'absolute';
|
clock_box.style.position = 'absolute';
|
||||||
clock_box.className = 'clockbox module';
|
clock_box.className = 'clockbox module';
|
||||||
@ -161,23 +161,23 @@
|
|||||||
clock_box.addEventListener('click', function(e) { e.stopPropagation(); });
|
clock_box.addEventListener('click', function(e) { e.stopPropagation(); });
|
||||||
|
|
||||||
quickElement('h2', clock_box, gettext('Choose a time'));
|
quickElement('h2', clock_box, gettext('Choose a time'));
|
||||||
var time_list = quickElement('ul', clock_box);
|
const time_list = quickElement('ul', clock_box);
|
||||||
time_list.className = 'timelist';
|
time_list.className = 'timelist';
|
||||||
// The list of choices can be overridden in JavaScript like this:
|
// The list of choices can be overridden in JavaScript like this:
|
||||||
// DateTimeShortcuts.clockHours.name = [['3 a.m.', 3]];
|
// DateTimeShortcuts.clockHours.name = [['3 a.m.', 3]];
|
||||||
// where name is the name attribute of the <input>.
|
// where name is the name attribute of the <input>.
|
||||||
var name = typeof DateTimeShortcuts.clockHours[inp.name] === 'undefined' ? 'default_' : inp.name;
|
const name = typeof DateTimeShortcuts.clockHours[inp.name] === 'undefined' ? 'default_' : inp.name;
|
||||||
DateTimeShortcuts.clockHours[name].forEach(function(element) {
|
DateTimeShortcuts.clockHours[name].forEach(function(element) {
|
||||||
var time_link = quickElement('a', quickElement('li', time_list), gettext(element[0]), 'href', '#');
|
const time_link = quickElement('a', quickElement('li', time_list), gettext(element[0]), 'href', '#');
|
||||||
time_link.addEventListener('click', function(e) {
|
time_link.addEventListener('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
DateTimeShortcuts.handleClockQuicklink(num, element[1]);
|
DateTimeShortcuts.handleClockQuicklink(num, element[1]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var cancel_p = quickElement('p', clock_box);
|
const cancel_p = quickElement('p', clock_box);
|
||||||
cancel_p.className = 'calendar-cancel';
|
cancel_p.className = 'calendar-cancel';
|
||||||
var cancel_link = quickElement('a', cancel_p, gettext('Cancel'), 'href', '#');
|
const cancel_link = quickElement('a', cancel_p, gettext('Cancel'), 'href', '#');
|
||||||
cancel_link.addEventListener('click', function(e) {
|
cancel_link.addEventListener('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
DateTimeShortcuts.dismissClock(num);
|
DateTimeShortcuts.dismissClock(num);
|
||||||
@ -192,8 +192,8 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
openClock: function(num) {
|
openClock: function(num) {
|
||||||
var clock_box = document.getElementById(DateTimeShortcuts.clockDivName + num);
|
const clock_box = document.getElementById(DateTimeShortcuts.clockDivName + num);
|
||||||
var clock_link = document.getElementById(DateTimeShortcuts.clockLinkName + num);
|
const clock_link = document.getElementById(DateTimeShortcuts.clockLinkName + num);
|
||||||
|
|
||||||
// Recalculate the clockbox position
|
// Recalculate the clockbox position
|
||||||
// is it left-to-right or right-to-left layout ?
|
// is it left-to-right or right-to-left layout ?
|
||||||
@ -216,7 +216,7 @@
|
|||||||
document.removeEventListener('click', DateTimeShortcuts.dismissClockFunc[num]);
|
document.removeEventListener('click', DateTimeShortcuts.dismissClockFunc[num]);
|
||||||
},
|
},
|
||||||
handleClockQuicklink: function(num, val) {
|
handleClockQuicklink: function(num, val) {
|
||||||
var d;
|
let d;
|
||||||
if (val === -1) {
|
if (val === -1) {
|
||||||
d = DateTimeShortcuts.now();
|
d = DateTimeShortcuts.now();
|
||||||
}
|
}
|
||||||
@ -229,23 +229,23 @@
|
|||||||
},
|
},
|
||||||
// Add calendar widget to a given field.
|
// Add calendar widget to a given field.
|
||||||
addCalendar: function(inp) {
|
addCalendar: function(inp) {
|
||||||
var num = DateTimeShortcuts.calendars.length;
|
const num = DateTimeShortcuts.calendars.length;
|
||||||
|
|
||||||
DateTimeShortcuts.calendarInputs[num] = inp;
|
DateTimeShortcuts.calendarInputs[num] = inp;
|
||||||
DateTimeShortcuts.dismissCalendarFunc[num] = function() { DateTimeShortcuts.dismissCalendar(num); return true; };
|
DateTimeShortcuts.dismissCalendarFunc[num] = function() { DateTimeShortcuts.dismissCalendar(num); return true; };
|
||||||
|
|
||||||
// Shortcut links (calendar icon and "Today" link)
|
// Shortcut links (calendar icon and "Today" link)
|
||||||
var shortcuts_span = document.createElement('span');
|
const shortcuts_span = document.createElement('span');
|
||||||
shortcuts_span.className = DateTimeShortcuts.shortCutsClass;
|
shortcuts_span.className = DateTimeShortcuts.shortCutsClass;
|
||||||
inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling);
|
inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling);
|
||||||
var today_link = document.createElement('a');
|
const today_link = document.createElement('a');
|
||||||
today_link.href = '#';
|
today_link.href = '#';
|
||||||
today_link.appendChild(document.createTextNode(gettext('Today')));
|
today_link.appendChild(document.createTextNode(gettext('Today')));
|
||||||
today_link.addEventListener('click', function(e) {
|
today_link.addEventListener('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
DateTimeShortcuts.handleCalendarQuickLink(num, 0);
|
DateTimeShortcuts.handleCalendarQuickLink(num, 0);
|
||||||
});
|
});
|
||||||
var cal_link = document.createElement('a');
|
const cal_link = document.createElement('a');
|
||||||
cal_link.href = '#';
|
cal_link.href = '#';
|
||||||
cal_link.id = DateTimeShortcuts.calendarLinkName + num;
|
cal_link.id = DateTimeShortcuts.calendarLinkName + num;
|
||||||
cal_link.addEventListener('click', function(e) {
|
cal_link.addEventListener('click', function(e) {
|
||||||
@ -281,7 +281,7 @@
|
|||||||
// </div>
|
// </div>
|
||||||
// <p class="calendar-cancel"><a href="#">Cancel</a></p>
|
// <p class="calendar-cancel"><a href="#">Cancel</a></p>
|
||||||
// </div>
|
// </div>
|
||||||
var cal_box = document.createElement('div');
|
const cal_box = document.createElement('div');
|
||||||
cal_box.style.display = 'none';
|
cal_box.style.display = 'none';
|
||||||
cal_box.style.position = 'absolute';
|
cal_box.style.position = 'absolute';
|
||||||
cal_box.className = 'calendarbox module';
|
cal_box.className = 'calendarbox module';
|
||||||
@ -290,15 +290,15 @@
|
|||||||
cal_box.addEventListener('click', function(e) { e.stopPropagation(); });
|
cal_box.addEventListener('click', function(e) { e.stopPropagation(); });
|
||||||
|
|
||||||
// next-prev links
|
// next-prev links
|
||||||
var cal_nav = quickElement('div', cal_box);
|
const cal_nav = quickElement('div', cal_box);
|
||||||
var cal_nav_prev = quickElement('a', cal_nav, '<', 'href', '#');
|
const cal_nav_prev = quickElement('a', cal_nav, '<', 'href', '#');
|
||||||
cal_nav_prev.className = 'calendarnav-previous';
|
cal_nav_prev.className = 'calendarnav-previous';
|
||||||
cal_nav_prev.addEventListener('click', function(e) {
|
cal_nav_prev.addEventListener('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
DateTimeShortcuts.drawPrev(num);
|
DateTimeShortcuts.drawPrev(num);
|
||||||
});
|
});
|
||||||
|
|
||||||
var cal_nav_next = quickElement('a', cal_nav, '>', 'href', '#');
|
const cal_nav_next = quickElement('a', cal_nav, '>', 'href', '#');
|
||||||
cal_nav_next.className = 'calendarnav-next';
|
cal_nav_next.className = 'calendarnav-next';
|
||||||
cal_nav_next.addEventListener('click', function(e) {
|
cal_nav_next.addEventListener('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -306,15 +306,15 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// main box
|
// main box
|
||||||
var cal_main = quickElement('div', cal_box, '', 'id', DateTimeShortcuts.calendarDivName2 + num);
|
const cal_main = quickElement('div', cal_box, '', 'id', DateTimeShortcuts.calendarDivName2 + num);
|
||||||
cal_main.className = 'calendar';
|
cal_main.className = 'calendar';
|
||||||
DateTimeShortcuts.calendars[num] = new Calendar(DateTimeShortcuts.calendarDivName2 + num, DateTimeShortcuts.handleCalendarCallback(num));
|
DateTimeShortcuts.calendars[num] = new Calendar(DateTimeShortcuts.calendarDivName2 + num, DateTimeShortcuts.handleCalendarCallback(num));
|
||||||
DateTimeShortcuts.calendars[num].drawCurrent();
|
DateTimeShortcuts.calendars[num].drawCurrent();
|
||||||
|
|
||||||
// calendar shortcuts
|
// calendar shortcuts
|
||||||
var shortcuts = quickElement('div', cal_box);
|
const shortcuts = quickElement('div', cal_box);
|
||||||
shortcuts.className = 'calendar-shortcuts';
|
shortcuts.className = 'calendar-shortcuts';
|
||||||
var day_link = quickElement('a', shortcuts, gettext('Yesterday'), 'href', '#');
|
let day_link = quickElement('a', shortcuts, gettext('Yesterday'), 'href', '#');
|
||||||
day_link.addEventListener('click', function(e) {
|
day_link.addEventListener('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
DateTimeShortcuts.handleCalendarQuickLink(num, -1);
|
DateTimeShortcuts.handleCalendarQuickLink(num, -1);
|
||||||
@ -333,9 +333,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// cancel bar
|
// cancel bar
|
||||||
var cancel_p = quickElement('p', cal_box);
|
const cancel_p = quickElement('p', cal_box);
|
||||||
cancel_p.className = 'calendar-cancel';
|
cancel_p.className = 'calendar-cancel';
|
||||||
var cancel_link = quickElement('a', cancel_p, gettext('Cancel'), 'href', '#');
|
const cancel_link = quickElement('a', cancel_p, gettext('Cancel'), 'href', '#');
|
||||||
cancel_link.addEventListener('click', function(e) {
|
cancel_link.addEventListener('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
DateTimeShortcuts.dismissCalendar(num);
|
DateTimeShortcuts.dismissCalendar(num);
|
||||||
@ -349,18 +349,18 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
openCalendar: function(num) {
|
openCalendar: function(num) {
|
||||||
var cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1 + num);
|
const cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1 + num);
|
||||||
var cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName + num);
|
const cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName + num);
|
||||||
var inp = DateTimeShortcuts.calendarInputs[num];
|
const inp = DateTimeShortcuts.calendarInputs[num];
|
||||||
|
|
||||||
// Determine if the current value in the input has a valid date.
|
// Determine if the current value in the input has a valid date.
|
||||||
// If so, draw the calendar with that date's year and month.
|
// If so, draw the calendar with that date's year and month.
|
||||||
if (inp.value) {
|
if (inp.value) {
|
||||||
var format = get_format('DATE_INPUT_FORMATS')[0];
|
const format = get_format('DATE_INPUT_FORMATS')[0];
|
||||||
var selected = inp.value.strptime(format);
|
const selected = inp.value.strptime(format);
|
||||||
var year = selected.getUTCFullYear();
|
const year = selected.getUTCFullYear();
|
||||||
var month = selected.getUTCMonth() + 1;
|
const month = selected.getUTCMonth() + 1;
|
||||||
var re = /\d{4}/;
|
const re = /\d{4}/;
|
||||||
if (re.test(year.toString()) && month >= 1 && month <= 12) {
|
if (re.test(year.toString()) && month >= 1 && month <= 12) {
|
||||||
DateTimeShortcuts.calendars[num].drawDate(month, year, selected);
|
DateTimeShortcuts.calendars[num].drawDate(month, year, selected);
|
||||||
}
|
}
|
||||||
@ -392,7 +392,7 @@
|
|||||||
DateTimeShortcuts.calendars[num].drawNextMonth();
|
DateTimeShortcuts.calendars[num].drawNextMonth();
|
||||||
},
|
},
|
||||||
handleCalendarCallback: function(num) {
|
handleCalendarCallback: function(num) {
|
||||||
var format = get_format('DATE_INPUT_FORMATS')[0];
|
let format = get_format('DATE_INPUT_FORMATS')[0];
|
||||||
// the format needs to be escaped a little
|
// the format needs to be escaped a little
|
||||||
format = format.replace('\\', '\\\\')
|
format = format.replace('\\', '\\\\')
|
||||||
.replace('\r', '\\r')
|
.replace('\r', '\\r')
|
||||||
@ -406,7 +406,7 @@
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
handleCalendarQuickLink: function(num, offset) {
|
handleCalendarQuickLink: function(num, offset) {
|
||||||
var d = DateTimeShortcuts.now();
|
const d = DateTimeShortcuts.now();
|
||||||
d.setDate(d.getDate() + offset);
|
d.setDate(d.getDate() + offset);
|
||||||
DateTimeShortcuts.calendarInputs[num].value = d.strftime(get_format('DATE_INPUT_FORMATS')[0]);
|
DateTimeShortcuts.calendarInputs[num].value = d.strftime(get_format('DATE_INPUT_FORMATS')[0]);
|
||||||
DateTimeShortcuts.calendarInputs[num].focus();
|
DateTimeShortcuts.calendarInputs[num].focus();
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function showAdminPopup(triggeringLink, name_regexp, add_popup) {
|
function showAdminPopup(triggeringLink, name_regexp, add_popup) {
|
||||||
var name = triggeringLink.id.replace(name_regexp, '');
|
const name = triggeringLink.id.replace(name_regexp, '');
|
||||||
var href = triggeringLink.href;
|
let href = triggeringLink.href;
|
||||||
if (add_popup) {
|
if (add_popup) {
|
||||||
if (href.indexOf('?') === -1) {
|
if (href.indexOf('?') === -1) {
|
||||||
href += '?_popup=1';
|
href += '?_popup=1';
|
||||||
@ -15,7 +15,7 @@
|
|||||||
href += '&_popup=1';
|
href += '&_popup=1';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
|
const win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
|
||||||
win.focus();
|
win.focus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -25,8 +25,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dismissRelatedLookupPopup(win, chosenId) {
|
function dismissRelatedLookupPopup(win, chosenId) {
|
||||||
var name = win.name;
|
const name = win.name;
|
||||||
var elem = document.getElementById(name);
|
const elem = document.getElementById(name);
|
||||||
if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) {
|
if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) {
|
||||||
elem.value += ',' + chosenId;
|
elem.value += ',' + chosenId;
|
||||||
} else {
|
} else {
|
||||||
@ -40,15 +40,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateRelatedObjectLinks(triggeringLink) {
|
function updateRelatedObjectLinks(triggeringLink) {
|
||||||
var $this = $(triggeringLink);
|
const $this = $(triggeringLink);
|
||||||
var siblings = $this.nextAll('.view-related, .change-related, .delete-related');
|
const siblings = $this.nextAll('.view-related, .change-related, .delete-related');
|
||||||
if (!siblings.length) {
|
if (!siblings.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var value = $this.val();
|
const value = $this.val();
|
||||||
if (value) {
|
if (value) {
|
||||||
siblings.each(function() {
|
siblings.each(function() {
|
||||||
var elm = $(this);
|
const elm = $(this);
|
||||||
elm.attr('href', elm.attr('data-href-template').replace('__fk__', value));
|
elm.attr('href', elm.attr('data-href-template').replace('__fk__', value));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -57,10 +57,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dismissAddRelatedObjectPopup(win, newId, newRepr) {
|
function dismissAddRelatedObjectPopup(win, newId, newRepr) {
|
||||||
var name = win.name;
|
const name = win.name;
|
||||||
var elem = document.getElementById(name);
|
const elem = document.getElementById(name);
|
||||||
if (elem) {
|
if (elem) {
|
||||||
var elemName = elem.nodeName.toUpperCase();
|
const elemName = elem.nodeName.toUpperCase();
|
||||||
if (elemName === 'SELECT') {
|
if (elemName === 'SELECT') {
|
||||||
elem.options[elem.options.length] = new Option(newRepr, newId, true, true);
|
elem.options[elem.options.length] = new Option(newRepr, newId, true, true);
|
||||||
} else if (elemName === 'INPUT') {
|
} else if (elemName === 'INPUT') {
|
||||||
@ -73,8 +73,8 @@
|
|||||||
// Trigger a change event to update related links if required.
|
// Trigger a change event to update related links if required.
|
||||||
$(elem).trigger('change');
|
$(elem).trigger('change');
|
||||||
} else {
|
} else {
|
||||||
var toId = name + "_to";
|
const toId = name + "_to";
|
||||||
var o = new Option(newRepr, newId);
|
const o = new Option(newRepr, newId);
|
||||||
SelectBox.add_to_cache(toId, o);
|
SelectBox.add_to_cache(toId, o);
|
||||||
SelectBox.redisplay(toId);
|
SelectBox.redisplay(toId);
|
||||||
}
|
}
|
||||||
@ -82,9 +82,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) {
|
function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) {
|
||||||
var id = win.name.replace(/^edit_/, '');
|
const id = win.name.replace(/^edit_/, '');
|
||||||
var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
|
const selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
|
||||||
var selects = $(selectsSelector);
|
const selects = $(selectsSelector);
|
||||||
selects.find('option').each(function() {
|
selects.find('option').each(function() {
|
||||||
if (this.value === objId) {
|
if (this.value === objId) {
|
||||||
this.textContent = newRepr;
|
this.textContent = newRepr;
|
||||||
@ -101,9 +101,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function dismissDeleteRelatedObjectPopup(win, objId) {
|
function dismissDeleteRelatedObjectPopup(win, objId) {
|
||||||
var id = win.name.replace(/^delete_/, '');
|
const id = win.name.replace(/^delete_/, '');
|
||||||
var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
|
const selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
|
||||||
var selects = $(selectsSelector);
|
const selects = $(selectsSelector);
|
||||||
selects.find('option').each(function() {
|
selects.find('option').each(function() {
|
||||||
if (this.value === objId) {
|
if (this.value === objId) {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
@ -132,7 +132,7 @@
|
|||||||
$('body').on('click', '.related-widget-wrapper-link', function(e) {
|
$('body').on('click', '.related-widget-wrapper-link', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (this.href) {
|
if (this.href) {
|
||||||
var event = $.Event('django:show-related', {href: this.href});
|
const event = $.Event('django:show-related', {href: this.href});
|
||||||
$(this).trigger(event);
|
$(this).trigger(event);
|
||||||
if (!event.isDefaultPrevented()) {
|
if (!event.isDefaultPrevented()) {
|
||||||
showRelatedObjectPopup(this);
|
showRelatedObjectPopup(this);
|
||||||
@ -140,7 +140,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('body').on('change', '.related-widget-wrapper select', function(e) {
|
$('body').on('change', '.related-widget-wrapper select', function(e) {
|
||||||
var event = $.Event('django:update-related');
|
const event = $.Event('django:update-related');
|
||||||
$(this).trigger(event);
|
$(this).trigger(event);
|
||||||
if (!event.isDefaultPrevented()) {
|
if (!event.isDefaultPrevented()) {
|
||||||
updateRelatedObjectLinks(this);
|
updateRelatedObjectLinks(this);
|
||||||
@ -149,7 +149,7 @@
|
|||||||
$('.related-widget-wrapper select').trigger('change');
|
$('.related-widget-wrapper select').trigger('change');
|
||||||
$('body').on('click', '.related-lookup', function(e) {
|
$('body').on('click', '.related-lookup', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var event = $.Event('django:lookup-related');
|
const event = $.Event('django:lookup-related');
|
||||||
$(this).trigger(event);
|
$(this).trigger(event);
|
||||||
if (!event.isDefaultPrevented()) {
|
if (!event.isDefaultPrevented()) {
|
||||||
showRelatedObjectLookupPopup(this);
|
showRelatedObjectLookupPopup(this);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
(function($) {
|
(function($) {
|
||||||
'use strict';
|
'use strict';
|
||||||
var init = function($element, options) {
|
const init = function($element, options) {
|
||||||
var settings = $.extend({
|
const settings = $.extend({
|
||||||
ajax: {
|
ajax: {
|
||||||
data: function(params) {
|
data: function(params) {
|
||||||
return {
|
return {
|
||||||
@ -15,9 +15,9 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
$.fn.djangoAdminSelect2 = function(options) {
|
$.fn.djangoAdminSelect2 = function(options) {
|
||||||
var settings = $.extend({}, options);
|
const settings = $.extend({}, options);
|
||||||
$.each(this, function(i, element) {
|
$.each(this, function(i, element) {
|
||||||
var $element = $(element);
|
const $element = $(element);
|
||||||
init($element, settings);
|
init($element, settings);
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
|
@ -7,7 +7,7 @@ depends on core.js for utility functions like removeChildren or quickElement
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
// CalendarNamespace -- Provides a collection of HTML calendar-related helper functions
|
// CalendarNamespace -- Provides a collection of HTML calendar-related helper functions
|
||||||
var CalendarNamespace = {
|
const CalendarNamespace = {
|
||||||
monthsOfYear: [
|
monthsOfYear: [
|
||||||
gettext('January'),
|
gettext('January'),
|
||||||
gettext('February'),
|
gettext('February'),
|
||||||
@ -36,7 +36,7 @@ depends on core.js for utility functions like removeChildren or quickElement
|
|||||||
return (((year % 4) === 0) && ((year % 100) !== 0 ) || ((year % 400) === 0));
|
return (((year % 4) === 0) && ((year % 100) !== 0 ) || ((year % 400) === 0));
|
||||||
},
|
},
|
||||||
getDaysInMonth: function(month, year) {
|
getDaysInMonth: function(month, year) {
|
||||||
var days;
|
let 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;
|
days = 31;
|
||||||
}
|
}
|
||||||
@ -52,11 +52,11 @@ depends on core.js for utility functions like removeChildren or quickElement
|
|||||||
return days;
|
return days;
|
||||||
},
|
},
|
||||||
draw: function(month, year, div_id, callback, selected) { // month = 1-12, year = 1-9999
|
draw: function(month, year, div_id, callback, selected) { // month = 1-12, year = 1-9999
|
||||||
var today = new Date();
|
const today = new Date();
|
||||||
var todayDay = today.getDate();
|
const todayDay = today.getDate();
|
||||||
var todayMonth = today.getMonth() + 1;
|
const todayMonth = today.getMonth() + 1;
|
||||||
var todayYear = today.getFullYear();
|
const todayYear = today.getFullYear();
|
||||||
var todayClass = '';
|
let todayClass = '';
|
||||||
|
|
||||||
// Use UTC functions here because the date field does not contain time
|
// Use UTC functions here because the date field does not contain time
|
||||||
// and using the UTC function variants prevent the local time offset
|
// and using the UTC function variants prevent the local time offset
|
||||||
@ -69,33 +69,33 @@ depends on core.js for utility functions like removeChildren or quickElement
|
|||||||
//
|
//
|
||||||
// The day variable above will be 1 instead of 2 in, say, US Pacific time
|
// The day variable above will be 1 instead of 2 in, say, US Pacific time
|
||||||
// zone.
|
// zone.
|
||||||
var isSelectedMonth = false;
|
let isSelectedMonth = false;
|
||||||
if (typeof selected !== 'undefined') {
|
if (typeof selected !== 'undefined') {
|
||||||
isSelectedMonth = (selected.getUTCFullYear() === year && (selected.getUTCMonth() + 1) === month);
|
isSelectedMonth = (selected.getUTCFullYear() === year && (selected.getUTCMonth() + 1) === month);
|
||||||
}
|
}
|
||||||
|
|
||||||
month = parseInt(month);
|
month = parseInt(month);
|
||||||
year = parseInt(year);
|
year = parseInt(year);
|
||||||
var calDiv = document.getElementById(div_id);
|
const calDiv = document.getElementById(div_id);
|
||||||
removeChildren(calDiv);
|
removeChildren(calDiv);
|
||||||
var calTable = document.createElement('table');
|
const calTable = document.createElement('table');
|
||||||
quickElement('caption', calTable, CalendarNamespace.monthsOfYear[month - 1] + ' ' + year);
|
quickElement('caption', calTable, CalendarNamespace.monthsOfYear[month - 1] + ' ' + year);
|
||||||
var tableBody = quickElement('tbody', calTable);
|
const tableBody = quickElement('tbody', calTable);
|
||||||
|
|
||||||
// Draw days-of-week header
|
// Draw days-of-week header
|
||||||
var tableRow = quickElement('tr', tableBody);
|
let tableRow = quickElement('tr', tableBody);
|
||||||
for (var i = 0; i < 7; i++) {
|
for (let i = 0; i < 7; i++) {
|
||||||
quickElement('th', tableRow, CalendarNamespace.daysOfWeek[(i + CalendarNamespace.firstDayOfWeek) % 7]);
|
quickElement('th', tableRow, CalendarNamespace.daysOfWeek[(i + CalendarNamespace.firstDayOfWeek) % 7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var startingPos = new Date(year, month - 1, 1 - CalendarNamespace.firstDayOfWeek).getDay();
|
const startingPos = new Date(year, month - 1, 1 - CalendarNamespace.firstDayOfWeek).getDay();
|
||||||
var days = CalendarNamespace.getDaysInMonth(month, year);
|
const days = CalendarNamespace.getDaysInMonth(month, year);
|
||||||
|
|
||||||
var nonDayCell;
|
let nonDayCell;
|
||||||
|
|
||||||
// Draw blanks before first of month
|
// Draw blanks before first of month
|
||||||
tableRow = quickElement('tr', tableBody);
|
tableRow = quickElement('tr', tableBody);
|
||||||
for (i = 0; i < startingPos; i++) {
|
for (let i = 0; i < startingPos; i++) {
|
||||||
nonDayCell = quickElement('td', tableRow, ' ');
|
nonDayCell = quickElement('td', tableRow, ' ');
|
||||||
nonDayCell.className = "nonday";
|
nonDayCell.className = "nonday";
|
||||||
}
|
}
|
||||||
@ -109,8 +109,8 @@ depends on core.js for utility functions like removeChildren or quickElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw days of month
|
// Draw days of month
|
||||||
var currentDay = 1;
|
let currentDay = 1;
|
||||||
for (i = startingPos; currentDay <= days; i++) {
|
for (let i = startingPos; currentDay <= days; i++) {
|
||||||
if (i % 7 === 0 && currentDay !== 1) {
|
if (i % 7 === 0 && currentDay !== 1) {
|
||||||
tableRow = quickElement('tr', tableBody);
|
tableRow = quickElement('tr', tableBody);
|
||||||
}
|
}
|
||||||
@ -128,8 +128,8 @@ depends on core.js for utility functions like removeChildren or quickElement
|
|||||||
todayClass += "selected";
|
todayClass += "selected";
|
||||||
}
|
}
|
||||||
|
|
||||||
var cell = quickElement('td', tableRow, '', 'class', todayClass);
|
const cell = quickElement('td', tableRow, '', 'class', todayClass);
|
||||||
var link = quickElement('a', cell, currentDay, 'href', '#');
|
const link = quickElement('a', cell, currentDay, 'href', '#');
|
||||||
link.addEventListener('click', calendarMonth(year, month));
|
link.addEventListener('click', calendarMonth(year, month));
|
||||||
currentDay++;
|
currentDay++;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var inputTags = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA'];
|
const inputTags = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA'];
|
||||||
var modelName = document.getElementById('django-admin-form-add-constants').dataset.modelName;
|
const modelName = document.getElementById('django-admin-form-add-constants').dataset.modelName;
|
||||||
if (modelName) {
|
if (modelName) {
|
||||||
var form = document.getElementById(modelName + '_form');
|
const form = document.getElementById(modelName + '_form');
|
||||||
for (var i = 0; i < form.elements.length; i++) {
|
for (let i = 0; i < form.elements.length; i++) {
|
||||||
var element = form.elements[i];
|
const element = form.elements[i];
|
||||||
// HTMLElement.offsetParent returns null when the element is not
|
// HTMLElement.offsetParent returns null when the element is not
|
||||||
// rendered.
|
// rendered.
|
||||||
if (inputTags.includes(element.tagName) && !element.disabled && element.offsetParent) {
|
if (inputTags.includes(element.tagName) && !element.disabled && element.offsetParent) {
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
window.addEventListener('load', function() {
|
window.addEventListener('load', function() {
|
||||||
// Add anchor tag for Show/Hide link
|
// Add anchor tag for Show/Hide link
|
||||||
var fieldsets = document.querySelectorAll('fieldset.collapse');
|
const fieldsets = document.querySelectorAll('fieldset.collapse');
|
||||||
for (var i = 0; i < fieldsets.length; i++) {
|
for (let i = 0; i < fieldsets.length; i++) {
|
||||||
var elem = fieldsets[i];
|
const elem = fieldsets[i];
|
||||||
// Don't hide if fields in this fieldset have errors
|
// Don't hide if fields in this fieldset have errors
|
||||||
if (elem.querySelectorAll('div.errors, ul.errorlist').length === 0) {
|
if (elem.querySelectorAll('div.errors, ul.errorlist').length === 0) {
|
||||||
elem.classList.add('collapsed');
|
elem.classList.add('collapsed');
|
||||||
var h2 = elem.querySelector('h2');
|
const h2 = elem.querySelector('h2');
|
||||||
var link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.id = 'fieldsetcollapser' + i;
|
link.id = 'fieldsetcollapser' + i;
|
||||||
link.className = 'collapse-toggle';
|
link.className = 'collapse-toggle';
|
||||||
link.href = '#';
|
link.href = '#';
|
||||||
@ -21,11 +21,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add toggle to hide/show anchor tag
|
// Add toggle to hide/show anchor tag
|
||||||
var toggleFunc = function(ev) {
|
const toggleFunc = function(ev) {
|
||||||
if (ev.target.matches('.collapse-toggle')) {
|
if (ev.target.matches('.collapse-toggle')) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
var fieldset = ev.target.closest('fieldset');
|
const fieldset = ev.target.closest('fieldset');
|
||||||
if (fieldset.classList.contains('collapsed')) {
|
if (fieldset.classList.contains('collapsed')) {
|
||||||
// Show
|
// Show
|
||||||
ev.target.textContent = gettext('Hide');
|
ev.target.textContent = gettext('Hide');
|
||||||
@ -37,8 +37,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var inlineDivs = document.querySelectorAll('fieldset.module');
|
const inlineDivs = document.querySelectorAll('fieldset.module');
|
||||||
for (i = 0; i < inlineDivs.length; i++) {
|
for (let i = 0; i < inlineDivs.length; i++) {
|
||||||
inlineDivs[i].addEventListener('click', toggleFunc);
|
inlineDivs[i].addEventListener('click', toggleFunc);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
(function(){window.addEventListener("load",function(){for(var d=document.querySelectorAll("fieldset.collapse"),b=0;b<d.length;b++){var a=d[b];if(0===a.querySelectorAll("div.errors, ul.errorlist").length){a.classList.add("collapsed");a=a.querySelector("h2");var c=document.createElement("a");c.id="fieldsetcollapser"+b;c.className="collapse-toggle";c.href="#";c.textContent=gettext("Show");a.appendChild(document.createTextNode(" ("));a.appendChild(c);a.appendChild(document.createTextNode(")"))}}d=function(a){if(a.target.matches(".collapse-toggle")){a.preventDefault();
|
'use strict';(function(){window.addEventListener("load",function(){var d=document.querySelectorAll("fieldset.collapse");for(var c=0;c<d.length;c++){var a=d[c];if(0===a.querySelectorAll("div.errors, ul.errorlist").length){a.classList.add("collapsed");a=a.querySelector("h2");const b=document.createElement("a");b.id="fieldsetcollapser"+c;b.className="collapse-toggle";b.href="#";b.textContent=gettext("Show");a.appendChild(document.createTextNode(" ("));a.appendChild(b);a.appendChild(document.createTextNode(")"))}}d=
|
||||||
a.stopPropagation();var b=a.target.closest("fieldset");b.classList.contains("collapsed")?(a.target.textContent=gettext("Hide"),b.classList.remove("collapsed")):(a.target.textContent=gettext("Show"),b.classList.add("collapsed"))}};a=document.querySelectorAll("fieldset.module");for(b=0;b<a.length;b++)a[b].addEventListener("click",d)})})();
|
function(b){if(b.target.matches(".collapse-toggle")){b.preventDefault();b.stopPropagation();const a=b.target.closest("fieldset");a.classList.contains("collapsed")?(b.target.textContent=gettext("Hide"),a.classList.remove("collapsed")):(b.target.textContent=gettext("Show"),a.classList.add("collapsed"))}};c=document.querySelectorAll("fieldset.module");for(a=0;a<c.length;a++)c[a].addEventListener("click",d)})})();
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
// quickElement(tagType, parentReference [, textInChildNode, attribute, attributeValue ...]);
|
// quickElement(tagType, parentReference [, textInChildNode, attribute, attributeValue ...]);
|
||||||
function quickElement() {
|
function quickElement() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var obj = document.createElement(arguments[0]);
|
const obj = document.createElement(arguments[0]);
|
||||||
if (arguments[2]) {
|
if (arguments[2]) {
|
||||||
var textNode = document.createTextNode(arguments[2]);
|
const textNode = document.createTextNode(arguments[2]);
|
||||||
obj.appendChild(textNode);
|
obj.appendChild(textNode);
|
||||||
}
|
}
|
||||||
var len = arguments.length;
|
const len = arguments.length;
|
||||||
for (var i = 3; i < len; i += 2) {
|
for (let i = 3; i < len; i += 2) {
|
||||||
obj.setAttribute(arguments[i], arguments[i + 1]);
|
obj.setAttribute(arguments[i], arguments[i + 1]);
|
||||||
}
|
}
|
||||||
arguments[1].appendChild(obj);
|
arguments[1].appendChild(obj);
|
||||||
@ -30,7 +30,7 @@ function removeChildren(a) {
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
function findPosX(obj) {
|
function findPosX(obj) {
|
||||||
'use strict';
|
'use strict';
|
||||||
var curleft = 0;
|
let curleft = 0;
|
||||||
if (obj.offsetParent) {
|
if (obj.offsetParent) {
|
||||||
while (obj.offsetParent) {
|
while (obj.offsetParent) {
|
||||||
curleft += obj.offsetLeft - obj.scrollLeft;
|
curleft += obj.offsetLeft - obj.scrollLeft;
|
||||||
@ -44,7 +44,7 @@ function findPosX(obj) {
|
|||||||
|
|
||||||
function findPosY(obj) {
|
function findPosY(obj) {
|
||||||
'use strict';
|
'use strict';
|
||||||
var curtop = 0;
|
let curtop = 0;
|
||||||
if (obj.offsetParent) {
|
if (obj.offsetParent) {
|
||||||
while (obj.offsetParent) {
|
while (obj.offsetParent) {
|
||||||
curtop += obj.offsetTop - obj.scrollTop;
|
curtop += obj.offsetTop - obj.scrollTop;
|
||||||
@ -96,7 +96,7 @@ function findPosY(obj) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Date.prototype.strftime = function(format) {
|
Date.prototype.strftime = function(format) {
|
||||||
var fields = {
|
const fields = {
|
||||||
B: this.getFullMonthName(),
|
B: this.getFullMonthName(),
|
||||||
c: this.toString(),
|
c: this.toString(),
|
||||||
d: this.getTwoDigitDate(),
|
d: this.getTwoDigitDate(),
|
||||||
@ -113,7 +113,7 @@ function findPosY(obj) {
|
|||||||
Y: '' + this.getFullYear(),
|
Y: '' + this.getFullYear(),
|
||||||
'%': '%'
|
'%': '%'
|
||||||
};
|
};
|
||||||
var result = '', i = 0;
|
let result = '', i = 0;
|
||||||
while (i < format.length) {
|
while (i < format.length) {
|
||||||
if (format.charAt(i) === '%') {
|
if (format.charAt(i) === '%') {
|
||||||
result = result + fields[format.charAt(i + 1)];
|
result = result + fields[format.charAt(i + 1)];
|
||||||
@ -131,10 +131,10 @@ function findPosY(obj) {
|
|||||||
// String object extensions
|
// String object extensions
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
String.prototype.strptime = function(format) {
|
String.prototype.strptime = function(format) {
|
||||||
var split_format = format.split(/[.\-/]/);
|
const split_format = format.split(/[.\-/]/);
|
||||||
var date = this.split(/[.\-/]/);
|
const date = this.split(/[.\-/]/);
|
||||||
var i = 0;
|
let i = 0;
|
||||||
var day, month, year;
|
let day, month, year;
|
||||||
while (i < split_format.length) {
|
while (i < split_format.length) {
|
||||||
switch (split_format[i]) {
|
switch (split_format[i]) {
|
||||||
case "%d":
|
case "%d":
|
||||||
|
@ -18,12 +18,12 @@
|
|||||||
(function($) {
|
(function($) {
|
||||||
'use strict';
|
'use strict';
|
||||||
$.fn.formset = function(opts) {
|
$.fn.formset = function(opts) {
|
||||||
var options = $.extend({}, $.fn.formset.defaults, opts);
|
const options = $.extend({}, $.fn.formset.defaults, opts);
|
||||||
var $this = $(this);
|
const $this = $(this);
|
||||||
var $parent = $this.parent();
|
const $parent = $this.parent();
|
||||||
var updateElementIndex = function(el, prefix, ndx) {
|
const updateElementIndex = function(el, prefix, ndx) {
|
||||||
var id_regex = new RegExp("(" + prefix + "-(\\d+|__prefix__))");
|
const id_regex = new RegExp("(" + prefix + "-(\\d+|__prefix__))");
|
||||||
var replacement = prefix + "-" + ndx;
|
const replacement = prefix + "-" + ndx;
|
||||||
if ($(el).prop("for")) {
|
if ($(el).prop("for")) {
|
||||||
$(el).prop("for", $(el).prop("for").replace(id_regex, replacement));
|
$(el).prop("for", $(el).prop("for").replace(id_regex, replacement));
|
||||||
}
|
}
|
||||||
@ -34,21 +34,21 @@
|
|||||||
el.name = el.name.replace(id_regex, replacement);
|
el.name = el.name.replace(id_regex, replacement);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS").prop("autocomplete", "off");
|
const totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS").prop("autocomplete", "off");
|
||||||
var nextIndex = parseInt(totalForms.val(), 10);
|
let nextIndex = parseInt(totalForms.val(), 10);
|
||||||
var maxForms = $("#id_" + options.prefix + "-MAX_NUM_FORMS").prop("autocomplete", "off");
|
const maxForms = $("#id_" + options.prefix + "-MAX_NUM_FORMS").prop("autocomplete", "off");
|
||||||
var minForms = $("#id_" + options.prefix + "-MIN_NUM_FORMS").prop("autocomplete", "off");
|
const minForms = $("#id_" + options.prefix + "-MIN_NUM_FORMS").prop("autocomplete", "off");
|
||||||
var addButton;
|
let addButton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The "Add another MyModel" button below the inline forms.
|
* The "Add another MyModel" button below the inline forms.
|
||||||
*/
|
*/
|
||||||
var addInlineAddButton = function() {
|
const addInlineAddButton = function() {
|
||||||
if (addButton === null) {
|
if (addButton === null) {
|
||||||
if ($this.prop("tagName") === "TR") {
|
if ($this.prop("tagName") === "TR") {
|
||||||
// If forms are laid out as table rows, insert the
|
// If forms are laid out as table rows, insert the
|
||||||
// "add" button in a new table row:
|
// "add" button in a new table row:
|
||||||
var numCols = $this.eq(-1).children().length;
|
const numCols = $this.eq(-1).children().length;
|
||||||
$parent.append('<tr class="' + options.addCssClass + '"><td colspan="' + numCols + '"><a href="#">' + options.addText + "</a></tr>");
|
$parent.append('<tr class="' + options.addCssClass + '"><td colspan="' + numCols + '"><a href="#">' + options.addText + "</a></tr>");
|
||||||
addButton = $parent.find("tr:last a");
|
addButton = $parent.find("tr:last a");
|
||||||
} else {
|
} else {
|
||||||
@ -60,10 +60,10 @@
|
|||||||
addButton.on('click', addInlineClickHandler);
|
addButton.on('click', addInlineClickHandler);
|
||||||
};
|
};
|
||||||
|
|
||||||
var addInlineClickHandler = function(e) {
|
const addInlineClickHandler = function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var template = $("#" + options.prefix + "-empty");
|
const template = $("#" + options.prefix + "-empty");
|
||||||
var row = template.clone(true);
|
const row = template.clone(true);
|
||||||
row.removeClass(options.emptyCssClass)
|
row.removeClass(options.emptyCssClass)
|
||||||
.addClass(options.formCssClass)
|
.addClass(options.formCssClass)
|
||||||
.attr("id", options.prefix + "-" + nextIndex);
|
.attr("id", options.prefix + "-" + nextIndex);
|
||||||
@ -94,7 +94,7 @@
|
|||||||
* The "X" button that is part of every unsaved inline.
|
* The "X" button that is part of every unsaved inline.
|
||||||
* (When saved, it is replaced with a "Delete" checkbox.)
|
* (When saved, it is replaced with a "Delete" checkbox.)
|
||||||
*/
|
*/
|
||||||
var addInlineDeleteButton = function(row) {
|
const addInlineDeleteButton = function(row) {
|
||||||
if (row.is("tr")) {
|
if (row.is("tr")) {
|
||||||
// If the forms are laid out in table rows, insert
|
// If the forms are laid out in table rows, insert
|
||||||
// the remove button into the last table cell:
|
// the remove button into the last table cell:
|
||||||
@ -112,14 +112,14 @@
|
|||||||
row.find("a." + options.deleteCssClass).on('click', inlineDeleteHandler.bind(this));
|
row.find("a." + options.deleteCssClass).on('click', inlineDeleteHandler.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
var inlineDeleteHandler = function(e1) {
|
const inlineDeleteHandler = function(e1) {
|
||||||
e1.preventDefault();
|
e1.preventDefault();
|
||||||
var deleteButton = $(e1.target);
|
const deleteButton = $(e1.target);
|
||||||
var row = deleteButton.closest('.' + options.formCssClass);
|
const row = deleteButton.closest('.' + options.formCssClass);
|
||||||
var inlineGroup = row.closest('.inline-group');
|
const inlineGroup = row.closest('.inline-group');
|
||||||
// Remove the parent form containing this button,
|
// Remove the parent form containing this button,
|
||||||
// and also remove the relevant row with non-field errors:
|
// and also remove the relevant row with non-field errors:
|
||||||
var prevRow = row.prev();
|
const prevRow = row.prev();
|
||||||
if (prevRow.length && prevRow.hasClass('row-form-errors')) {
|
if (prevRow.length && prevRow.hasClass('row-form-errors')) {
|
||||||
prevRow.remove();
|
prevRow.remove();
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@
|
|||||||
}
|
}
|
||||||
$(document).trigger('formset:removed', [row, options.prefix]);
|
$(document).trigger('formset:removed', [row, options.prefix]);
|
||||||
// Update the TOTAL_FORMS form count.
|
// Update the TOTAL_FORMS form count.
|
||||||
var forms = $("." + options.formCssClass);
|
const forms = $("." + options.formCssClass);
|
||||||
$("#id_" + options.prefix + "-TOTAL_FORMS").val(forms.length);
|
$("#id_" + options.prefix + "-TOTAL_FORMS").val(forms.length);
|
||||||
// Show add button again once below maximum number.
|
// Show add button again once below maximum number.
|
||||||
if ((maxForms.val() === '') || (maxForms.val() - forms.length) > 0) {
|
if ((maxForms.val() === '') || (maxForms.val() - forms.length) > 0) {
|
||||||
@ -141,8 +141,8 @@
|
|||||||
toggleDeleteButtonVisibility(inlineGroup);
|
toggleDeleteButtonVisibility(inlineGroup);
|
||||||
// Also, update names and ids for all remaining form controls so
|
// Also, update names and ids for all remaining form controls so
|
||||||
// they remain in sequence:
|
// they remain in sequence:
|
||||||
var i, formCount;
|
let i, formCount;
|
||||||
var updateElementCallback = function() {
|
const updateElementCallback = function() {
|
||||||
updateElementIndex(this, options.prefix, i);
|
updateElementIndex(this, options.prefix, i);
|
||||||
};
|
};
|
||||||
for (i = 0, formCount = forms.length; i < formCount; i++) {
|
for (i = 0, formCount = forms.length; i < formCount; i++) {
|
||||||
@ -151,7 +151,7 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var toggleDeleteButtonVisibility = function(inlineGroup) {
|
const toggleDeleteButtonVisibility = function(inlineGroup) {
|
||||||
if ((minForms.val() !== '') && (minForms.val() - totalForms.val()) >= 0) {
|
if ((minForms.val() !== '') && (minForms.val() - totalForms.val()) >= 0) {
|
||||||
inlineGroup.find('.inline-deletelink').hide();
|
inlineGroup.find('.inline-deletelink').hide();
|
||||||
} else {
|
} else {
|
||||||
@ -175,7 +175,7 @@
|
|||||||
|
|
||||||
// Show the add button if allowed to add more items.
|
// Show the add button if allowed to add more items.
|
||||||
// Note that max_num = None translates to a blank string.
|
// Note that max_num = None translates to a blank string.
|
||||||
var showAddButton = maxForms.val() === '' || (maxForms.val() - totalForms.val()) > 0;
|
const showAddButton = maxForms.val() === '' || (maxForms.val() - totalForms.val()) > 0;
|
||||||
if ($this.length && showAddButton) {
|
if ($this.length && showAddButton) {
|
||||||
addButton.parent().show();
|
addButton.parent().show();
|
||||||
} else {
|
} else {
|
||||||
@ -202,9 +202,9 @@
|
|||||||
|
|
||||||
// Tabular inlines ---------------------------------------------------------
|
// Tabular inlines ---------------------------------------------------------
|
||||||
$.fn.tabularFormset = function(selector, options) {
|
$.fn.tabularFormset = function(selector, options) {
|
||||||
var $rows = $(this);
|
const $rows = $(this);
|
||||||
|
|
||||||
var reinitDateTimeShortCuts = function() {
|
const reinitDateTimeShortCuts = function() {
|
||||||
// Reinitialize the calendar and clock widgets by force
|
// Reinitialize the calendar and clock widgets by force
|
||||||
if (typeof DateTimeShortcuts !== "undefined") {
|
if (typeof DateTimeShortcuts !== "undefined") {
|
||||||
$(".datetimeshortcuts").remove();
|
$(".datetimeshortcuts").remove();
|
||||||
@ -212,24 +212,24 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var updateSelectFilter = function() {
|
const updateSelectFilter = function() {
|
||||||
// If any SelectFilter widgets are a part of the new form,
|
// If any SelectFilter widgets are a part of the new form,
|
||||||
// instantiate a new SelectFilter instance for it.
|
// instantiate a new SelectFilter instance for it.
|
||||||
if (typeof SelectFilter !== 'undefined') {
|
if (typeof SelectFilter !== 'undefined') {
|
||||||
$('.selectfilter').each(function(index, value) {
|
$('.selectfilter').each(function(index, value) {
|
||||||
var namearr = value.name.split('-');
|
const namearr = value.name.split('-');
|
||||||
SelectFilter.init(value.id, namearr[namearr.length - 1], false);
|
SelectFilter.init(value.id, namearr[namearr.length - 1], false);
|
||||||
});
|
});
|
||||||
$('.selectfilterstacked').each(function(index, value) {
|
$('.selectfilterstacked').each(function(index, value) {
|
||||||
var namearr = value.name.split('-');
|
const namearr = value.name.split('-');
|
||||||
SelectFilter.init(value.id, namearr[namearr.length - 1], true);
|
SelectFilter.init(value.id, namearr[namearr.length - 1], true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var initPrepopulatedFields = function(row) {
|
const initPrepopulatedFields = function(row) {
|
||||||
row.find('.prepopulated_field').each(function() {
|
row.find('.prepopulated_field').each(function() {
|
||||||
var field = $(this),
|
const field = $(this),
|
||||||
input = field.find('input, select, textarea'),
|
input = field.find('input, select, textarea'),
|
||||||
dependency_list = input.data('dependency_list') || [],
|
dependency_list = input.data('dependency_list') || [],
|
||||||
dependencies = [];
|
dependencies = [];
|
||||||
@ -262,15 +262,15 @@
|
|||||||
|
|
||||||
// Stacked inlines ---------------------------------------------------------
|
// Stacked inlines ---------------------------------------------------------
|
||||||
$.fn.stackedFormset = function(selector, options) {
|
$.fn.stackedFormset = function(selector, options) {
|
||||||
var $rows = $(this);
|
const $rows = $(this);
|
||||||
var updateInlineLabel = function(row) {
|
const updateInlineLabel = function(row) {
|
||||||
$(selector).find(".inline_label").each(function(i) {
|
$(selector).find(".inline_label").each(function(i) {
|
||||||
var count = i + 1;
|
const count = i + 1;
|
||||||
$(this).html($(this).html().replace(/(#\d+)/g, "#" + count));
|
$(this).html($(this).html().replace(/(#\d+)/g, "#" + count));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var reinitDateTimeShortCuts = function() {
|
const reinitDateTimeShortCuts = function() {
|
||||||
// Reinitialize the calendar and clock widgets by force, yuck.
|
// Reinitialize the calendar and clock widgets by force, yuck.
|
||||||
if (typeof DateTimeShortcuts !== "undefined") {
|
if (typeof DateTimeShortcuts !== "undefined") {
|
||||||
$(".datetimeshortcuts").remove();
|
$(".datetimeshortcuts").remove();
|
||||||
@ -278,23 +278,23 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var updateSelectFilter = function() {
|
const updateSelectFilter = function() {
|
||||||
// If any SelectFilter widgets were added, instantiate a new instance.
|
// If any SelectFilter widgets were added, instantiate a new instance.
|
||||||
if (typeof SelectFilter !== "undefined") {
|
if (typeof SelectFilter !== "undefined") {
|
||||||
$(".selectfilter").each(function(index, value) {
|
$(".selectfilter").each(function(index, value) {
|
||||||
var namearr = value.name.split('-');
|
const namearr = value.name.split('-');
|
||||||
SelectFilter.init(value.id, namearr[namearr.length - 1], false);
|
SelectFilter.init(value.id, namearr[namearr.length - 1], false);
|
||||||
});
|
});
|
||||||
$(".selectfilterstacked").each(function(index, value) {
|
$(".selectfilterstacked").each(function(index, value) {
|
||||||
var namearr = value.name.split('-');
|
const namearr = value.name.split('-');
|
||||||
SelectFilter.init(value.id, namearr[namearr.length - 1], true);
|
SelectFilter.init(value.id, namearr[namearr.length - 1], true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var initPrepopulatedFields = function(row) {
|
const initPrepopulatedFields = function(row) {
|
||||||
row.find('.prepopulated_field').each(function() {
|
row.find('.prepopulated_field').each(function() {
|
||||||
var field = $(this),
|
const field = $(this),
|
||||||
input = field.find('input, select, textarea'),
|
input = field.find('input, select, textarea'),
|
||||||
dependency_list = input.data('dependency_list') || [],
|
dependency_list = input.data('dependency_list') || [],
|
||||||
dependencies = [];
|
dependencies = [];
|
||||||
@ -329,9 +329,9 @@
|
|||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$(".js-inline-admin-formset").each(function() {
|
$(".js-inline-admin-formset").each(function() {
|
||||||
var data = $(this).data(),
|
const data = $(this).data(),
|
||||||
inlineOptions = data.inlineFormset,
|
inlineOptions = data.inlineFormset;
|
||||||
selector;
|
let selector;
|
||||||
switch(data.inlineType) {
|
switch(data.inlineType) {
|
||||||
case "stacked":
|
case "stacked":
|
||||||
selector = inlineOptions.name + "-group .inline-related";
|
selector = inlineOptions.name + "-group .inline-related";
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
(function(b){b.fn.formset=function(c){var a=b.extend({},b.fn.formset.defaults,c),e=b(this),l=e.parent(),m=function(a,d,h){var g=new RegExp("("+d+"-(\\d+|__prefix__))");d=d+"-"+h;b(a).prop("for")&&b(a).prop("for",b(a).prop("for").replace(g,d));a.id&&(a.id=a.id.replace(g,d));a.name&&(a.name=a.name.replace(g,d))},f=b("#id_"+a.prefix+"-TOTAL_FORMS").prop("autocomplete","off"),n=parseInt(f.val(),10),h=b("#id_"+a.prefix+"-MAX_NUM_FORMS").prop("autocomplete","off"),q=b("#id_"+a.prefix+"-MIN_NUM_FORMS").prop("autocomplete",
|
'use strict';(function(b){b.fn.formset=function(c){const a=b.extend({},b.fn.formset.defaults,c),e=b(this),l=e.parent(),m=function(a,d,h){const g=new RegExp("("+d+"-(\\d+|__prefix__))");d=d+"-"+h;b(a).prop("for")&&b(a).prop("for",b(a).prop("for").replace(g,d));a.id&&(a.id=a.id.replace(g,d));a.name&&(a.name=a.name.replace(g,d))},f=b("#id_"+a.prefix+"-TOTAL_FORMS").prop("autocomplete","off");let n=parseInt(f.val(),10);const h=b("#id_"+a.prefix+"-MAX_NUM_FORMS").prop("autocomplete","off"),q=b("#id_"+
|
||||||
"off"),t=function(g){g.preventDefault();g=b("#"+a.prefix+"-empty");var d=g.clone(!0);d.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+n);r(d);d.find("*").each(function(){m(this,a.prefix,f.val())});d.insertBefore(b(g));b(f).val(parseInt(f.val(),10)+1);n+=1;""!==h.val()&&0>=h.val()-f.val()&&k.parent().hide();p(d.closest(".inline-group"));a.added&&a.added(d);b(document).trigger("formset:added",[d,a.prefix])},r=function(b){b.is("tr")?b.children(":last").append('<div><a class="'+
|
a.prefix+"-MIN_NUM_FORMS").prop("autocomplete","off");let k;const t=function(g){g.preventDefault();g=b("#"+a.prefix+"-empty");const d=g.clone(!0);d.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+n);r(d);d.find("*").each(function(){m(this,a.prefix,f.val())});d.insertBefore(b(g));b(f).val(parseInt(f.val(),10)+1);n+=1;""!==h.val()&&0>=h.val()-f.val()&&k.parent().hide();p(d.closest(".inline-group"));a.added&&a.added(d);b(document).trigger("formset:added",[d,a.prefix])},r=
|
||||||
a.deleteCssClass+'" href="#">'+a.deleteText+"</a></div>"):b.is("ul")||b.is("ol")?b.append('<li><a class="'+a.deleteCssClass+'" href="#">'+a.deleteText+"</a></li>"):b.children(":first").append('<span><a class="'+a.deleteCssClass+'" href="#">'+a.deleteText+"</a></span>");b.find("a."+a.deleteCssClass).on("click",u.bind(this))},u=function(g){g.preventDefault();var d=b(g.target).closest("."+a.formCssClass);g=d.closest(".inline-group");var f=d.prev();f.length&&f.hasClass("row-form-errors")&&f.remove();
|
function(b){b.is("tr")?b.children(":last").append('<div><a class="'+a.deleteCssClass+'" href="#">'+a.deleteText+"</a></div>"):b.is("ul")||b.is("ol")?b.append('<li><a class="'+a.deleteCssClass+'" href="#">'+a.deleteText+"</a></li>"):b.children(":first").append('<span><a class="'+a.deleteCssClass+'" href="#">'+a.deleteText+"</a></span>");b.find("a."+a.deleteCssClass).on("click",u.bind(this))},u=function(g){g.preventDefault();var d=b(g.target).closest("."+a.formCssClass);g=d.closest(".inline-group");
|
||||||
d.remove();--n;a.removed&&a.removed(d);b(document).trigger("formset:removed",[d,a.prefix]);d=b("."+a.formCssClass);b("#id_"+a.prefix+"-TOTAL_FORMS").val(d.length);(""===h.val()||0<h.val()-d.length)&&k.parent().show();p(g);f=function(){m(this,a.prefix,c)};var c=0;for(g=d.length;c<g;c++)m(b(d).get(c),a.prefix,c),b(d.get(c)).find("*").each(f)},p=function(a){""!==q.val()&&0<=q.val()-f.val()?a.find(".inline-deletelink").hide():a.find(".inline-deletelink").show()};e.each(function(c){b(this).not("."+a.emptyCssClass).addClass(a.formCssClass)});
|
var f=d.prev();f.length&&f.hasClass("row-form-errors")&&f.remove();d.remove();--n;a.removed&&a.removed(d);b(document).trigger("formset:removed",[d,a.prefix]);d=b("."+a.formCssClass);b("#id_"+a.prefix+"-TOTAL_FORMS").val(d.length);(""===h.val()||0<h.val()-d.length)&&k.parent().show();p(g);let c;f=function(){m(this,a.prefix,c)};c=0;for(g=d.length;c<g;c++)m(b(d).get(c),a.prefix,c),b(d.get(c)).find("*").each(f)},p=function(a){""!==q.val()&&0<=q.val()-f.val()?a.find(".inline-deletelink").hide():a.find(".inline-deletelink").show()};
|
||||||
e.filter("."+a.formCssClass+":not(.has_original):not(."+a.emptyCssClass+")").each(function(){r(b(this))});p(e);var k=a.addButton;(function(){if(null===k)if("TR"===e.prop("tagName")){var b=e.eq(-1).children().length;l.append('<tr class="'+a.addCssClass+'"><td colspan="'+b+'"><a href="#">'+a.addText+"</a></tr>");k=l.find("tr:last a")}else e.filter(":last").after('<div class="'+a.addCssClass+'"><a href="#">'+a.addText+"</a></div>"),k=e.filter(":last").next().find("a");k.on("click",t)})();c=""===h.val()||
|
e.each(function(c){b(this).not("."+a.emptyCssClass).addClass(a.formCssClass)});e.filter("."+a.formCssClass+":not(.has_original):not(."+a.emptyCssClass+")").each(function(){r(b(this))});p(e);k=a.addButton;(function(){if(null===k)if("TR"===e.prop("tagName")){const b=e.eq(-1).children().length;l.append('<tr class="'+a.addCssClass+'"><td colspan="'+b+'"><a href="#">'+a.addText+"</a></tr>");k=l.find("tr:last a")}else e.filter(":last").after('<div class="'+a.addCssClass+'"><a href="#">'+a.addText+"</a></div>"),
|
||||||
0<h.val()-f.val();e.length&&c?k.parent().show():k.parent().hide();return this};b.fn.formset.defaults={prefix:"form",addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null,addButton:null};b.fn.tabularFormset=function(c,a){c=b(this);var e=function(){"undefined"!==typeof SelectFilter&&(b(".selectfilter").each(function(a,b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!1)}),b(".selectfilterstacked").each(function(a,
|
k=e.filter(":last").next().find("a");k.on("click",t)})();c=""===h.val()||0<h.val()-f.val();e.length&&c?k.parent().show():k.parent().hide();return this};b.fn.formset.defaults={prefix:"form",addText:"add another",deleteText:"remove",addCssClass:"add-row",deleteCssClass:"delete-row",emptyCssClass:"empty-row",formCssClass:"dynamic-form",added:null,removed:null,addButton:null};b.fn.tabularFormset=function(c,a){c=b(this);const e=function(){"undefined"!==typeof SelectFilter&&(b(".selectfilter").each(function(a,
|
||||||
b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!0)}))},l=function(a){a.find(".prepopulated_field").each(function(){var c=b(this).find("input, select, textarea"),n=c.data("dependency_list")||[],h=[];b.each(n,function(b,c){h.push("#"+a.find(".field-"+c).find("input, select, textarea").attr("id"))});h.length&&c.prepopulate(h,c.attr("maxlength"))})};c.formset({prefix:a.prefix,addText:a.addText,formCssClass:"dynamic-"+a.prefix,deleteCssClass:"inline-deletelink",deleteText:a.deleteText,emptyCssClass:"empty-form",
|
b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!1)}),b(".selectfilterstacked").each(function(a,b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!0)}))},l=function(a){a.find(".prepopulated_field").each(function(){const c=b(this).find("input, select, textarea"),n=c.data("dependency_list")||[],h=[];b.each(n,function(b,c){h.push("#"+a.find(".field-"+c).find("input, select, textarea").attr("id"))});h.length&&c.prepopulate(h,c.attr("maxlength"))})};c.formset({prefix:a.prefix,addText:a.addText,
|
||||||
added:function(a){l(a);"undefined"!==typeof DateTimeShortcuts&&(b(".datetimeshortcuts").remove(),DateTimeShortcuts.init());e()},addButton:a.addButton});return c};b.fn.stackedFormset=function(c,a){var e=b(this),l=function(a){b(c).find(".inline_label").each(function(a){a+=1;b(this).html(b(this).html().replace(/(#\d+)/g,"#"+a))})},m=function(){"undefined"!==typeof SelectFilter&&(b(".selectfilter").each(function(a,b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!1)}),b(".selectfilterstacked").each(function(a,
|
formCssClass:"dynamic-"+a.prefix,deleteCssClass:"inline-deletelink",deleteText:a.deleteText,emptyCssClass:"empty-form",added:function(a){l(a);"undefined"!==typeof DateTimeShortcuts&&(b(".datetimeshortcuts").remove(),DateTimeShortcuts.init());e()},addButton:a.addButton});return c};b.fn.stackedFormset=function(c,a){const e=b(this),l=function(a){b(c).find(".inline_label").each(function(a){a+=1;b(this).html(b(this).html().replace(/(#\d+)/g,"#"+a))})},m=function(){"undefined"!==typeof SelectFilter&&(b(".selectfilter").each(function(a,
|
||||||
b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!0)}))},f=function(a){a.find(".prepopulated_field").each(function(){var c=b(this).find("input, select, textarea"),f=c.data("dependency_list")||[],e=[];b.each(f,function(b,c){e.push("#"+a.find(".form-row .field-"+c).find("input, select, textarea").attr("id"))});e.length&&c.prepopulate(e,c.attr("maxlength"))})};e.formset({prefix:a.prefix,addText:a.addText,formCssClass:"dynamic-"+a.prefix,deleteCssClass:"inline-deletelink",deleteText:a.deleteText,
|
b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!1)}),b(".selectfilterstacked").each(function(a,b){a=b.name.split("-");SelectFilter.init(b.id,a[a.length-1],!0)}))},f=function(a){a.find(".prepopulated_field").each(function(){const c=b(this).find("input, select, textarea"),f=c.data("dependency_list")||[],e=[];b.each(f,function(b,c){e.push("#"+a.find(".form-row .field-"+c).find("input, select, textarea").attr("id"))});e.length&&c.prepopulate(e,c.attr("maxlength"))})};e.formset({prefix:a.prefix,
|
||||||
emptyCssClass:"empty-form",removed:l,added:function(a){f(a);"undefined"!==typeof DateTimeShortcuts&&(b(".datetimeshortcuts").remove(),DateTimeShortcuts.init());m();l(a)},addButton:a.addButton});return e};b(document).ready(function(){b(".js-inline-admin-formset").each(function(){var c=b(this).data(),a=c.inlineFormset;switch(c.inlineType){case "stacked":c=a.name+"-group .inline-related";b(c).stackedFormset(c,a.options);break;case "tabular":c=a.name+"-group .tabular.inline-related tbody:first > tr.form-row",
|
addText:a.addText,formCssClass:"dynamic-"+a.prefix,deleteCssClass:"inline-deletelink",deleteText:a.deleteText,emptyCssClass:"empty-form",removed:l,added:function(a){f(a);"undefined"!==typeof DateTimeShortcuts&&(b(".datetimeshortcuts").remove(),DateTimeShortcuts.init());m();l(a)},addButton:a.addButton});return e};b(document).ready(function(){b(".js-inline-admin-formset").each(function(){var c=b(this).data();const a=c.inlineFormset;switch(c.inlineType){case "stacked":c=a.name+"-group .inline-related";
|
||||||
b(c).tabularFormset(c,a.options)}})})})(django.jQuery);
|
b(c).stackedFormset(c,a.options);break;case "tabular":c=a.name+"-group .tabular.inline-related tbody:first > tr.form-row",b(c).tabularFormset(c,a.options)}})})})(django.jQuery);
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
/*global django:true, jQuery:false*/
|
/*global jQuery:false*/
|
||||||
/* Puts the included jQuery into our own namespace using noConflict and passing
|
/* Puts the included jQuery into our own namespace using noConflict and passing
|
||||||
* it 'true'. This ensures that the included jQuery doesn't pollute the global
|
* it 'true'. This ensures that the included jQuery doesn't pollute the global
|
||||||
* namespace (i.e. this preserves pre-existing values for both window.$ and
|
* namespace (i.e. this preserves pre-existing values for both window.$ and
|
||||||
* window.jQuery).
|
* window.jQuery).
|
||||||
*/
|
*/
|
||||||
var django = django || {};
|
window.django = {jQuery: jQuery.noConflict(true)};
|
||||||
django.jQuery = jQuery.noConflict(true);
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*global opener */
|
/*global opener */
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse);
|
const initData = JSON.parse(document.getElementById('django-admin-popup-response-constants').dataset.popupResponse);
|
||||||
switch(initData.action) {
|
switch(initData.action) {
|
||||||
case 'change':
|
case 'change':
|
||||||
opener.dismissChangeRelatedObjectPopup(window, initData.value, initData.obj, initData.new_value);
|
opener.dismissChangeRelatedObjectPopup(window, initData.value, initData.obj, initData.new_value);
|
||||||
|
@ -11,15 +11,15 @@
|
|||||||
allowUnicode - Unicode support of the URLify'd string
|
allowUnicode - Unicode support of the URLify'd string
|
||||||
*/
|
*/
|
||||||
return this.each(function() {
|
return this.each(function() {
|
||||||
var prepopulatedField = $(this);
|
const prepopulatedField = $(this);
|
||||||
|
|
||||||
var populate = function() {
|
const populate = function() {
|
||||||
// Bail if the field's value has been changed by the user
|
// Bail if the field's value has been changed by the user
|
||||||
if (prepopulatedField.data('_changed')) {
|
if (prepopulatedField.data('_changed')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var values = [];
|
const values = [];
|
||||||
$.each(dependencies, function(i, field) {
|
$.each(dependencies, function(i, field) {
|
||||||
field = $(field);
|
field = $(field);
|
||||||
if (field.val().length > 0) {
|
if (field.val().length > 0) {
|
||||||
|
@ -1 +1 @@
|
|||||||
(function(b){b.fn.prepopulate=function(d,f,g){return this.each(function(){var a=b(this),h=function(){if(!a.data("_changed")){var e=[];b.each(d,function(a,c){c=b(c);0<c.val().length&&e.push(c.val())});a.val(URLify(e.join(" "),f,g))}};a.data("_changed",!1);a.on("change",function(){a.data("_changed",!0)});if(!a.val())b(d.join(",")).on("keyup change focus",h)})}})(django.jQuery);
|
'use strict';(function(b){b.fn.prepopulate=function(d,f,g){return this.each(function(){const a=b(this),h=function(){if(!a.data("_changed")){var e=[];b.each(d,function(a,c){c=b(c);0<c.val().length&&e.push(c.val())});a.val(URLify(e.join(" "),f,g))}};a.data("_changed",!1);a.on("change",function(){a.data("_changed",!0)});if(!a.val())b(d.join(",")).on("keyup change focus",h)})}})(django.jQuery);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
(function($) {
|
(function($) {
|
||||||
'use strict';
|
'use strict';
|
||||||
var fields = $('#django-admin-prepopulated-fields-constants').data('prepopulatedFields');
|
const fields = $('#django-admin-prepopulated-fields-constants').data('prepopulatedFields');
|
||||||
$.each(fields, function(index, field) {
|
$.each(fields, function(index, field) {
|
||||||
$('.empty-form .form-row .field-' + field.name + ', .empty-form.form-row .field-' + field.name).addClass('prepopulated_field');
|
$('.empty-form .form-row .field-' + field.name + ', .empty-form.form-row .field-' + field.name).addClass('prepopulated_field');
|
||||||
$(field.id).data('dependency_list', field.dependency_list).prepopulate(
|
$(field.id).data('dependency_list', field.dependency_list).prepopulate(
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var LATIN_MAP = {
|
const LATIN_MAP = {
|
||||||
'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE',
|
'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE',
|
||||||
'Ç': 'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I',
|
'Ç': 'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I',
|
||||||
'Î': 'I', 'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O',
|
'Î': 'I', 'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O',
|
||||||
@ -14,10 +14,10 @@
|
|||||||
'ö': 'o', 'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u',
|
'ö': 'o', 'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u',
|
||||||
'ű': 'u', 'ý': 'y', 'þ': 'th', 'ÿ': 'y'
|
'ű': 'u', 'ý': 'y', 'þ': 'th', 'ÿ': 'y'
|
||||||
};
|
};
|
||||||
var LATIN_SYMBOLS_MAP = {
|
const LATIN_SYMBOLS_MAP = {
|
||||||
'©': '(c)'
|
'©': '(c)'
|
||||||
};
|
};
|
||||||
var GREEK_MAP = {
|
const GREEK_MAP = {
|
||||||
'α': 'a', 'β': 'b', 'γ': 'g', 'δ': 'd', 'ε': 'e', 'ζ': 'z', 'η': 'h',
|
'α': 'a', 'β': 'b', 'γ': 'g', 'δ': 'd', 'ε': 'e', 'ζ': 'z', 'η': 'h',
|
||||||
'θ': '8', 'ι': 'i', 'κ': 'k', 'λ': 'l', 'μ': 'm', 'ν': 'n', 'ξ': '3',
|
'θ': '8', 'ι': 'i', 'κ': 'k', 'λ': 'l', 'μ': 'm', 'ν': 'n', 'ξ': '3',
|
||||||
'ο': 'o', 'π': 'p', 'ρ': 'r', 'σ': 's', 'τ': 't', 'υ': 'y', 'φ': 'f',
|
'ο': 'o', 'π': 'p', 'ρ': 'r', 'σ': 's', 'τ': 't', 'υ': 'y', 'φ': 'f',
|
||||||
@ -29,15 +29,15 @@
|
|||||||
'Φ': 'F', 'Χ': 'X', 'Ψ': 'PS', 'Ω': 'W', 'Ά': 'A', 'Έ': 'E', 'Ί': 'I',
|
'Φ': 'F', 'Χ': 'X', 'Ψ': 'PS', 'Ω': 'W', 'Ά': 'A', 'Έ': 'E', 'Ί': 'I',
|
||||||
'Ό': 'O', 'Ύ': 'Y', 'Ή': 'H', 'Ώ': 'W', 'Ϊ': 'I', 'Ϋ': 'Y'
|
'Ό': 'O', 'Ύ': 'Y', 'Ή': 'H', 'Ώ': 'W', 'Ϊ': 'I', 'Ϋ': 'Y'
|
||||||
};
|
};
|
||||||
var TURKISH_MAP = {
|
const TURKISH_MAP = {
|
||||||
'ş': 's', 'Ş': 'S', 'ı': 'i', 'İ': 'I', 'ç': 'c', 'Ç': 'C', 'ü': 'u',
|
'ş': 's', 'Ş': 'S', 'ı': 'i', 'İ': 'I', 'ç': 'c', 'Ç': 'C', 'ü': 'u',
|
||||||
'Ü': 'U', 'ö': 'o', 'Ö': 'O', 'ğ': 'g', 'Ğ': 'G'
|
'Ü': 'U', 'ö': 'o', 'Ö': 'O', 'ğ': 'g', 'Ğ': 'G'
|
||||||
};
|
};
|
||||||
var ROMANIAN_MAP = {
|
const ROMANIAN_MAP = {
|
||||||
'ă': 'a', 'î': 'i', 'ș': 's', 'ț': 't', 'â': 'a',
|
'ă': 'a', 'î': 'i', 'ș': 's', 'ț': 't', 'â': 'a',
|
||||||
'Ă': 'A', 'Î': 'I', 'Ș': 'S', 'Ț': 'T', 'Â': 'A'
|
'Ă': 'A', 'Î': 'I', 'Ș': 'S', 'Ț': 'T', 'Â': 'A'
|
||||||
};
|
};
|
||||||
var RUSSIAN_MAP = {
|
const RUSSIAN_MAP = {
|
||||||
'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'yo',
|
'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'yo',
|
||||||
'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'j', 'к': 'k', 'л': 'l', 'м': 'm',
|
'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'j', 'к': 'k', 'л': 'l', 'м': 'm',
|
||||||
'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
|
'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
|
||||||
@ -49,16 +49,16 @@
|
|||||||
'Ф': 'F', 'Х': 'H', 'Ц': 'C', 'Ч': 'Ch', 'Ш': 'Sh', 'Щ': 'Sh', 'Ъ': '',
|
'Ф': 'F', 'Х': 'H', 'Ц': 'C', 'Ч': 'Ch', 'Ш': 'Sh', 'Щ': 'Sh', 'Ъ': '',
|
||||||
'Ы': 'Y', 'Ь': '', 'Э': 'E', 'Ю': 'Yu', 'Я': 'Ya'
|
'Ы': 'Y', 'Ь': '', 'Э': 'E', 'Ю': 'Yu', 'Я': 'Ya'
|
||||||
};
|
};
|
||||||
var UKRAINIAN_MAP = {
|
const UKRAINIAN_MAP = {
|
||||||
'Є': 'Ye', 'І': 'I', 'Ї': 'Yi', 'Ґ': 'G', 'є': 'ye', 'і': 'i',
|
'Є': 'Ye', 'І': 'I', 'Ї': 'Yi', 'Ґ': 'G', 'є': 'ye', 'і': 'i',
|
||||||
'ї': 'yi', 'ґ': 'g'
|
'ї': 'yi', 'ґ': 'g'
|
||||||
};
|
};
|
||||||
var CZECH_MAP = {
|
const CZECH_MAP = {
|
||||||
'č': 'c', 'ď': 'd', 'ě': 'e', 'ň': 'n', 'ř': 'r', 'š': 's', 'ť': 't',
|
'č': 'c', 'ď': 'd', 'ě': 'e', 'ň': 'n', 'ř': 'r', 'š': 's', 'ť': 't',
|
||||||
'ů': 'u', 'ž': 'z', 'Č': 'C', 'Ď': 'D', 'Ě': 'E', 'Ň': 'N', 'Ř': 'R',
|
'ů': 'u', 'ž': 'z', 'Č': 'C', 'Ď': 'D', 'Ě': 'E', 'Ň': 'N', 'Ř': 'R',
|
||||||
'Š': 'S', 'Ť': 'T', 'Ů': 'U', 'Ž': 'Z'
|
'Š': 'S', 'Ť': 'T', 'Ů': 'U', 'Ž': 'Z'
|
||||||
};
|
};
|
||||||
var SLOVAK_MAP = {
|
const SLOVAK_MAP = {
|
||||||
'á': 'a', 'ä': 'a', 'č': 'c', 'ď': 'd', 'é': 'e', 'í': 'i', 'ľ': 'l',
|
'á': 'a', 'ä': 'a', 'č': 'c', 'ď': 'd', 'é': 'e', 'í': 'i', 'ľ': 'l',
|
||||||
'ĺ': 'l', 'ň': 'n', 'ó': 'o', 'ô': 'o', 'ŕ': 'r', 'š': 's', 'ť': 't',
|
'ĺ': 'l', 'ň': 'n', 'ó': 'o', 'ô': 'o', 'ŕ': 'r', 'š': 's', 'ť': 't',
|
||||||
'ú': 'u', 'ý': 'y', 'ž': 'z',
|
'ú': 'u', 'ý': 'y', 'ž': 'z',
|
||||||
@ -66,40 +66,40 @@
|
|||||||
'Ĺ': 'L', 'Ň': 'N', 'Ó': 'O', 'Ô': 'O', 'Ŕ': 'R', 'Š': 'S', 'Ť': 'T',
|
'Ĺ': 'L', 'Ň': 'N', 'Ó': 'O', 'Ô': 'O', 'Ŕ': 'R', 'Š': 'S', 'Ť': 'T',
|
||||||
'Ú': 'U', 'Ý': 'Y', 'Ž': 'Z'
|
'Ú': 'U', 'Ý': 'Y', 'Ž': 'Z'
|
||||||
};
|
};
|
||||||
var POLISH_MAP = {
|
const POLISH_MAP = {
|
||||||
'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', 'ó': 'o', 'ś': 's',
|
'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', 'ó': 'o', 'ś': 's',
|
||||||
'ź': 'z', 'ż': 'z',
|
'ź': 'z', 'ż': 'z',
|
||||||
'Ą': 'A', 'Ć': 'C', 'Ę': 'E', 'Ł': 'L', 'Ń': 'N', 'Ó': 'O', 'Ś': 'S',
|
'Ą': 'A', 'Ć': 'C', 'Ę': 'E', 'Ł': 'L', 'Ń': 'N', 'Ó': 'O', 'Ś': 'S',
|
||||||
'Ź': 'Z', 'Ż': 'Z'
|
'Ź': 'Z', 'Ż': 'Z'
|
||||||
};
|
};
|
||||||
var LATVIAN_MAP = {
|
const LATVIAN_MAP = {
|
||||||
'ā': 'a', 'č': 'c', 'ē': 'e', 'ģ': 'g', 'ī': 'i', 'ķ': 'k', 'ļ': 'l',
|
'ā': 'a', 'č': 'c', 'ē': 'e', 'ģ': 'g', 'ī': 'i', 'ķ': 'k', 'ļ': 'l',
|
||||||
'ņ': 'n', 'š': 's', 'ū': 'u', 'ž': 'z',
|
'ņ': 'n', 'š': 's', 'ū': 'u', 'ž': 'z',
|
||||||
'Ā': 'A', 'Č': 'C', 'Ē': 'E', 'Ģ': 'G', 'Ī': 'I', 'Ķ': 'K', 'Ļ': 'L',
|
'Ā': 'A', 'Č': 'C', 'Ē': 'E', 'Ģ': 'G', 'Ī': 'I', 'Ķ': 'K', 'Ļ': 'L',
|
||||||
'Ņ': 'N', 'Š': 'S', 'Ū': 'U', 'Ž': 'Z'
|
'Ņ': 'N', 'Š': 'S', 'Ū': 'U', 'Ž': 'Z'
|
||||||
};
|
};
|
||||||
var ARABIC_MAP = {
|
const ARABIC_MAP = {
|
||||||
'أ': 'a', 'ب': 'b', 'ت': 't', 'ث': 'th', 'ج': 'g', 'ح': 'h', 'خ': 'kh', 'د': 'd',
|
'أ': 'a', 'ب': 'b', 'ت': 't', 'ث': 'th', 'ج': 'g', 'ح': 'h', 'خ': 'kh', 'د': 'd',
|
||||||
'ذ': 'th', 'ر': 'r', 'ز': 'z', 'س': 's', 'ش': 'sh', 'ص': 's', 'ض': 'd', 'ط': 't',
|
'ذ': 'th', 'ر': 'r', 'ز': 'z', 'س': 's', 'ش': 'sh', 'ص': 's', 'ض': 'd', 'ط': 't',
|
||||||
'ظ': 'th', 'ع': 'aa', 'غ': 'gh', 'ف': 'f', 'ق': 'k', 'ك': 'k', 'ل': 'l', 'م': 'm',
|
'ظ': 'th', 'ع': 'aa', 'غ': 'gh', 'ف': 'f', 'ق': 'k', 'ك': 'k', 'ل': 'l', 'م': 'm',
|
||||||
'ن': 'n', 'ه': 'h', 'و': 'o', 'ي': 'y'
|
'ن': 'n', 'ه': 'h', 'و': 'o', 'ي': 'y'
|
||||||
};
|
};
|
||||||
var LITHUANIAN_MAP = {
|
const LITHUANIAN_MAP = {
|
||||||
'ą': 'a', 'č': 'c', 'ę': 'e', 'ė': 'e', 'į': 'i', 'š': 's', 'ų': 'u',
|
'ą': 'a', 'č': 'c', 'ę': 'e', 'ė': 'e', 'į': 'i', 'š': 's', 'ų': 'u',
|
||||||
'ū': 'u', 'ž': 'z',
|
'ū': 'u', 'ž': 'z',
|
||||||
'Ą': 'A', 'Č': 'C', 'Ę': 'E', 'Ė': 'E', 'Į': 'I', 'Š': 'S', 'Ų': 'U',
|
'Ą': 'A', 'Č': 'C', 'Ę': 'E', 'Ė': 'E', 'Į': 'I', 'Š': 'S', 'Ų': 'U',
|
||||||
'Ū': 'U', 'Ž': 'Z'
|
'Ū': 'U', 'Ž': 'Z'
|
||||||
};
|
};
|
||||||
var SERBIAN_MAP = {
|
const SERBIAN_MAP = {
|
||||||
'ђ': 'dj', 'ј': 'j', 'љ': 'lj', 'њ': 'nj', 'ћ': 'c', 'џ': 'dz',
|
'ђ': 'dj', 'ј': 'j', 'љ': 'lj', 'њ': 'nj', 'ћ': 'c', 'џ': 'dz',
|
||||||
'đ': 'dj', 'Ђ': 'Dj', 'Ј': 'j', 'Љ': 'Lj', 'Њ': 'Nj', 'Ћ': 'C',
|
'đ': 'dj', 'Ђ': 'Dj', 'Ј': 'j', 'Љ': 'Lj', 'Њ': 'Nj', 'Ћ': 'C',
|
||||||
'Џ': 'Dz', 'Đ': 'Dj'
|
'Џ': 'Dz', 'Đ': 'Dj'
|
||||||
};
|
};
|
||||||
var AZERBAIJANI_MAP = {
|
const AZERBAIJANI_MAP = {
|
||||||
'ç': 'c', 'ə': 'e', 'ğ': 'g', 'ı': 'i', 'ö': 'o', 'ş': 's', 'ü': 'u',
|
'ç': 'c', 'ə': 'e', 'ğ': 'g', 'ı': 'i', 'ö': 'o', 'ş': 's', 'ü': 'u',
|
||||||
'Ç': 'C', 'Ə': 'E', 'Ğ': 'G', 'İ': 'I', 'Ö': 'O', 'Ş': 'S', 'Ü': 'U'
|
'Ç': 'C', 'Ə': 'E', 'Ğ': 'G', 'İ': 'I', 'Ö': 'O', 'Ş': 'S', 'Ü': 'U'
|
||||||
};
|
};
|
||||||
var GEORGIAN_MAP = {
|
const GEORGIAN_MAP = {
|
||||||
'ა': 'a', 'ბ': 'b', 'გ': 'g', 'დ': 'd', 'ე': 'e', 'ვ': 'v', 'ზ': 'z',
|
'ა': 'a', 'ბ': 'b', 'გ': 'g', 'დ': 'd', 'ე': 'e', 'ვ': 'v', 'ზ': 'z',
|
||||||
'თ': 't', 'ი': 'i', 'კ': 'k', 'ლ': 'l', 'მ': 'm', 'ნ': 'n', 'ო': 'o',
|
'თ': 't', 'ი': 'i', 'კ': 'k', 'ლ': 'l', 'მ': 'm', 'ნ': 'n', 'ო': 'o',
|
||||||
'პ': 'p', 'ჟ': 'j', 'რ': 'r', 'ს': 's', 'ტ': 't', 'უ': 'u', 'ფ': 'f',
|
'პ': 'p', 'ჟ': 'j', 'რ': 'r', 'ს': 's', 'ტ': 't', 'უ': 'u', 'ფ': 'f',
|
||||||
@ -107,7 +107,7 @@
|
|||||||
'წ': 'w', 'ჭ': 'ch', 'ხ': 'x', 'ჯ': 'j', 'ჰ': 'h'
|
'წ': 'w', 'ჭ': 'ch', 'ხ': 'x', 'ჯ': 'j', 'ჰ': 'h'
|
||||||
};
|
};
|
||||||
|
|
||||||
var ALL_DOWNCODE_MAPS = [
|
const ALL_DOWNCODE_MAPS = [
|
||||||
LATIN_MAP,
|
LATIN_MAP,
|
||||||
LATIN_SYMBOLS_MAP,
|
LATIN_SYMBOLS_MAP,
|
||||||
GREEK_MAP,
|
GREEK_MAP,
|
||||||
@ -126,22 +126,22 @@
|
|||||||
GEORGIAN_MAP
|
GEORGIAN_MAP
|
||||||
];
|
];
|
||||||
|
|
||||||
var Downcoder = {
|
const Downcoder = {
|
||||||
'Initialize': function() {
|
'Initialize': function() {
|
||||||
if (Downcoder.map) { // already made
|
if (Downcoder.map) { // already made
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Downcoder.map = {};
|
Downcoder.map = {};
|
||||||
Downcoder.chars = [];
|
Downcoder.chars = [];
|
||||||
for (var i = 0; i < ALL_DOWNCODE_MAPS.length; i++) {
|
for (let i = 0; i < ALL_DOWNCODE_MAPS.length; i++) {
|
||||||
var lookup = ALL_DOWNCODE_MAPS[i];
|
const lookup = ALL_DOWNCODE_MAPS[i];
|
||||||
for (var c in lookup) {
|
for (const c in lookup) {
|
||||||
if (lookup.hasOwnProperty(c)) {
|
if (lookup.hasOwnProperty(c)) {
|
||||||
Downcoder.map[c] = lookup[c];
|
Downcoder.map[c] = lookup[c];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (var k in Downcoder.map) {
|
for (const k in Downcoder.map) {
|
||||||
if (Downcoder.map.hasOwnProperty(k)) {
|
if (Downcoder.map.hasOwnProperty(k)) {
|
||||||
Downcoder.chars.push(k);
|
Downcoder.chars.push(k);
|
||||||
}
|
}
|
||||||
@ -164,17 +164,17 @@
|
|||||||
if (!allowUnicode) {
|
if (!allowUnicode) {
|
||||||
s = downcode(s);
|
s = downcode(s);
|
||||||
}
|
}
|
||||||
var hasUnicodeChars = /[^\u0000-\u007f]/.test(s);
|
const hasUnicodeChars = /[^\u0000-\u007f]/.test(s);
|
||||||
// Remove English words only if the string contains ASCII (English)
|
// Remove English words only if the string contains ASCII (English)
|
||||||
// characters.
|
// characters.
|
||||||
if (!hasUnicodeChars) {
|
if (!hasUnicodeChars) {
|
||||||
var removeList = [
|
const removeList = [
|
||||||
"a", "an", "as", "at", "before", "but", "by", "for", "from",
|
"a", "an", "as", "at", "before", "but", "by", "for", "from",
|
||||||
"is", "in", "into", "like", "of", "off", "on", "onto", "per",
|
"is", "in", "into", "like", "of", "off", "on", "onto", "per",
|
||||||
"since", "than", "the", "this", "that", "to", "up", "via",
|
"since", "than", "the", "this", "that", "to", "up", "via",
|
||||||
"with"
|
"with"
|
||||||
];
|
];
|
||||||
var r = new RegExp('\\b(' + removeList.join('|') + ')\\b', 'gi');
|
const r = new RegExp('\\b(' + removeList.join('|') + ')\\b', 'gi');
|
||||||
s = s.replace(r, '');
|
s = s.replace(r, '');
|
||||||
}
|
}
|
||||||
s = s.toLowerCase(); // convert to lowercase
|
s = s.toLowerCase(); // convert to lowercase
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
/* global ol */
|
/* global ol */
|
||||||
|
|
||||||
var GeometryTypeControl = function(opt_options) {
|
function GeometryTypeControl(opt_options) {
|
||||||
'use strict';
|
'use strict';
|
||||||
// Map control to switch type when geometry type is unknown
|
// Map control to switch type when geometry type is unknown
|
||||||
var options = opt_options || {};
|
const options = opt_options || {};
|
||||||
|
|
||||||
var element = document.createElement('div');
|
const element = document.createElement('div');
|
||||||
element.className = 'switch-type type-' + options.type + ' ol-control ol-unselectable';
|
element.className = 'switch-type type-' + options.type + ' ol-control ol-unselectable';
|
||||||
if (options.active) {
|
if (options.active) {
|
||||||
element.classList.add("type-active");
|
element.classList.add("type-active");
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
const self = this;
|
||||||
var switchType = function(e) {
|
const switchType = function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (options.widget.currentGeometryType !== self) {
|
if (options.widget.currentGeometryType !== self) {
|
||||||
options.widget.map.removeInteraction(options.widget.interactions.draw);
|
options.widget.map.removeInteraction(options.widget.interactions.draw);
|
||||||
@ -39,7 +39,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
|
|||||||
// TODO: allow deleting individual features (#8972)
|
// TODO: allow deleting individual features (#8972)
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var jsonFormat = new ol.format.GeoJSON();
|
const jsonFormat = new ol.format.GeoJSON();
|
||||||
|
|
||||||
function MapWidget(options) {
|
function MapWidget(options) {
|
||||||
this.map = null;
|
this.map = null;
|
||||||
@ -56,7 +56,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Altering using user-provided options
|
// Altering using user-provided options
|
||||||
for (var property in options) {
|
for (const property in options) {
|
||||||
if (options.hasOwnProperty(property)) {
|
if (options.hasOwnProperty(property)) {
|
||||||
this.options[property] = options[property];
|
this.options[property] = options[property];
|
||||||
}
|
}
|
||||||
@ -78,9 +78,9 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Populate and set handlers for the feature container
|
// Populate and set handlers for the feature container
|
||||||
var self = this;
|
const self = this;
|
||||||
this.featureCollection.on('add', function(event) {
|
this.featureCollection.on('add', function(event) {
|
||||||
var feature = event.element;
|
const feature = event.element;
|
||||||
feature.on('change', function() {
|
feature.on('change', function() {
|
||||||
self.serializeFeatures();
|
self.serializeFeatures();
|
||||||
});
|
});
|
||||||
@ -92,10 +92,10 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var initial_value = document.getElementById(this.options.id).value;
|
const initial_value = document.getElementById(this.options.id).value;
|
||||||
if (initial_value) {
|
if (initial_value) {
|
||||||
var features = jsonFormat.readFeatures('{"type": "Feature", "geometry": ' + initial_value + '}');
|
const features = jsonFormat.readFeatures('{"type": "Feature", "geometry": ' + initial_value + '}');
|
||||||
var extent = ol.extent.createEmpty();
|
const extent = ol.extent.createEmpty();
|
||||||
features.forEach(function(feature) {
|
features.forEach(function(feature) {
|
||||||
this.featureOverlay.getSource().addFeature(feature);
|
this.featureOverlay.getSource().addFeature(feature);
|
||||||
ol.extent.extend(extent, feature.getGeometry().getExtent());
|
ol.extent.extend(extent, feature.getGeometry().getExtent());
|
||||||
@ -113,7 +113,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
|
|||||||
}
|
}
|
||||||
|
|
||||||
MapWidget.prototype.createMap = function() {
|
MapWidget.prototype.createMap = function() {
|
||||||
var map = new ol.Map({
|
const map = new ol.Map({
|
||||||
target: this.options.map_id,
|
target: this.options.map_id,
|
||||||
layers: [this.options.base_layer],
|
layers: [this.options.base_layer],
|
||||||
view: new ol.View({
|
view: new ol.View({
|
||||||
@ -134,7 +134,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Initialize the draw interaction
|
// Initialize the draw interaction
|
||||||
var geomType = this.options.geom_name;
|
let geomType = this.options.geom_name;
|
||||||
if (geomType === "Unknown" || geomType === "GeometryCollection") {
|
if (geomType === "Unknown" || geomType === "GeometryCollection") {
|
||||||
// Default to Point, but create icons to switch type
|
// Default to Point, but create icons to switch type
|
||||||
geomType = "Point";
|
geomType = "Point";
|
||||||
@ -154,7 +154,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
|
|||||||
};
|
};
|
||||||
|
|
||||||
MapWidget.prototype.defaultCenter = function() {
|
MapWidget.prototype.defaultCenter = function() {
|
||||||
var center = [this.options.default_lon, this.options.default_lat];
|
const center = [this.options.default_lon, this.options.default_lat];
|
||||||
if (this.options.map_srid) {
|
if (this.options.map_srid) {
|
||||||
return ol.proj.transform(center, 'EPSG:4326', this.map.getView().getProjection());
|
return ol.proj.transform(center, 'EPSG:4326', this.map.getView().getProjection());
|
||||||
}
|
}
|
||||||
@ -165,8 +165,8 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
|
|||||||
this.interactions.draw.setActive(true);
|
this.interactions.draw.setActive(true);
|
||||||
if (this.typeChoices) {
|
if (this.typeChoices) {
|
||||||
// Show geometry type icons
|
// Show geometry type icons
|
||||||
var divs = document.getElementsByClassName("switch-type");
|
const divs = document.getElementsByClassName("switch-type");
|
||||||
for (var i = 0; i !== divs.length; i++) {
|
for (let i = 0; i !== divs.length; i++) {
|
||||||
divs[i].style.visibility = "visible";
|
divs[i].style.visibility = "visible";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,8 +177,8 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
|
|||||||
this.interactions.draw.setActive(false);
|
this.interactions.draw.setActive(false);
|
||||||
if (this.typeChoices) {
|
if (this.typeChoices) {
|
||||||
// Hide geometry type icons
|
// Hide geometry type icons
|
||||||
var divs = document.getElementsByClassName("switch-type");
|
const divs = document.getElementsByClassName("switch-type");
|
||||||
for (var i = 0; i !== divs.length; i++) {
|
for (let i = 0; i !== divs.length; i++) {
|
||||||
divs[i].style.visibility = "hidden";
|
divs[i].style.visibility = "hidden";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,18 +194,18 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
|
|||||||
|
|
||||||
MapWidget.prototype.serializeFeatures = function() {
|
MapWidget.prototype.serializeFeatures = function() {
|
||||||
// Three use cases: GeometryCollection, multigeometries, and single geometry
|
// Three use cases: GeometryCollection, multigeometries, and single geometry
|
||||||
var geometry = null;
|
let geometry = null;
|
||||||
var features = this.featureOverlay.getSource().getFeatures();
|
const features = this.featureOverlay.getSource().getFeatures();
|
||||||
if (this.options.is_collection) {
|
if (this.options.is_collection) {
|
||||||
if (this.options.geom_name === "GeometryCollection") {
|
if (this.options.geom_name === "GeometryCollection") {
|
||||||
var geometries = [];
|
const geometries = [];
|
||||||
for (var i = 0; i < features.length; i++) {
|
for (let i = 0; i < features.length; i++) {
|
||||||
geometries.push(features[i].getGeometry());
|
geometries.push(features[i].getGeometry());
|
||||||
}
|
}
|
||||||
geometry = new ol.geom.GeometryCollection(geometries);
|
geometry = new ol.geom.GeometryCollection(geometries);
|
||||||
} else {
|
} else {
|
||||||
geometry = features[0].getGeometry().clone();
|
geometry = features[0].getGeometry().clone();
|
||||||
for (var j = 1; j < features.length; j++) {
|
for (let j = 1; j < features.length; j++) {
|
||||||
switch (geometry.getType()) {
|
switch (geometry.getType()) {
|
||||||
case "MultiPoint":
|
case "MultiPoint":
|
||||||
geometry.appendPoint(features[j].getGeometry().getPoint(0));
|
geometry.appendPoint(features[j].getGeometry().getPoint(0));
|
||||||
|
@ -5,14 +5,14 @@
|
|||||||
QUnit.module('admin.DateTimeShortcuts');
|
QUnit.module('admin.DateTimeShortcuts');
|
||||||
|
|
||||||
QUnit.test('init', function(assert) {
|
QUnit.test('init', function(assert) {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
|
|
||||||
var dateField = $('<input type="text" class="vDateField" value="2015-03-16"><br>');
|
const dateField = $('<input type="text" class="vDateField" value="2015-03-16"><br>');
|
||||||
$('#qunit-fixture').append(dateField);
|
$('#qunit-fixture').append(dateField);
|
||||||
|
|
||||||
DateTimeShortcuts.init();
|
DateTimeShortcuts.init();
|
||||||
|
|
||||||
var shortcuts = $('.datetimeshortcuts');
|
const shortcuts = $('.datetimeshortcuts');
|
||||||
assert.equal(shortcuts.length, 1);
|
assert.equal(shortcuts.length, 1);
|
||||||
assert.equal(shortcuts.find('a:first').text(), 'Today');
|
assert.equal(shortcuts.find('a:first').text(), 'Today');
|
||||||
assert.equal(shortcuts.find('a:last .date-icon').length, 1);
|
assert.equal(shortcuts.find('a:last .date-icon').length, 1);
|
||||||
@ -23,8 +23,8 @@ QUnit.test('init', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('custom time shortcuts', function(assert) {
|
QUnit.test('custom time shortcuts', function(assert) {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
var timeField = $('<input type="text" name="time_test" class="vTimeField">');
|
const timeField = $('<input type="text" name="time_test" class="vTimeField">');
|
||||||
$('#qunit-fixture').append(timeField);
|
$('#qunit-fixture').append(timeField);
|
||||||
DateTimeShortcuts.clockHours.time_test = [['3 a.m.', 3]];
|
DateTimeShortcuts.clockHours.time_test = [['3 a.m.', 3]];
|
||||||
DateTimeShortcuts.init();
|
DateTimeShortcuts.init();
|
||||||
@ -32,9 +32,9 @@ QUnit.test('custom time shortcuts', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('time zone offset warning', function(assert) {
|
QUnit.test('time zone offset warning', function(assert) {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
var savedOffset = $('body').attr('data-admin-utc-offset');
|
const savedOffset = $('body').attr('data-admin-utc-offset');
|
||||||
var timeField = $('<input type="text" name="time_test" class="vTimeField">');
|
const timeField = $('<input type="text" name="time_test" class="vTimeField">');
|
||||||
$('#qunit-fixture').append(timeField);
|
$('#qunit-fixture').append(timeField);
|
||||||
$('body').attr('data-admin-utc-offset', new Date().getTimezoneOffset() * -60 + 3600);
|
$('body').attr('data-admin-utc-offset', new Date().getTimezoneOffset() * -60 + 3600);
|
||||||
DateTimeShortcuts.init();
|
DateTimeShortcuts.init();
|
||||||
|
@ -5,14 +5,14 @@
|
|||||||
QUnit.module('admin.SelectBox');
|
QUnit.module('admin.SelectBox');
|
||||||
|
|
||||||
QUnit.test('init: no options', function(assert) {
|
QUnit.test('init: no options', function(assert) {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
$('<select id="id"></select>').appendTo('#qunit-fixture');
|
$('<select id="id"></select>').appendTo('#qunit-fixture');
|
||||||
SelectBox.init('id');
|
SelectBox.init('id');
|
||||||
assert.equal(SelectBox.cache.id.length, 0);
|
assert.equal(SelectBox.cache.id.length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('filter', function(assert) {
|
QUnit.test('filter', function(assert) {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
$('<select id="id"></select>').appendTo('#qunit-fixture');
|
$('<select id="id"></select>').appendTo('#qunit-fixture');
|
||||||
$('<option value="0">A</option>').appendTo('#id');
|
$('<option value="0">A</option>').appendTo('#id');
|
||||||
$('<option value="1">B</option>').appendTo('#id');
|
$('<option value="1">B</option>').appendTo('#id');
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
QUnit.module('admin.SelectFilter2');
|
QUnit.module('admin.SelectFilter2');
|
||||||
|
|
||||||
QUnit.test('init', function(assert) {
|
QUnit.test('init', function(assert) {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
$('<form><select id="id"></select></form>').appendTo('#qunit-fixture');
|
$('<form><select id="id"></select></form>').appendTo('#qunit-fixture');
|
||||||
$('<option value="0">A</option>').appendTo('#id');
|
$('<option value="0">A</option>').appendTo('#id');
|
||||||
SelectFilter.init('id', 'things', 0);
|
SelectFilter.init('id', 'things', 0);
|
||||||
|
@ -9,7 +9,7 @@ QUnit.module('admin.actions', {
|
|||||||
window._actions_icnt = '100';
|
window._actions_icnt = '100';
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
|
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
$('#qunit-fixture').append($('#result-table').text());
|
$('#qunit-fixture').append($('#result-table').text());
|
||||||
|
|
||||||
$('tr input.action-select').actions();
|
$('tr input.action-select').actions();
|
||||||
@ -17,7 +17,7 @@ QUnit.module('admin.actions', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('check', function(assert) {
|
QUnit.test('check', function(assert) {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
assert.notOk($('.action-select').is(':checked'));
|
assert.notOk($('.action-select').is(':checked'));
|
||||||
$('#action-toggle').click();
|
$('#action-toggle').click();
|
||||||
assert.ok($('.action-select').is(':checked'));
|
assert.ok($('.action-select').is(':checked'));
|
||||||
|
@ -42,7 +42,7 @@ QUnit.test('Date.getTwoDigitSecond', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('Date.strftime', function(assert) {
|
QUnit.test('Date.strftime', function(assert) {
|
||||||
var date = new Date(2014, 6, 1, 11, 0, 5);
|
const date = new Date(2014, 6, 1, 11, 0, 5);
|
||||||
assert.equal(date.strftime('%Y-%m-%d %H:%M:%S'), '2014-07-01 11:00:05');
|
assert.equal(date.strftime('%Y-%m-%d %H:%M:%S'), '2014-07-01 11:00:05');
|
||||||
assert.equal(date.strftime('%B %d, %Y'), 'July 01, 2014');
|
assert.equal(date.strftime('%B %d, %Y'), 'July 01, 2014');
|
||||||
});
|
});
|
||||||
@ -50,26 +50,26 @@ QUnit.test('Date.strftime', function(assert) {
|
|||||||
QUnit.test('String.strptime', function(assert) {
|
QUnit.test('String.strptime', function(assert) {
|
||||||
// Use UTC functions for extracting dates since the calendar uses them as
|
// Use UTC functions for extracting dates since the calendar uses them as
|
||||||
// well. Month numbering starts with 0 (January).
|
// well. Month numbering starts with 0 (January).
|
||||||
var firstParsedDate = '1988-02-26'.strptime('%Y-%m-%d');
|
const firstParsedDate = '1988-02-26'.strptime('%Y-%m-%d');
|
||||||
assert.equal(firstParsedDate.getUTCDate(), 26);
|
assert.equal(firstParsedDate.getUTCDate(), 26);
|
||||||
assert.equal(firstParsedDate.getUTCMonth(), 1);
|
assert.equal(firstParsedDate.getUTCMonth(), 1);
|
||||||
assert.equal(firstParsedDate.getUTCFullYear(), 1988);
|
assert.equal(firstParsedDate.getUTCFullYear(), 1988);
|
||||||
|
|
||||||
// A %y value in the range of [69, 99] is in the previous century.
|
// A %y value in the range of [69, 99] is in the previous century.
|
||||||
var secondParsedDate = '26/02/88'.strptime('%d/%m/%y');
|
const secondParsedDate = '26/02/88'.strptime('%d/%m/%y');
|
||||||
assert.equal(secondParsedDate.getUTCDate(), 26);
|
assert.equal(secondParsedDate.getUTCDate(), 26);
|
||||||
assert.equal(secondParsedDate.getUTCMonth(), 1);
|
assert.equal(secondParsedDate.getUTCMonth(), 1);
|
||||||
assert.equal(secondParsedDate.getUTCFullYear(), 1988);
|
assert.equal(secondParsedDate.getUTCFullYear(), 1988);
|
||||||
|
|
||||||
var format = django.get_format('DATE_INPUT_FORMATS')[0];
|
const format = django.get_format('DATE_INPUT_FORMATS')[0];
|
||||||
var thirdParsedDate = '1983-11-20'.strptime(format);
|
const thirdParsedDate = '1983-11-20'.strptime(format);
|
||||||
|
|
||||||
assert.equal(thirdParsedDate.getUTCDate(), 20);
|
assert.equal(thirdParsedDate.getUTCDate(), 20);
|
||||||
assert.equal(thirdParsedDate.getUTCMonth(), 10);
|
assert.equal(thirdParsedDate.getUTCMonth(), 10);
|
||||||
assert.equal(thirdParsedDate.getUTCFullYear(), 1983);
|
assert.equal(thirdParsedDate.getUTCFullYear(), 1983);
|
||||||
|
|
||||||
// A %y value in the range of [00, 68] is in the current century.
|
// A %y value in the range of [00, 68] is in the current century.
|
||||||
var fourthParsedDate = '27/09/68'.strptime('%d/%m/%y');
|
const fourthParsedDate = '27/09/68'.strptime('%d/%m/%y');
|
||||||
assert.equal(fourthParsedDate.getUTCDate(), 27);
|
assert.equal(fourthParsedDate.getUTCDate(), 27);
|
||||||
assert.equal(fourthParsedDate.getUTCMonth(), 8);
|
assert.equal(fourthParsedDate.getUTCMonth(), 8);
|
||||||
assert.equal(fourthParsedDate.getUTCFullYear(), 2068);
|
assert.equal(fourthParsedDate.getUTCFullYear(), 2068);
|
||||||
@ -80,10 +80,9 @@ QUnit.test('String.strptime', function(assert) {
|
|||||||
// Feb 26, 1988 00:00:00 EEST is Feb 25, 21:00:00 UTC.
|
// Feb 26, 1988 00:00:00 EEST is Feb 25, 21:00:00 UTC.
|
||||||
|
|
||||||
// Checking timezones from GMT+0100 to GMT+1200
|
// Checking timezones from GMT+0100 to GMT+1200
|
||||||
var i, tz, date;
|
for (let i = 1; i <= 12; i++) {
|
||||||
for (i = 1; i <= 12; i++) {
|
const tz = i > 9 ? '' + i : '0' + i;
|
||||||
tz = i > 9 ? '' + i : '0' + i;
|
const date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT+' + tz + '00'));
|
||||||
date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT+' + tz + '00'));
|
|
||||||
assert.notEqual(date.getUTCDate(), 26);
|
assert.notEqual(date.getUTCDate(), 26);
|
||||||
assert.equal(date.getUTCDate(), 25);
|
assert.equal(date.getUTCDate(), 25);
|
||||||
assert.equal(date.getUTCMonth(), 1);
|
assert.equal(date.getUTCMonth(), 1);
|
||||||
@ -91,9 +90,9 @@ QUnit.test('String.strptime', function(assert) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Checking timezones from GMT+0000 to GMT-1100
|
// Checking timezones from GMT+0000 to GMT-1100
|
||||||
for (i = 0; i <= 11; i++) {
|
for (let i = 0; i <= 11; i++) {
|
||||||
tz = i > 9 ? '' + i : '0' + i;
|
const tz = i > 9 ? '' + i : '0' + i;
|
||||||
date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT-' + tz + '00'));
|
const date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT-' + tz + '00'));
|
||||||
assert.equal(date.getUTCDate(), 26);
|
assert.equal(date.getUTCDate(), 26);
|
||||||
assert.equal(date.getUTCMonth(), 1);
|
assert.equal(date.getUTCMonth(), 1);
|
||||||
assert.equal(date.getUTCFullYear(), 1988);
|
assert.equal(date.getUTCFullYear(), 1988);
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
QUnit.module('admin.inlines: tabular formsets', {
|
QUnit.module('admin.inlines: tabular formsets', {
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
var that = this;
|
const that = this;
|
||||||
this.addText = 'Add another';
|
this.addText = 'Add another';
|
||||||
|
|
||||||
$('#qunit-fixture').append($('#tabular-formset').text());
|
$('#qunit-fixture').append($('#tabular-formset').text());
|
||||||
@ -25,14 +25,14 @@ QUnit.test('no forms', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('add form', function(assert) {
|
QUnit.test('add form', function(assert) {
|
||||||
var addButton = this.table.find('.add-row a');
|
const addButton = this.table.find('.add-row a');
|
||||||
assert.equal(addButton.text(), this.addText);
|
assert.equal(addButton.text(), this.addText);
|
||||||
addButton.click();
|
addButton.click();
|
||||||
assert.ok(this.table.find('#first-1'));
|
assert.ok(this.table.find('#first-1'));
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('added form has remove button', function(assert) {
|
QUnit.test('added form has remove button', function(assert) {
|
||||||
var addButton = this.table.find('.add-row a');
|
const addButton = this.table.find('.add-row a');
|
||||||
assert.equal(addButton.text(), this.addText);
|
assert.equal(addButton.text(), this.addText);
|
||||||
addButton.click();
|
addButton.click();
|
||||||
assert.equal(this.table.find('#first-1 .inline-deletelink').length, 1);
|
assert.equal(this.table.find('#first-1 .inline-deletelink').length, 1);
|
||||||
@ -40,9 +40,9 @@ QUnit.test('added form has remove button', function(assert) {
|
|||||||
|
|
||||||
QUnit.test('add/remove form events', function(assert) {
|
QUnit.test('add/remove form events', function(assert) {
|
||||||
assert.expect(6);
|
assert.expect(6);
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
var $document = $(document);
|
const $document = $(document);
|
||||||
var addButton = this.table.find('.add-row a');
|
const addButton = this.table.find('.add-row a');
|
||||||
$document.on('formset:added', function(event, $row, formsetName) {
|
$document.on('formset:added', function(event, $row, formsetName) {
|
||||||
assert.ok(true, 'event `formset:added` triggered');
|
assert.ok(true, 'event `formset:added` triggered');
|
||||||
assert.equal(true, $row.is('#first-1'));
|
assert.equal(true, $row.is('#first-1'));
|
||||||
@ -50,8 +50,8 @@ QUnit.test('add/remove form events', function(assert) {
|
|||||||
$document.off('formset:added');
|
$document.off('formset:added');
|
||||||
});
|
});
|
||||||
addButton.click();
|
addButton.click();
|
||||||
var deletedRow = $('#first-1');
|
const deletedRow = $('#first-1');
|
||||||
var deleteLink = this.table.find('.inline-deletelink');
|
const deleteLink = this.table.find('.inline-deletelink');
|
||||||
$document.on('formset:removed', function(event, $row, formsetName) {
|
$document.on('formset:removed', function(event, $row, formsetName) {
|
||||||
assert.ok(true, 'event `formset:removed` triggered');
|
assert.ok(true, 'event `formset:removed` triggered');
|
||||||
assert.equal(true, $row.is(deletedRow));
|
assert.equal(true, $row.is(deletedRow));
|
||||||
@ -62,13 +62,13 @@ QUnit.test('add/remove form events', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('existing add button', function(assert) {
|
QUnit.test('existing add button', function(assert) {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
$('#qunit-fixture').empty(); // Clear the table added in beforeEach
|
$('#qunit-fixture').empty(); // Clear the table added in beforeEach
|
||||||
$('#qunit-fixture').append($('#tabular-formset').text());
|
$('#qunit-fixture').append($('#tabular-formset').text());
|
||||||
this.table = $('table.inline');
|
this.table = $('table.inline');
|
||||||
this.inlineRow = this.table.find('tr');
|
this.inlineRow = this.table.find('tr');
|
||||||
this.table.append('<i class="add-button"></i>');
|
this.table.append('<i class="add-button"></i>');
|
||||||
var addButton = this.table.find('.add-button');
|
const addButton = this.table.find('.add-button');
|
||||||
this.inlineRow.tabularFormset('table.inline tr', {
|
this.inlineRow.tabularFormset('table.inline tr', {
|
||||||
prefix: 'first',
|
prefix: 'first',
|
||||||
deleteText: 'Remove',
|
deleteText: 'Remove',
|
||||||
@ -82,7 +82,7 @@ QUnit.test('existing add button', function(assert) {
|
|||||||
|
|
||||||
QUnit.module('admin.inlines: tabular formsets with validation errors', {
|
QUnit.module('admin.inlines: tabular formsets with validation errors', {
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
|
|
||||||
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
|
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
|
||||||
this.table = $('table.inline');
|
this.table = $('table.inline');
|
||||||
@ -94,7 +94,7 @@ QUnit.module('admin.inlines: tabular formsets with validation errors', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('first form has delete checkbox and no button', function(assert) {
|
QUnit.test('first form has delete checkbox and no button', function(assert) {
|
||||||
var tr = this.inlineRows.slice(0, 1);
|
const tr = this.inlineRows.slice(0, 1);
|
||||||
assert.ok(tr.hasClass('dynamic-second'));
|
assert.ok(tr.hasClass('dynamic-second'));
|
||||||
assert.ok(tr.hasClass('has_original'));
|
assert.ok(tr.hasClass('has_original'));
|
||||||
assert.equal(tr.find('td.delete input').length, 1);
|
assert.equal(tr.find('td.delete input').length, 1);
|
||||||
@ -102,14 +102,14 @@ QUnit.test('first form has delete checkbox and no button', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('dynamic form has remove button', function(assert) {
|
QUnit.test('dynamic form has remove button', function(assert) {
|
||||||
var tr = this.inlineRows.slice(1, 2);
|
const tr = this.inlineRows.slice(1, 2);
|
||||||
assert.ok(tr.hasClass('dynamic-second'));
|
assert.ok(tr.hasClass('dynamic-second'));
|
||||||
assert.notOk(tr.hasClass('has_original'));
|
assert.notOk(tr.hasClass('has_original'));
|
||||||
assert.equal(tr.find('.inline-deletelink').length, 1);
|
assert.equal(tr.find('.inline-deletelink').length, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('dynamic template has nothing', function(assert) {
|
QUnit.test('dynamic template has nothing', function(assert) {
|
||||||
var tr = this.inlineRows.slice(2, 3);
|
const tr = this.inlineRows.slice(2, 3);
|
||||||
assert.ok(tr.hasClass('empty-form'));
|
assert.ok(tr.hasClass('empty-form'));
|
||||||
assert.notOk(tr.hasClass('dynamic-second'));
|
assert.notOk(tr.hasClass('dynamic-second'));
|
||||||
assert.notOk(tr.hasClass('has_original'));
|
assert.notOk(tr.hasClass('has_original'));
|
||||||
@ -117,19 +117,19 @@ QUnit.test('dynamic template has nothing', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('removing a form-row also removed related row with non-field errors', function(assert) {
|
QUnit.test('removing a form-row also removed related row with non-field errors', function(assert) {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
assert.ok(this.table.find('.row-form-errors').length);
|
assert.ok(this.table.find('.row-form-errors').length);
|
||||||
var tr = this.inlineRows.slice(1, 2);
|
const tr = this.inlineRows.slice(1, 2);
|
||||||
var trWithErrors = tr.prev();
|
const trWithErrors = tr.prev();
|
||||||
assert.ok(trWithErrors.hasClass('row-form-errors'));
|
assert.ok(trWithErrors.hasClass('row-form-errors'));
|
||||||
var deleteLink = tr.find('a.inline-deletelink');
|
const deleteLink = tr.find('a.inline-deletelink');
|
||||||
deleteLink.trigger($.Event('click', {target: deleteLink}));
|
deleteLink.trigger($.Event('click', {target: deleteLink}));
|
||||||
assert.notOk(this.table.find('.row-form-errors').length);
|
assert.notOk(this.table.find('.row-form-errors').length);
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.module('admin.inlines: tabular formsets with max_num', {
|
QUnit.module('admin.inlines: tabular formsets with max_num', {
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
|
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
|
||||||
this.table = $('table.inline');
|
this.table = $('table.inline');
|
||||||
this.maxNum = $('input.id_second-MAX_NUM_FORMS');
|
this.maxNum = $('input.id_second-MAX_NUM_FORMS');
|
||||||
@ -142,14 +142,14 @@ QUnit.module('admin.inlines: tabular formsets with max_num', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('does not show the add button if already at max_num', function(assert) {
|
QUnit.test('does not show the add button if already at max_num', function(assert) {
|
||||||
var addButton = this.table.find('tr.add_row > td > a');
|
const addButton = this.table.find('tr.add_row > td > a');
|
||||||
assert.notOk(addButton.is(':visible'));
|
assert.notOk(addButton.is(':visible'));
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('make addButton visible again', function(assert) {
|
QUnit.test('make addButton visible again', function(assert) {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
var addButton = this.table.find('tr.add_row > td > a');
|
const addButton = this.table.find('tr.add_row > td > a');
|
||||||
var removeButton = this.table.find('tr.form-row:first').find('a.inline-deletelink');
|
const removeButton = this.table.find('tr.form-row:first').find('a.inline-deletelink');
|
||||||
removeButton.trigger($.Event( "click", { target: removeButton } ));
|
removeButton.trigger($.Event( "click", { target: removeButton } ));
|
||||||
assert.notOk(addButton.is(':visible'));
|
assert.notOk(addButton.is(':visible'));
|
||||||
});
|
});
|
||||||
@ -157,7 +157,7 @@ QUnit.test('make addButton visible again', function(assert) {
|
|||||||
|
|
||||||
QUnit.module('admin.inlines: tabular formsets with min_num', {
|
QUnit.module('admin.inlines: tabular formsets with min_num', {
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
|
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
|
||||||
this.table = $('table.inline');
|
this.table = $('table.inline');
|
||||||
this.minNum = $('input#id_second-MIN_NUM_FORMS');
|
this.minNum = $('input#id_second-MIN_NUM_FORMS');
|
||||||
@ -174,8 +174,8 @@ QUnit.test('does not show the remove buttons if already at min_num', function(as
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('make removeButtons visible again', function(assert) {
|
QUnit.test('make removeButtons visible again', function(assert) {
|
||||||
var $ = django.jQuery;
|
const $ = django.jQuery;
|
||||||
var addButton = this.table.find('tr.add-row > td > a');
|
const addButton = this.table.find('tr.add-row > td > a');
|
||||||
addButton.trigger($.Event( "click", { target: addButton } ));
|
addButton.trigger($.Event( "click", { target: addButton } ));
|
||||||
assert.equal(this.table.find('.inline-deletelink:visible').length, 2);
|
assert.equal(this.table.find('.inline-deletelink:visible').length, 2);
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
(function(globals) {
|
(function(globals) {
|
||||||
'use strict';
|
'use strict';
|
||||||
var django = globals.django || (globals.django = {});
|
const django = globals.django;
|
||||||
|
|
||||||
django.pluralidx = function(count) { return (count === 1) ? 0 : 1; };
|
django.pluralidx = function(count) { return (count === 1) ? 0 : 1; };
|
||||||
|
|
||||||
@ -69,7 +69,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
django.get_format = function(format_type) {
|
django.get_format = function(format_type) {
|
||||||
var value = django.formats[format_type];
|
const value = django.formats[format_type];
|
||||||
if (typeof value === 'undefined') {
|
if (typeof value === 'undefined') {
|
||||||
return format_type;
|
return format_type;
|
||||||
} else {
|
} else {
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
QUnit.module('gis.OLMapWidget');
|
QUnit.module('gis.OLMapWidget');
|
||||||
|
|
||||||
QUnit.test('MapWidget.featureAdded', function(assert) {
|
QUnit.test('MapWidget.featureAdded', function(assert) {
|
||||||
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
||||||
var widget = new MapWidget(options);
|
const widget = new MapWidget(options);
|
||||||
assert.equal(widget.featureCollection.getLength(), 1);
|
assert.equal(widget.featureCollection.getLength(), 1);
|
||||||
widget.serializeFeatures();
|
widget.serializeFeatures();
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@ -17,14 +17,14 @@ QUnit.test('MapWidget.featureAdded', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('MapWidget.map_srid', function(assert) {
|
QUnit.test('MapWidget.map_srid', function(assert) {
|
||||||
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
||||||
var widget = new MapWidget(options);
|
const widget = new MapWidget(options);
|
||||||
assert.equal(widget.map.getView().getProjection().getCode(), 'EPSG:3857', 'SRID 3857');
|
assert.equal(widget.map.getView().getProjection().getCode(), 'EPSG:3857', 'SRID 3857');
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('MapWidget.defaultCenter', function(assert) {
|
QUnit.test('MapWidget.defaultCenter', function(assert) {
|
||||||
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
||||||
var widget = new MapWidget(options);
|
let widget = new MapWidget(options);
|
||||||
assert.equal(widget.defaultCenter().toString(), '0,0', 'Default center at 0, 0');
|
assert.equal(widget.defaultCenter().toString(), '0,0', 'Default center at 0, 0');
|
||||||
options.default_lat = 47.08;
|
options.default_lat = 47.08;
|
||||||
options.default_lon = 6.81;
|
options.default_lon = 6.81;
|
||||||
@ -38,32 +38,32 @@ QUnit.test('MapWidget.defaultCenter', function(assert) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('MapWidget.interactions', function(assert) {
|
QUnit.test('MapWidget.interactions', function(assert) {
|
||||||
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
||||||
var widget = new MapWidget(options);
|
const widget = new MapWidget(options);
|
||||||
assert.equal(Object.keys(widget.interactions).length, 2);
|
assert.equal(Object.keys(widget.interactions).length, 2);
|
||||||
assert.equal(widget.interactions.draw.getActive(), false, "Draw is inactive with an existing point");
|
assert.equal(widget.interactions.draw.getActive(), false, "Draw is inactive with an existing point");
|
||||||
assert.equal(widget.interactions.modify.getActive(), true, "Modify is active with an existing point");
|
assert.equal(widget.interactions.modify.getActive(), true, "Modify is active with an existing point");
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('MapWidget.clearFeatures', function(assert) {
|
QUnit.test('MapWidget.clearFeatures', function(assert) {
|
||||||
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
||||||
var widget = new MapWidget(options);
|
const widget = new MapWidget(options);
|
||||||
var initial_value = document.getElementById('id_point').value;
|
const initial_value = document.getElementById('id_point').value;
|
||||||
widget.clearFeatures();
|
widget.clearFeatures();
|
||||||
assert.equal(document.getElementById('id_point').value, "");
|
assert.equal(document.getElementById('id_point').value, "");
|
||||||
document.getElementById('id_point').value = initial_value;
|
document.getElementById('id_point').value = initial_value;
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('MapWidget.multipolygon', function(assert) {
|
QUnit.test('MapWidget.multipolygon', function(assert) {
|
||||||
var options = {id: 'id_multipolygon', map_id: 'id_multipolygon_map', geom_name: 'MultiPolygon'};
|
const options = {id: 'id_multipolygon', map_id: 'id_multipolygon_map', geom_name: 'MultiPolygon'};
|
||||||
var widget = new MapWidget(options);
|
const widget = new MapWidget(options);
|
||||||
assert.ok(widget.options.is_collection);
|
assert.ok(widget.options.is_collection);
|
||||||
assert.equal(widget.interactions.draw.getActive(), true, "Draw is active with no existing content");
|
assert.equal(widget.interactions.draw.getActive(), true, "Draw is active with no existing content");
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('MapWidget.IsCollection', function(assert) {
|
QUnit.test('MapWidget.IsCollection', function(assert) {
|
||||||
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
|
||||||
var widget = new MapWidget(options);
|
let widget = new MapWidget(options);
|
||||||
assert.notOk(widget.options.is_collection);
|
assert.notOk(widget.options.is_collection);
|
||||||
// Empty the default initial Point
|
// Empty the default initial Point
|
||||||
document.getElementById('id_point').value = "";
|
document.getElementById('id_point').value = "";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user