mirror of https://github.com/django/django.git
Fixed #25006 -- Allowed custom time shortcuts in admin's time picker.
This commit is contained in:
parent
5b6181f4d5
commit
385cf7091e
|
@ -8,6 +8,15 @@
|
||||||
calendars: [],
|
calendars: [],
|
||||||
calendarInputs: [],
|
calendarInputs: [],
|
||||||
clockInputs: [],
|
clockInputs: [],
|
||||||
|
clockHours: {
|
||||||
|
default_: [
|
||||||
|
['Now', -1],
|
||||||
|
['Midnight', 0],
|
||||||
|
['6 a.m.', 6],
|
||||||
|
['Noon', 12],
|
||||||
|
['6 p.m.', 18]
|
||||||
|
]
|
||||||
|
},
|
||||||
dismissClockFunc: [],
|
dismissClockFunc: [],
|
||||||
dismissCalendarFunc: [],
|
dismissCalendarFunc: [],
|
||||||
calendarDivName1: 'calendarbox', // name of calendar <div> that gets toggled
|
calendarDivName1: 'calendarbox', // name of calendar <div> that gets toggled
|
||||||
|
@ -157,30 +166,16 @@
|
||||||
quickElement('h2', clock_box, gettext('Choose a time'));
|
quickElement('h2', clock_box, gettext('Choose a time'));
|
||||||
var time_list = quickElement('ul', clock_box);
|
var time_list = quickElement('ul', clock_box);
|
||||||
time_list.className = 'timelist';
|
time_list.className = 'timelist';
|
||||||
var time_link = quickElement("a", quickElement("li", time_list), gettext("Now"), "href", "#");
|
// 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;
|
||||||
|
DateTimeShortcuts.clockHours[name].forEach(function(element) {
|
||||||
|
var time_link = quickElement('a', quickElement('li', time_list), gettext(element[0]), 'href', '#');
|
||||||
addEvent(time_link, 'click', function(e) {
|
addEvent(time_link, 'click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
DateTimeShortcuts.handleClockQuicklink(num, -1);
|
DateTimeShortcuts.handleClockQuicklink(num, element[1]);
|
||||||
});
|
});
|
||||||
time_link = quickElement("a", quickElement("li", time_list), gettext("Midnight"), "href", "#");
|
|
||||||
addEvent(time_link, 'click', function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
DateTimeShortcuts.handleClockQuicklink(num, 0);
|
|
||||||
});
|
|
||||||
time_link = quickElement("a", quickElement("li", time_list), gettext("6 a.m."), "href", "#");
|
|
||||||
addEvent(time_link, 'click', function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
DateTimeShortcuts.handleClockQuicklink(num, 6);
|
|
||||||
});
|
|
||||||
time_link = quickElement("a", quickElement("li", time_list), gettext("Noon"), "href", "#");
|
|
||||||
addEvent(time_link, 'click', function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
DateTimeShortcuts.handleClockQuicklink(num, 12);
|
|
||||||
});
|
|
||||||
time_link = quickElement("a", quickElement("li", time_list), gettext("6 p.m."), "href", "#");
|
|
||||||
addEvent(time_link, 'click', function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
DateTimeShortcuts.handleClockQuicklink(num, 18);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var cancel_p = quickElement('p', clock_box);
|
var cancel_p = quickElement('p', clock_box);
|
||||||
|
|
|
@ -21,3 +21,12 @@ QUnit.test('init', function(assert) {
|
||||||
// should be 0 when a timezone offset isn't set in the HTML body attribute.
|
// should be 0 when a timezone offset isn't set in the HTML body attribute.
|
||||||
assert.equal(DateTimeShortcuts.timezoneOffset, 0);
|
assert.equal(DateTimeShortcuts.timezoneOffset, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test('custom time shortcuts', function(assert) {
|
||||||
|
var $ = django.jQuery;
|
||||||
|
var timeField = $('<input type="text" name="time_test" class="vTimeField">');
|
||||||
|
$('#qunit-fixture').append(timeField);
|
||||||
|
DateTimeShortcuts.clockHours.time_test = [['3 a.m.', 3]];
|
||||||
|
DateTimeShortcuts.init();
|
||||||
|
assert.equal($('.clockbox').find('a').first().text(), '3 a.m.');
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue