// Discussion.js - implementation of the Discussion sub-application FIRSTCLASS.apps.Discussion = function(config) { this._domElement = config.domElement; this._dataSource = config.dataSource; this._instance = FIRSTCLASS.apps.Discussion._nInstances++; this._config = config; var that = this; if (!FIRSTCLASS.apps.Discussion.prototype._rowSubElement) { FIRSTCLASS.apps.Discussion.prototype._rowSubElement = document.createElement("div"); FIRSTCLASS.apps.Discussion.prototype._rowSubElement.innerHTML = "
"; } if (!this._appTBElement) { this._appTBElement = document.createElement("div"); this._rightAppTBElement = document.createElement("div"); var appTBCfg = { domElement:this._appTBElement, vertical: true, buttons: [ { id: "fcDiscussNewTopic"+this._instance, label: "New Topic", click: function(evt) { YAHOO.util.Event.stopPropagation(evt); var msgCfg = { callback: that, element: that._newMessageInlineElement, op: "__Send", baseURL: config.containerBaseUrl, objType: FIRSTCLASS.objTypes.message, formID: 21000, formElId: "fcDocForm", bodyType: "HTML", quoteText: null, sendTo: null, initHeight: "300px", showAddr: false, tbType: "message", params: "InitialText=" }; that._message = new FIRSTCLASS.util.Message(msgCfg); }, priv: FIRSTCLASS.permissions.ACL.SEND }, { id: "fcDiscussAskQuestion"+this._instance, label: "Ask a Question", click: function(evt) { YAHOO.util.Event.stopPropagation(evt); var msgCfg = { callback: that, element: that._newMessageInlineElement, op: "__Send", baseURL: config.containerBaseUrl, objType: FIRSTCLASS.objTypes.message, formID: 21001, formElId: "fcDocForm", bodyType: "HTML", quoteText: null, sendTo: null, initHeight: "300px", showAddr: false, tbType: "message", params: "InitialText=" }; that._message = new FIRSTCLASS.util.Message(msgCfg); }, priv: FIRSTCLASS.permissions.ACL.SEND }, { id: "fcDiscussDisclosure"+this._instance, type: "disclosure", change: function(newoffset) { if(newoffset == NaN) { return; } YAHOO.util.Dom.removeClass(that._lvDomElement, "fcDiscloseNone"); YAHOO.util.Dom.removeClass(that._lvDomElement, "fcDiscloseItems"); YAHOO.util.Dom.removeClass(that._lvDomElement, "fcDisclosePreviews"); YAHOO.util.Dom.removeClass(that._lvDomElement, "fcDiscloseBodies"); switch (newoffset) { case 0: // fcDiscloseNone YAHOO.util.Dom.addClass(that._lvDomElement, "fcDiscloseNone"); break; case 50: YAHOO.util.Dom.addClass(that._lvDomElement, "fcDiscloseItems"); break; case 100: // fcDisclosePreviews YAHOO.util.Dom.addClass(that._lvDomElement, "fcDisclosePreviews"); break; //case 150: default: // fcDiscloseAll YAHOO.util.Dom.addClass(that._lvDomElement, "fcDiscloseBodies"); } } } /*, { id: "fcDiscussNextUnread"+this._instance, label: "Next Unread", click: function(evt) { YAHOO.util.Event.stopPropagation(evt); alert("Next Unread"); } }, { id: "fcDiscussSeparator"+this._instance, label: "", type: "ralign" }, { id: "fcDiscussFind"+this._instance, label: "Find", type: "find", click: function(evt) { YAHOO.util.Event.stopPropagation(evt); alert("Find"); } }*/ ] }; /*var rightAppTBCfg = { domElement: this._rightAppTBElement, buttons: [ ] };*/ this._appTB = new FIRSTCLASS.ui.toolBar(appTBCfg); //this._rightAppTB = new FIRSTCLASS.ui.toolBar(rightAppTBCfg); }; /*this._toolBar = document.createElement("div"); this._toolBar.innerHTML = "
"; this._toolBar.childNodes[0].childNodes[0].childNodes[0].childNodes[0].appendChild(this._appTBElement); this._toolBar.childNodes[0].childNodes[0].childNodes[0].childNodes[1].appendChild(this._rightAppTBElement); this._domElement.appendChild(this._toolBar);*/ /*this._actions = document.createElement("div"); this._actions.innerHTML = "New Topic
New Question"; YAHOO.util.Event.addListener(this._actions.firstChild, "click", function(evt) { YAHOO.util.Event.stopPropagation(evt); var msgCfg = { callback: that, element: that._newMessageInlineElement, op: "__Send", baseURL: config.containerBaseUrl, objType: FIRSTCLASS.objTypes.message, formID: 21000, formElId: "fcDocForm", bodyType: "HTML", quoteText: null, sendTo: null, tbType: "message", showAddr: false }; that._message = new FIRSTCLASS.util.Message(msgCfg); }); YAHOO.util.Event.addListener(this._actions.lastChild, "click", function(evt) { YAHOO.util.Event.stopPropagation(evt); var msgCfg = { callback: that, element: that._newMessageInlineElement, op: "__Send", baseURL: config.containerBaseUrl, objType: FIRSTCLASS.objTypes.message, formID: 21001, formElId: "fcDocForm", bodyType: "HTML", quoteText: null, sendTo: null, tbType: "message", showAddr: false }; that._message = new FIRSTCLASS.util.Message(msgCfg); });*/ this._dataSource.addDataListener({ onHeaderData:function(data, contents) { that._listView.updatePadText("No More Items Available"); switch (data) { case "acl": that._appTB.reconfigure(null, contents); break; default: } }, filter: function(dataname) { switch (dataname) { case "acl": if (!that._aclConfigured) { return true; } default: return false; } } }); this._lvDomElement = document.createElement("div"); this._newMessageInlineElement = document.createElement("div"); this._message = null; YAHOO.util.Dom.addClass(this._newMessageInlineElement, 'fcInlineComposeMessage'); this._domElement.appendChild(this._newMessageInlineElement); YAHOO.util.Dom.addClass(this._lvDomElement, "fcAppScrollingContent"); YAHOO.util.Dom.addClass(this._lvDomElement, "fcDiscloseBodies"); this._domElement.appendChild(this._lvDomElement); var lvConfig = { rowHandler: this, domElement: this._lvDomElement, dataSource: this._dataSource, fillOnScroll:true, threading: { format: "bythread", sortfunc: this._rowSort, threadsortfunc: this.rowSort, originRowIsHeader: true, collapseRead: true }, listenForNavKeys: true, selectionFollowsScroll: true, //rowFilter: this.rowFilter, padHeight: true, padText: "Loading" }; 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, "discussion"); if (config.rowToOpen) { this.showRowInContext(config.rowToOpen); } }; // class variables FIRSTCLASS.apps.Discussion._nInstances = 0; FIRSTCLASS.apps.Discussion.prototype._dataSource = null; FIRSTCLASS.apps.Discussion.prototype._domElement = null; FIRSTCLASS.apps.Discussion.prototype._listView = null; FIRSTCLASS.apps.Discussion.prototype._myFeed = null; FIRSTCLASS.apps.Discussion.prototype._rowSubElement = null; FIRSTCLASS.apps.Discussion.prototype.updateHeight = function(newheight) { this._listView.updatePadHeight(newheight); }; // class methods FIRSTCLASS.apps.Discussion.prototype.createRow = function(row) { var myRowContents = null; var myRowElement = null; var children = null; if (this._myFeed) { myRowContents = this._myFeed.createRow(row); } else { myRowContents = document.createElement("div"); } YAHOO.util.Dom.addClass(myRowContents, "fcDiscussionItem"); /*myRowElement = FIRSTCLASS.apps.Discussion.prototype._rowSubElement.cloneNode(true); var child = myRowElement.childNodes[0].childNodes[0].childNodes[0].childNodes[1]; // var child = FIRSTCLASS.ui.Dom.getChildByClassName("fcDiscussionItemCell", myRowElement); child.appendChild(myRowContents); myRowElement.row = myRowContents.row;*/ return myRowContents; }; FIRSTCLASS.apps.Discussion.prototype.updateRow = function(row, element) { /*var myRowContents = FIRSTCLASS.ui.Dom.getChildByClassName("fcDiscussionItem", element); if (this._myFeed && (myRowContents)) { this._myFeed.updateRow(row,myRowContents); }*/ this._myFeed.updateRow(row,element); }; FIRSTCLASS.apps.Discussion.prototype.onRowClick = function(row, elem) { this._myFeed.onRowClick(row, elem); }; FIRSTCLASS.apps.Discussion.prototype.generateUniqueId = function(row) { return row.messageid; }; FIRSTCLASS.apps.Discussion.prototype.onSelectionChange = function(from, to, torow) { return this._myFeed.onSelectionChange(from, to, torow); }; // sort thread items in reverse chrono FIRSTCLASS.apps.Discussion.prototype._rowSort = function(row1, row2) { var result = true; if (row1 && row2) { result = row1.parsedDate >= row2.parsedDate; } return result; }; FIRSTCLASS.apps.Discussion.prototype.rowSort = function(row1, row2) { var result = true; if (row1 && row2) { result = row1.parsedDate <= row2.parsedDate; } return result; }; FIRSTCLASS.apps.Discussion.prototype.activate = function () { this._listView.activate(); this._dataSource.activate(); FIRSTCLASS.ui.rightSideBar.updateBoxContents("ACTIONS", this._appTBElement); if (this._config.onResize) { this._config.onResize(); } }; FIRSTCLASS.apps.Discussion.prototype.deactivate = function(internal) { this._listView.deactivate(); // this._dataSource.deactivate(); }; FIRSTCLASS.apps.Discussion.prototype.rowFilter = function(row) { if (row.replyobjtype) { return (row.replyobjtype == FIRSTCLASS.objTypes.message || row.replyobjtype == FIRSTCLASS.objTypes.confitem); } return (row.typedef.objtype == FIRSTCLASS.objTypes.message || row.typedef.objtype == FIRSTCLASS.objTypes.confitem); }; FIRSTCLASS.apps.Discussion.prototype.showRowInContext = function(row) { this._listView.selectRow(row); }; FIRSTCLASS.apps.Discussion.prototype.onCancel = function() { if (this._message !== null) { this._message.destroy(); this._message = null; } this._newMessageInlineElement.innerHTML = ""; }; FIRSTCLASS.apps.Discussion.prototype.onSave = function() { this.onCancel(); }; YAHOO.register("fcDiscussion", FIRSTCLASS.apps.Discussion, {version: "0.0.1", build: "1"});