| 1 |
define("dojox/widget/MultiSelectCalendar", [ |
| 2 |
"dojo/main", "dijit", |
| 3 |
"dojo/text!./MultiSelectCalendar/MultiSelectCalendar.html", |
| 4 |
"dojo/cldr/supplemental", |
| 5 |
"dojo/date", "dojo/date/stamp", |
| 6 |
"dojo/date/locale", |
| 7 |
"dijit/_Widget", "dijit/_TemplatedMixin", "dijit/_WidgetsInTemplateMixin", |
| 8 |
"dijit/_CssStateMixin", "dijit/form/DropDownButton", "dijit/typematic" |
| 9 |
], |
| 10 |
function(dojo, dijit, template, supplemental, date, stamp, locale, |
| 11 |
_Widget, _TemplatedMixin, _WidgetsInTemplateMixin, |
| 12 |
_CssStateMixin, DropDownButton, typematic) { |
| 13 |
|
| 14 |
dojo.experimental("dojox.widget.MultiSelectCalendar"); |
| 15 |
|
| 16 |
var MultiSelectCalendar = dojo.declare( |
| 17 |
"dojox.widget.MultiSelectCalendar", |
| 18 |
[_Widget, _TemplatedMixin, _WidgetsInTemplateMixin, _CssStateMixin], |
| 19 |
{ |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
templateString: template, |
| 36 |
widgetsInTemplate: true, |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
value: {}, |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
datePackage: "dojo.date", |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
dayWidth: "narrow", |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
tabIndex: "0", |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
returnIsoRanges : false, |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
currentFocus: new Date(), |
| 64 |
|
| 65 |
baseClass:"dijitCalendar", |
| 66 |
|
| 67 |
cssStateNodes: { |
| 68 |
"decrementMonth": "dijitCalendarArrow", |
| 69 |
"incrementMonth": "dijitCalendarArrow", |
| 70 |
"previousYearLabelNode": "dijitCalendarPreviousYear", |
| 71 |
"nextYearLabelNode": "dijitCalendarNextYear" |
| 72 |
}, |
| 73 |
|
| 74 |
_areValidDates: function( value){ |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
for (var selDate in this.value){ |
| 81 |
valid = (selDate && !isNaN(selDate) && typeof value == "object" && selDate.toString() != this.constructor.prototype.value.toString()); |
| 82 |
if(!valid){ return false; } |
| 83 |
} |
| 84 |
return true; |
| 85 |
}, |
| 86 |
|
| 87 |
_getValueAttr: function(){ |
| 88 |
|
| 89 |
|
| 90 |
if(this.returnIsoRanges){ |
| 91 |
datesWithRanges = this._returnDatesWithIsoRanges(this._sort()); |
| 92 |
return datesWithRanges; |
| 93 |
}else{ |
| 94 |
return this._sort(); |
| 95 |
} |
| 96 |
}, |
| 97 |
|
| 98 |
_setValueAttr: function( value, priorityChange){ |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
this.value = {}; |
| 112 |
if(dojo.isArray(value)) { |
| 113 |
dojo.forEach(value,function(element, i){ |
| 114 |
|
| 115 |
var slashPosition = element.indexOf("/"); |
| 116 |
if(slashPosition == -1){ |
| 117 |
|
| 118 |
this.value[element] = 1; |
| 119 |
}else{ |
| 120 |
|
| 121 |
var dateA = stamp.fromISOString(element.substr(0,10)); |
| 122 |
var dateB = stamp.fromISOString(element.substr(11,10)); |
| 123 |
|
| 124 |
this.toggleDate(dateA,[],[]); |
| 125 |
if((dateA - dateB) > 0){ |
| 126 |
|
| 127 |
this._addToRangeRTL(dateA, dateB, [], []); |
| 128 |
}else{ |
| 129 |
|
| 130 |
this._addToRangeLTR(dateA, dateB, [], []); |
| 131 |
} |
| 132 |
} |
| 133 |
},this); |
| 134 |
if(value.length > 0){ |
| 135 |
this.focusOnLastDate(value[value.length-1]); |
| 136 |
} |
| 137 |
}else{ |
| 138 |
if(value){ |
| 139 |
|
| 140 |
|
| 141 |
value = new this.dateClassObj(value); |
| 142 |
} |
| 143 |
if(this._isValidDate(value)){ |
| 144 |
value.setHours(1, 0, 0, 0); |
| 145 |
|
| 146 |
if(!this.isDisabledDate(value, this.lang)){ |
| 147 |
dateIndex = stamp.toISOString(value).substring(0,10); |
| 148 |
|
| 149 |
this.value[dateIndex] = 1; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
this.set("currentFocus", value); |
| 155 |
|
| 156 |
if(priorityChange || typeof priorityChange == "undefined"){ |
| 157 |
this.onChange(this.get('value')); |
| 158 |
this.onValueSelected(this.get('value')); |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
this._populateGrid(); |
| 164 |
}, |
| 165 |
focusOnLastDate : function(lastElement){ |
| 166 |
|
| 167 |
|
| 168 |
var slashPositionLastDate = lastElement.indexOf("/"); |
| 169 |
var dateA,dateB; |
| 170 |
if(slashPositionLastDate == -1){ |
| 171 |
|
| 172 |
lastDate = stamp.fromISOString(lastElement); |
| 173 |
}else{ |
| 174 |
dateA = stamp.fromISOString(lastElement.substr(0,10)); |
| 175 |
dateB = stamp.fromISOString(lastElement.substr(11,10)); |
| 176 |
if((dateA - dateB) > 0){ |
| 177 |
lastDate = dateA; |
| 178 |
}else{ |
| 179 |
lastDate = dateB; |
| 180 |
} |
| 181 |
} |
| 182 |
this.set("currentFocus", lastDate); |
| 183 |
}, |
| 184 |
_isValidDate: function( value){ |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
return value && !isNaN(value) && typeof value == "object" && |
| 191 |
value.toString() != this.constructor.prototype.value.toString(); |
| 192 |
}, |
| 193 |
_setText: function(node, text){ |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
while(node.firstChild){ |
| 200 |
node.removeChild(node.firstChild); |
| 201 |
} |
| 202 |
node.appendChild(dojo.doc.createTextNode(text)); |
| 203 |
}, |
| 204 |
|
| 205 |
_populateGrid: function(){ |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
var month = new this.dateClassObj(this.currentFocus); |
| 212 |
month.setDate(1); |
| 213 |
|
| 214 |
var firstDay = month.getDay(), |
| 215 |
daysInMonth = this.dateFuncObj.getDaysInMonth(month), |
| 216 |
daysInPreviousMonth = this.dateFuncObj.getDaysInMonth(this.dateFuncObj.add(month, "month", -1)), |
| 217 |
today = new this.dateClassObj(), |
| 218 |
dayOffset = dojo.cldr.supplemental.getFirstDayOfWeek(this.lang); |
| 219 |
if(dayOffset > firstDay){ dayOffset -= 7; } |
| 220 |
|
| 221 |
|
| 222 |
this.listOfNodes = dojo.query(".dijitCalendarDateTemplate", this.domNode); |
| 223 |
|
| 224 |
|
| 225 |
this.listOfNodes.forEach(function(template, i){ |
| 226 |
i += dayOffset; |
| 227 |
var date = new this.dateClassObj(month), |
| 228 |
number, clazz = "dijitCalendar", adj = 0; |
| 229 |
|
| 230 |
if(i < firstDay){ |
| 231 |
number = daysInPreviousMonth - firstDay + i + 1; |
| 232 |
adj = -1; |
| 233 |
clazz += "Previous"; |
| 234 |
}else if(i >= (firstDay + daysInMonth)){ |
| 235 |
number = i - firstDay - daysInMonth + 1; |
| 236 |
adj = 1; |
| 237 |
clazz += "Next"; |
| 238 |
}else{ |
| 239 |
number = i - firstDay + 1; |
| 240 |
clazz += "Current"; |
| 241 |
} |
| 242 |
|
| 243 |
if(adj){ |
| 244 |
date = this.dateFuncObj.add(date, "month", adj); |
| 245 |
} |
| 246 |
date.setDate(number); |
| 247 |
|
| 248 |
if(!this.dateFuncObj.compare(date, today, "date")){ |
| 249 |
clazz = "dijitCalendarCurrentDate " + clazz; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
dateIndex = stamp.toISOString(date).substring(0,10); |
| 254 |
|
| 255 |
if(!this.isDisabledDate(date, this.lang)){ |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
if(this._isSelectedDate(date, this.lang)){ |
| 260 |
if(this.value[dateIndex]){ |
| 261 |
clazz = "dijitCalendarSelectedDate " + clazz; |
| 262 |
}else{ |
| 263 |
clazz = clazz.replace("dijitCalendarSelectedDate ",""); |
| 264 |
} |
| 265 |
} |
| 266 |
} |
| 267 |
if(this._isSelectedDate(date, this.lang)){ |
| 268 |
clazz = "dijitCalendarBrowsingDate " + clazz; |
| 269 |
} |
| 270 |
|
| 271 |
if(this.isDisabledDate(date, this.lang)){ |
| 272 |
clazz = "dijitCalendarDisabledDate " + clazz; |
| 273 |
} |
| 274 |
|
| 275 |
var clazz2 = this.getClassForDate(date, this.lang); |
| 276 |
if(clazz2){ |
| 277 |
clazz = clazz2 + " " + clazz; |
| 278 |
} |
| 279 |
|
| 280 |
template.className = clazz + "Month dijitCalendarDateTemplate"; |
| 281 |
template.dijitDateValue = date.valueOf(); |
| 282 |
dojo.attr(template, "dijitDateValue", date.valueOf()); |
| 283 |
var label = dojo.query(".dijitCalendarDateLabel", template)[0], |
| 284 |
text = date.getDateLocalized ? date.getDateLocalized(this.lang) : date.getDate(); |
| 285 |
this._setText(label, text); |
| 286 |
}, this); |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
var monthNames = this.dateLocaleModule.getNames('months', 'wide', 'standAlone', this.lang, month); |
| 291 |
this.monthDropDownButton.dropDown.set("months", monthNames); |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
this.monthDropDownButton.containerNode.innerHTML = |
| 297 |
(dojo.isIE == 6 ? "" : "<div class='dijitSpacer'>" + this.monthDropDownButton.dropDown.domNode.innerHTML + "</div>") + |
| 298 |
"<div class='dijitCalendarMonthLabel dijitCalendarCurrentMonthLabel'>" + monthNames[month.getMonth()] + "</div>"; |
| 299 |
|
| 300 |
|
| 301 |
var y = month.getFullYear() - 1; |
| 302 |
var d = new this.dateClassObj(); |
| 303 |
dojo.forEach(["previous", "current", "next"], function(name){ |
| 304 |
d.setFullYear(y++); |
| 305 |
this._setText(this[name+"YearLabelNode"], |
| 306 |
this.dateLocaleModule.format(d, {selector:'year', locale:this.lang})); |
| 307 |
}, this); |
| 308 |
}, |
| 309 |
|
| 310 |
goToToday: function(){ |
| 311 |
|
| 312 |
|
| 313 |
this.set('currentFocus', new this.dateClassObj(), false); |
| 314 |
}, |
| 315 |
|
| 316 |
constructor: function(args){ |
| 317 |
var dateClass = (args.datePackage && (args.datePackage != "dojo.date"))? args.datePackage + ".Date" : "Date"; |
| 318 |
this.dateClassObj = dojo.getObject(dateClass, false); |
| 319 |
this.datePackage = args.datePackage || this.datePackage; |
| 320 |
this.dateFuncObj = dojo.getObject(this.datePackage, false); |
| 321 |
this.dateLocaleModule = dojo.getObject(this.datePackage + ".locale", false); |
| 322 |
}, |
| 323 |
|
| 324 |
buildRendering: function(){ |
| 325 |
this.inherited(arguments); |
| 326 |
dojo.setSelectable(this.domNode, false); |
| 327 |
|
| 328 |
var cloneClass = dojo.hitch(this, function(clazz, n){ |
| 329 |
var template = dojo.query(clazz, this.domNode)[0]; |
| 330 |
for(var i=0; i<n; i++){ |
| 331 |
template.parentNode.appendChild(template.cloneNode(true)); |
| 332 |
} |
| 333 |
}); |
| 334 |
|
| 335 |
|
| 336 |
cloneClass(".dijitCalendarDayLabelTemplate", 6); |
| 337 |
cloneClass(".dijitCalendarDateTemplate", 6); |
| 338 |
|
| 339 |
|
| 340 |
cloneClass(".dijitCalendarWeekTemplate", 5); |
| 341 |
|
| 342 |
|
| 343 |
var dayNames = this.dateLocaleModule.getNames('days', this.dayWidth, 'standAlone', this.lang); |
| 344 |
var dayOffset = dojo.cldr.supplemental.getFirstDayOfWeek(this.lang); |
| 345 |
dojo.query(".dijitCalendarDayLabel", this.domNode).forEach(function(label, i){ |
| 346 |
this._setText(label, dayNames[(i + dayOffset) % 7]); |
| 347 |
}, this); |
| 348 |
|
| 349 |
var dateObj = new this.dateClassObj(this.currentFocus); |
| 350 |
|
| 351 |
this.monthDropDownButton.dropDown = new MonthDropDown({ |
| 352 |
id: this.id + "_mdd", |
| 353 |
onChange: dojo.hitch(this, "_onMonthSelect") |
| 354 |
}); |
| 355 |
|
| 356 |
this.set('currentFocus', dateObj, false); |
| 357 |
|
| 358 |
|
| 359 |
var _this = this; |
| 360 |
var typematic = function(nodeProp, dateProp, adj){ |
| 361 |
_this._connects.push( |
| 362 |
dijit.typematic.addMouseListener(_this[nodeProp], _this, function(count){ |
| 363 |
if(count >= 0){ _this._adjustDisplay(dateProp, adj); } |
| 364 |
}, 0.8, 500) |
| 365 |
); |
| 366 |
}; |
| 367 |
typematic("incrementMonth", "month", 1); |
| 368 |
typematic("decrementMonth", "month", -1); |
| 369 |
typematic("nextYearLabelNode", "year", 1); |
| 370 |
typematic("previousYearLabelNode", "year", -1); |
| 371 |
}, |
| 372 |
|
| 373 |
_adjustDisplay: function( part, amount){ |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
this._setCurrentFocusAttr(this.dateFuncObj.add(this.currentFocus, part, amount)); |
| 383 |
}, |
| 384 |
|
| 385 |
_setCurrentFocusAttr: function( date, forceFocus){ |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
var oldFocus = this.currentFocus, |
| 395 |
oldCell = oldFocus ? dojo.query("[dijitDateValue=" + oldFocus.valueOf() + "]", this.domNode)[0] : null; |
| 396 |
|
| 397 |
|
| 398 |
date = new this.dateClassObj(date); |
| 399 |
date.setHours(1, 0, 0, 0); |
| 400 |
|
| 401 |
this._set("currentFocus", date); |
| 402 |
var currentMonth = stamp.toISOString(date).substring(0,7); |
| 403 |
|
| 404 |
if(currentMonth != this.previousMonth){ |
| 405 |
this._populateGrid(); |
| 406 |
this.previousMonth = currentMonth; |
| 407 |
} |
| 408 |
|
| 409 |
|
| 410 |
var newCell = dojo.query("[dijitDateValue='" + date.valueOf() + "']", this.domNode)[0]; |
| 411 |
newCell.setAttribute("tabIndex", this.tabIndex); |
| 412 |
if(this._focused || forceFocus){ |
| 413 |
newCell.focus(); |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
if(oldCell && oldCell != newCell){ |
| 418 |
if(dojo.isWebKit){ |
| 419 |
oldCell.setAttribute("tabIndex", "-1"); |
| 420 |
}else{ |
| 421 |
oldCell.removeAttribute("tabIndex"); |
| 422 |
} |
| 423 |
} |
| 424 |
}, |
| 425 |
|
| 426 |
focus: function(){ |
| 427 |
|
| 428 |
|
| 429 |
this._setCurrentFocusAttr(this.currentFocus, true); |
| 430 |
}, |
| 431 |
|
| 432 |
_onMonthSelect: function( newMonth){ |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
this.currentFocus = this.dateFuncObj.add(this.currentFocus, "month", |
| 441 |
newMonth - this.currentFocus.getMonth()); |
| 442 |
this._populateGrid(); |
| 443 |
}, |
| 444 |
|
| 445 |
toggleDate : function( dateToToggle, selectedDates, unselectedDates){ |
| 446 |
|
| 447 |
|
| 448 |
var dateIndex = stamp.toISOString(dateToToggle).substring(0,10); |
| 449 |
|
| 450 |
if(this.value[dateIndex]){ |
| 451 |
this.unselectDate(dateToToggle, unselectedDates); |
| 452 |
}else{ |
| 453 |
this.selectDate(dateToToggle, selectedDates); |
| 454 |
} |
| 455 |
}, |
| 456 |
|
| 457 |
selectDate : function( dateToSelect, selectedDates){ |
| 458 |
|
| 459 |
var node = this._getNodeByDate(dateToSelect); |
| 460 |
var clazz = node.className; |
| 461 |
var dateIndex = stamp.toISOString(dateToSelect).substring(0,10); |
| 462 |
this.value[dateIndex] = 1; |
| 463 |
selectedDates.push(dateIndex); |
| 464 |
clazz = "dijitCalendarSelectedDate " + clazz; |
| 465 |
|
| 466 |
node.className = clazz; |
| 467 |
}, |
| 468 |
|
| 469 |
unselectDate : function( dateToUnselect, unselectedDates){ |
| 470 |
|
| 471 |
var node = this._getNodeByDate(dateToUnselect); |
| 472 |
var clazz = node.className; |
| 473 |
var dateIndex = stamp.toISOString(dateToUnselect).substring(0,10); |
| 474 |
delete(this.value[dateIndex]); |
| 475 |
unselectedDates.push(dateIndex); |
| 476 |
clazz = clazz.replace("dijitCalendarSelectedDate ",""); |
| 477 |
|
| 478 |
node.className = clazz; |
| 479 |
}, |
| 480 |
|
| 481 |
_getNodeByDate : function( dateNode){ |
| 482 |
|
| 483 |
var firstDate = new this.dateClassObj(this.listOfNodes[0].dijitDateValue); |
| 484 |
var difference = Math.abs(dojo.date.difference(firstDate, dateNode, "day")); |
| 485 |
return this.listOfNodes[difference]; |
| 486 |
}, |
| 487 |
|
| 488 |
_onDayClick: function( evt){ |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
dojo.stopEvent(evt); |
| 498 |
for(var node = evt.target; node && !node.dijitDateValue; node = node.parentNode); |
| 499 |
if(node && !dojo.hasClass(node, "dijitCalendarDisabledDate")){ |
| 500 |
value = new this.dateClassObj(node.dijitDateValue); |
| 501 |
if(!this.rangeJustSelected){ |
| 502 |
this.toggleDate(value,[],[]); |
| 503 |
|
| 504 |
|
| 505 |
this.previouslySelectedDay = value; |
| 506 |
this.set("currentFocus", value); |
| 507 |
this.onValueSelected([stamp.toISOString(value).substring(0,10)]); |
| 508 |
|
| 509 |
}else{ |
| 510 |
this.rangeJustSelected = false; |
| 511 |
this.set("currentFocus", value); |
| 512 |
} |
| 513 |
} |
| 514 |
}, |
| 515 |
|
| 516 |
_onDayMouseOver: function( evt){ |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
var node = |
| 525 |
dojo.hasClass(evt.target, "dijitCalendarDateLabel") ? |
| 526 |
evt.target.parentNode : |
| 527 |
evt.target; |
| 528 |
|
| 529 |
if(node && (node.dijitDateValue || node == this.previousYearLabelNode || node == this.nextYearLabelNode) ){ |
| 530 |
dojo.addClass(node, "dijitCalendarHoveredDate"); |
| 531 |
this._currentNode = node; |
| 532 |
} |
| 533 |
}, |
| 534 |
_setEndRangeAttr: function( value){ |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
value = new this.dateClassObj(value); |
| 540 |
value.setHours(1); |
| 541 |
this.endRange = value; |
| 542 |
}, |
| 543 |
_getEndRangeAttr: function(){ |
| 544 |
|
| 545 |
var value = new this.dateClassObj(this.endRange); |
| 546 |
value.setHours(0, 0, 0, 0); |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
if(value.getDate() < this.endRange.getDate()){ |
| 551 |
value = this.dateFuncObj.add(value, "hour", 1); |
| 552 |
} |
| 553 |
return value; |
| 554 |
}, |
| 555 |
|
| 556 |
_onDayMouseOut: function( evt){ |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
if(!this._currentNode){ return; } |
| 563 |
|
| 564 |
|
| 565 |
if(evt.relatedTarget && evt.relatedTarget.parentNode == this._currentNode){ return; } |
| 566 |
var cls = "dijitCalendarHoveredDate"; |
| 567 |
if(dojo.hasClass(this._currentNode, "dijitCalendarActiveDate")) { |
| 568 |
cls += " dijitCalendarActiveDate"; |
| 569 |
} |
| 570 |
dojo.removeClass(this._currentNode, cls); |
| 571 |
this._currentNode = null; |
| 572 |
}, |
| 573 |
_onDayMouseDown: function( evt){ |
| 574 |
var node = evt.target.parentNode; |
| 575 |
if(node && node.dijitDateValue){ |
| 576 |
dojo.addClass(node, "dijitCalendarActiveDate"); |
| 577 |
this._currentNode = node; |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
if(evt.shiftKey && this.previouslySelectedDay){ |
| 582 |
|
| 583 |
this.selectingRange = true; |
| 584 |
this.set('endRange', node.dijitDateValue); |
| 585 |
this._selectRange(); |
| 586 |
}else{ |
| 587 |
this.selectingRange = false; |
| 588 |
this.previousRangeStart = null; |
| 589 |
this.previousRangeEnd = null; |
| 590 |
} |
| 591 |
}, |
| 592 |
|
| 593 |
_onDayMouseUp: function( evt){ |
| 594 |
var node = evt.target.parentNode; |
| 595 |
if(node && node.dijitDateValue){ |
| 596 |
dojo.removeClass(node, "dijitCalendarActiveDate"); |
| 597 |
} |
| 598 |
}, |
| 599 |
|
| 600 |
|
| 601 |
handleKey: function( evt){ |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
var dk = dojo.keys, |
| 614 |
increment = -1, |
| 615 |
interval, |
| 616 |
newValue = this.currentFocus; |
| 617 |
switch(evt.keyCode){ |
| 618 |
case dk.RIGHT_ARROW: |
| 619 |
increment = 1; |
| 620 |
|
| 621 |
case dk.LEFT_ARROW: |
| 622 |
interval = "day"; |
| 623 |
if(!this.isLeftToRight()){ increment *= -1; } |
| 624 |
break; |
| 625 |
case dk.DOWN_ARROW: |
| 626 |
increment = 1; |
| 627 |
|
| 628 |
case dk.UP_ARROW: |
| 629 |
interval = "week"; |
| 630 |
break; |
| 631 |
case dk.PAGE_DOWN: |
| 632 |
increment = 1; |
| 633 |
|
| 634 |
case dk.PAGE_UP: |
| 635 |
interval = evt.ctrlKey || evt.altKey ? "year" : "month"; |
| 636 |
break; |
| 637 |
case dk.END: |
| 638 |
|
| 639 |
newValue = this.dateFuncObj.add(newValue, "month", 1); |
| 640 |
|
| 641 |
interval = "day"; |
| 642 |
|
| 643 |
case dk.HOME: |
| 644 |
newValue = new this.dateClassObj(newValue); |
| 645 |
newValue.setDate(1); |
| 646 |
break; |
| 647 |
case dk.ENTER: |
| 648 |
case dk.SPACE: |
| 649 |
if(evt.shiftKey && this.previouslySelectedDay){ |
| 650 |
this.selectingRange = true; |
| 651 |
this.set('endRange', newValue); |
| 652 |
this._selectRange(); |
| 653 |
}else{ |
| 654 |
this.selectingRange = false; |
| 655 |
this.toggleDate(newValue,[],[]); |
| 656 |
|
| 657 |
|
| 658 |
this.previouslySelectedDay = newValue; |
| 659 |
this.previousRangeStart = null; |
| 660 |
this.previousRangeEnd = null; |
| 661 |
this.onValueSelected([stamp.toISOString(newValue).substring(0,10)]); |
| 662 |
|
| 663 |
} |
| 664 |
break; |
| 665 |
default: |
| 666 |
return true; |
| 667 |
} |
| 668 |
|
| 669 |
if(interval){ |
| 670 |
newValue = this.dateFuncObj.add(newValue, interval, increment); |
| 671 |
} |
| 672 |
|
| 673 |
this.set("currentFocus", newValue); |
| 674 |
|
| 675 |
return false; |
| 676 |
}, |
| 677 |
|
| 678 |
_onKeyDown: function( evt){ |
| 679 |
|
| 680 |
|
| 681 |
if(!this.handleKey(evt)){ |
| 682 |
dojo.stopEvent(evt); |
| 683 |
} |
| 684 |
}, |
| 685 |
|
| 686 |
_removeFromRangeLTR : function( beginning, end, selectedDates, unselectedDates){ |
| 687 |
|
| 688 |
difference = Math.abs(dojo.date.difference(beginning, end, "day")); |
| 689 |
for(var i = 0; i <= difference; i++){ |
| 690 |
var nextDay = date.add(beginning, 'day',i); |
| 691 |
this.toggleDate(nextDay, selectedDates, unselectedDates); |
| 692 |
} |
| 693 |
if(this.previousRangeEnd === null){ |
| 694 |
|
| 695 |
this.previousRangeEnd = end; |
| 696 |
}else{ |
| 697 |
if(dojo.date.compare(end, this.previousRangeEnd, 'date') > 0 ) |
| 698 |
this.previousRangeEnd = end; |
| 699 |
} |
| 700 |
if(this.previousRangeStart === null){ |
| 701 |
|
| 702 |
this.previousRangeStart = end; |
| 703 |
}else{ |
| 704 |
if(dojo.date.compare(end, this.previousRangeStart, 'date') > 0 ) |
| 705 |
this.previousRangeStart = end; |
| 706 |
} |
| 707 |
|
| 708 |
this.previouslySelectedDay = date.add(nextDay, 'day',1); |
| 709 |
}, |
| 710 |
_removeFromRangeRTL : function( beginning, end, selectedDates, unselectedDates){ |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
difference = Math.abs(dojo.date.difference(beginning, end, "day")); |
| 715 |
for(var i = 0; i <= difference; i++){ |
| 716 |
var nextDay = dojo.date.add(beginning, 'day',-i); |
| 717 |
this.toggleDate(nextDay, selectedDates, unselectedDates); |
| 718 |
} |
| 719 |
if(this.previousRangeEnd === null){ |
| 720 |
this.previousRangeEnd = end; |
| 721 |
}else{ |
| 722 |
if(dojo.date.compare(end, this.previousRangeEnd, 'date') < 0 ){ |
| 723 |
this.previousRangeEnd = end; |
| 724 |
} |
| 725 |
} |
| 726 |
if(this.previousRangeStart === null){ |
| 727 |
this.previousRangeStart = end; |
| 728 |
}else{ |
| 729 |
if(dojo.date.compare(end, this.previousRangeStart, 'date') < 0 ){ |
| 730 |
this.previousRangeStart = end; |
| 731 |
} |
| 732 |
} |
| 733 |
|
| 734 |
this.previouslySelectedDay = date.add(nextDay, 'day',-1); |
| 735 |
}, |
| 736 |
_addToRangeRTL : function( beginning, end, selectedDates, unselectedDates){ |
| 737 |
|
| 738 |
difference = Math.abs(date.difference(beginning, end, "day")); |
| 739 |
|
| 740 |
|
| 741 |
for(var i = 1; i <= difference; i++){ |
| 742 |
var nextDay = date.add(beginning, 'day',-i); |
| 743 |
this.toggleDate(nextDay, selectedDates, unselectedDates); |
| 744 |
} |
| 745 |
|
| 746 |
if(this.previousRangeStart === null){ |
| 747 |
this.previousRangeStart = end; |
| 748 |
}else{ |
| 749 |
if(dojo.date.compare(end, this.previousRangeStart, 'date') < 0 ){ |
| 750 |
this.previousRangeStart = end; |
| 751 |
} |
| 752 |
} |
| 753 |
if(this.previousRangeEnd === null){ |
| 754 |
this.previousRangeEnd = beginning; |
| 755 |
}else{ |
| 756 |
if(dojo.date.compare(beginning, this.previousRangeEnd, 'date') > 0 ){ |
| 757 |
this.previousRangeEnd = beginning; |
| 758 |
} |
| 759 |
} |
| 760 |
|
| 761 |
this.previouslySelectedDay = nextDay; |
| 762 |
}, |
| 763 |
_addToRangeLTR : function( beginning, end, selectedDates, unselectedDates){ |
| 764 |
|
| 765 |
|
| 766 |
difference = Math.abs(dojo.date.difference(beginning, end, "day")); |
| 767 |
for(var i = 1; i <= difference; i++){ |
| 768 |
var nextDay = dojo.date.add(beginning, 'day',i); |
| 769 |
this.toggleDate(nextDay, selectedDates, unselectedDates); |
| 770 |
} |
| 771 |
if(this.previousRangeStart === null){ |
| 772 |
this.previousRangeStart = beginning; |
| 773 |
}else{ |
| 774 |
if(dojo.date.compare(beginning, this.previousRangeStart, 'date') < 0 ){ |
| 775 |
this.previousRangeStart = beginning; |
| 776 |
} |
| 777 |
} |
| 778 |
if(this.previousRangeEnd === null){ |
| 779 |
this.previousRangeEnd = end; |
| 780 |
}else{ |
| 781 |
if(dojo.date.compare(end, this.previousRangeEnd, 'date') > 0 ){ |
| 782 |
this.previousRangeEnd = end; |
| 783 |
} |
| 784 |
} |
| 785 |
|
| 786 |
this.previouslySelectedDay = nextDay; |
| 787 |
}, |
| 788 |
_selectRange : function(){ |
| 789 |
|
| 790 |
var selectedDates = []; |
| 791 |
var unselectedDates = []; |
| 792 |
var beginning = this.previouslySelectedDay; |
| 793 |
var end = this.get('endRange'); |
| 794 |
|
| 795 |
if(!this.previousRangeStart && !this.previousRangeEnd){ |
| 796 |
removingFromRange = false; |
| 797 |
}else{ |
| 798 |
if((dojo.date.compare(end, this.previousRangeStart, 'date') < 0) || (dojo.date.compare(end, this.previousRangeEnd, 'date') > 0)){ |
| 799 |
|
| 800 |
removingFromRange = false; |
| 801 |
}else{ |
| 802 |
removingFromRange = true; |
| 803 |
} |
| 804 |
} |
| 805 |
if(removingFromRange === true){ |
| 806 |
if(dojo.date.compare(end, beginning, 'date') < 0){ |
| 807 |
|
| 808 |
this._removeFromRangeRTL(beginning, end, selectedDates, unselectedDates); |
| 809 |
}else{ |
| 810 |
|
| 811 |
this._removeFromRangeLTR(beginning, end, selectedDates, unselectedDates); |
| 812 |
} |
| 813 |
}else{ |
| 814 |
|
| 815 |
if(dojo.date.compare(end, beginning, 'date') < 0){ |
| 816 |
this._addToRangeRTL(beginning, end, selectedDates, unselectedDates); |
| 817 |
}else{ |
| 818 |
this._addToRangeLTR(beginning, end, selectedDates, unselectedDates); |
| 819 |
} |
| 820 |
} |
| 821 |
|
| 822 |
if(selectedDates.length > 0){ |
| 823 |
this.onValueSelected(selectedDates); |
| 824 |
} |
| 825 |
if(unselectedDates.length > 0){ |
| 826 |
this.onValueUnselected(unselectedDates); |
| 827 |
} |
| 828 |
this.rangeJustSelected = true; |
| 829 |
}, |
| 830 |
|
| 831 |
onValueSelected: function( dates){ |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
}, |
| 839 |
|
| 840 |
onValueUnselected: function( dates){ |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
}, |
| 848 |
onChange: function( date){ |
| 849 |
|
| 850 |
|
| 851 |
}, |
| 852 |
|
| 853 |
_isSelectedDate: function( dateObject, locale){ |
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
dateIndex = stamp.toISOString(dateObject).substring(0,10); |
| 858 |
return this.value[dateIndex]; |
| 859 |
}, |
| 860 |
|
| 861 |
isDisabledDate: function( dateObject, locale){ |
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
}, |
| 870 |
|
| 871 |
getClassForDate: function( dateObject, locale){ |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
}, |
| 882 |
_sort : function(){ |
| 883 |
|
| 884 |
if(this.value == {}){return [];} |
| 885 |
|
| 886 |
var selectedDates = []; |
| 887 |
for (var selDate in this.value){ |
| 888 |
selectedDates.push(selDate); |
| 889 |
} |
| 890 |
|
| 891 |
selectedDates.sort(function(a, b){ |
| 892 |
var dateA = new Date(a), dateB = new Date(b); |
| 893 |
return dateA - dateB; |
| 894 |
}); |
| 895 |
return selectedDates; |
| 896 |
}, |
| 897 |
_returnDatesWithIsoRanges : function(selectedDates ){ |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
var returnDates = []; |
| 902 |
if(selectedDates.length > 1){ |
| 903 |
|
| 904 |
var weHaveRange = false, |
| 905 |
rangeCount = 0, |
| 906 |
startRange = null, |
| 907 |
lastDayRange = null, |
| 908 |
previousDate = stamp.fromISOString(selectedDates[0]); |
| 909 |
|
| 910 |
for(var i = 1; i < selectedDates.length+1; i++){ |
| 911 |
currentDate = stamp.fromISOString(selectedDates[i]); |
| 912 |
if(weHaveRange){ |
| 913 |
|
| 914 |
difference = Math.abs(date.difference(previousDate, currentDate, "day")); |
| 915 |
if(difference == 1){ |
| 916 |
|
| 917 |
lastDayRange = currentDate; |
| 918 |
}else{ |
| 919 |
|
| 920 |
range = stamp.toISOString(startRange).substring(0,10) + |
| 921 |
"/" + stamp.toISOString(lastDayRange).substring(0,10); |
| 922 |
returnDates.push(range); |
| 923 |
weHaveRange = false; |
| 924 |
} |
| 925 |
}else{ |
| 926 |
|
| 927 |
difference = Math.abs(date.difference(previousDate, currentDate, "day")); |
| 928 |
if(difference == 1){ |
| 929 |
|
| 930 |
weHaveRange = true; |
| 931 |
startRange = previousDate; |
| 932 |
lastDayRange = currentDate; |
| 933 |
}else{ |
| 934 |
|
| 935 |
returnDates.push(stamp.toISOString(previousDate).substring(0,10)); |
| 936 |
} |
| 937 |
} |
| 938 |
previousDate = currentDate; |
| 939 |
} |
| 940 |
return returnDates; |
| 941 |
}else{ |
| 942 |
|
| 943 |
return selectedDates; |
| 944 |
} |
| 945 |
} |
| 946 |
} |
| 947 |
); |
| 948 |
|
| 949 |
|
| 950 |
var MonthDropDown = MultiSelectCalendar._MonthDropDown = dojo.declare("dojox.widget._MonthDropDown", |
| 951 |
[_Widget, _TemplatedMixin, _WidgetsInTemplateMixin], { |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
months: [], |
| 959 |
|
| 960 |
templateString: "<div class='dijitCalendarMonthMenu dijitMenu' " + |
| 961 |
"dojoAttachEvent='onclick:_onClick,onmouseover:_onMenuHover,onmouseout:_onMenuHover'></div>", |
| 962 |
|
| 963 |
_setMonthsAttr: function( months){ |
| 964 |
this.domNode.innerHTML = dojo.map(months, function(month, idx){ |
| 965 |
return month ? "<div class='dijitCalendarMonthLabel' month='" + idx +"'>" + month + "</div>" : ""; |
| 966 |
}).join(""); |
| 967 |
}, |
| 968 |
|
| 969 |
_onClick: function( evt){ |
| 970 |
this.onChange(dojo.attr(evt.target, "month")); |
| 971 |
}, |
| 972 |
|
| 973 |
onChange: function( month){ |
| 974 |
|
| 975 |
|
| 976 |
}, |
| 977 |
|
| 978 |
_onMenuHover: function(evt){ |
| 979 |
dojo.toggleClass(evt.target, "dijitCalendarMonthLabelHover", evt.type == "mouseover"); |
| 980 |
} |
| 981 |
}); |
| 982 |
|
| 983 |
return MultiSelectCalendar; |
| 984 |
|
| 985 |
}); |