require({cache:{ 'url:dojox/calendar/templates/SimpleColumnView.html':"
rowHeaderTimePattern
property can be used to set a custom time pattern to the formatter.
// d: Date
// The date to format
// tags:
// protected
return this.renderData.dateLocaleModule.format(d, {
selector: "time",
timePattern: this.rowHeaderTimePattern
});
},
_formatColumnHeaderLabel: function(/*Date*/d){
// summary:
// Computes the column header label for the specified date.
// By default a formatter is used, optionally the columnHeaderDatePattern
property can be used to set a custom date pattern to the formatter.
// d: Date
// The date to format
// tags:
// protected
return this.renderData.dateLocaleModule.format(d, {
selector: "date",
datePattern: this.columnHeaderDatePattern,
formatLength: "medium"
});
},
//////////////////////////////////////////
//
// Time of day management
//
//////////////////////////////////////////
// startTimeOfDay: Object
// The scroll position of the view. The value is an object made of "hours" and "minutes" properties.
startTimeOfDay: null,
// scrollBarRTLPosition: String
// Position of the scroll bar in right-to-left display.
// Valid values are "left" and "right", default value is "left".
scrollBarRTLPosition: "left",
_getStartTimeOfDay: function(){
// summary:
// Returns the visible first time of day.
// tags:
// protected
// returns: Integer[]
var v = (this.get("maxHours") - this.get("minHours")) *
this._getScrollPosition() / this.renderData.sheetHeight;
return {
hours: this.renderData.minHours + Math.floor(v),
minutes: (v - Math.floor(v)) * 60
};
},
_getEndTimeOfDay: function(){
// summary:
// Returns the visible last time of day.
// tags:
// protected
// returns: Integer[]
var v = (this.get("maxHours") - this.get("minHours")) *
(this._getScrollPosition() + this.scrollContainer.offsetHeight) / this.renderData.sheetHeight;
return {
hours: this.renderData.minHours + Math.floor(v),
minutes: (v - Math.floor(v)) * 60
};
},
_setStartTimeOfDayAttr: function(value){
this._setStartTimeOfDay(value.hours, value.minutes, value.duration, value.easing)
},
_getStartTimeOfDayAttr: function(){
return this._getStartTimeOfDay();
},
_setStartTimeOfDay: function(hour, minutes, maxDuration, easing){
// summary:
// Scrolls the view to show the specified first time of day.
// hour: Integer
// The hour of the start time of day.
// minutes: Integer
// The minutes part of the start time of day.
// maxDuration: Integer
// The max duration of the scroll animation.
// tags:
// protected
var rd = this.renderData;
hour = hour || rd.minHours;
minutes = minutes || 0;
maxDuration = maxDuration || 0;
if (minutes < 0){
minutes = 0;
}else if (minutes > 59){
minutes = 59;
}
if (hour < 0){
hour = 0;
}else if (hour > 24){
hour = 24;
}
var timeInMinutes = hour * 60 + minutes;
var minH = rd.minHours*60;
var maxH = rd.maxHours*60;
if (timeInMinutes < minH){
timeInMinutes = minH;
}else if(timeInMinutes > maxH){
timeInMinutes = maxH;
}
var pos = (timeInMinutes - minH) * rd.sheetHeight / (maxH - minH);
pos = Math.min(rd.sheetHeight - this.scrollContainer.offsetHeight, pos);
this._scrollToPosition(pos, maxDuration, easing);
},
_scrollToPosition: function(position, maxDuration, easing){
// summary:
// Scrolls the view to show the specified first time of day.
// position: Integer
// The position in pixels.
// maxDuration: Integer
// The max duration of the scroll animation.
// tags:
// protected
if (maxDuration) {
if(this._scrollAnimation){
this._scrollAnimation.stop();
}
var scrollPos = this._getScrollPosition();
var duration = Math.abs(((position - scrollPos) * maxDuration) / this.renderData.sheetHeight);
this._scrollAnimation = new fx.Animation({
curve: [scrollPos, position],
duration: duration,
easing: easing,
onAnimate: lang.hitch(this, function(position) {
this._setScrollImpl(position);
})
});
this._scrollAnimation.play();
}else{
this._setScrollImpl(position);
}
},
_setScrollImpl: function(v){
this._setScrollPosition(v);
if(this.scrollBar){
this.scrollBar.set("value", v);
}
},
ensureVisibility: function(start, end, visibilityTarget, margin, duration){
// summary:
// Scrolls the view if the [start, end] time range is not visible or only partially visible.
// start: Date
// Start time of the range of interest.
// end: Date
// End time of the range of interest.
// margin: Integer
// Margin in minutes around the time range.
// visibilityTarget: String
// The end(s) of the time range to make visible.
// Valid values are: "start", "end", "both".
// duration: Number
// Optional, the maximum duration of the scroll animation.
margin = margin == undefined ? this.renderData.slotDuration : margin;
if(this.scrollable && this.autoScroll){
var s = start.getHours() * 60 + start.getMinutes() - margin;
var e = end.getHours() * 60 + end.getMinutes() + margin;
var vs = this._getStartTimeOfDay();
var ve = this._getEndTimeOfDay();
var viewStart = vs.hours * 60 + vs.minutes;
var viewEnd = ve.hours * 60 + ve.minutes;
var visible = false;
var target = null;
switch(visibilityTarget){
case "start":
visible = s >= viewStart && s <= viewEnd;
target = s ;
break;
case "end":
visible = e >= viewStart && e <= viewEnd;
target = e - (viewEnd - viewStart);
break;
case "both":
visible = s >= viewStart && e <= viewEnd;
target = s;
break;
}
if(!visible){
this._setStartTimeOfDay(Math.floor(target/60), target%60, duration);
}
}
},
scrollView: function(dir){
// summary:
// Scrolls the view to the specified direction of one time slot duration.
// dir: Integer
// Direction of the scroll. Valid values are -1 and 1.
//
var t = this._getStartTimeOfDay();
t = t.hours*60 + t.minutes + (dir * this.timeSlotDuration);
this._setStartTimeOfDay(Math.floor(t/60), t%60);
},
_mouseWheelScrollHander: function(e){
// summary:
// Mouse wheel handler.
// tags:
// protected
this.scrollView(e.wheelDelta > 0 ? -1 : 1);
},
//////////////////////////////////////////
//
// HTML structure management
//
//////////////////////////////////////////
refreshRendering: function(){
if(!this._initialized){
return;
}
this._validateProperties();
var oldRd = this.renderData;
var rd = this._createRenderData();
this.renderData = rd;
this._createRendering(rd, oldRd);
this._layoutRenderers(rd);
},
_createRendering: function(/*Object*/renderData, /*Object*/oldRenderData){
// tags:
// private
domStyle.set(this.sheetContainer, "height", renderData.sheetHeight + "px");
// padding for the scroll bar.
this._configureScrollBar(renderData);
this._buildColumnHeader(renderData, oldRenderData);
this._buildRowHeader(renderData, oldRenderData);
this._buildGrid(renderData, oldRenderData);
this._buildItemContainer(renderData, oldRenderData);
},
_configureScrollBar: function(renderData){
// summary:
// Sets the scroll bar size and position.
// renderData: Object
// The render data.
// tags:
// protected
if(has("ie") && this.scrollBar){
domStyle.set(this.scrollBar.domNode, "width", (renderData.scrollbarWidth + 1) + "px");
}
var atRight = this.isLeftToRight() ? true : this.scrollBarRTLPosition == "right";
var rPos = atRight ? "right" : "left";
var lPos = atRight? "left" : "right";
if(this.scrollBar){
this.scrollBar.set("maximum", renderData.sheetHeight);
domStyle.set(this.scrollBar.domNode, rPos, 0);
domStyle.set(this.scrollBar.domNode, atRight? "left" : "right", "auto");
}
domStyle.set(this.scrollContainer, rPos, renderData.scrollbarWidth + "px");
domStyle.set(this.scrollContainer, lPos, "0");
domStyle.set(this.header, rPos, renderData.scrollbarWidth + "px");
domStyle.set(this.header, lPos, "0");
if(this.buttonContainer && this.owner != null && this.owner.currentView == this){
domStyle.set(this.buttonContainer, rPos, renderData.scrollbarWidth + "px");
domStyle.set(this.buttonContainer, lPos, "0");
}
},
_columnHeaderClick: function(e){
// tags:
// private
event.stop(e);
var index = query("td", this.columnHeaderTable).indexOf(e.currentTarget);
this._onColumnHeaderClick({
index: index,
date: this.renderData.dates[index],
triggerEvent: e
});
},
_buildColumnHeader: function(renderData, oldRenderData){
// summary:
// Creates incrementally the HTML structure of the column header and configures its content.
//
// renderData:
// The render data to display.
//
// oldRenderData:
// The previously render data displayed, if any.
// tags:
// private
var table = this.columnHeaderTable;
if (!table){
return;
}
var count = renderData.columnCount - (oldRenderData ? oldRenderData.columnCount : 0);
if(has("ie") == 8){
// workaround Internet Explorer 8 bug.
// if on the table, width: 100% and table-layout: fixed are set
// and columns are removed, width of remaining columns is not
// recomputed: must rebuild all.
if(this._colTableSave == null){
this._colTableSave = lang.clone(table);
}else if(count < 0){
this._cleanupColumnHeader();
this.columnHeader.removeChild(table);
domConstruct.destroy(table);
table = lang.clone(this._colTableSave);
this.columnHeaderTable = table;
this.columnHeader.appendChild(table);
count = renderData.columnCount;
}
} // else incremental dom add/remove for real browsers.
var tbodies = query("tbody", table);
var trs = query("tr", table);
var tbody, tr, td;
if (tbodies.length == 1){
tbody = tbodies[0];
}else{
tbody = html.create("tbody", null, table);
}
if (trs.length == 1){
tr = trs[0];
}else{
tr = domConstruct.create("tr", null, tbody);
}
// Build HTML structure (incremental)
if(count > 0){ // creation
for(var i=0; i < count; i++){
td = domConstruct.create("td", null, tr);
var h = [];
h.push(on(td, "click", lang.hitch(this, this._columnHeaderClick)));
if(has("touch")){
h.push(on(td, "touchstart", function(e){
event.stop(e);
domClass.add(e.currentTarget, "Active");
}));
h.push(on(td, "touchend", function(e){
event.stop(e);
domClass.remove(e.currentTarget, "Active");
}));
}else{
h.push(on(td, "mousedown", function(e){
event.stop(e);
domClass.add(e.currentTarget, "Active");
}));
h.push(on(td, "mouseup", function(e){
event.stop(e);
domClass.remove(e.currentTarget, "Active");
}));
h.push(on(td, "mouseover", function(e){
event.stop(e);
domClass.add(e.currentTarget, "Hover");
}));
h.push(on(td, "mouseout", function(e){
event.stop(e);
domClass.remove(e.currentTarget, "Hover");
}));
}
this._columnHeaderHandlers.push(h);
}
}else{ // deletion
count = -count;
for(var i=0; i < count; i++){
td = tr.lastChild;
tr.removeChild(td);
domConstruct.destroy(td);
var list = this._columnHeaderHandlers.pop();
while(list.length>0){
list.pop().remove();
}
}
}
// fill & configure
query("td", table).forEach(function(td, i){
td.className = "";
if(i == 0){
domClass.add(td, "first-child");
}else if(i == this.renderData.columnCount-1){
domClass.add(td, "last-child");
}
var d = renderData.dates[i];
this._setText(td, this._formatColumnHeaderLabel(d));
this.styleColumnHeaderCell(td, d, renderData);
}, this);
if(this.yearColumnHeaderContent){
var d = renderData.dates[0];
this._setText(this.yearColumnHeaderContent, renderData.dateLocaleModule.format(d,
{selector: "date", datePattern:"yyyy"}));
}
},
_cleanupColumnHeader: function(){
while(this._columnHeaderHandlers.length > 0){
var list = this._columnHeaderHandlers.pop();
while(list.length > 0){
list.pop().remove();
}
}
},
styleColumnHeaderCell: function(node, date, renderData){
// summary:
// Styles the CSS classes to the node that displays a column header cell.
// By default this method is setting the "dojoxCalendarToday" class name if the
// date displayed is the current date or "dojoxCalendarWeekend" if the date represents a weekend.
// node: Node
// The DOM node that displays the column in the grid.
// date: Date
// The date displayed by this column
// renderData: Object
// The render data.
// tags:
// protected
if(this.isToday(date)){
return domClass.add(node, "dojoxCalendarToday");
} else if(this.isWeekEnd(date)){
return domClass.add(node, "dojoxCalendarWeekend");
}
},
_buildRowHeader: function(renderData, oldRenderData){
// summary:
// Creates incrementally the HTML structure of the row header and configures its content.
//
// renderData:
// The render data to display.
//
// oldRenderData:
// The previously render data displayed, if any.
// tags:
// private
var rowHeaderTable = this.rowHeaderTable;
if (!rowHeaderTable){
return;
}
domStyle.set(rowHeaderTable, "height", renderData.sheetHeight + "px");
var tbodies = query("tbody", rowHeaderTable);
var tbody, tr, td;
if (tbodies.length == 1){
tbody = tbodies[0];
}else{
tbody = domConstruct.create("tbody", null, rowHeaderTable);
}
var count = renderData.hourCount - (oldRenderData ? oldRenderData.hourCount : 0);
// Build HTML structure
if(count>0){ // creation
for(var i=0; i < count; i++){
tr = domConstruct.create("tr", null, tbody);
td = domConstruct.create("td", null, tr);
}
}else{
count = -count;
// deletion of existing nodes
for(var i=0; i < count; i++){
tbody.removeChild(tbody.lastChild);
}
}
// fill labels
var d = new Date(2000, 0, 1, 0, 0, 0);
query("tr", rowHeaderTable).forEach(function(tr, i){
var td = query("td", tr)[0];
td.className = "";
var size = renderData.hourSize;
if (has("ie") == 7) {
// ie7 workaournd: do not take border into account.
size -= 2;
}
domStyle.set(tr, "height", size + "px");
d.setHours(this.renderData.minHours + (i));
this.styleRowHeaderCell(td, d.getHours(), renderData);
this._setText(td, this._formatRowHeaderLabel(d));
}, this);
},
styleRowHeaderCell: function(node, h, renderData){
// summary:
// Styles the CSS classes to the node that displays a row header cell.
// By default this method is doing nothing.
// node: Node
// The DOM node that displays the column in the grid.
// h: Integer
// The time of day displayed by this row header cell.
// renderData: Object
// The render data.
// tags:
// protected
},
_buildGrid: function (renderData, oldRenderData){
// summary:
// Creates incrementally the HTML structure of the grid and configures its content.
//
// renderData:
// The render data to display.
//
// oldRenderData:
// The previously render data displayed, if any.
// tags:
// private
var table = this.gridTable;
if (!table){
return;
}
domStyle.set(table, "height", renderData.sheetHeight + "px");
var nbRows = Math.floor(60 / renderData.slotDuration) * renderData.hourCount;
var rowDiff = nbRows -
(oldRenderData ? Math.floor(60 / oldRenderData.slotDuration) * oldRenderData.hourCount : 0);
var addRows = rowDiff > 0;
var colDiff = renderData.columnCount - (oldRenderData ? oldRenderData.columnCount : 0);
if(has("ie") == 8){
// workaround Internet Explorer 8 bug.
// if on the table, width: 100% and table-layout: fixed are set
// and columns are removed, width of remaining columns is not
// recomputed: must rebuild all.
if(this._gridTableSave == null){
this._gridTableSave = lang.clone(table);
}else if(colDiff < 0){
this.grid.removeChild(table);
domConstruct.destroy(table);
table = lang.clone(this._gridTableSave);
this.gridTable = table;
this.grid.appendChild(table);
colDiff = renderData.columnCount;
rowDiff = nbRows;
addRows = true;
}
}
var tbodies = query("tbody", table);
var tbody;
if (tbodies.length == 1){
tbody = tbodies[0];
}else{
tbody = domConstruct.create("tbody", null, table);
}
// Build time slots (lines) HTML structure (incremental)
if(addRows){ // creation
for(var i=0; i