A Qcodo based CMS/ecommerce framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
6.0 KiB

12 years ago
  1. /////////////////////////////////////////////
  2. // Control: Dialog Box functionality
  3. /////////////////////////////////////////////
  4. qcodo.monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
  5. qcodo.monthNamesAbbreviated = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
  6. qcodo.dayNames = new Array("Su","Mo","Tu","We","Th","Fr","Sa");
  7. qcodo.registerCalendar = function(mixControl, strDtxControlId) {
  8. // Initialize the Event Handler
  9. qcodo.handleEvent();
  10. // Get Control/Wrapper
  11. var objControl; if (!(objControl = qcodo.getControl(mixControl))) return;
  12. var objWrapper = objControl.wrapper;
  13. // Get Linked DateTimeTextbox
  14. objControl.dateTimeTextBox = qcodo.getControl(strDtxControlId);
  15. // Get CalendarPane and Hide it
  16. objControl.calendarPane = document.getElementById(objControl.id + "_cal");
  17. objControl.calendarPane.style.display = "none";
  18. objControl.showCalendar = function() {
  19. var strPositionArray = this.wrapper.getAbsolutePosition();
  20. this.calendarPane.style.left = strPositionArray.x + "px";
  21. this.calendarPane.style.top = strPositionArray.y + "px";
  22. this.calendarPane.style.position = "absolute";
  23. this.calendarPane.style.zIndex = 10;
  24. this.calendarPane.style.display = "block";
  25. this.drawCalendar(0, 0);
  26. };
  27. objControl.setDate = function(intYear, intMonth, intDay) {
  28. this.dateTimeTextBox.value = qcodo.monthNamesAbbreviated[intMonth] + " " + intDay + " " + intYear;
  29. this.hideCalendar();
  30. };
  31. objControl.setToToday = function() {
  32. var dttToday = new Date();
  33. this.setDate(dttToday.getFullYear(), dttToday.getMonth(), dttToday.getDate())
  34. };
  35. objControl.drawCalendar = function(intYear, intMonth) {
  36. // Get the "selected" date and the "current" date
  37. var dttSelected;
  38. if (this.dateTimeTextBox.value)
  39. dttSelected = new Date(this.dateTimeTextBox.value);
  40. var dttToday = new Date();
  41. // Get the month to view
  42. var dttMonthToView;
  43. // If viewing a specific month/year, use it
  44. if (intYear)
  45. dttMonthToView = new Date(intYear, intMonth, 1);
  46. // If no "selected date" use "today"
  47. else if (!dttSelected || dttSelected == "Invalid Date")
  48. dttMonthToView = new Date();
  49. // Otherwise, use the "selected date"
  50. else
  51. dttMonthToView = new Date(dttSelected);
  52. dttMonthToView.setDate(1);
  53. var intViewMonth = dttMonthToView.getMonth();
  54. var intViewYear = dttMonthToView.getFullYear();
  55. // Render the month to view
  56. var strCalendar = '<table border="0" cellspacing="0"><thead><tr>';
  57. for (var intDay = 0; intDay < qcodo.dayNames.length; ++intDay) strCalendar += "<th>" + qcodo.dayNames[intDay] + "</th>";
  58. strCalendar += "</tr></thead>";
  59. for (var intDaysBack = dttMonthToView.getDay(); intDaysBack > 0; intDaysBack--)
  60. dttMonthToView.setDate(dttMonthToView.getDate() - 1);
  61. for (var intWeek = 0; intWeek < 6; intWeek++) {
  62. strCalendar += '<tr>';
  63. for (var intDay = 0; intDay < 7; intDay++) {
  64. var strStyle = (intWeek == 5) ? "lastRow " : "";
  65. if ((dttMonthToView.getDate() == dttToday.getDate()) && (dttMonthToView.getMonth() == dttToday.getMonth()) && (dttMonthToView.getFullYear() == dttToday.getFullYear()))
  66. strStyle += 'today ';
  67. if (dttSelected && (dttMonthToView.getDate() == dttSelected.getDate()) && (dttMonthToView.getMonth() == dttSelected.getMonth()) && (dttMonthToView.getFullYear() == dttSelected.getFullYear()))
  68. strStyle += 'selected ';
  69. if (dttMonthToView.getMonth() != intViewMonth)
  70. strStyle += 'nonMonth';
  71. if (strStyle)
  72. strStyle = ' class="' + strStyle + '"';
  73. strCalendar += '<td' + strStyle + '><a href="#" onclick="qc.getC(\'' + this.id + '\').setDate(' +
  74. dttMonthToView.getFullYear() + ',' + dttMonthToView.getMonth() + ',' + dttMonthToView.getDate() + ');return false;">' +
  75. dttMonthToView.getDate() + '</a></td>';
  76. dttMonthToView.setDate(dttMonthToView.getDate() + 1);
  77. };
  78. strCalendar += '</tr>';
  79. };
  80. strCalendar += '</table>';
  81. var intViewPreviousMonth = intViewMonth - 1;
  82. var intViewPreviousYear = intViewYear;
  83. if (intViewPreviousMonth == -1) {
  84. intViewPreviousMonth = 11;
  85. intViewPreviousYear--;
  86. };
  87. var strPreviousMonth = intViewPreviousYear + ',' + intViewPreviousMonth;
  88. var intViewNextMonth = intViewMonth + 1;
  89. var intViewNextYear = intViewYear;
  90. if (intViewNextMonth == 12) {
  91. intViewNextMonth = 0;
  92. intViewNextYear++;
  93. };
  94. var strNextMonth = intViewNextYear + ',' + intViewNextMonth;
  95. var strPreviousYear = (intViewYear - 1) + ',' + intViewMonth;
  96. var strNextYear = (intViewYear + 1) + ',' + intViewMonth;
  97. var strNavigator = '<div class="navigator">';
  98. strNavigator += '<div class="left"><a href="#" onclick="qc.getC(\'' + this.id + '\').drawCalendar(' + strPreviousMonth + ');return false;">&laquo;</a></div>';
  99. strNavigator += '<div class="month">' + qcodo.monthNames[intViewMonth] + '</div>';
  100. strNavigator += '<div class="left"><a href="#" onclick="qc.getC(\'' + this.id + '\').drawCalendar(' + strNextMonth + ');return false;">&raquo;</a></div>';
  101. strNavigator += '<div class="year"><a href="#" onclick="qc.getC(\'' + this.id + '\').drawCalendar(' + strPreviousYear + ');return false;">&laquo;</a>';
  102. strNavigator += '<span>' + intViewYear + '</span>';
  103. strNavigator += '<a href="#" onclick="qc.getC(\'' + this.id + '\').drawCalendar(' + strNextYear + ');return false;">&raquo;</a></div>';
  104. strNavigator += '</div>';
  105. var strOptions = '<div class="options">';
  106. strOptions += '<a href="#" onclick="qc.getC(\'' + this.id + '\').setToToday(); return false;">&quot;Today&quot;</a> &nbsp; &nbsp; ';
  107. strOptions += '<a href="#" onclick="qc.getC(\'' + this.id + '\').hideCalendar(); return false;">Cancel</a></div>';
  108. this.calendarPane.innerHTML = strNavigator + strCalendar + strOptions;
  109. };
  110. objControl.hideCalendar = function() {
  111. this.calendarPane.style.display = 'none';
  112. };
  113. objControl.onclick = objControl.showCalendar;
  114. };
  115. //////////////////
  116. // Qcodo Shortcuts
  117. //////////////////
  118. qc.regCAL = qcodo.registerCalendar;