1
0
mirror of https://github.com/django/django.git synced 2024-12-22 09:05:43 +00:00

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:
Jon Dufresne 2020-04-20 17:39:15 -07:00 committed by Carlton Gibson
parent 0dafadadb9
commit 5d37cc703b
30 changed files with 401 additions and 406 deletions

View File

@ -16,8 +16,10 @@
"no-unused-vars": ["error", {"vars": "local", "args": "none"}],
"no-script-url": ["error"],
"no-shadow": ["error", {"hoist": "functions"}],
"no-var": ["error"],
"quotes": ["off", "single"],
"linebreak-style": ["error", "unix"],
"prefer-const": ["error"],
"semi": ["error", "always"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", {"anonymous": "never", "named": "never"}],
@ -25,7 +27,8 @@
"strict": ["warn", "function"]
},
"env": {
"browser": true
"browser": true,
"es6": true
},
"globals": {
"django": false

View File

@ -36,6 +36,7 @@ and Java version 7 or later."""
cmd.append('-q')
cmd.extend([
'google-closure-compiler',
'--language_out=ECMASCRIPT_2015',
'--rewrite_polyfills=false',
'--js', str(to_compress),
'--js_output_file', str(to_compress_min),

View File

@ -1,29 +1,27 @@
(function() {
'use strict';
var SelectBox = {
const SelectBox = {
cache: {},
init: function(id) {
var box = document.getElementById(id);
var node;
const box = document.getElementById(id);
SelectBox.cache[id] = [];
var cache = SelectBox.cache[id];
var boxOptions = box.options;
var boxOptionsLength = boxOptions.length;
for (var i = 0, j = boxOptionsLength; i < j; i++) {
node = boxOptions[i];
const cache = SelectBox.cache[id];
const boxOptions = box.options;
const boxOptionsLength = boxOptions.length;
for (let i = 0, j = boxOptionsLength; i < j; i++) {
const node = boxOptions[i];
cache.push({value: node.value, text: node.text, displayed: 1});
}
},
redisplay: function(id) {
// Repopulate HTML select box from cache
var box = document.getElementById(id);
var node;
const box = document.getElementById(id);
box.innerHTML = '';
var cache = SelectBox.cache[id];
for (var i = 0, j = cache.length; i < j; i++) {
node = cache[i];
const cache = SelectBox.cache[id];
for (let i = 0, j = cache.length; i < j; i++) {
const node = cache[i];
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
new_option.title = node.text;
box.appendChild(new_option);
@ -33,16 +31,15 @@
filter: function(id, text) {
// Redisplay the HTML select box, displaying only the choices containing ALL
// the words in text. (It's an AND search.)
var tokens = text.toLowerCase().split(/\s+/);
var node, token;
var cache = SelectBox.cache[id];
for (var i = 0, j = cache.length; i < j; i++) {
node = cache[i];
const tokens = text.toLowerCase().split(/\s+/);
const cache = SelectBox.cache[id];
for (let i = 0, j = cache.length; i < j; i++) {
const node = cache[i];
node.displayed = 1;
var node_text = node.text.toLowerCase();
var numTokens = tokens.length;
for (var k = 0; k < numTokens; k++) {
token = tokens[k];
const node_text = node.text.toLowerCase();
const numTokens = tokens.length;
for (let k = 0; k < numTokens; k++) {
const token = tokens[k];
if (node_text.indexOf(token) === -1) {
node.displayed = 0;
break; // Once the first token isn't found we're done
@ -52,10 +49,10 @@
SelectBox.redisplay(id);
},
delete_from_cache: function(id, value) {
var node, delete_index = null;
var cache = SelectBox.cache[id];
for (var i = 0, j = cache.length; i < j; i++) {
node = cache[i];
let delete_index = null;
const cache = SelectBox.cache[id];
for (let i = 0, j = cache.length; i < j; i++) {
const node = cache[i];
if (node.value === value) {
delete_index = i;
break;
@ -68,10 +65,9 @@
},
cache_contains: function(id, value) {
// Check if an item is contained in the cache
var node;
var cache = SelectBox.cache[id];
for (var i = 0, j = cache.length; i < j; i++) {
node = cache[i];
const cache = SelectBox.cache[id];
for (let i = 0, j = cache.length; i < j; i++) {
const node = cache[i];
if (node.value === value) {
return true;
}
@ -79,13 +75,12 @@
return false;
},
move: function(from, to) {
var from_box = document.getElementById(from);
var option;
var boxOptions = from_box.options;
var boxOptionsLength = boxOptions.length;
for (var i = 0, j = boxOptionsLength; i < j; i++) {
option = boxOptions[i];
var option_value = option.value;
const from_box = document.getElementById(from);
const boxOptions = from_box.options;
const boxOptionsLength = boxOptions.length;
for (let i = 0, j = boxOptionsLength; i < j; i++) {
const option = boxOptions[i];
const option_value = 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.delete_from_cache(from, option_value);
@ -95,13 +90,12 @@
SelectBox.redisplay(to);
},
move_all: function(from, to) {
var from_box = document.getElementById(from);
var option;
var boxOptions = from_box.options;
var boxOptionsLength = boxOptions.length;
for (var i = 0, j = boxOptionsLength; i < j; i++) {
option = boxOptions[i];
var option_value = option.value;
const from_box = document.getElementById(from);
const boxOptions = from_box.options;
const boxOptionsLength = boxOptions.length;
for (let i = 0, j = boxOptionsLength; i < j; i++) {
const option = boxOptions[i];
const option_value = option.value;
if (SelectBox.cache_contains(from, option_value)) {
SelectBox.add_to_cache(to, {value: option_value, text: option.text, displayed: 1});
SelectBox.delete_from_cache(from, option_value);
@ -124,10 +118,10 @@
} );
},
select_all: function(id) {
var box = document.getElementById(id);
var boxOptions = box.options;
var boxOptionsLength = boxOptions.length;
for (var i = 0; i < boxOptionsLength; i++) {
const box = document.getElementById(id);
const boxOptions = box.options;
const boxOptionsLength = boxOptions.length;
for (let i = 0; i < boxOptionsLength; i++) {
boxOptions[i].selected = 'selected';
}
}

View File

@ -12,12 +12,12 @@ Requires core.js and SelectBox.js.
// Don't initialize on empty forms.
return;
}
var from_box = document.getElementById(field_id);
const from_box = document.getElementById(field_id);
from_box.id += '_from'; // change its ID
from_box.className = 'filtered';
var ps = from_box.parentNode.getElementsByTagName('p');
for (var i = 0; i < ps.length; i++) {
const ps = from_box.parentNode.getElementsByTagName('p');
for (let i = 0; i < ps.length; i++) {
if (ps[i].classList.contains("info")) {
// Remove <p class="info">, because it just gets in the way.
from_box.parentNode.removeChild(ps[i]);
@ -30,13 +30,13 @@ Requires core.js and SelectBox.js.
}
// <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';
// <div class="selector-available">
var selector_available = quickElement('div', selector_div);
const selector_available = quickElement('div', selector_div);
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(
'span', title_available, '',
'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';
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(
'span', search_filter_label, '',
@ -63,25 +63,25 @@ Requires core.js and SelectBox.js.
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';
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';
// <ul class="selector-chooser">
var selector_chooser = quickElement('ul', selector_div);
const selector_chooser = quickElement('ul', selector_div);
selector_chooser.className = 'selector-chooser';
var add_link = quickElement('a', quickElement('li', selector_chooser), gettext('Choose'), 'title', gettext('Choose'), 'href', '#', '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';
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';
// <div class="selector-chosen">
var selector_chosen = quickElement('div', selector_div);
const selector_chosen = quickElement('div', selector_div);
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(
'span', title_chosen, '',
'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';
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';
from_box.name = from_box.name + '_old';
// 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')) {
move_func(from, to);
SelectFilter.refresh_icons(field_id);
@ -156,11 +156,11 @@ Requires core.js and SelectBox.js.
if (!is_stacked) {
// In horizontal mode, give the same height to the two boxes.
var j_from_box = document.getElementById(field_id + '_from');
var j_to_box = document.getElementById(field_id + '_to');
var height = filter_p.offsetHeight + j_from_box.offsetHeight;
const j_from_box = document.getElementById(field_id + '_from');
const j_to_box = document.getElementById(field_id + '_to');
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') {
// Add the padding and border to the final height.
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);
},
any_selected: function(field) {
var any_selected = false;
// Temporarily add the required attribute and check validity.
field.required = true;
any_selected = field.checkValidity();
const any_selected = field.checkValidity();
field.required = false;
return any_selected;
},
refresh_icons: function(field_id) {
var from = document.getElementById(field_id + '_from');
var to = document.getElementById(field_id + '_to');
const from = document.getElementById(field_id + '_from');
const to = document.getElementById(field_id + '_to');
// 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 + '_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'));
},
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
if ((event.which && event.which === 13) || (event.keyCode && event.keyCode === 13)) {
from.selectedIndex = 0;
@ -204,16 +203,16 @@ Requires core.js and SelectBox.js.
}
},
filter_key_up: function(event, field_id) {
var from = document.getElementById(field_id + '_from');
var temp = from.selectedIndex;
const from = document.getElementById(field_id + '_from');
const temp = from.selectedIndex;
SelectBox.filter(field_id + '_from', document.getElementById(field_id + '_input').value);
from.selectedIndex = temp;
},
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
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');
from.selectedIndex = (old_index === from.length) ? from.length - 1 : old_index;
return;
@ -231,7 +230,7 @@ Requires core.js and SelectBox.js.
window.addEventListener('load', function(e) {
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));
});
});

View File

@ -1,13 +1,13 @@
/*global gettext, interpolate, ngettext*/
(function($) {
'use strict';
var lastChecked;
let lastChecked;
$.fn.actions = function(opts) {
var options = $.extend({}, $.fn.actions.defaults, opts);
var actionCheckboxes = $(this);
var list_editable_changed = false;
var showQuestion = function() {
const options = $.extend({}, $.fn.actions.defaults, opts);
const actionCheckboxes = $(this);
let list_editable_changed = false;
const showQuestion = function() {
$(options.acrossClears).hide();
$(options.acrossQuestions).show();
$(options.allContainer).hide();
@ -40,17 +40,17 @@
.parent().parent().toggleClass(options.selectedClass, checked);
},
updateCounter = function() {
var sel = $(actionCheckboxes).filter(":checked").length;
const sel = $(actionCheckboxes).filter(":checked").length;
// data-actions-icnt is defined in the generated HTML
// 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(
ngettext('%(sel)s of %(cnt)s selected', '%(sel)s of %(cnt)s selected', sel), {
sel: sel,
cnt: actions_icnt
}, true));
$(options.allToggle).prop("checked", function() {
var value;
let value;
if (sel === actionCheckboxes.length) {
value = true;
showQuestion();
@ -90,9 +90,9 @@
lastChecked = null;
$(actionCheckboxes).on('click', function(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) {
var inrange = false;
let inrange = false;
$(lastChecked).prop("checked", target.checked)
.parent().parent().toggleClass(options.selectedClass, target.checked);
$(actionCheckboxes).each(function() {
@ -118,7 +118,7 @@
}
});
$('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() {
if ($(this).val()) {
action_changed = true;
@ -145,7 +145,7 @@
selectedClass: "selected"
};
$(document).ready(function() {
var $actionsEls = $('tr input.action-select');
const $actionsEls = $('tr input.action-select');
if ($actionsEls.length > 0) {
$actionsEls.actions();
}

View File

@ -4,7 +4,7 @@
// <input type="text" class="vTimeField">
(function() {
'use strict';
var DateTimeShortcuts = {
const DateTimeShortcuts = {
calendars: [],
calendarInputs: [],
clockInputs: [],
@ -28,16 +28,16 @@
timezoneWarningClass: 'timezonewarning', // class of the warning for timezone mismatch
timezoneOffset: 0,
init: function() {
var body = document.getElementsByTagName('body')[0];
var serverOffset = body.dataset.adminUtcOffset;
const body = document.getElementsByTagName('body')[0];
const serverOffset = body.dataset.adminUtcOffset;
if (serverOffset) {
var localOffset = new Date().getTimezoneOffset() * -60;
const localOffset = new Date().getTimezoneOffset() * -60;
DateTimeShortcuts.timezoneOffset = localOffset - serverOffset;
}
var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
var inp = inputs[i];
const inputs = document.getElementsByTagName('input');
for (let i = 0; i < inputs.length; i++) {
const inp = inputs[i];
if (inp.type === 'text' && inp.classList.contains('vTimeField')) {
DateTimeShortcuts.addClock(inp);
DateTimeShortcuts.addTimezoneWarning(inp);
@ -50,11 +50,11 @@
},
// Return the current time while accounting for the server timezone.
now: function() {
var body = document.getElementsByTagName('body')[0];
var serverOffset = body.dataset.adminUtcOffset;
const body = document.getElementsByTagName('body')[0];
const serverOffset = body.dataset.adminUtcOffset;
if (serverOffset) {
var localNow = new Date();
var localOffset = localNow.getTimezoneOffset() * -60;
const localNow = new Date();
const localOffset = localNow.getTimezoneOffset() * -60;
localNow.setTime(localNow.getTime() + 1000 * (serverOffset - localOffset));
return localNow;
} else {
@ -63,8 +63,8 @@
},
// Add a warning when the time zone in the browser and backend do not match.
addTimezoneWarning: function(inp) {
var warningClass = DateTimeShortcuts.timezoneWarningClass;
var timezoneOffset = DateTimeShortcuts.timezoneOffset / 3600;
const warningClass = DateTimeShortcuts.timezoneWarningClass;
let timezoneOffset = DateTimeShortcuts.timezoneOffset / 3600;
// Only warn if there is a time zone mismatch.
if (!timezoneOffset) {
@ -76,7 +76,7 @@
return;
}
var message;
let message;
if (timezoneOffset > 0) {
message = ngettext(
'Note: You are %s hour ahead of server time.',
@ -94,7 +94,7 @@
}
message = interpolate(message, [timezoneOffset]);
var warning = document.createElement('span');
const warning = document.createElement('span');
warning.className = warningClass;
warning.textContent = message;
inp.parentNode.appendChild(document.createElement('br'));
@ -102,22 +102,22 @@
},
// Add clock widget to a given field
addClock: function(inp) {
var num = DateTimeShortcuts.clockInputs.length;
const num = DateTimeShortcuts.clockInputs.length;
DateTimeShortcuts.clockInputs[num] = inp;
DateTimeShortcuts.dismissClockFunc[num] = function() { DateTimeShortcuts.dismissClock(num); return true; };
// Shortcut links (clock icon and "Now" link)
var shortcuts_span = document.createElement('span');
const shortcuts_span = document.createElement('span');
shortcuts_span.className = DateTimeShortcuts.shortCutsClass;
inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling);
var now_link = document.createElement('a');
const now_link = document.createElement('a');
now_link.href = "#";
now_link.textContent = gettext('Now');
now_link.addEventListener('click', function(e) {
e.preventDefault();
DateTimeShortcuts.handleClockQuicklink(num, -1);
});
var clock_link = document.createElement('a');
const clock_link = document.createElement('a');
clock_link.href = '#';
clock_link.id = DateTimeShortcuts.clockLinkName + num;
clock_link.addEventListener('click', function(e) {
@ -152,7 +152,7 @@
// <p class="calendar-cancel"><a href="#">Cancel</a></p>
// </div>
var clock_box = document.createElement('div');
const clock_box = document.createElement('div');
clock_box.style.display = 'none';
clock_box.style.position = 'absolute';
clock_box.className = 'clockbox module';
@ -161,23 +161,23 @@
clock_box.addEventListener('click', function(e) { e.stopPropagation(); });
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';
// The list of choices can be overridden in JavaScript like this:
// DateTimeShortcuts.clockHours.name = [['3 a.m.', 3]];
// 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) {
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) {
e.preventDefault();
DateTimeShortcuts.handleClockQuicklink(num, element[1]);
});
});
var cancel_p = quickElement('p', clock_box);
const cancel_p = quickElement('p', clock_box);
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) {
e.preventDefault();
DateTimeShortcuts.dismissClock(num);
@ -192,8 +192,8 @@
});
},
openClock: function(num) {
var clock_box = document.getElementById(DateTimeShortcuts.clockDivName + num);
var clock_link = document.getElementById(DateTimeShortcuts.clockLinkName + num);
const clock_box = document.getElementById(DateTimeShortcuts.clockDivName + num);
const clock_link = document.getElementById(DateTimeShortcuts.clockLinkName + num);
// Recalculate the clockbox position
// is it left-to-right or right-to-left layout ?
@ -216,7 +216,7 @@
document.removeEventListener('click', DateTimeShortcuts.dismissClockFunc[num]);
},
handleClockQuicklink: function(num, val) {
var d;
let d;
if (val === -1) {
d = DateTimeShortcuts.now();
}
@ -229,23 +229,23 @@
},
// Add calendar widget to a given field.
addCalendar: function(inp) {
var num = DateTimeShortcuts.calendars.length;
const num = DateTimeShortcuts.calendars.length;
DateTimeShortcuts.calendarInputs[num] = inp;
DateTimeShortcuts.dismissCalendarFunc[num] = function() { DateTimeShortcuts.dismissCalendar(num); return true; };
// Shortcut links (calendar icon and "Today" link)
var shortcuts_span = document.createElement('span');
const shortcuts_span = document.createElement('span');
shortcuts_span.className = DateTimeShortcuts.shortCutsClass;
inp.parentNode.insertBefore(shortcuts_span, inp.nextSibling);
var today_link = document.createElement('a');
const today_link = document.createElement('a');
today_link.href = '#';
today_link.appendChild(document.createTextNode(gettext('Today')));
today_link.addEventListener('click', function(e) {
e.preventDefault();
DateTimeShortcuts.handleCalendarQuickLink(num, 0);
});
var cal_link = document.createElement('a');
const cal_link = document.createElement('a');
cal_link.href = '#';
cal_link.id = DateTimeShortcuts.calendarLinkName + num;
cal_link.addEventListener('click', function(e) {
@ -281,7 +281,7 @@
// </div>
// <p class="calendar-cancel"><a href="#">Cancel</a></p>
// </div>
var cal_box = document.createElement('div');
const cal_box = document.createElement('div');
cal_box.style.display = 'none';
cal_box.style.position = 'absolute';
cal_box.className = 'calendarbox module';
@ -290,15 +290,15 @@
cal_box.addEventListener('click', function(e) { e.stopPropagation(); });
// next-prev links
var cal_nav = quickElement('div', cal_box);
var cal_nav_prev = quickElement('a', cal_nav, '<', 'href', '#');
const cal_nav = quickElement('div', cal_box);
const cal_nav_prev = quickElement('a', cal_nav, '<', 'href', '#');
cal_nav_prev.className = 'calendarnav-previous';
cal_nav_prev.addEventListener('click', function(e) {
e.preventDefault();
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.addEventListener('click', function(e) {
e.preventDefault();
@ -306,15 +306,15 @@
});
// 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';
DateTimeShortcuts.calendars[num] = new Calendar(DateTimeShortcuts.calendarDivName2 + num, DateTimeShortcuts.handleCalendarCallback(num));
DateTimeShortcuts.calendars[num].drawCurrent();
// calendar shortcuts
var shortcuts = quickElement('div', cal_box);
const shortcuts = quickElement('div', cal_box);
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) {
e.preventDefault();
DateTimeShortcuts.handleCalendarQuickLink(num, -1);
@ -333,9 +333,9 @@
});
// cancel bar
var cancel_p = quickElement('p', cal_box);
const cancel_p = quickElement('p', cal_box);
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) {
e.preventDefault();
DateTimeShortcuts.dismissCalendar(num);
@ -349,18 +349,18 @@
});
},
openCalendar: function(num) {
var cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1 + num);
var cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName + num);
var inp = DateTimeShortcuts.calendarInputs[num];
const cal_box = document.getElementById(DateTimeShortcuts.calendarDivName1 + num);
const cal_link = document.getElementById(DateTimeShortcuts.calendarLinkName + num);
const inp = DateTimeShortcuts.calendarInputs[num];
// 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 (inp.value) {
var format = get_format('DATE_INPUT_FORMATS')[0];
var selected = inp.value.strptime(format);
var year = selected.getUTCFullYear();
var month = selected.getUTCMonth() + 1;
var re = /\d{4}/;
const format = get_format('DATE_INPUT_FORMATS')[0];
const selected = inp.value.strptime(format);
const year = selected.getUTCFullYear();
const month = selected.getUTCMonth() + 1;
const re = /\d{4}/;
if (re.test(year.toString()) && month >= 1 && month <= 12) {
DateTimeShortcuts.calendars[num].drawDate(month, year, selected);
}
@ -392,7 +392,7 @@
DateTimeShortcuts.calendars[num].drawNextMonth();
},
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
format = format.replace('\\', '\\\\')
.replace('\r', '\\r')
@ -406,7 +406,7 @@
};
},
handleCalendarQuickLink: function(num, offset) {
var d = DateTimeShortcuts.now();
const d = DateTimeShortcuts.now();
d.setDate(d.getDate() + offset);
DateTimeShortcuts.calendarInputs[num].value = d.strftime(get_format('DATE_INPUT_FORMATS')[0]);
DateTimeShortcuts.calendarInputs[num].focus();

View File

@ -6,8 +6,8 @@
'use strict';
function showAdminPopup(triggeringLink, name_regexp, add_popup) {
var name = triggeringLink.id.replace(name_regexp, '');
var href = triggeringLink.href;
const name = triggeringLink.id.replace(name_regexp, '');
let href = triggeringLink.href;
if (add_popup) {
if (href.indexOf('?') === -1) {
href += '?_popup=1';
@ -15,7 +15,7 @@
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();
return false;
}
@ -25,8 +25,8 @@
}
function dismissRelatedLookupPopup(win, chosenId) {
var name = win.name;
var elem = document.getElementById(name);
const name = win.name;
const elem = document.getElementById(name);
if (elem.classList.contains('vManyToManyRawIdAdminField') && elem.value) {
elem.value += ',' + chosenId;
} else {
@ -40,15 +40,15 @@
}
function updateRelatedObjectLinks(triggeringLink) {
var $this = $(triggeringLink);
var siblings = $this.nextAll('.view-related, .change-related, .delete-related');
const $this = $(triggeringLink);
const siblings = $this.nextAll('.view-related, .change-related, .delete-related');
if (!siblings.length) {
return;
}
var value = $this.val();
const value = $this.val();
if (value) {
siblings.each(function() {
var elm = $(this);
const elm = $(this);
elm.attr('href', elm.attr('data-href-template').replace('__fk__', value));
});
} else {
@ -57,10 +57,10 @@
}
function dismissAddRelatedObjectPopup(win, newId, newRepr) {
var name = win.name;
var elem = document.getElementById(name);
const name = win.name;
const elem = document.getElementById(name);
if (elem) {
var elemName = elem.nodeName.toUpperCase();
const elemName = elem.nodeName.toUpperCase();
if (elemName === 'SELECT') {
elem.options[elem.options.length] = new Option(newRepr, newId, true, true);
} else if (elemName === 'INPUT') {
@ -73,8 +73,8 @@
// Trigger a change event to update related links if required.
$(elem).trigger('change');
} else {
var toId = name + "_to";
var o = new Option(newRepr, newId);
const toId = name + "_to";
const o = new Option(newRepr, newId);
SelectBox.add_to_cache(toId, o);
SelectBox.redisplay(toId);
}
@ -82,9 +82,9 @@
}
function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) {
var id = win.name.replace(/^edit_/, '');
var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
var selects = $(selectsSelector);
const id = win.name.replace(/^edit_/, '');
const selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
const selects = $(selectsSelector);
selects.find('option').each(function() {
if (this.value === objId) {
this.textContent = newRepr;
@ -101,9 +101,9 @@
}
function dismissDeleteRelatedObjectPopup(win, objId) {
var id = win.name.replace(/^delete_/, '');
var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
var selects = $(selectsSelector);
const id = win.name.replace(/^delete_/, '');
const selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
const selects = $(selectsSelector);
selects.find('option').each(function() {
if (this.value === objId) {
$(this).remove();
@ -132,7 +132,7 @@
$('body').on('click', '.related-widget-wrapper-link', function(e) {
e.preventDefault();
if (this.href) {
var event = $.Event('django:show-related', {href: this.href});
const event = $.Event('django:show-related', {href: this.href});
$(this).trigger(event);
if (!event.isDefaultPrevented()) {
showRelatedObjectPopup(this);
@ -140,7 +140,7 @@
}
});
$('body').on('change', '.related-widget-wrapper select', function(e) {
var event = $.Event('django:update-related');
const event = $.Event('django:update-related');
$(this).trigger(event);
if (!event.isDefaultPrevented()) {
updateRelatedObjectLinks(this);
@ -149,7 +149,7 @@
$('.related-widget-wrapper select').trigger('change');
$('body').on('click', '.related-lookup', function(e) {
e.preventDefault();
var event = $.Event('django:lookup-related');
const event = $.Event('django:lookup-related');
$(this).trigger(event);
if (!event.isDefaultPrevented()) {
showRelatedObjectLookupPopup(this);

View File

@ -1,7 +1,7 @@
(function($) {
'use strict';
var init = function($element, options) {
var settings = $.extend({
const init = function($element, options) {
const settings = $.extend({
ajax: {
data: function(params) {
return {
@ -15,9 +15,9 @@
};
$.fn.djangoAdminSelect2 = function(options) {
var settings = $.extend({}, options);
const settings = $.extend({}, options);
$.each(this, function(i, element) {
var $element = $(element);
const $element = $(element);
init($element, settings);
});
return this;

View File

@ -7,7 +7,7 @@ depends on core.js for utility functions like removeChildren or quickElement
(function() {
'use strict';
// CalendarNamespace -- Provides a collection of HTML calendar-related helper functions
var CalendarNamespace = {
const CalendarNamespace = {
monthsOfYear: [
gettext('January'),
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));
},
getDaysInMonth: function(month, year) {
var days;
let days;
if (month === 1 || month === 3 || month === 5 || month === 7 || month === 8 || month === 10 || month === 12) {
days = 31;
}
@ -52,11 +52,11 @@ depends on core.js for utility functions like removeChildren or quickElement
return days;
},
draw: function(month, year, div_id, callback, selected) { // month = 1-12, year = 1-9999
var today = new Date();
var todayDay = today.getDate();
var todayMonth = today.getMonth() + 1;
var todayYear = today.getFullYear();
var todayClass = '';
const today = new Date();
const todayDay = today.getDate();
const todayMonth = today.getMonth() + 1;
const todayYear = today.getFullYear();
let todayClass = '';
// Use UTC functions here because the date field does not contain time
// 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
// zone.
var isSelectedMonth = false;
let isSelectedMonth = false;
if (typeof selected !== 'undefined') {
isSelectedMonth = (selected.getUTCFullYear() === year && (selected.getUTCMonth() + 1) === month);
}
month = parseInt(month);
year = parseInt(year);
var calDiv = document.getElementById(div_id);
const calDiv = document.getElementById(div_id);
removeChildren(calDiv);
var calTable = document.createElement('table');
const calTable = document.createElement('table');
quickElement('caption', calTable, CalendarNamespace.monthsOfYear[month - 1] + ' ' + year);
var tableBody = quickElement('tbody', calTable);
const tableBody = quickElement('tbody', calTable);
// Draw days-of-week header
var tableRow = quickElement('tr', tableBody);
for (var i = 0; i < 7; i++) {
let tableRow = quickElement('tr', tableBody);
for (let i = 0; i < 7; i++) {
quickElement('th', tableRow, CalendarNamespace.daysOfWeek[(i + CalendarNamespace.firstDayOfWeek) % 7]);
}
var startingPos = new Date(year, month - 1, 1 - CalendarNamespace.firstDayOfWeek).getDay();
var days = CalendarNamespace.getDaysInMonth(month, year);
const startingPos = new Date(year, month - 1, 1 - CalendarNamespace.firstDayOfWeek).getDay();
const days = CalendarNamespace.getDaysInMonth(month, year);
var nonDayCell;
let nonDayCell;
// Draw blanks before first of month
tableRow = quickElement('tr', tableBody);
for (i = 0; i < startingPos; i++) {
for (let i = 0; i < startingPos; i++) {
nonDayCell = quickElement('td', tableRow, ' ');
nonDayCell.className = "nonday";
}
@ -109,8 +109,8 @@ depends on core.js for utility functions like removeChildren or quickElement
}
// Draw days of month
var currentDay = 1;
for (i = startingPos; currentDay <= days; i++) {
let currentDay = 1;
for (let i = startingPos; currentDay <= days; i++) {
if (i % 7 === 0 && currentDay !== 1) {
tableRow = quickElement('tr', tableBody);
}
@ -128,8 +128,8 @@ depends on core.js for utility functions like removeChildren or quickElement
todayClass += "selected";
}
var cell = quickElement('td', tableRow, '', 'class', todayClass);
var link = quickElement('a', cell, currentDay, 'href', '#');
const cell = quickElement('td', tableRow, '', 'class', todayClass);
const link = quickElement('a', cell, currentDay, 'href', '#');
link.addEventListener('click', calendarMonth(year, month));
currentDay++;
}

View File

@ -1,11 +1,11 @@
(function() {
'use strict';
var inputTags = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA'];
var modelName = document.getElementById('django-admin-form-add-constants').dataset.modelName;
const inputTags = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA'];
const modelName = document.getElementById('django-admin-form-add-constants').dataset.modelName;
if (modelName) {
var form = document.getElementById(modelName + '_form');
for (var i = 0; i < form.elements.length; i++) {
var element = form.elements[i];
const form = document.getElementById(modelName + '_form');
for (let i = 0; i < form.elements.length; i++) {
const element = form.elements[i];
// HTMLElement.offsetParent returns null when the element is not
// rendered.
if (inputTags.includes(element.tagName) && !element.disabled && element.offsetParent) {

View File

@ -3,14 +3,14 @@
'use strict';
window.addEventListener('load', function() {
// Add anchor tag for Show/Hide link
var fieldsets = document.querySelectorAll('fieldset.collapse');
for (var i = 0; i < fieldsets.length; i++) {
var elem = fieldsets[i];
const fieldsets = document.querySelectorAll('fieldset.collapse');
for (let i = 0; i < fieldsets.length; i++) {
const elem = fieldsets[i];
// Don't hide if fields in this fieldset have errors
if (elem.querySelectorAll('div.errors, ul.errorlist').length === 0) {
elem.classList.add('collapsed');
var h2 = elem.querySelector('h2');
var link = document.createElement('a');
const h2 = elem.querySelector('h2');
const link = document.createElement('a');
link.id = 'fieldsetcollapser' + i;
link.className = 'collapse-toggle';
link.href = '#';
@ -21,11 +21,11 @@
}
}
// Add toggle to hide/show anchor tag
var toggleFunc = function(ev) {
const toggleFunc = function(ev) {
if (ev.target.matches('.collapse-toggle')) {
ev.preventDefault();
ev.stopPropagation();
var fieldset = ev.target.closest('fieldset');
const fieldset = ev.target.closest('fieldset');
if (fieldset.classList.contains('collapsed')) {
// Show
ev.target.textContent = gettext('Hide');
@ -37,8 +37,8 @@
}
}
};
var inlineDivs = document.querySelectorAll('fieldset.module');
for (i = 0; i < inlineDivs.length; i++) {
const inlineDivs = document.querySelectorAll('fieldset.module');
for (let i = 0; i < inlineDivs.length; i++) {
inlineDivs[i].addEventListener('click', toggleFunc);
}
});

View File

@ -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();
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)})})();
'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=
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)})})();

View File

@ -3,13 +3,13 @@
// quickElement(tagType, parentReference [, textInChildNode, attribute, attributeValue ...]);
function quickElement() {
'use strict';
var obj = document.createElement(arguments[0]);
const obj = document.createElement(arguments[0]);
if (arguments[2]) {
var textNode = document.createTextNode(arguments[2]);
const textNode = document.createTextNode(arguments[2]);
obj.appendChild(textNode);
}
var len = arguments.length;
for (var i = 3; i < len; i += 2) {
const len = arguments.length;
for (let i = 3; i < len; i += 2) {
obj.setAttribute(arguments[i], arguments[i + 1]);
}
arguments[1].appendChild(obj);
@ -30,7 +30,7 @@ function removeChildren(a) {
// ----------------------------------------------------------------------------
function findPosX(obj) {
'use strict';
var curleft = 0;
let curleft = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curleft += obj.offsetLeft - obj.scrollLeft;
@ -44,7 +44,7 @@ function findPosX(obj) {
function findPosY(obj) {
'use strict';
var curtop = 0;
let curtop = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curtop += obj.offsetTop - obj.scrollTop;
@ -96,7 +96,7 @@ function findPosY(obj) {
};
Date.prototype.strftime = function(format) {
var fields = {
const fields = {
B: this.getFullMonthName(),
c: this.toString(),
d: this.getTwoDigitDate(),
@ -113,7 +113,7 @@ function findPosY(obj) {
Y: '' + this.getFullYear(),
'%': '%'
};
var result = '', i = 0;
let result = '', i = 0;
while (i < format.length) {
if (format.charAt(i) === '%') {
result = result + fields[format.charAt(i + 1)];
@ -131,10 +131,10 @@ function findPosY(obj) {
// String object extensions
// ----------------------------------------------------------------------------
String.prototype.strptime = function(format) {
var split_format = format.split(/[.\-/]/);
var date = this.split(/[.\-/]/);
var i = 0;
var day, month, year;
const split_format = format.split(/[.\-/]/);
const date = this.split(/[.\-/]/);
let i = 0;
let day, month, year;
while (i < split_format.length) {
switch (split_format[i]) {
case "%d":

View File

@ -18,12 +18,12 @@
(function($) {
'use strict';
$.fn.formset = function(opts) {
var options = $.extend({}, $.fn.formset.defaults, opts);
var $this = $(this);
var $parent = $this.parent();
var updateElementIndex = function(el, prefix, ndx) {
var id_regex = new RegExp("(" + prefix + "-(\\d+|__prefix__))");
var replacement = prefix + "-" + ndx;
const options = $.extend({}, $.fn.formset.defaults, opts);
const $this = $(this);
const $parent = $this.parent();
const updateElementIndex = function(el, prefix, ndx) {
const id_regex = new RegExp("(" + prefix + "-(\\d+|__prefix__))");
const replacement = prefix + "-" + ndx;
if ($(el).prop("for")) {
$(el).prop("for", $(el).prop("for").replace(id_regex, replacement));
}
@ -34,21 +34,21 @@
el.name = el.name.replace(id_regex, replacement);
}
};
var totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS").prop("autocomplete", "off");
var nextIndex = parseInt(totalForms.val(), 10);
var maxForms = $("#id_" + options.prefix + "-MAX_NUM_FORMS").prop("autocomplete", "off");
var minForms = $("#id_" + options.prefix + "-MIN_NUM_FORMS").prop("autocomplete", "off");
var addButton;
const totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS").prop("autocomplete", "off");
let nextIndex = parseInt(totalForms.val(), 10);
const maxForms = $("#id_" + options.prefix + "-MAX_NUM_FORMS").prop("autocomplete", "off");
const minForms = $("#id_" + options.prefix + "-MIN_NUM_FORMS").prop("autocomplete", "off");
let addButton;
/**
* The "Add another MyModel" button below the inline forms.
*/
var addInlineAddButton = function() {
const addInlineAddButton = function() {
if (addButton === null) {
if ($this.prop("tagName") === "TR") {
// If forms are laid out as table rows, insert the
// "add" button in a new table row:
var numCols = $this.eq(-1).children().length;
const numCols = $this.eq(-1).children().length;
$parent.append('<tr class="' + options.addCssClass + '"><td colspan="' + numCols + '"><a href="#">' + options.addText + "</a></tr>");
addButton = $parent.find("tr:last a");
} else {
@ -60,10 +60,10 @@
addButton.on('click', addInlineClickHandler);
};
var addInlineClickHandler = function(e) {
const addInlineClickHandler = function(e) {
e.preventDefault();
var template = $("#" + options.prefix + "-empty");
var row = template.clone(true);
const template = $("#" + options.prefix + "-empty");
const row = template.clone(true);
row.removeClass(options.emptyCssClass)
.addClass(options.formCssClass)
.attr("id", options.prefix + "-" + nextIndex);
@ -94,7 +94,7 @@
* The "X" button that is part of every unsaved inline.
* (When saved, it is replaced with a "Delete" checkbox.)
*/
var addInlineDeleteButton = function(row) {
const addInlineDeleteButton = function(row) {
if (row.is("tr")) {
// If the forms are laid out in table rows, insert
// the remove button into the last table cell:
@ -112,14 +112,14 @@
row.find("a." + options.deleteCssClass).on('click', inlineDeleteHandler.bind(this));
};
var inlineDeleteHandler = function(e1) {
const inlineDeleteHandler = function(e1) {
e1.preventDefault();
var deleteButton = $(e1.target);
var row = deleteButton.closest('.' + options.formCssClass);
var inlineGroup = row.closest('.inline-group');
const deleteButton = $(e1.target);
const row = deleteButton.closest('.' + options.formCssClass);
const inlineGroup = row.closest('.inline-group');
// Remove the parent form containing this button,
// 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')) {
prevRow.remove();
}
@ -131,7 +131,7 @@
}
$(document).trigger('formset:removed', [row, options.prefix]);
// Update the TOTAL_FORMS form count.
var forms = $("." + options.formCssClass);
const forms = $("." + options.formCssClass);
$("#id_" + options.prefix + "-TOTAL_FORMS").val(forms.length);
// Show add button again once below maximum number.
if ((maxForms.val() === '') || (maxForms.val() - forms.length) > 0) {
@ -141,8 +141,8 @@
toggleDeleteButtonVisibility(inlineGroup);
// Also, update names and ids for all remaining form controls so
// they remain in sequence:
var i, formCount;
var updateElementCallback = function() {
let i, formCount;
const updateElementCallback = function() {
updateElementIndex(this, options.prefix, 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) {
inlineGroup.find('.inline-deletelink').hide();
} else {
@ -175,7 +175,7 @@
// Show the add button if allowed to add more items.
// 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) {
addButton.parent().show();
} else {
@ -202,9 +202,9 @@
// Tabular inlines ---------------------------------------------------------
$.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
if (typeof DateTimeShortcuts !== "undefined") {
$(".datetimeshortcuts").remove();
@ -212,24 +212,24 @@
}
};
var updateSelectFilter = function() {
const updateSelectFilter = function() {
// If any SelectFilter widgets are a part of the new form,
// instantiate a new SelectFilter instance for it.
if (typeof SelectFilter !== 'undefined') {
$('.selectfilter').each(function(index, value) {
var namearr = value.name.split('-');
const namearr = value.name.split('-');
SelectFilter.init(value.id, namearr[namearr.length - 1], false);
});
$('.selectfilterstacked').each(function(index, value) {
var namearr = value.name.split('-');
const namearr = value.name.split('-');
SelectFilter.init(value.id, namearr[namearr.length - 1], true);
});
}
};
var initPrepopulatedFields = function(row) {
const initPrepopulatedFields = function(row) {
row.find('.prepopulated_field').each(function() {
var field = $(this),
const field = $(this),
input = field.find('input, select, textarea'),
dependency_list = input.data('dependency_list') || [],
dependencies = [];
@ -262,15 +262,15 @@
// Stacked inlines ---------------------------------------------------------
$.fn.stackedFormset = function(selector, options) {
var $rows = $(this);
var updateInlineLabel = function(row) {
const $rows = $(this);
const updateInlineLabel = function(row) {
$(selector).find(".inline_label").each(function(i) {
var count = i + 1;
const count = i + 1;
$(this).html($(this).html().replace(/(#\d+)/g, "#" + count));
});
};
var reinitDateTimeShortCuts = function() {
const reinitDateTimeShortCuts = function() {
// Reinitialize the calendar and clock widgets by force, yuck.
if (typeof DateTimeShortcuts !== "undefined") {
$(".datetimeshortcuts").remove();
@ -278,23 +278,23 @@
}
};
var updateSelectFilter = function() {
const updateSelectFilter = function() {
// If any SelectFilter widgets were added, instantiate a new instance.
if (typeof SelectFilter !== "undefined") {
$(".selectfilter").each(function(index, value) {
var namearr = value.name.split('-');
const namearr = value.name.split('-');
SelectFilter.init(value.id, namearr[namearr.length - 1], false);
});
$(".selectfilterstacked").each(function(index, value) {
var namearr = value.name.split('-');
const namearr = value.name.split('-');
SelectFilter.init(value.id, namearr[namearr.length - 1], true);
});
}
};
var initPrepopulatedFields = function(row) {
const initPrepopulatedFields = function(row) {
row.find('.prepopulated_field').each(function() {
var field = $(this),
const field = $(this),
input = field.find('input, select, textarea'),
dependency_list = input.data('dependency_list') || [],
dependencies = [];
@ -329,9 +329,9 @@
$(document).ready(function() {
$(".js-inline-admin-formset").each(function() {
var data = $(this).data(),
inlineOptions = data.inlineFormset,
selector;
const data = $(this).data(),
inlineOptions = data.inlineFormset;
let selector;
switch(data.inlineType) {
case "stacked":
selector = inlineOptions.name + "-group .inline-related";

View File

@ -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",
"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.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();
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)});
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()||
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,
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",
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,
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,
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",
b(c).tabularFormset(c,a.options)}})})})(django.jQuery);
'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_"+
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=
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");
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.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>"),
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],!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,
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],!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,
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).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);

View File

@ -1,8 +1,7 @@
/*global django:true, jQuery:false*/
/*global jQuery:false*/
/* 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
* namespace (i.e. this preserves pre-existing values for both window.$ and
* window.jQuery).
*/
var django = django || {};
django.jQuery = jQuery.noConflict(true);
window.django = {jQuery: jQuery.noConflict(true)};

View File

@ -1,7 +1,7 @@
/*global opener */
(function() {
'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) {
case 'change':
opener.dismissChangeRelatedObjectPopup(window, initData.value, initData.obj, initData.new_value);

View File

@ -11,15 +11,15 @@
allowUnicode - Unicode support of the URLify'd string
*/
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
if (prepopulatedField.data('_changed')) {
return;
}
var values = [];
const values = [];
$.each(dependencies, function(i, field) {
field = $(field);
if (field.val().length > 0) {

View File

@ -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);

View File

@ -1,6 +1,6 @@
(function($) {
'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) {
$('.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(

View File

@ -2,7 +2,7 @@
(function() {
'use strict';
var LATIN_MAP = {
const LATIN_MAP = {
'À': 'A', 'Á': 'A', 'Â': 'A', 'Ã': 'A', 'Ä': 'A', 'Å': 'A', 'Æ': 'AE',
'Ç': 'C', 'È': 'E', 'É': 'E', 'Ê': 'E', 'Ë': 'E', 'Ì': 'I', 'Í': 'I',
'Î': 'I', 'Ï': 'I', 'Ð': 'D', 'Ñ': 'N', 'Ò': 'O', 'Ó': 'O', 'Ô': 'O',
@ -14,10 +14,10 @@
'ö': 'o', 'ő': 'o', 'ø': 'o', 'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u',
'ű': 'u', 'ý': 'y', 'þ': 'th', 'ÿ': 'y'
};
var LATIN_SYMBOLS_MAP = {
const LATIN_SYMBOLS_MAP = {
'©': '(c)'
};
var GREEK_MAP = {
const GREEK_MAP = {
'α': 'a', 'β': 'b', 'γ': 'g', 'δ': 'd', 'ε': 'e', 'ζ': 'z', 'η': 'h',
'θ': '8', 'ι': 'i', 'κ': 'k', 'λ': 'l', 'μ': 'm', 'ν': 'n', 'ξ': '3',
'ο': 'o', 'π': 'p', 'ρ': 'r', 'σ': 's', 'τ': 't', 'υ': 'y', 'φ': 'f',
@ -29,15 +29,15 @@
'Φ': 'F', 'Χ': 'X', 'Ψ': 'PS', 'Ω': 'W', 'Ά': 'A', 'Έ': 'E', 'Ί': 'I',
'Ό': 'O', 'Ύ': 'Y', 'Ή': 'H', 'Ώ': 'W', 'Ϊ': 'I', 'Ϋ': 'Y'
};
var TURKISH_MAP = {
const TURKISH_MAP = {
'ş': 's', 'Ş': 'S', 'ı': 'i', 'İ': 'I', 'ç': 'c', 'Ç': 'C', 'ü': 'u',
'Ü': 'U', 'ö': 'o', 'Ö': 'O', 'ğ': 'g', 'Ğ': 'G'
};
var ROMANIAN_MAP = {
const ROMANIAN_MAP = {
'ă': 'a', 'î': 'i', 'ș': 's', 'ț': 't', 'â': 'a',
'Ă': 'A', 'Î': 'I', 'Ș': 'S', 'Ț': 'T', 'Â': 'A'
};
var RUSSIAN_MAP = {
const RUSSIAN_MAP = {
'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd', 'е': 'e', 'ё': 'yo',
'ж': 'zh', 'з': 'z', 'и': 'i', 'й': 'j', 'к': 'k', 'л': 'l', 'м': 'm',
'н': 'n', 'о': 'o', 'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
@ -49,16 +49,16 @@
'Ф': 'F', 'Х': 'H', 'Ц': 'C', 'Ч': 'Ch', 'Ш': 'Sh', 'Щ': 'Sh', 'Ъ': '',
'Ы': 'Y', 'Ь': '', 'Э': 'E', 'Ю': 'Yu', 'Я': 'Ya'
};
var UKRAINIAN_MAP = {
const UKRAINIAN_MAP = {
'Є': 'Ye', 'І': 'I', 'Ї': 'Yi', 'Ґ': 'G', 'є': 'ye', 'і': 'i',
'ї': 'yi', 'ґ': 'g'
};
var CZECH_MAP = {
const CZECH_MAP = {
'č': 'c', 'ď': 'd', 'ě': 'e', 'ň': 'n', 'ř': 'r', 'š': 's', 'ť': 't',
'ů': 'u', 'ž': 'z', 'Č': 'C', 'Ď': 'D', 'Ě': 'E', 'Ň': 'N', 'Ř': 'R',
'Š': 'S', 'Ť': 'T', 'Ů': 'U', 'Ž': 'Z'
};
var SLOVAK_MAP = {
const SLOVAK_MAP = {
'á': 'a', 'ä': 'a', 'č': 'c', 'ď': 'd', 'é': 'e', 'í': 'i', 'ľ': 'l',
'ĺ': 'l', 'ň': 'n', 'ó': 'o', 'ô': 'o', 'ŕ': 'r', 'š': 's', 'ť': 't',
'ú': 'u', 'ý': 'y', 'ž': 'z',
@ -66,40 +66,40 @@
'Ĺ': 'L', 'Ň': 'N', 'Ó': 'O', 'Ô': 'O', 'Ŕ': 'R', 'Š': 'S', 'Ť': 'T',
'Ú': 'U', 'Ý': 'Y', 'Ž': 'Z'
};
var POLISH_MAP = {
const POLISH_MAP = {
'ą': 'a', 'ć': 'c', 'ę': 'e', 'ł': 'l', 'ń': 'n', 'ó': 'o', 'ś': 's',
'ź': 'z', 'ż': 'z',
'Ą': 'A', 'Ć': 'C', 'Ę': 'E', 'Ł': 'L', 'Ń': 'N', 'Ó': 'O', 'Ś': 'S',
'Ź': 'Z', 'Ż': 'Z'
};
var LATVIAN_MAP = {
const LATVIAN_MAP = {
'ā': 'a', 'č': 'c', 'ē': 'e', 'ģ': 'g', 'ī': 'i', 'ķ': 'k', 'ļ': 'l',
'ņ': 'n', 'š': 's', 'ū': 'u', 'ž': 'z',
'Ā': 'A', 'Č': 'C', 'Ē': 'E', 'Ģ': 'G', 'Ī': 'I', 'Ķ': 'K', 'Ļ': 'L',
'Ņ': 'N', 'Š': 'S', 'Ū': 'U', 'Ž': 'Z'
};
var ARABIC_MAP = {
const ARABIC_MAP = {
'أ': 'a', 'ب': 'b', 'ت': 't', 'ث': 'th', 'ج': 'g', 'ح': 'h', 'خ': 'kh', 'د': 'd',
'ذ': 'th', 'ر': 'r', 'ز': 'z', 'س': 's', 'ش': 'sh', 'ص': 's', 'ض': 'd', 'ط': 't',
'ظ': 'th', 'ع': 'aa', 'غ': 'gh', 'ف': 'f', 'ق': 'k', 'ك': 'k', 'ل': 'l', 'م': 'm',
'ن': 'n', 'ه': 'h', 'و': 'o', 'ي': 'y'
};
var LITHUANIAN_MAP = {
const LITHUANIAN_MAP = {
'ą': 'a', 'č': 'c', 'ę': 'e', 'ė': 'e', 'į': 'i', 'š': 's', 'ų': 'u',
'ū': 'u', 'ž': 'z',
'Ą': 'A', 'Č': 'C', 'Ę': 'E', 'Ė': 'E', 'Į': 'I', 'Š': 'S', 'Ų': 'U',
'Ū': 'U', 'Ž': 'Z'
};
var SERBIAN_MAP = {
const SERBIAN_MAP = {
'ђ': 'dj', 'ј': 'j', 'љ': 'lj', 'њ': 'nj', 'ћ': 'c', 'џ': 'dz',
'đ': 'dj', 'Ђ': 'Dj', 'Ј': 'j', 'Љ': 'Lj', 'Њ': 'Nj', 'Ћ': 'C',
'Џ': 'Dz', 'Đ': 'Dj'
};
var AZERBAIJANI_MAP = {
const AZERBAIJANI_MAP = {
'ç': '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',
'თ': 't', 'ი': 'i', 'კ': 'k', 'ლ': 'l', 'მ': 'm', 'ნ': 'n', 'ო': 'o',
'პ': 'p', 'ჟ': 'j', 'რ': 'r', 'ს': 's', 'ტ': 't', 'უ': 'u', 'ფ': 'f',
@ -107,7 +107,7 @@
'წ': 'w', 'ჭ': 'ch', 'ხ': 'x', 'ჯ': 'j', 'ჰ': 'h'
};
var ALL_DOWNCODE_MAPS = [
const ALL_DOWNCODE_MAPS = [
LATIN_MAP,
LATIN_SYMBOLS_MAP,
GREEK_MAP,
@ -126,22 +126,22 @@
GEORGIAN_MAP
];
var Downcoder = {
const Downcoder = {
'Initialize': function() {
if (Downcoder.map) { // already made
return;
}
Downcoder.map = {};
Downcoder.chars = [];
for (var i = 0; i < ALL_DOWNCODE_MAPS.length; i++) {
var lookup = ALL_DOWNCODE_MAPS[i];
for (var c in lookup) {
for (let i = 0; i < ALL_DOWNCODE_MAPS.length; i++) {
const lookup = ALL_DOWNCODE_MAPS[i];
for (const c in lookup) {
if (lookup.hasOwnProperty(c)) {
Downcoder.map[c] = lookup[c];
}
}
}
for (var k in Downcoder.map) {
for (const k in Downcoder.map) {
if (Downcoder.map.hasOwnProperty(k)) {
Downcoder.chars.push(k);
}
@ -164,17 +164,17 @@
if (!allowUnicode) {
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)
// characters.
if (!hasUnicodeChars) {
var removeList = [
const removeList = [
"a", "an", "as", "at", "before", "but", "by", "for", "from",
"is", "in", "into", "like", "of", "off", "on", "onto", "per",
"since", "than", "the", "this", "that", "to", "up", "via",
"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.toLowerCase(); // convert to lowercase

View File

@ -1,18 +1,18 @@
/* global ol */
var GeometryTypeControl = function(opt_options) {
function GeometryTypeControl(opt_options) {
'use strict';
// 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';
if (options.active) {
element.classList.add("type-active");
}
var self = this;
var switchType = function(e) {
const self = this;
const switchType = function(e) {
e.preventDefault();
if (options.widget.currentGeometryType !== self) {
options.widget.map.removeInteraction(options.widget.interactions.draw);
@ -39,7 +39,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
// TODO: allow deleting individual features (#8972)
(function() {
'use strict';
var jsonFormat = new ol.format.GeoJSON();
const jsonFormat = new ol.format.GeoJSON();
function MapWidget(options) {
this.map = null;
@ -56,7 +56,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
};
// Altering using user-provided options
for (var property in options) {
for (const property in options) {
if (options.hasOwnProperty(property)) {
this.options[property] = options[property];
}
@ -78,9 +78,9 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
});
// Populate and set handlers for the feature container
var self = this;
const self = this;
this.featureCollection.on('add', function(event) {
var feature = event.element;
const feature = event.element;
feature.on('change', function() {
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) {
var features = jsonFormat.readFeatures('{"type": "Feature", "geometry": ' + initial_value + '}');
var extent = ol.extent.createEmpty();
const features = jsonFormat.readFeatures('{"type": "Feature", "geometry": ' + initial_value + '}');
const extent = ol.extent.createEmpty();
features.forEach(function(feature) {
this.featureOverlay.getSource().addFeature(feature);
ol.extent.extend(extent, feature.getGeometry().getExtent());
@ -113,7 +113,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
}
MapWidget.prototype.createMap = function() {
var map = new ol.Map({
const map = new ol.Map({
target: this.options.map_id,
layers: [this.options.base_layer],
view: new ol.View({
@ -134,7 +134,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
});
// Initialize the draw interaction
var geomType = this.options.geom_name;
let geomType = this.options.geom_name;
if (geomType === "Unknown" || geomType === "GeometryCollection") {
// Default to Point, but create icons to switch type
geomType = "Point";
@ -154,7 +154,7 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
};
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) {
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);
if (this.typeChoices) {
// Show geometry type icons
var divs = document.getElementsByClassName("switch-type");
for (var i = 0; i !== divs.length; i++) {
const divs = document.getElementsByClassName("switch-type");
for (let i = 0; i !== divs.length; i++) {
divs[i].style.visibility = "visible";
}
}
@ -177,8 +177,8 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
this.interactions.draw.setActive(false);
if (this.typeChoices) {
// Hide geometry type icons
var divs = document.getElementsByClassName("switch-type");
for (var i = 0; i !== divs.length; i++) {
const divs = document.getElementsByClassName("switch-type");
for (let i = 0; i !== divs.length; i++) {
divs[i].style.visibility = "hidden";
}
}
@ -194,18 +194,18 @@ ol.inherits(GeometryTypeControl, ol.control.Control);
MapWidget.prototype.serializeFeatures = function() {
// Three use cases: GeometryCollection, multigeometries, and single geometry
var geometry = null;
var features = this.featureOverlay.getSource().getFeatures();
let geometry = null;
const features = this.featureOverlay.getSource().getFeatures();
if (this.options.is_collection) {
if (this.options.geom_name === "GeometryCollection") {
var geometries = [];
for (var i = 0; i < features.length; i++) {
const geometries = [];
for (let i = 0; i < features.length; i++) {
geometries.push(features[i].getGeometry());
}
geometry = new ol.geom.GeometryCollection(geometries);
} else {
geometry = features[0].getGeometry().clone();
for (var j = 1; j < features.length; j++) {
for (let j = 1; j < features.length; j++) {
switch (geometry.getType()) {
case "MultiPoint":
geometry.appendPoint(features[j].getGeometry().getPoint(0));

View File

@ -5,14 +5,14 @@
QUnit.module('admin.DateTimeShortcuts');
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);
DateTimeShortcuts.init();
var shortcuts = $('.datetimeshortcuts');
const shortcuts = $('.datetimeshortcuts');
assert.equal(shortcuts.length, 1);
assert.equal(shortcuts.find('a:first').text(), 'Today');
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) {
var $ = django.jQuery;
var timeField = $('<input type="text" name="time_test" class="vTimeField">');
const $ = django.jQuery;
const timeField = $('<input type="text" name="time_test" class="vTimeField">');
$('#qunit-fixture').append(timeField);
DateTimeShortcuts.clockHours.time_test = [['3 a.m.', 3]];
DateTimeShortcuts.init();
@ -32,9 +32,9 @@ QUnit.test('custom time shortcuts', function(assert) {
});
QUnit.test('time zone offset warning', function(assert) {
var $ = django.jQuery;
var savedOffset = $('body').attr('data-admin-utc-offset');
var timeField = $('<input type="text" name="time_test" class="vTimeField">');
const $ = django.jQuery;
const savedOffset = $('body').attr('data-admin-utc-offset');
const timeField = $('<input type="text" name="time_test" class="vTimeField">');
$('#qunit-fixture').append(timeField);
$('body').attr('data-admin-utc-offset', new Date().getTimezoneOffset() * -60 + 3600);
DateTimeShortcuts.init();

View File

@ -5,14 +5,14 @@
QUnit.module('admin.SelectBox');
QUnit.test('init: no options', function(assert) {
var $ = django.jQuery;
const $ = django.jQuery;
$('<select id="id"></select>').appendTo('#qunit-fixture');
SelectBox.init('id');
assert.equal(SelectBox.cache.id.length, 0);
});
QUnit.test('filter', function(assert) {
var $ = django.jQuery;
const $ = django.jQuery;
$('<select id="id"></select>').appendTo('#qunit-fixture');
$('<option value="0">A</option>').appendTo('#id');
$('<option value="1">B</option>').appendTo('#id');

View File

@ -5,7 +5,7 @@
QUnit.module('admin.SelectFilter2');
QUnit.test('init', function(assert) {
var $ = django.jQuery;
const $ = django.jQuery;
$('<form><select id="id"></select></form>').appendTo('#qunit-fixture');
$('<option value="0">A</option>').appendTo('#id');
SelectFilter.init('id', 'things', 0);

View File

@ -9,7 +9,7 @@ QUnit.module('admin.actions', {
window._actions_icnt = '100';
/* eslint-enable */
var $ = django.jQuery;
const $ = django.jQuery;
$('#qunit-fixture').append($('#result-table').text());
$('tr input.action-select').actions();
@ -17,7 +17,7 @@ QUnit.module('admin.actions', {
});
QUnit.test('check', function(assert) {
var $ = django.jQuery;
const $ = django.jQuery;
assert.notOk($('.action-select').is(':checked'));
$('#action-toggle').click();
assert.ok($('.action-select').is(':checked'));

View File

@ -42,7 +42,7 @@ QUnit.test('Date.getTwoDigitSecond', 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('%B %d, %Y'), 'July 01, 2014');
});
@ -50,26 +50,26 @@ QUnit.test('Date.strftime', function(assert) {
QUnit.test('String.strptime', function(assert) {
// Use UTC functions for extracting dates since the calendar uses them as
// 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.getUTCMonth(), 1);
assert.equal(firstParsedDate.getUTCFullYear(), 1988);
// 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.getUTCMonth(), 1);
assert.equal(secondParsedDate.getUTCFullYear(), 1988);
var format = django.get_format('DATE_INPUT_FORMATS')[0];
var thirdParsedDate = '1983-11-20'.strptime(format);
const format = django.get_format('DATE_INPUT_FORMATS')[0];
const thirdParsedDate = '1983-11-20'.strptime(format);
assert.equal(thirdParsedDate.getUTCDate(), 20);
assert.equal(thirdParsedDate.getUTCMonth(), 10);
assert.equal(thirdParsedDate.getUTCFullYear(), 1983);
// 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.getUTCMonth(), 8);
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.
// Checking timezones from GMT+0100 to GMT+1200
var i, tz, date;
for (i = 1; i <= 12; i++) {
tz = i > 9 ? '' + i : '0' + i;
date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT+' + tz + '00'));
for (let i = 1; i <= 12; i++) {
const tz = i > 9 ? '' + i : '0' + i;
const date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT+' + tz + '00'));
assert.notEqual(date.getUTCDate(), 26);
assert.equal(date.getUTCDate(), 25);
assert.equal(date.getUTCMonth(), 1);
@ -91,9 +90,9 @@ QUnit.test('String.strptime', function(assert) {
}
// Checking timezones from GMT+0000 to GMT-1100
for (i = 0; i <= 11; i++) {
tz = i > 9 ? '' + i : '0' + i;
date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT-' + tz + '00'));
for (let i = 0; i <= 11; i++) {
const tz = i > 9 ? '' + i : '0' + i;
const date = new Date(Date.parse('Feb 26, 1988 00:00:00 GMT-' + tz + '00'));
assert.equal(date.getUTCDate(), 26);
assert.equal(date.getUTCMonth(), 1);
assert.equal(date.getUTCFullYear(), 1988);

View File

@ -4,8 +4,8 @@
QUnit.module('admin.inlines: tabular formsets', {
beforeEach: function() {
var $ = django.jQuery;
var that = this;
const $ = django.jQuery;
const that = this;
this.addText = 'Add another';
$('#qunit-fixture').append($('#tabular-formset').text());
@ -25,14 +25,14 @@ QUnit.test('no forms', 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);
addButton.click();
assert.ok(this.table.find('#first-1'));
});
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);
addButton.click();
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) {
assert.expect(6);
var $ = django.jQuery;
var $document = $(document);
var addButton = this.table.find('.add-row a');
const $ = django.jQuery;
const $document = $(document);
const addButton = this.table.find('.add-row a');
$document.on('formset:added', function(event, $row, formsetName) {
assert.ok(true, 'event `formset:added` triggered');
assert.equal(true, $row.is('#first-1'));
@ -50,8 +50,8 @@ QUnit.test('add/remove form events', function(assert) {
$document.off('formset:added');
});
addButton.click();
var deletedRow = $('#first-1');
var deleteLink = this.table.find('.inline-deletelink');
const deletedRow = $('#first-1');
const deleteLink = this.table.find('.inline-deletelink');
$document.on('formset:removed', function(event, $row, formsetName) {
assert.ok(true, 'event `formset:removed` triggered');
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) {
var $ = django.jQuery;
const $ = django.jQuery;
$('#qunit-fixture').empty(); // Clear the table added in beforeEach
$('#qunit-fixture').append($('#tabular-formset').text());
this.table = $('table.inline');
this.inlineRow = this.table.find('tr');
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', {
prefix: 'first',
deleteText: 'Remove',
@ -82,7 +82,7 @@ QUnit.test('existing add button', function(assert) {
QUnit.module('admin.inlines: tabular formsets with validation errors', {
beforeEach: function() {
var $ = django.jQuery;
const $ = django.jQuery;
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
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) {
var tr = this.inlineRows.slice(0, 1);
const tr = this.inlineRows.slice(0, 1);
assert.ok(tr.hasClass('dynamic-second'));
assert.ok(tr.hasClass('has_original'));
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) {
var tr = this.inlineRows.slice(1, 2);
const tr = this.inlineRows.slice(1, 2);
assert.ok(tr.hasClass('dynamic-second'));
assert.notOk(tr.hasClass('has_original'));
assert.equal(tr.find('.inline-deletelink').length, 1);
});
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.notOk(tr.hasClass('dynamic-second'));
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) {
var $ = django.jQuery;
const $ = django.jQuery;
assert.ok(this.table.find('.row-form-errors').length);
var tr = this.inlineRows.slice(1, 2);
var trWithErrors = tr.prev();
const tr = this.inlineRows.slice(1, 2);
const trWithErrors = tr.prev();
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}));
assert.notOk(this.table.find('.row-form-errors').length);
});
QUnit.module('admin.inlines: tabular formsets with max_num', {
beforeEach: function() {
var $ = django.jQuery;
const $ = django.jQuery;
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
this.table = $('table.inline');
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) {
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'));
});
QUnit.test('make addButton visible again', function(assert) {
var $ = django.jQuery;
var addButton = this.table.find('tr.add_row > td > a');
var removeButton = this.table.find('tr.form-row:first').find('a.inline-deletelink');
const $ = django.jQuery;
const addButton = this.table.find('tr.add_row > td > a');
const removeButton = this.table.find('tr.form-row:first').find('a.inline-deletelink');
removeButton.trigger($.Event( "click", { target: removeButton } ));
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', {
beforeEach: function() {
var $ = django.jQuery;
const $ = django.jQuery;
$('#qunit-fixture').append($('#tabular-formset-with-validation-error').text());
this.table = $('table.inline');
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) {
var $ = django.jQuery;
var addButton = this.table.find('tr.add-row > td > a');
const $ = django.jQuery;
const addButton = this.table.find('tr.add-row > td > a');
addButton.trigger($.Event( "click", { target: addButton } ));
assert.equal(this.table.find('.inline-deletelink:visible').length, 2);
});

View File

@ -1,6 +1,6 @@
(function(globals) {
'use strict';
var django = globals.django || (globals.django = {});
const django = globals.django;
django.pluralidx = function(count) { return (count === 1) ? 0 : 1; };
@ -69,7 +69,7 @@
};
django.get_format = function(format_type) {
var value = django.formats[format_type];
const value = django.formats[format_type];
if (typeof value === 'undefined') {
return format_type;
} else {

View File

@ -5,8 +5,8 @@
QUnit.module('gis.OLMapWidget');
QUnit.test('MapWidget.featureAdded', function(assert) {
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
var widget = new MapWidget(options);
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
const widget = new MapWidget(options);
assert.equal(widget.featureCollection.getLength(), 1);
widget.serializeFeatures();
assert.equal(
@ -17,14 +17,14 @@ QUnit.test('MapWidget.featureAdded', function(assert) {
});
QUnit.test('MapWidget.map_srid', function(assert) {
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
var widget = new MapWidget(options);
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
const widget = new MapWidget(options);
assert.equal(widget.map.getView().getProjection().getCode(), 'EPSG:3857', 'SRID 3857');
});
QUnit.test('MapWidget.defaultCenter', function(assert) {
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
var widget = new MapWidget(options);
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
let widget = new MapWidget(options);
assert.equal(widget.defaultCenter().toString(), '0,0', 'Default center at 0, 0');
options.default_lat = 47.08;
options.default_lon = 6.81;
@ -38,32 +38,32 @@ QUnit.test('MapWidget.defaultCenter', function(assert) {
});
QUnit.test('MapWidget.interactions', function(assert) {
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
var widget = new MapWidget(options);
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
const widget = new MapWidget(options);
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.modify.getActive(), true, "Modify is active with an existing point");
});
QUnit.test('MapWidget.clearFeatures', function(assert) {
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
var widget = new MapWidget(options);
var initial_value = document.getElementById('id_point').value;
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
const widget = new MapWidget(options);
const initial_value = document.getElementById('id_point').value;
widget.clearFeatures();
assert.equal(document.getElementById('id_point').value, "");
document.getElementById('id_point').value = initial_value;
});
QUnit.test('MapWidget.multipolygon', function(assert) {
var options = {id: 'id_multipolygon', map_id: 'id_multipolygon_map', geom_name: 'MultiPolygon'};
var widget = new MapWidget(options);
const options = {id: 'id_multipolygon', map_id: 'id_multipolygon_map', geom_name: 'MultiPolygon'};
const widget = new MapWidget(options);
assert.ok(widget.options.is_collection);
assert.equal(widget.interactions.draw.getActive(), true, "Draw is active with no existing content");
});
QUnit.test('MapWidget.IsCollection', function(assert) {
var options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
var widget = new MapWidget(options);
const options = {id: 'id_point', map_id: 'id_point_map', geom_name: 'Point'};
let widget = new MapWidget(options);
assert.notOk(widget.options.is_collection);
// Empty the default initial Point
document.getElementById('id_point').value = "";