DatePicker.prototype._updateTable = function()

in tapestry-core/src/main/resources/META-INF/modules/t5/core/datepicker.js [483:571]


  DatePicker.prototype._updateTable = function ()
  {
      // if no element no need to continue
      if (this._table == null) return;

      var i;
      var str = "";
      var rows = 6;
      var cols = 7;
      var currentWeek = 0;

      var cells = new Array(rows);
      this._matrix = new Array(rows)
      for (i = 0; i < rows; i++)
      {
          cells[i] = new Array(cols);
          this._matrix[i] = new Array(cols);
      }

      // Set the tmpDate to this month
      var tmpDate = new Date(this._calendarDate.getFullYear(),
              this._calendarDate.getMonth(), 1);
      var today = new Date();
      // go thorugh all days this month and store the text
      // and the class name in the cells matrix
      for (i = 1; i < 32; i++)
      {
          tmpDate.setDate(i);
          // convert to ISO, Monday is 0 and 6 is Sunday
          var weekDay = ( tmpDate.getDay() + 6 ) % 7;
          var colIndex = ( weekDay - this._firstWeekDay + 7 ) % 7;
          if (tmpDate.getMonth() == this._calendarDate.getMonth())
          {

              var isToday = this._datesAreSame(tmpDate, today);

              cells[currentWeek][colIndex] = { text: "", className: "" };

              if (this._datesAreSame(this._selectedDate, tmpDate)) 
                  cells[currentWeek][colIndex].className += "selected ";
              if (isToday)
                  cells[currentWeek][colIndex].className += "today ";
              if (( tmpDate.getDay() + 6 ) % 7 == this._redWeekDay) // ISO
                  cells[currentWeek][colIndex].className += "red";

              cells[currentWeek][colIndex].text =
              this._matrix[currentWeek][colIndex] = tmpDate.getDate();

              if (colIndex == 6)
                  currentWeek++;
          }
      }

      // fix day letter order if not standard
      var weekDays = this._days;
      if (this._firstWeekDay != 0)
      {
          weekDays = new Array(7);
          for (i = 0; i < 7; i++)
              weekDays[i] = this._days[ (i + this._firstWeekDay) % 7];
      }

      // update text in days row
      var tds = this._table.firstChild.tBodies[0].rows[0].cells;
      for (i = 0; i < cols; i++)
          tds[i].firstChild.data = weekDays[i];

      // update the text nodes and class names
      var trs = this._table.firstChild.tBodies[0].rows;
      var tmpCell;
      var nbsp = String.fromCharCode(160);
      for (var y = 0; y < rows; y++)
      {
          for (var x = 0; x < cols; x++)
          {
              tmpCell = trs[y + 2].cells[x];
              if (typeof cells[y][x] != "undefined")
              {
                  tmpCell.className = cells[y][x].className;
                  tmpCell.firstChild.data = cells[y][x].text;
              }
              else
              {
                  tmpCell.className = "";
                  tmpCell.firstChild.data = nbsp;
              }
          }
      }
  }