// Calendar.js - implementation of the Calendar sub-application
FIRSTCLASS.apps.Calendar = function(config) {
this._domElement = config.domElement;
this._dataSource = config.dataSource;
if (!FIRSTCLASS.apps.Calendar.prototype._rowSubElement) {
FIRSTCLASS.apps.Calendar.prototype._rowTemplate = document.createElement("div");
FIRSTCLASS.apps.Calendar.prototype._rowTemplate.innerHTML = "
";
}
var lvConfig = {
rowHandler: this,
domElement: this._domElement,
dataSource: this._dataSource,
fillOnScroll:true,
threading: {
format: "bycolumn",
column: "col1001",
coltype: FIRSTCLASS.layout.ThreadHandler.coltypes.FRIENDLYDATE,
sortfunc: function(row1, row2) {
if (!row1.parsedMtgStartDate) {
row1.parsedMtgStartDate = Date.parse(row1.col1001);
}
if (!row2.parsedMtgStartDate) {
row2.parsedMtgStartDate = Date.parse(row2.col1001);
}
return row1.parsedMtgStartDate < row2.parsedMtgStartDate;
}
},
listenForNavKeys: true,
rowFilter: function(row) {
return (row.iscalitem == 1 && row.col1011 == 0);
}
};
if(config.onResize) {
lvConfig.onResize = config.onResize;
}
this._myFeed = new FIRSTCLASS.layout.Feed( {listView:null, dataSource:config.dataSource});
this._listView = new FIRSTCLASS.layout.ListView(lvConfig);
this._myFeed.listView = this._listView; // punch in after
FIRSTCLASS.session.setActiveApplication(this, "calendar");
};
// class variables
FIRSTCLASS.apps.Calendar.prototype._dataSource = null;
FIRSTCLASS.apps.Calendar.prototype._domElement = null;
FIRSTCLASS.apps.Calendar.prototype._listView = null;
FIRSTCLASS.apps.Calendar.prototype._myFeed = null;
FIRSTCLASS.apps.Calendar.prototype._rowTemplate = null;
// class methods
FIRSTCLASS.apps.Calendar.prototype.createRow = function(row) {
var myRowElement = this._rowTemplate.cloneNode(true);
this.updateRow(row, myRowElement);
return myRowElement;
};
FIRSTCLASS.apps.Calendar.prototype.updateRow = function(row, element) {
var duration = FIRSTCLASS.ui.Dom.getChildByClassName("fcCalEventDur", element);
var name = FIRSTCLASS.ui.Dom.getChildByClassName("fcCalEventName", element);
var location = FIRSTCLASS.ui.Dom.getChildByClassName("fcCalEventLoc", element);
var creator = FIRSTCLASS.ui.Dom.getChildByClassName("fcCalEventCreator", element);
// duration
var mydate = new Date();
mydate.setTime(Date.parse(row.col1001));
var endDate = new Date();
endDate.setTime(mydate.getTime() + row.col1002);
var str = [];
str.push(mydate.getHours());
str.push(":");
if (mydate.getMinutes() < 10) {
str.push("0");
}
str.push(mydate.getMinutes());
str.push(" - ");
str.push(endDate.getHours());
str.push(":");
str.push(endDate.getMinutes());
if (endDate.getMinutes() < 10) {
str.push("0");
}
duration.innerHTML = str.join("");
if (row.subject) name.innerHTML = row.subject;
if (row.col1009) location.innerHTML = row.col1009;
if (row.name) creator.innerHTML = row.name;
element.row = row;
};
FIRSTCLASS.apps.Calendar.prototype.generateUniqueId = function(row) {
return row.messageid;
};
FIRSTCLASS.apps.Calendar.prototype.onSelectionChange = function(from, to) {
return this._myFeed.onSelectionChange(from, to);
};
// sort thread items in forward chrono
FIRSTCLASS.apps.Calendar.prototype.rowSort = function(row1, row2) {
var result = true;
if (row1 && row2) {
result = row1.parsedDate >= row2.parsedDate;
}
return result;
};
FIRSTCLASS.apps.Calendar.prototype.activate = function () {
this._listView.activate();
this._dataSource.activate();
};
FIRSTCLASS.apps.Calendar.prototype.deactivate = function() {
this._listView.deactivate();
this._dataSource.deactivate();
};
YAHOO.register("fcCalendar", FIRSTCLASS.apps.Calendar, {version: "0.0.1", build: "1"});