Code

Ticket #1848: dts.diff

File dts.diff, 3.9 KB (added by oggie rob, 8 years ago)

Javascript diff of DateTimeShortcuts

Line 
1Index: django/contrib/admin/media/js/admin/DateTimeShortcuts.js
2===================================================================
3--- django/contrib/admin/media/js/admin/DateTimeShortcuts.js    (revision 2714)
4+++ django/contrib/admin/media/js/admin/DateTimeShortcuts.js    (working copy)
5@@ -52,16 +52,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@@ -77,13 +80,31 @@
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().getHourMinute());")
35-        quickElement("a", quickElement("li", time_list, ""), gettext("Midnight"), "href", "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", '00:00');")
36-        quickElement("a", quickElement("li", time_list, ""), gettext("6 a.m."), "href", "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", '06:00');")
37-        quickElement("a", quickElement("li", time_list, ""), gettext("Noon"), "href", "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", '12: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+                    time_text = time.toLocaleTimeString().replace(":00 ", ""); // its waaifer theen
60+                quickElement("a", quickElement("li", time_list, ""), time_text, "href", "javascript:DateTimeShortcuts.handleClockQuicklink(" + num + ", '" + time.getHourMinute() + "');");
61+                time = new Date(time.getTime() + (interval_mins * 60 * 1000)); // interval * seconds in a minute * millis in second
62+            }
63+        }
64         cancel_p = quickElement('p', clock_box, '');
65         cancel_p.className = 'calendar-cancel';
66         quickElement('a', cancel_p, gettext('Cancel'), 'href', 'javascript:DateTimeShortcuts.dismissClock(' + num + ');');