Ticket #4574: 4574.diff

File 4574.diff, 3.3 KB (added by fcurella, 4 years ago)

patch with updated js code. No tests yet, since I have no idea on how to write tests for js code

  • django/contrib/admin/static/admin/js/calendar.js

     
    4545        }
    4646        return days;
    4747    },
    48     draw: function(month, year, div_id, callback) { // month = 1-12, year = 1-9999
     48    draw: function(month, year, div_id, callback, selected) { // month = 1-12, year = 1-9999
    4949        var today = new Date();
    5050        var todayDay = today.getDate();
    5151        var todayMonth = today.getMonth()+1;
    5252        var todayYear = today.getFullYear();
    5353        var todayClass = '';
    54 
     54        var is_selected_month = false;
     55        if (typeof selected != 'undefined') {
     56            is_selected_month = (selected.getFullYear() == year && (selected.getMonth()+1) == month);
     57        }
    5558        month = parseInt(month);
    5659        year = parseInt(year);
    5760        var calDiv = document.getElementById(div_id);
     
    7477        for (var i = 0; i < startingPos; i++) {
    7578            var _cell = quickElement('td', tableRow, ' ');
    7679            _cell.style.backgroundColor = '#f3f3f3';
     80            _cell.className = "nonday";
    7781        }
    7882
    7983        // Draw days of month
     
    8286            if (i%7 == 0 && currentDay != 1) {
    8387                tableRow = quickElement('tr', tableBody);
    8488            }
     89            todayClass='';
    8590            if ((currentDay==todayDay) && (month==todayMonth) && (year==todayYear)) {
    8691                todayClass='today';
    87             } else {
    88                 todayClass='';
    8992            }
     93            if (is_selected_month && currentDay == selected.getDate()) {
     94                if (todayclass != '') todayclass += " ";
     95                todayclass += "selected"; /* e.g: class="today selected" */
     96            }
    9097            var cell = quickElement('td', tableRow, '', 'class', todayClass);
    9198
    9299            quickElement('a', cell, currentDay, 'href', 'javascript:void(' + callback + '('+year+','+month+','+currentDay+'));');
     
    97104        while (tableRow.childNodes.length < 7) {
    98105            var _cell = quickElement('td', tableRow, ' ');
    99106            _cell.style.backgroundColor = '#f3f3f3';
     107            _cell.className = "nonday";
    100108        }
    101109
    102110        calDiv.appendChild(calTable);
     
    104112}
    105113
    106114// Calendar -- A calendar instance
    107 function Calendar(div_id, callback) {
     115function Calendar(div_id, callback, selected) {
    108116    // div_id (string) is the ID of the element in which the calendar will
    109117    //     be displayed
    110118    // callback (string) is the name of a JavaScript function that will be
     
    115123    this.today = new Date();
    116124    this.currentMonth = this.today.getMonth() + 1;
    117125    this.currentYear = this.today.getFullYear();
     126    if (typeof selected == 'undefined') {
     127            this.selected = this.today;
     128        }
     129        else {
     130            this.selected = selected;
     131        }
    118132}
    119133Calendar.prototype = {
    120134    drawCurrent: function() {
    121         CalendarNamespace.draw(this.currentMonth, this.currentYear, this.div_id, this.callback);
     135        CalendarNamespace.draw(this.currentMonth, this.currentYear, this.div_id, this.callback, this.selected);
    122136    },
    123137    drawDate: function(month, year) {
    124138        this.currentMonth = month;
Back to Top