Ticket #4574: calendar_css_today_and_selected.diff
File calendar_css_today_and_selected.diff, 5.7 KB (added by , 13 years ago) |
---|
-
django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js
diff --git a/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js b/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js
a b 247 247 format = format.replace('\n', '\\n'); 248 248 format = format.replace('\t', '\\t'); 249 249 format = format.replace("'", "\\'"); 250 return ["function(y, m, d) { DateTimeShortcuts.calendarInputs[", 251 num, 252 "].value = new Date(y, m-1, d).strftime('", 253 format, 254 "');DateTimeShortcuts.calendarInputs[", 255 num, 256 "].focus();document.getElementById(DateTimeShortcuts.calendarDivName1+", 257 num, 258 ").style.display='none';}"].join(''); 250 return ["function(y, m, d) { selected = new Date(y, m-1, d);", 251 "DateTimeShortcuts.calendarInputs[", 252 num, 253 "].value = selected.strftime('", 254 format, 255 "');DateTimeShortcuts.calendarInputs[", 256 num, 257 "].focus();document.getElementById(DateTimeShortcuts.calendarDivName1+", 258 num, 259 ").style.display='none';", 260 "DateTimeShortcuts.calendars[", 261 num, 262 "].selected = selected;}"].join(''); 259 263 }, 260 264 handleCalendarQuickLink: function(num, offset) { 261 265 var d = new Date(); -
django/contrib/admin/static/admin/js/calendar.js
diff --git a/django/contrib/admin/static/admin/js/calendar.js b/django/contrib/admin/static/admin/js/calendar.js
a b 46 46 return days; 47 47 }, 48 48 draw: function(month, year, div_id, callback, selected) { // month = 1-12, year = 1-9999 49 var today = new Date();50 var todayDay = today.getDate();51 var todayMonth = today.getMonth()+1;52 var todayYear = today.getFullYear();53 var todayClass = '';54 var is_selected_month = false;55 if (typeof selected != 'undefined') {56 is_selected_month = (selected.getFullYear() == year && (selected.getMonth()+1) == month);57 }58 49 month = parseInt(month); 59 50 year = parseInt(year); 51 60 52 var calDiv = document.getElementById(div_id); 61 53 removeChildren(calDiv); 62 54 var calTable = document.createElement('table'); 63 quickElement('caption', calTable, CalendarNamespace.monthsOfYear[month-1] + ' ' + year); 55 var caption = CalendarNamespace.monthsOfYear[month-1] + ' ' + year; 56 quickElement('caption', calTable, caption); 64 57 var tableBody = quickElement('tbody', calTable); 65 58 66 59 // Draw days-of-week header 67 60 var tableRow = quickElement('tr', tableBody); 68 61 for (var i = 0; i < 7; i++) { 69 quickElement('th', tableRow, CalendarNamespace.daysOfWeek[(i + CalendarNamespace.firstDayOfWeek) % 7]); 62 var dayNum = (i + CalendarNamespace.firstDayOfWeek) % 7 63 var dayName = CalendarNamespace.daysOfWeek[dayNum] 64 quickElement('th', tableRow, dayName); 70 65 } 71 66 72 var startingPos = new Date(year, month-1, 1 - CalendarNamespace.firstDayOfWeek).getDay(); 67 var startingPos = new Date(year, month-1, 68 1-CalendarNamespace.firstDayOfWeek).getDay(); 73 69 var days = CalendarNamespace.getDaysInMonth(month, year); 74 70 75 71 // Draw blanks before first of month … … 81 77 } 82 78 83 79 // Draw days of month 80 var is_selected_month = false; 81 if (typeof selected != 'undefined') { 82 is_selected_month = (selected.getFullYear() == year && 83 (selected.getMonth() + 1) == month); 84 } 85 var today = new Date(); 86 var todayDay = today.getDate(); 87 var todayMonth = today.getMonth() + 1; 88 var todayYear = today.getFullYear(); 84 89 var currentDay = 1; 90 console.log(selected) 85 91 for (var i = startingPos; currentDay <= days; i++) { 86 if (i %7 == 0 && currentDay != 1) {92 if (i % 7 == 0 && currentDay != 1) { 87 93 tableRow = quickElement('tr', tableBody); 88 94 } 89 todayClass=''; 90 if ((currentDay==todayDay) && (month==todayMonth) && (year==todayYear)) { 91 todayClass='today'; 95 96 var currentClass = ''; 97 if ((currentDay == todayDay) && (month == todayMonth) && (year == todayYear)) { 98 currentClass = 'today'; 92 99 } 100 93 101 if (is_selected_month && currentDay == selected.getDate()) { 94 if ( todayclass != '') todayclass += " ";95 todayclass += "selected"; /* e.g: class="today selected" */102 if (currentClass != '') currentClass += " "; 103 currentClass += "selected"; /* e.g: class="today selected" */ 96 104 } 97 var cell = quickElement('td', tableRow, '', 'class', todayClass);105 var cell = quickElement('td', tableRow, '', 'class', currentClass); 98 106 99 107 quickElement('a', cell, currentDay, 'href', 'javascript:void(' + callback + '('+year+','+month+','+currentDay+'));'); 100 108 currentDay++; … … 123 131 this.today = new Date(); 124 132 this.currentMonth = this.today.getMonth() + 1; 125 133 this.currentYear = this.today.getFullYear(); 126 if (typeof selected == 'undefined') { 127 this.selected = this.today; 128 } 129 else { 130 this.selected = selected; 131 } 134 this.selected = typeof selected == 'undefined' ? this.today : selected; 132 135 } 133 136 Calendar.prototype = { 134 137 drawCurrent: function() {