Code

Ticket #1848: django_mods.diff

File django_mods.diff, 4.2 KB (added by oggie_rob, 6 years ago)

Updated changes & synced to trunk, in case anybody wants it for their own

Line 
1Index: django/contrib/admin/media/js/admin/DateTimeShortcuts.js
2===================================================================
3--- django/contrib/admin/media/js/admin/DateTimeShortcuts.js    (revision 7403)
4+++ django/contrib/admin/media/js/admin/DateTimeShortcuts.js    (working copy)
5@@ -55,16 +55,19 @@
6         shortcuts_span.appendChild(document.createTextNode('\240|\240'));
7         shortcuts_span.appendChild(clock_link);
8 
9-        // Create clock link div
10+        // Create clock link div. Intervals are in 30 minutes, but may be adjusted by modifying values below
11         //
12         // Markup looks like:
13         // <div id="clockbox1" class="clockbox module">
14         //     <h2>Choose a time</h2>
15         //     <ul class="timelist">
16-        //         <li><a href="#">Now</a></li>
17         //         <li><a href="#">Midnight</a></li>
18-        //         <li><a href="#">6 a.m.</a></li>
19+        //         <li><a href="#">12:30 AM</a></li>
20+        //         <li><a href="#"><1:00 AM</a></li>
21+        //         ...
22         //         <li><a href="#">Noon</a></li>
23+        //         <li><a href="#">12:30 PM</a></li>
24+        //         ...
25         //     </ul>
26         //     <p class="calendar-cancel"><a href="#">Cancel</a></p>
27         // </div>
28@@ -78,13 +81,44 @@
29         addEvent(clock_box, 'click', DateTimeShortcuts.cancelEventPropagation);
30 
31         quickElement('h2', clock_box, gettext('Choose a time'));
32-        time_list = quickElement('ul', clock_box, '');
33-        time_list.className = 'timelist';
34-        quickElement("a", quickElement("li", time_list, ""), gettext("Now"), "href", "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", new Date().getHourMinuteSecond());")
35-        quickElement("a", quickElement("li", time_list, ""), gettext("Midnight"), "href", "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", '00:00:00');")
36-        quickElement("a", quickElement("li", time_list, ""), gettext("6 a.m."), "href", "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", '06:00:00');")
37-        quickElement("a", quickElement("li", time_list, ""), gettext("Noon"), "href", "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", '12:00:00');")
38-
39+        var interval_mins = 30; // minutes between displayed times
40+        var columns = 4;        // number of columns in popup
41+        var total_intervals = 24 * 60 / interval_mins;
42+        var time = new Date(0,0,0,0,0,0,0);
43+        var midnight = new Date(0,0,0,0,0,0,0);
44+        var noon = new Date(0,0,0,12,0,0,0);
45+        for (var si=0; si<columns; si++) {
46+            time_list = quickElement('ul', clock_box, '');
47+            time_list.className = 'timelist';
48+            if (si == columns-1) {
49+                time_list.id = 'timelist-end';
50+            }
51+            var this_col_count = total_intervals / columns;
52+            for (var sj=0; sj<this_col_count; sj++) {
53+                var time_text = null;
54+                if (time.getTime() == midnight.getTime())
55+                    time_text = gettext("Midnight");
56+                else if (time.getTime() == noon.getTime())
57+                    time_text = gettext("Noon");
58+                else {
59+                    var hrs = time.getHours();
60+                    if (hrs > 12) {
61+                        hrs -= 12;
62+                    }
63+                    else if (hrs == 0) {
64+                        hrs = 12;
65+                    }
66+                    var mins = "" + time.getMinutes();
67+                    if (mins == "0") {
68+                        mins = "00"
69+                    }
70+                    var ap = time.getHours() >= 12 ? "PM" : "AM";
71+                    time_text = "" + hrs + ":" + mins + " " + ap;
72+                }
73+                quickElement("a", quickElement("li", time_list, ""), time_text, "href", "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", '" + time.getHourMinute() + "');");
74+                time = new Date(time.getTime() + (interval_mins * 60 * 1000)); // interval * seconds in a minute * millis in second
75+            }
76+        }
77         cancel_p = quickElement('p', clock_box, '');
78         cancel_p.className = 'calendar-cancel';
79         quickElement('a', cancel_p, gettext('Cancel'), 'href', 'javascript:DateTimeShortcuts.dismissClock(' + num + ');');