Login

More admin clock time increments

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

  1. Django Collapsed Stacked Inlines by applecat 1 year ago
  2. Django Collapsed Stacked Inlines by mkarajohn 3 years, 2 months ago
  3. Dynamically adding forms to a formset. OOP version. by halfnibble 8 years, 10 months ago
  4. Convert multiple select for m2m to multiple checkboxes in django admin form by abidibo 10 years, 11 months ago
  5. Django admin inline ordering - javascript only implementation by ojhilt 11 years, 3 months ago

Comments

robharvey (on April 17, 2007):

CSS changes required to support columns:

.clockbox {
    width:              25em;
}

.clockbox h2 {
    text-align:         center;
}

ul.timelist {
    float:              left;
    padding-right:      5px;
    padding-left:       5px;
    border-right:       1px solid lightblue;
}

ul.timelist a:visited {
    color:              black;
}

ul#timelist-end {
    float:              none;
}

#

Please login first before commenting.