// History.js - implements an item history viewer
// history configuration:
// domEl - element to install into
// dataSource - current data source
// dsRow - row of owning item
// toolbar - toolbar for selected item
// scrolling - this view scrolls on its own
FIRSTCLASS.apps.history = function(config) {
this._domEl = config.domElement;
this._ds = config.dataSource;
this._dsr = config.dsRow;
this._toolbar = config.toolbar;
var that = this;
var html = [];
this._versByDate = []; // array of version dates, keyed by version
this._commDates = []; // array of comment dates, keyed by messageid
this._versTypes = [];
this._versTypes[FIRSTCLASS.objTypes.file] = true;
this._versTypes[FIRSTCLASS.objTypes.formdoc] = true;
this._versTypes[FIRSTCLASS.objTypes.odocument] = true;
this._versTypes[FIRSTCLASS.objTypes.fcfile] = true;
this.calcVersionID(this._dsr);
// item template
if (!FIRSTCLASS.apps.history._rowTemplateEl) {
FIRSTCLASS.apps.history._rowTemplateEl = document.createElement("div");
var template = [];
template.push("
| | |
");
template.push(" | ");
template.push(" | | |
");
template.push(" | ");
template.push("");
template.push("");
template.push(" | ");
template.push("");
template.push(" | | ");
template.push("");
template.push(" |
| | |
");
template.push(" | | |
");
template.push(" | | | |
");
template.push(" | | | |
");
template.push(" | | |
");
FIRSTCLASS.apps.history._rowTemplateEl.innerHTML = template.join("");
}
this._lvEl = document.createElement("div");
this._domEl.appendChild(this._lvEl);
this._newMessageInlineElement = document.createElement("div");
YAHOO.util.Dom.addClass(this._newMessageInlineElement, 'fcInlineComposeMessage');
this._domEl.appendChild(this._newMessageInlineElement);
if (config.scrolling) {
YAHOO.util.Dom.addClass(this._lvEl, "fcHistoryList");
}
YAHOO.util.Dom.addClass(this._lvEl, "fcDiscloseSingleLine");
// version mapper listener
this._mapProc = {
onRow: function(row) {
if (that.rowFilter(row) && (row.typedef.objtype == that._dsr.typedef.objtype)) {
that.calcVersionID(row);
}
}
};
this._ds.addRowListener(this._mapProc);
var mapCallback = {
completed: function() {
if (that._mapProc) {
// remove mapper listener
that._ds.removeRowListener(that._mapProc);
// add row preprocessor listener
that._rowProc = {
onRow: function(row) {
if (that.rowFilter(row) && (row.typedef.objtype == that._dsr.typedef.objtype)) {
that.calcVersionID(row);
}
}
};
that._commDates = [];
that._ds.addRowListener(that._rowProc);
that._ds.fetchRowsByThread(that._dsr.threadid, mapCallback);
that.createListView();
that._selRow = null;
that._mapProc = null;
}
}
};
this._ds.activate();
this._ds.fetchRowsByThread(this._dsr.threadid, mapCallback);
};
// instantiate the list view once the data is in
FIRSTCLASS.apps.history.prototype.createListView = function() {
if (!this._lv) {
var that = this;
var lvConfig = {
rowHandler: this,
domElement: this._lvEl,
dataSource: this._ds,
fillOnScroll: false,
threading: {
format: "bycolumn",
column: "versionID",
sortfunc: function(row1, row2) { return that.commentSort(row1, row2); },
threadsortfunc: function(row1, row2) { return that.versionSort(row1, row2); },
originRowIsHeader: true,
collapseRead: true,
displayThreadContributors: true
},
listenForNavKeys: true,
selectionFollowsScroll: false,
rowFilter: function(row) { return that.rowFilter(row); },
drawOffScreen: false
};
this._myFeed = new FIRSTCLASS.layout.Feed(
{
allowReplies: false,
listView: null,
dataSource: this._ds,
thumbnailClickLoadsItem: true
});
this._lv = new FIRSTCLASS.layout.ListView(lvConfig);
this._myFeed.listView = this._lv; // punch in after
// replace feed toolbar if one is passed in
if (this._toolbar) {
this._myFeed.toolBarDomElement.innerHTML = "";
this._myFeed.toolBar = new FIRSTCLASS.ui.toolBar({
domElement: this._myFeed.toolBarDomElement,
buttons: this._toolbar
});
}
this.activate();
}
};
// history vars
FIRSTCLASS.apps.history.prototype._domEl = null;
FIRSTCLASS.apps.history.prototype._ds = null;
FIRSTCLASS.apps.history.prototype._dsr = null;
FIRSTCLASS.apps.history.prototype._lv = null;
FIRSTCLASS.apps.history.prototype._commEl = null;
FIRSTCLASS.apps.history.prototype._versEl = null;
// history functions
FIRSTCLASS.apps.history.prototype.rowFromEvent = function(evt){
var tg = evt.target;
if (!tg) {
tg = evt.srcElement;
}
if (tg && this._lv) {
var row = this._lv._rowmap[tg.id];
while (tg && !row && tg !== this._lv.contentsDomElement) {
tg = tg.parentNode;
row = this._lv._rowmap[tg.id];
}
if (row) {
return {"el":tg, "row":row};
} else {
return null;
}
} else {
return null;
}
};
FIRSTCLASS.apps.history.prototype.createRow = function(row) {
var myRowEl = document.createElement("div");
var table = FIRSTCLASS.apps.history._rowTemplateEl.firstChild.cloneNode(true);
var html = "