- Author:
- robharvey
- Posted:
- April 17, 2007
- Language:
- JavaScript
- Version:
- Not specified
- Score:
- 2 (after 2 ratings)
This is quite a hack (need to modify Django code), but relatively simple and stable. It displays various times in whichever increments and columns you specify, rather than just Midnight, Noon, Now & 6am. You can use it throughout your admin and newforms-admin code.
This is a (slightly updated) copy of the ticket #1848 which wasn't included in trunk. http://code.djangoproject.com/ticket/1848
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | /*
Update contrib/admin/media/js/admin/DateTimeShortcuts addClock function, replace all "quickElement" lines with the following
*/
var interval_mins = 30; // minutes between displayed times
var columns = 4; // number of columns in popup
var total_intervals = 24 * 60 / interval_mins;
var time = new Date(0,0,0,0,0,0,0);
var midnight = new Date(0,0,0,0,0,0,0);
var noon = new Date(0,0,0,12,0,0,0);
for (var si=0; si<columns; si++) {
time_list = quickElement('ul', clock_box, '');
time_list.className = 'timelist';
if (si == columns-1) {
time_list.id = 'timelist-end';
}
var this_col_count = total_intervals / columns;
for (var sj=0; sj<this_col_count; sj++) {
var time_text = null;
if (time.getTime() == midnight.getTime())
time_text = gettext("Midnight");
else if (time.getTime() == noon.getTime())
time_text = gettext("Noon");
else {
var hours = time.getHours();
hours = hours > 12 ? hours - 12 : hours;
time_text = "" + (hours == 0 ? 12 : hours);
var mins = time.getMinutes();
time_text += ":" + (mins > 9 ? "" : "0") + mins;
time_text += (hours >= 12 ? " PM" : " AM");
}
quickElement("a", quickElement("li", time_list, ""), time_text, "href", "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", '" + time.getHourMinute() + "');");
time = new Date(time.getTime() + (interval_mins * 60 * 1000)); // interval * seconds in a minute * millis in second
}
}
|
More like this
- Django Collapsed Stacked Inlines by applecat 1 year, 9 months ago
- Django Collapsed Stacked Inlines by mkarajohn 3 years, 10 months ago
- Dynamically adding forms to a formset. OOP version. by halfnibble 9 years, 6 months ago
- Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 11 years, 7 months ago
- Django admin inline ordering - javascript only implementation by ojhilt 11 years, 11 months ago
Comments
CSS changes required to support columns:
#
Please login first before commenting.