// Documents.js - implementation of the Documents sub-application FIRSTCLASS.apps.Documents = function(config) { var that = this; this._enableFill = false; this._acceptTypes = []; this._acceptTypes[FIRSTCLASS.objTypes.file] = true; this._acceptTypes[FIRSTCLASS.objTypes.odocument] = true; this._acceptTypes[FIRSTCLASS.objTypes.formdoc] = true; this._acceptTypes[FIRSTCLASS.objTypes.fcfile] = true; this._domElement = config.domElement; this._masterDS = config.dataSource; this._dataSource = config.dataSource.createSlave({}); this._dataSource.filter = function(row) { return that.filter(row); }; this._dataSource._data.records = []; this._community = config.community; this._config = config; this._instance = FIRSTCLASS.apps.Documents.instances++; // initialization this._headerEl = null; // docs tab header this._countEl = null; // document count this._quickFilter = null; // filter control this._filterEl = null; // row filter input container this._filterStr = null; // row filter value this._listEl = null; // the list of documents this._selPanel = null; // selection panel this._selTBEl = null; // selection toolbar holder this._selTB = null; // selection toolbar this._history = null; // history manager this._histEl = null; // history display area this._histRow = null; // history row this._commentEl = null; // history comment entry area this._commEditor = null; // history comment editor instance this._pds = []; // pseudo data source this._firstFill = true; // flag initial draw this._flushTimer = null; this._uploader = null; this._nQueued = 0; this._nItems = 0; this._nTRows = 0; this._dt = null; // header bar var html = []; this._headerEl = document.createElement("div"); YAHOO.util.Dom.addClass(this._headerEl, "fcDocsHeader"); this._domElement.appendChild(this._headerEl); html.push(""); html.push(""); html.push(""); html.push(""); html.push("
 
"); html.push(""); html.push("
 "); html.push("
 
"); html.push("
"); this._headerEl.innerHTML = html.join(""); this._pluginEl = FIRSTCLASS.ui.Dom.getChildByClassName('fcOfficePlugin', this._headerEl); if (FIRSTCLASS.ui.webdav.hasOfficePlugin()) { FIRSTCLASS.ui.webdav.loadOfficePlugin(this._pluginEl); } this._filterEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocPick", this._headerEl); this._countEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocCounter", this._headerEl); // selection panel this._selPanel = document.createElement("div"); html = []; html.push(""); html.push(""); html.push(""); html.push(""); html.push(""); html.push("
"); html.push(""); html.push(""); html.push("
"); this._selPanel.innerHTML = html.join(""); this._taggerEl = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocTagEditor', this._selPanel); this._selHeader = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocSelPanel', this._selPanel); this._selContainer = document.createElement("div"); this._selContainer.appendChild(this._selPanel); YAHOO.util.Dom.addClass(this._selPanel, 'fcHidden'); this._domElement.appendChild(this._selContainer); this._selCloser = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocSelClose', this._selPanel); this._histEl = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocSelHistory', this._selPanel); // list table this._listEl = document.createElement("div"); this._domElement.appendChild(this._listEl); this._yds = new YAHOO.util.FunctionDataSource(function() { return that._pds; }); this._cols = this._dataSource.getColumns(); // full data source column list this._cols.push("bytesize"); this._cols.push("suffix"); this._yds.responseSchema = { fields: this._cols }; // offline element this._offlineEl = document.createElement("div"); // initialize selection and associated elements this._selRow = null; this._selTBEl = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocSelTB', this._selPanel); var selTBCfg = { domElement: this._selTBEl, buttons: [ { id: "fcDocItemView" + this._instance, label: FIRSTCLASS.locale.toolbars.documents.open, fcid: "docopen", condition: function(row) { return row !== null; }, customizer: function(el) { if (that._selRow) { var itemUrl = that.createDownloadUrl(that._selRow); var fmt = "$content$"; FIRSTCLASS.locale.setElementString(this.label, el, fmt); } } }, { id: "fcDocItemComment" + this._instance, label: FIRSTCLASS.locale.toolbars.documents.comment, fcid: "doccomment", condition: function(row) { return that._commentEl === null; } }, { id: "fcDocItemEdit" + this._instance, label: FIRSTCLASS.locale.toolbars.documents.edit, fcid: "docedit", condition: function(row) { var enable = false; if (row !== null) { if ((FIRSTCLASS.ui.webdav.osPlatform() == "windows") && FIRSTCLASS.util.Display.isEditableOfficeFile(row.name)) { if (YAHOO.env.ua.ie || YAHOO.env.ua.gecko) { enable = true; } } if (row.linkinfo) { enable = false; } } return enable; } }, { id: "fcDocItemUpdate" + this._instance, label: FIRSTCLASS.locale.toolbars.documents.update, condition: function(row) { if (row !== null) { return !row.linkinfo; } return false; }, fcid: "docupdate" }, { id: "fcDocItemForward" + this._instance, label: FIRSTCLASS.locale.toolbars.documents.sendto, condition: function(row) { return row !== null; }, fcid: "docsendto" }, { id: "fcDocItemDelete" + this._instance, label: FIRSTCLASS.locale.toolbars.documents.del, fcid: "docdelete", condition: function(row) { if (row !== null) { if (row.threadid == "0") { return false; } var delown = FIRSTCLASS.permissions.hasPriv(row.acl, FIRSTCLASS.permissions.ACL.DELETEOWN); var del = FIRSTCLASS.permissions.hasPriv(row.acl, FIRSTCLASS.permissions.ACL.DELETE); if (del) { return true; } else if (delown && FIRSTCLASS.session.user.cid == row.creatorcid) { return true; } } return false; } }, { id: "fcDocItemWatch" + this._instance, label: FIRSTCLASS.locale.toolbars.documents.watch, fcid: "docwatch", condition: function(row) { return row !== null; }, customizer: function(el) { var fmt = "$content$"; if (that._selRow !== null) { if (that._selRow.watched) { fmt = "$content$ "; } } FIRSTCLASS.locale.setElementString(this.label, el, fmt); } }, { id: "fcDocTag" + this.instance, label: FIRSTCLASS.locale.toolbars.documents.tag, fcid: 'doctag', condition: function(row) { return row !== null; } }, { id: "fcDocPermaLink" + this.instance, label: FIRSTCLASS.locale.toolbars.documents.permalink, condition: function(row) { return row !== null; }, fcid: 'permalink', customizer: function(el) { if (that._selRow) { var l = FIRSTCLASS.locale.toolbars.documents.permalink; var fmt = "$content$"; FIRSTCLASS.locale.setElementString(l, el, fmt); } } }, { id: "fcDocClose" + this.instance, label: FIRSTCLASS.locale.community.docs.close, fcid: 'docselclose' } ] }; this._selTB = new FIRSTCLASS.ui.toolBar(selTBCfg); // actions bar this._actionsEl = document.createElement("div"); // actions var actionTBCfg = { domElement: this._actionsEl, vertical: true, buttons: [ { id: "fcDocUpload" + this._instance, label: FIRSTCLASS.locale.community.docs.actions.upload, fcid: "docupload", priv: FIRSTCLASS.permissions.ACL.CREATE }, { id: "fcDocClearUnread" + this._instance, label: FIRSTCLASS.locale.toolbars.readall, fcid: "cleardocflags" } ] }; this._actionsTB = new FIRSTCLASS.ui.toolBar(actionTBCfg); FIRSTCLASS.ui.rightSideBar.updateBoxContents(FIRSTCLASS.locale.community.actions.lbl, this._actionsEl); this._actionsTB.reconfigure(null, this._dataSource.getAcl()); // filter var qfCfg = { domEl: this._filterEl, callback: { filter: function(str) { that.filterRows(str); }, reset: function() { that.unFilter(); } } }; this._quickFilter = new FIRSTCLASS.util.quickFilter(qfCfg); this.instance = FIRSTCLASS.apps.Documents.instances++; // wake up this.myResizeEvent(); YAHOO.util.Dom.addClass(this._domElement, 'fcDocsTab'); YAHOO.util.Dom.setStyle(this._listEl, 'background-color', '#FFFFFF'); this._dataSource.addRowListener(this, true); FIRSTCLASS.session.setActiveApplication(this, "documents"); this.clearSelection(); if (config.rowToOpen) { // decouple from initial thread window.setTimeout(function() { that.showRowInContext(config.rowToOpen); }, 100); } this._fillIdx = 0; this._enableFill = true; this.sequentialFill(); // display fill indicator in doc counter element this._fillIndicator = window.setInterval(function() { if (that._countEl && that._nItems == 0) { var ind = that._countEl.innerHTML; that._countEl.innerHTML = ind + "."; } }, 500); }; FIRSTCLASS.apps.Documents.instances = 0; // class methods FIRSTCLASS.apps.Documents.prototype.__fcAppName = "FIRSTCLASS.apps.Documents"; FIRSTCLASS.apps.Documents.prototype.isRelatedApp = function(app) { return this._community.isSubApp(app); }; FIRSTCLASS.apps.Documents.prototype.getCommunity = function() { return this._community; }; FIRSTCLASS.apps.Documents.prototype.handleEvent = function(evt, fcevent) { var rc = false; if (this._community.membersApp && this._community.membersApp.isVisible()) { rc = this._community.membersApp.handleEvent(evt, fcevent); } if (this._history !== null) { rc = this._history.handleEvent(evt, fcevent); } if (!rc) { var handlers = this.eventHandlers[evt.type]; if (handlers) { var handler = handlers[fcevent.fcid]; if (handler) { rc = handler(this, fcevent, evt); if (typeof rc == "undefined") { rc = true; } } } } return rc; }; FIRSTCLASS.apps.Documents.prototype.eventHandlers = { click: { // the initial page docfirstpage: function(that) { that.uploadDocument(false); }, // actions bar docupload: function(that) { that.uploadDocument(false); }, cleardocflags: function(that) { that._dataSource.markAllAsRead(false); FIRSTCLASS.ui.navBar.setProfileUnread(0); }, // page toolbar docedit: function(that) { FIRSTCLASS.ui.webdav.edit(that._pluginEl, that._selRow, that._dataSource); }, docupdate: function(that) { that.uploadDocument(true); }, doccomment: function(that) { that.addComment(); }, docwatch: function(that) { if (that._selRow) { if (that._selRow.watched) { FIRSTCLASS.session.desktop.deleteWatch(that._selRow); that._selRow.watched = false; } else { that._dataSource.watchItem(that._selRow); that._selRow.watched = true; } that._selTB.reconfigure(that._selRow); } }, docsendto: function(that, fcevent) { that.sendTo(that._selRow, fcevent); }, docdelete: function(that) { that.deleteDocument(that._selRow); }, doctag: function(that, fcevent) { that.editTags(); }, // history toolbar fcDocHistMakeCurrent: function(that) { that.revertToVersion(); }, dochistsendto: function(that, fcevent) { that.sendTo(that._history._selRow, fcevent); }, dochistdel: function(that) { that._dataSource.deleteRow(that._history._selRow); }, // tag cloud search: function(that, fcevent) { that.filterByTag(fcevent.fcattrs); } }, mouseup: { dochistview: function(that) { if (that._history._selRow.status.unread) { that._dataSource.toggleUnRead(that._history._selRow, false); } }, docopen: function(that) { if (that._selRow.status.unread) { that._dataSource.toggleUnRead(that._selRow, false); } }, docselclose: function(that) { that.clearSelection(); }, // select panel docselpanel: function(that, fcevent) { if (that._history !== null) { that._history.onSelectionChange(that._history._lv._currentSelection, null,null); that._history._lv.clearSelection(); that._selTB.reconfigure(that._selRow); } } } }; FIRSTCLASS.apps.Documents.prototype.dispose = function() { this.removeListView(); }; // upload or update a document FIRSTCLASS.apps.Documents.prototype.uploadDocument = function(isUpdate) { if (!FIRSTCLASS.apps.Workflows.uploadDocument._isOpen) { var that = this; var uploadConfig = { ds: this._dataSource, dsr: isUpdate ? this._selRow : null, paneEl: this._domElement, onComplete: function() { that._uploader = null; that._masterDS.fetchNewRows(); } }; this._uploader = new FIRSTCLASS.apps.Workflows.uploadDocument(uploadConfig); } }; FIRSTCLASS.apps.Documents.prototype.setColumnWidths = function(totalWidth) { if (this._dt !== null) { var tblWidth = totalWidth; var bdEl = this._dt.getBdContainerEl(); if (bdEl) { if (bdEl.scrollHeight > bdEl.clientHeight) { tblWidth -= 16; } } this.calcColumnWidths(tblWidth); var col = null; for (var i=0; i < this._colDefs.length; i++) { col = this._dt.getColumn(this._colDefs[i].key); this._dt.setColumnWidth(col,this._colWidths[i]); } } }; FIRSTCLASS.apps.Documents.prototype.calcColumnWidths = function(totalWidth) { this._colPercents = [ 4, // icon 32, // name 6, // size 15, // author 7, // version 14, // last mod 22 // tags ]; this._colWidths = []; var pSum = 0, cSum = 0, currBound = 0; var pad = 4; for (var i in this._colPercents) { if (typeof this._colPercents[i] == "number") { cSum += this._colPercents[i]; currBound = totalWidth * (cSum / 100.0); this._colWidths[i] = Math.floor(currBound - (pSum + pad)); pSum = currBound; } } }; FIRSTCLASS.apps.Documents.prototype.installListView = function () { var that = this; this.calcColumnWidths(this._listEl.offsetWidth); this._colDefs = [ { label: FIRSTCLASS.locale.community.docs.columns.type, key: "suffix", width: this._colWidths[0], formatter: function(elCell, oRow, oColumn, oData) { that.formatType(elCell, oRow, oColumn, oData); }, className: "fcDocsIcon", sortable: true }, { label: FIRSTCLASS.locale.community.docs.columns.name, key: "name", width: this._colWidths[1], abbr: "file name", formatter: function(elCell, oRow, oColumn, oData) { that.formatName(elCell, oRow, oColumn, oData); }, className: "fcDocsTitle", sortable: true }, { label: FIRSTCLASS.locale.community.docs.columns.fize + " ", abbr: "file size", key: "bytesize", width: this._colWidths[2], formatter: function(elCell, oRow, oColumn, oData) { that.formatSize(elCell, oRow, oColumn, oData); }, className: "fcDocsFilesize", sortable: true }, { label: FIRSTCLASS.locale.community.docs.columns.author, key: "col8082", width: this._colWidths[3], formatter: function(elCell, oRow, oColumn, oData) { that.formatAuthor(elCell, oRow, oColumn, oData); }, className: "fcDocsAuthor", sortable: true }, { label: FIRSTCLASS.locale.community.docs.columns.version, abbr: "version", key: "col8090", width: this._colWidths[4], formatter: function(elCell, oRow, oColumn, oData) { that.formatVersion(elCell, oRow, oColumn, oData); }, className: "fcDocsVersion", sortable: true }, { label: FIRSTCLASS.locale.community.docs.columns.lastmod + " ", key: "parsedDate", width: this._colWidths[5], formatter: function(elCell, oRow, oColumn, oData) { that.formatDate(elCell, oRow, oColumn, oData); }, className: "fcDocsDate", sortable: true }, { label: FIRSTCLASS.locale.community.docs.columns.tags, key: "tags", width: this._colWidths[6], formatter: function(elCell, oRow, oColumn, oData) { that.formatTags(elCell, oRow, oColumn, oData); }, className: "fcDocsTags", sortable: true } ]; var height = (this._listEl.offsetHeight - 27); if (height < 0) { height = 0; } var dtConfig = { height: height + "px", selectionMode: "single", initialLoad: false }; YAHOO.util.Dom.setStyle(this._listEl,'background-color',""); this._dt = new YAHOO.widget.ScrollingDataTable(this._listEl, this._colDefs, this._yds, dtConfig); this._dt.subscribe("rowsAddEvent", function(oRecords) { if (oRecords.records.length == that._flushRows.length) { for (var i in oRecords.records) { if (typeof oRecords.records[i] == "object") { if (typeof oRecords.records[i]._oData == "object") { that._flushRows[i].yId = oRecords.records[i]._sId; } } } that._flushRows = []; } }); this._dt.subscribe("rowClickEvent", function(oArgs) { that.selectClickedItem(oArgs); }); this._dt.subscribe("rowMouseoverEvent", this._dt.onEventHighlightRow); this._dt.subscribe("rowMouseoutEvent", this._dt.onEventUnhighlightRow); // crappy workaround for YUI 2.7.0 column sort bug YAHOO.widget.DataTable.prototype.getTdEl = function(cell) { var Dom = YAHOO.util.Dom, lang = YAHOO.lang, elCell, el = Dom.get(cell); // Validate HTML element if (el && (el.ownerDocument == document)) { // Validate TD element if(el.nodeName.toLowerCase() != "td") { // Traverse up the DOM to find the corresponding TR element elCell = Dom.getAncestorByTagName(el, "td"); } else { elCell = el; } // Make sure the TD is in this TBODY if (elCell && (elCell.parentNode.parentNode == this._elTbody)) { // Now we can return the TD element return elCell; } } else if(cell) { var oRecord, nColKeyIndex; if (lang.isString(cell.columnKey) && lang.isString(cell.recordId)) { oRecord = this.getRecord(cell.recordId); var oColumn = this.getColumn(cell.columnKey); if (oColumn) { nColKeyIndex = oColumn.getKeyIndex(); } } if (cell.record && cell.column && cell.column.getKeyIndex) { oRecord = cell.record; nColKeyIndex = cell.column.getKeyIndex(); } var elRow = this.getTrEl(oRecord); if ((nColKeyIndex !== null) && elRow && elRow.cells && elRow.cells.length > 0) { return elRow.cells[nColKeyIndex]; } } return null; }; this.myResizeEvent(); return; }; FIRSTCLASS.apps.Documents.prototype.removeListView = function() { this._listEl.innerHTML = ""; YAHOO.util.Dom.setStyle(this._listEl,'background-color','#FFFFFF'); this.insertPlaceholder(this._listEl); if (this._dt !== null) { this._dt.destroy(); this._dt = null; } }; FIRSTCLASS.apps.Documents.prototype.resizeEvent = function(event) { this._community.resizeEvent(event); }; FIRSTCLASS.apps.Documents.prototype.editTags = function() { var el = this._taggerEl; var row = this._selRow; if (el.tagger) { // close tagger if open FIRSTCLASS.apps.Workflows.Tags.cleanup(); if (el.formElement) { YAHOO.util.Event.purgeElement(el.formElement, true); el.removeChild(el.formElement); el.formElement = false; } if (el.message) { el.message = false; } el.tagger = false; } else { var tags = document.createElement("div"); var that = this; if (el.formElement) { YAHOO.util.Event.purgeElement(el.formElement, true); el.formElement.parentNode.removeChild(el.formElement); el.formElement = false; } if (el.message) { el.message = false; } el.appendChild(tags); el.formElement = tags; var config = { domElement:tags, item: FIRSTCLASS.ui.parseServerTags(row.tags), personal:FIRSTCLASS.session.desktop.personaltags, container: FIRSTCLASS.ui.parseServerTags(this._dataSource.getTags()), editable: true, dataSource: this._dataSource, row: row, showonconfig:true }; el.tagger = true; FIRSTCLASS.apps.Workflows.Tags.reconfigure(config); } this.resizeEvent(); }; FIRSTCLASS.apps.Documents.prototype.myResizeEvent = function(event, recursive) { // detect first call if (this._dt === null) { var scroller = YAHOO.util.Dom.getElementsByClassName("fcTabContentPane"); if (scroller[0]) { scroller[0] = scroller[0].parentNode; if (scroller[0]) { YAHOO.util.Dom.setStyle(scroller[0], "overflow", "hidden"); YAHOO.util.Dom.setStyle(scroller[0], "height", "auto"); } } YAHOO.util.Dom.setStyle(this._domElement, "overflow", "hidden"); YAHOO.util.Dom.setStyle(this._domElement, "height", "auto"); } // calculate available real estate var viewport = FIRSTCLASS.ui.Dom.getViewportBounds(); var docsY = null, listY = null, histY = null; var minListY = 400; var minSelY = 350; docsY = viewport.ht - YAHOO.util.Dom.getY(this._domElement); docsY -= this._headerEl.offsetHeight; if (this._selRow !== null) { histY = docsY - this._selHeader.offsetHeight; listY = 0.0; } else { listY = docsY; histY = 0.0; } var docsX = null; var minDocsX = 400; var sbwid = viewport.wd * 0.2; if (sbwid < 180) { sbwid = 180; } docsX = viewport.wd - (YAHOO.util.Dom.getX(this._domElement) + sbwid); if (docsX < minDocsX) { docsX = minDocsX; } if (listY < 0) { listY = 0; } if (histY < 16) { histY = 16; } // apply if (!isNaN(docsY)) { YAHOO.util.Dom.setStyle(this._domElement, "width", docsX + "px"); YAHOO.util.Dom.setStyle(this._listEl, "height", listY + "px"); YAHOO.util.Dom.setStyle(this._listEl, "overflow", "hidden"); if (this._selRow !== null) { YAHOO.util.Dom.setStyle(this._histEl.firstChild, "height", (histY - 16) + "px"); YAHOO.util.Dom.setStyle(this._histEl.firstChild, "overflow", "auto"); } if (this._dt !== null) { var el = this._dt.getContainerEl(); YAHOO.util.Dom.setStyle(el, "width", docsX + "px"); el = this._dt.getBdContainerEl(); listY -= this._dt.getHdContainerEl().offsetHeight; if (listY < 0) { listY = 0; } YAHOO.util.Dom.setStyle(el, "height", listY + "px"); this.setColumnWidths(docsX); if (docsX < 0) { docsX = 0; } YAHOO.util.Dom.setStyle(el, "width", docsX + "px"); } } }; FIRSTCLASS.apps.Documents.prototype.filter = function(row) { var accept = this._acceptTypes[row.typedef.objtype] ? true : false; if (row.status.deleted) { accept = false; } else if (row.name.indexOf(".tmp") != -1) { accept = false; } else if (row.icon.id == 70) { accept = true; } if (!this._enableFill) { accept = false; } if (row.typedef.objtype == FIRSTCLASS.objTypes.odocument && !row.linkinfo) { accept = false; } return accept; }; FIRSTCLASS.apps.Documents.prototype.onRow = function(row, dataSource, atEnd, hasMore) { var oldRow; // install list view if none if (this._dt === null) { this.installListView(); } // add item to list keyed by id if (this._pds[row.threadid]) { // already have a version of this item oldRow = this._pds[row.threadid]; if (this.rowIsAnUpdate(oldRow, row)) { // replace old with new this.deleteRowFromTable(oldRow); this._pds[oldRow.threadid] = row; this.queueRow(row); } } else { // just add the new row this._pds[row.threadid] = row; this.queueRow(row); this._nItems++; } }; FIRSTCLASS.apps.Documents.prototype.onRows = function(rows, dataSource, atEnd, hasMore) { var oldRow; // install list view if none if (this._dt === null) { this.installListView(); } // add item to list keyed by id for (var row in rows) { if (this._pds[rows[row].threadid]) { // already have a version of this item oldRow = this._pds[rows[row].threadid]; if (this.rowIsAnUpdate(oldRow, rows[row])) { // replace old with new this.deleteRowFromTable(oldRow); this._pds[oldRow.threadid] = rows[row]; this.queueRow(rows[row]); } } else { // just add the new row this._pds[rows[row].threadid] = rows[row]; this.queueRow(rows[row]); this._nItems++; } } }; FIRSTCLASS.apps.Documents.prototype.rowIsAnUpdate = function(oldRow, newRow) { var isNewer = false; if (newRow.typedef.objtype == oldRow.typedef.objtype) { if (newRow.lastmods > oldRow.lastmods) { isNewer = true; } else if (newRow.version && oldRow.version && newRow.version > oldRow.version) { isNewer = true; } else if (newRow.status.unread != oldRow.status.unread) { isNewer = true; } } return isNewer; }; FIRSTCLASS.apps.Documents.prototype.onRowChanged = function(row, dataSource) { this.onRow(row, dataSource, true, false); }; FIRSTCLASS.apps.Documents.prototype.onRowDeleted = function(row, dataSource) { var nRows = 0; for (var i in this._pds) { nRows++; } // delete row from list; if it was visible, update the display if (this._pds[row.threadid]) { if (nRows > 1) { this.deleteRowFromTable(this._pds[row.threadid]); } else { this.removeListView(); } this._pds.splice(row.threadid, 1); if (this._nItems > 0) { this._nItems--; } } if (this._countEl) { this._countEl.innerHTML = this._nItems + " " + FIRSTCLASS.locale.community.docs.count; } }; FIRSTCLASS.apps.Documents.prototype.insertPlaceholder = function(domEl) { var that = this; var firstPageEl = document.createElement("div"); firstPageEl.setAttribute('width','100%'); YAHOO.util.Dom.setStyle(firstPageEl,'padding-top','8px'); YAHOO.util.Dom.setStyle(firstPageEl,'padding-left','8px'); var TBCfg = { domElement: firstPageEl, buttons: [ { id: "makefirstdocpage" + this._instance, label: FIRSTCLASS.locale.community.docs.initial, fcid: "docfirstpage" } ] }; var tb = new FIRSTCLASS.ui.toolBar(TBCfg); domEl.appendChild(firstPageEl); // header update if (this._countEl) { this._countEl.innerHTML = this._nItems + " " + FIRSTCLASS.locale.community.docs.count; } }; // Sequential fill sequence to ensure serialization of list fill requests. // Steps are: // 0. deactivate master DS to eliminate paged feed polling // 1. load items of type "file" // 2. load items of type "document" // 3. reactivate the master DS // Steps are incremented by fillFinished, as there is no other request-complete confirmation. // Note: may need to add a failsafe timer to this thing if fillFinished is unreliable. FIRSTCLASS.apps.Documents.prototype.sequentialFill = function() { switch (this._fillIdx) { case 0: this._masterDS.deactivate(); this._dataSource.fetchRowsByObjType([FIRSTCLASS.objTypes.file, FIRSTCLASS.objTypes.odocument], false); this._fillIdx++; break; case 1: this._masterDS.activate(); this._fillIdx++; } }; FIRSTCLASS.apps.Documents.prototype.fillFinished = function() { this.flushRowsToTable(); this.sequentialFill(); }; FIRSTCLASS.apps.Documents.prototype.onFillCompleted = function() { if (this._nItems === 0) { this.insertPlaceholder(this._listEl); } this._firstFill = false; if (this._fillIndicator) { window.clearInterval(this._fillIndicator); this._fillIndicator = false; } if (this._countEl) { this._countEl.innerHTML = this._nItems + " " + FIRSTCLASS.locale.community.docs.count; } }; // delete entire thread FIRSTCLASS.apps.Documents.prototype.deleteDocument = function(row) { var that = this; // put up dialog var delDlg = new YAHOO.widget.SimpleDialog("dlg", { width: '320px', fixedcenter: true, postmethod: 'none', visible: false, draggable: false }); var str = FIRSTCLASS.locale.community.docs.del.header.replace("$name$",row.name); delDlg.setHeader(str); str = FIRSTCLASS.locale.community.docs.del.prompt.replace("$name$",row.name); delDlg.setBody(str); delDlg.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_WARN); var doContinue = function() { that._masterDS.deleteThread(row); delDlg.destroy(); that.clearSelection(); }; var doCancel = function() { delDlg.destroy(); }; delDlg.cfg.queueProperty('buttons', [ { text: FIRSTCLASS.locale.community.docs.del.cancel, handler: doCancel }, { text: FIRSTCLASS.locale.community.docs.del.cont, handler: doContinue } ]); delDlg.render(document.body); delDlg.show(); }; // queue row to add to table FIRSTCLASS.apps.Documents.prototype.queueRow = function(row) { var that = this; var suffix = ""; var bytes = 0; if (row.name) { suffix = row.name.slice(row.name.lastIndexOf(".")+1); } row.suffix = suffix; if (row.col6) { bytes = Number(row.col6); } row.bytesize = bytes; var queueIt = true; if (this._filterStr !== null) { queueIt = row.name.toLowerCase().indexOf(this._filterStr) >= 0; } if (queueIt) { row.inQueue = true; if (this._nQueued++ > 50) { this.flushRowsToTable(); this._nQueued = 0; } } if (this._flushTimer !== null) { window.clearTimeout(this._flushTimer); } this._flushTimer = window.setTimeout(function(){ that.flushRowsToTable(); }, 5000); }; // flush queued rows to table and sort them in according to the current sort FIRSTCLASS.apps.Documents.prototype.flushRowsToTable = function() { this._flushRows = []; // fetch the queued rows for (var i in this._pds) { if (this._pds[i].inQueue) { delete this._pds[i].inQueue; this._flushRows.push(this._pds[i]); // selection update if (this._selRow && this._selRow.threadid == this._pds[i].threadid && this.rowIsAnUpdate(this._selRow, this._pds[i])) { this.selectItem(this._pds[i]); } } } if (this._dt !== null && this._flushRows.length > 0) { this._dt.addRows(this._flushRows); var state = this._dt.getState(); var key = "parsedDate"; var dir = YAHOO.widget.DataTable.CLASS_DESC; if (state.sortedBy !== null) { key = state.sortedBy.key; dir = state.sortedBy.dir; } var sortCol = this._dt.getColumn(key); this._dt.sortColumn(sortCol, dir); } // header update if (this._countEl && this._nItems > 0) { this._countEl.innerHTML = this._nItems + " " + FIRSTCLASS.locale.community.docs.count; } }; FIRSTCLASS.apps.Documents.prototype.deleteRowFromTable = function(row) { if (this._dt !== null) { this._dt.deleteRow(row.yId); } }; // show icon based on filename, with flag FIRSTCLASS.apps.Documents.prototype.formatType = function(elCell, oRow, oColumn, oData) { var row = oRow._oData; var fileUrl = this.createDownloadUrl(row); var icon = this.getIcon(row); var html = ""; if (row.status.unread) { YAHOO.util.Dom.addClass(elCell,'fcDocsUnreadCell'); } elCell.innerHTML = html; }; // show name FIRSTCLASS.apps.Documents.prototype.formatName = function(elCell, oRow, oColumn, oData) { elCell.innerHTML = "" + oData + ""; var row = oRow._oData; if (row.col8101) { elCell.title = row.col8101; } }; // logical file size FIRSTCLASS.apps.Documents.prototype.formatSize = function(elCell, oRow, oColumn, oData) { elCell.innerHTML = FIRSTCLASS.util.Display.getFileSizeString(oData); }; FIRSTCLASS.apps.Documents.prototype.formatAuthor = function(elCell, oRow, oColumn, oData) { var row = oRow._oData; var name = row.col8082; var mds = this._community._memberlistds; if (mds) { var author = mds.query("uid","" + row.creatorcid); if (author && author.length) { author = author[0][1]; name = author.name; } } elCell.innerHTML = name; }; FIRSTCLASS.apps.Documents.prototype.formatDate = function(elCell, oRow, oColumn, oData) { var row = oRow._oData; elCell.innerHTML = FIRSTCLASS.util.Date.getFriendlyShortDateString(row.lastmods); }; FIRSTCLASS.apps.Documents.prototype.formatVersion = function(elCell, oRow, oColumn, oData) { var vers = 1; if (typeof oData == "number") { vers = oData; } elCell.innerHTML = vers + ""; }; FIRSTCLASS.apps.Documents.prototype.formatTags = function(elCell, oRow, oColumn, oData) { var tags = ""; if (oData) { tags = oData; tags = FIRSTCLASS.ui.generateTagDisplayList(FIRSTCLASS.ui.parseServerTags(tags, {clickable:false, weight:1})); if (tags.length > 45) { tags = tags.substring(0,45) + "..."; } } elCell.innerHTML = "" + tags + ""; }; FIRSTCLASS.apps.Documents.prototype.getIcon = function(row) { var icon = {}; // thumbnail if (row.col8065) { icon.url = this._dataSource.getContainerUrl() + row.col8065; icon.type = "thumbnail"; } else { var iconID = FIRSTCLASS.util.Display.getIconID(row.name); icon.url = "/icons/"+iconID; icon.type = "icon"; } return icon; }; FIRSTCLASS.apps.Documents.prototype.revertToVersion = function() { return; }; FIRSTCLASS.apps.Documents.prototype.clearSelection = function() { if (this._selRow !== null) { YAHOO.util.Dom.addClass(this._selPanel, 'fcHidden'); } if (this._dt) { this._dt.unselectAllRows(); YAHOO.util.Dom.removeClass(this._dt, 'fcHidden'); } this._selRow = null; this.hideHistory(); this.myResizeEvent(); this.scrollSelectionIntoView(); FIRSTCLASS.session.addHistoryEntry(this._community.generateHistoryEntry('Documents', this, null)); }; FIRSTCLASS.apps.Documents.prototype.selectClickedItem = function(oArgs) { var tagName = ""; if (YAHOO.env.ua.gecko) { tagName = oArgs.event.originalTarget.tagName; } else { tagName = oArgs.event.srcElement.tagName; } if ((tagName == 'A') || (tagName == 'IMG')) { return; } this._dt.onEventSelectRow(oArgs); this._dt.unhighlightRow(oArgs.target.id); // if new row is the same one, just deselect var rec = this._dt.getRecord(oArgs.target.id); var row = rec._oData; this.selectItem(row); }; FIRSTCLASS.apps.Documents.prototype.updateSelectPanel = function(row) { var fileUrl = this._dataSource.getItemUrl(row, true, true, true); var icon = this.getIcon(row); // insert row info into selection header var elem = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocSelIcon", this._selPanel); if (elem) { elem.innerHTML = ""; } elem = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocSelPreview", this._selPanel); if (elem) { if (icon.type == "thumbnail") { elem.innerHTML = ""; } else { elem.innerHTML = FIRSTCLASS.locale.community.docs.nopre; } } elem = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocSelTitle", this._selPanel); if (elem) { elem.innerHTML = row.name; } elem = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocSelFilesize", this._selPanel); if (elem && row.col6) { elem.innerHTML = " (" + FIRSTCLASS.util.Display.getFileSizeString(row.col6) + ")"; } elem = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocSelDescription", this._selPanel); if (elem) { if (row.col8101) { elem.innerHTML = FIRSTCLASS.locale.community.docs.desc + " " + row.col8101; } else { elem.innerHTML =""; } } elem = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocSelTags", this._selPanel); if (elem) { if (row.tags) { elem.innerHTML = "" + FIRSTCLASS.locale.community.docs.tags + " " + FIRSTCLASS.ui.generateTagDisplayList(FIRSTCLASS.ui.parseServerTags(row.tags, {clickable:true})); } else { elem.innerHTML = ""; } } }; FIRSTCLASS.apps.Documents.prototype.selectItem = function(row, oncomplete) { if (row.status.unread) { this._dataSource.toggleUnRead(row, false); } YAHOO.util.Dom.addClass(this._dt, 'fcHidden'); this.hideHistory(); if (row != this._selRow) { FIRSTCLASS.session.addHistoryEntry(this._community.generateHistoryEntry('Documents', this, row)); this._selRow = row; } this.updateSelectPanel(row); this.showHistory(); this._selTB.reconfigure(row); YAHOO.util.Dom.removeClass(this._selPanel, 'fcHidden'); this.myResizeEvent(); this.scrollSelectionIntoView(); if (this._taggerEl && this._taggerEl.tagger) { this.editTags(); } if (oncomplete) { oncomplete(); } }; FIRSTCLASS.apps.Documents.prototype.scrollSelectionIntoView = function() { // scroll selected item to top of list if (this._dt !== null) { var bdContEl = this._dt.getBdContainerEl(); var selectedTR = this._dt.getSelectedTrEls(); if (selectedTR.length > 0) { var row = selectedTR[0]; var target = row.offsetTop - 2; // scroll if required if (target > bdContEl.scrollHeight - bdContEl.clientHeight) { target = bdContEl.scrollHeight - bdContEl.clientHeight; } if (target < 0) { target = 0; } bdContEl.scrollTop = target; } } }; FIRSTCLASS.apps.Documents.prototype.showRowInContext = function(row, oncomplete) { this.selectItem(row, oncomplete); }; FIRSTCLASS.apps.Documents.prototype.sendTo = function(row, fcevent) { var rgn = YAHOO.util.Dom.getRegion(fcevent.target); var xy = [rgn.left + rgn.width, rgn.top]; var config = { xy: xy, row: row, dataSource: this._dataSource, community: { uri: this._dataSource.getContainerUrl(), name: this._dataSource._data.name, cid: this._dataSource._data.cid }, permalink: this._dataSource.getPermalink(row) }; FIRSTCLASS.apps.Workflows.SendTo.draw(config); }; FIRSTCLASS.apps.Documents.prototype.showHistory = function() { var that = this; // create the history object if there is none if (!this._history) { if (this._selRow) { var histCfg = { domElement: this._histEl, dataSource: this._dataSource, dsRow: this._selRow, owner: this, toolbar: [ { id: "fcDocHistOpen", label: FIRSTCLASS.locale.toolbars.documents.open, fcid: 'dochistview', condition: function(row) { // chain master toolbar reconfig to this one that._selTB.reconfigure(null); return (row.typedef.objtype == that._selRow.typedef.objtype); }, customizer: function(el) { if (that._history && that._history._selRow) { var itemUrl = that.createDownloadUrl(that._history._selRow); var fmt = "$content$"; FIRSTCLASS.locale.setElementString(this.label, el, fmt); } } }, { id: "fcDocHistMakeCurrent", label: FIRSTCLASS.locale.history.makecurrent, fcid: 'dochistmakecurrent', condition: function(row) { var show = (row.typedef.objtype == that._selRow.typedef.objtype); if (show) { show = FIRSTCLASS.session.ui.experimental; } return show; } }, { id: "fcDocHistSendTo", label: FIRSTCLASS.locale.toolbars.documents.sendto, fcid: 'dochistsendto', condition: function(row) { return (row.typedef.objtype == that._selRow.typedef.objtype); } }, { id: "fcDocHistDelete", label: FIRSTCLASS.locale.toolbars.documents.del, fcid: 'dochistdel', condition: function(row) { if (row.threadid == "0") { return false; } var delown = FIRSTCLASS.permissions.hasPriv(row.acl, FIRSTCLASS.permissions.ACL.DELETEOWN); var del = FIRSTCLASS.permissions.hasPriv(row.acl, FIRSTCLASS.permissions.ACL.DELETE); if (del) { return true; } else if (delown && FIRSTCLASS.session.user.cid == row.creatorcid) { return true; } return false; } } ] }; this._history = new FIRSTCLASS.apps.history(histCfg); } } }; // create a downloadable file url FIRSTCLASS.apps.Documents.prototype.createDownloadUrl = function(row) { var itemUrl = ""; if (this._acceptTypes[row.typedef.objtype]) { if (row.linkinfo && row.linkinfo.url) { itemUrl = row.linkinfo.url.substr(1); } else if (row.typedef.objtype == FIRSTCLASS.objTypes.formdoc) { itemUrl = this._dataSource.getItemUrl(row); } else { var rowParts = row.uri.split("?"); var fName = rowParts[0]; if (row.col8090 && (row.status.backversion !== 0)) { var dotPos = fName.lastIndexOf("."); var name = fName.slice(0,dotPos) + "_v" + row.col8090 + fName.slice(dotPos); fName = name; } rowParts = rowParts[1].split("="); itemUrl = FIRSTCLASS.lang.ensureSlashUrl(this._dataSource.getContainerUrl()); itemUrl += rowParts[1] + ".-1/" + fName; } } return itemUrl; } FIRSTCLASS.apps.Documents.prototype.hideHistory = function() { // clear pending comment if any this.clearComment(); // clean up history objects if (this._history) { this._history.dispose(); this._history = null; } if (this._histEl) { this._histEl.innerHTML = ""; } }; FIRSTCLASS.apps.Documents.prototype.isSafeToNavigate = function() { return (this._commentEl === null); }; FIRSTCLASS.apps.Documents.prototype.addComment = function() { if (FIRSTCLASS.permissions.hasPriv(this._dataSource.getAcl(), FIRSTCLASS.permissions.ACL.SEND)) { var that = this; // show history if it isn't visible this.showHistory(); // insert the receiving element into the dom this._commentEl = document.createElement('div'); YAHOO.util.Dom.addClass(this._commentEl, 'fcEditorContainer'); if (this._histEl.hasChildNodes()) { YAHOO.util.Dom.insertBefore(this._commentEl, this._histEl.firstChild); } else { this._histEl.appendChild(this._commentEl); } this._selTB.reconfigure(this._selRow); // create the message var msgCfg = { callback: { onDisplay: function () { var btn = document.getElementById("fcDocFormCancel"); if (btn) { YAHOO.util.Dom.setStyle(btn,'display','inline'); } btn = document.getElementById("fcDocFormClear"); if (btn) { YAHOO.util.Dom.setStyle(btn,'display','none'); } }, onCancel: function () { that.clearComment(); }, onSave: function () { that.clearComment(); that._masterDS.fetchNewRows(); } }, element: this._commentEl, op: FIRSTCLASS.opCodes.Reply, params: "Quote=0", baseURL: FIRSTCLASS.lang.ensureSlashUrl(this._dataSource.getItemUrl(this._selRow)), objType: FIRSTCLASS.objTypes.message, formID: 21003, formElId: "fcDocForm", bodyType: "HTML", quoteText: null, sendTo: null, tbType: "reply", initHeight: "180px", showAddr: false }; this._commEditor = new FIRSTCLASS.util.Message(msgCfg); } }; FIRSTCLASS.apps.Documents.prototype.clearComment = function() { if (this._commEditor !== null) { this._commEditor.destroy(); this._commEditor = null; } if (this._commentEl) { this._commentEl.parentNode.removeChild(this._commentEl); this._commentEl = null; this._selTB.reconfigure(this._selRow); } }; FIRSTCLASS.apps.Documents.prototype.filterByTag = function(tag) { if (this._quickFilter) { var lTag = tag.toLowerCase(); if (lTag !== this._filterStr) { this._quickFilter._inputEl.value = lTag; this._quickFilter.doFilter(lTag); } else { this._quickFilter.doFilter(""); } } }; FIRSTCLASS.apps.Documents.prototype.filterRows = function(queryStr) { // save filter string this._filterStr = queryStr; if (this._dt !== null) { // mark/accumulate rows to display if (this._pds && this._nItems > 0) { var field = "", colname=""; var cols = ["name","col8082","tags"]; // search these var row, col; for (var row in this._pds) { for (col=0; col < cols.length; col++) { colname = cols[col]; field = this._pds[row][colname]; if (field && field.toLowerCase().indexOf(this._filterStr) >= 0) { this._pds[row].inQueue = true; } } } } // clear data table and re-add filtered rows this.clearTable(); this.flushRowsToTable(); } }; FIRSTCLASS.apps.Documents.prototype.unFilter = function() { this._filterStr = null; if (this._dt !== null) { // mark/accumulate rows to display if (this._pds && this._nItems > 0) { for (var i in this._pds) { this._pds[i].inQueue = true; } } // clear data table if any this.clearTable(); // re-add the rows this.flushRowsToTable(); } }; FIRSTCLASS.apps.Documents.prototype.clearTable = function() { // clear data table var nRows = this._dt.getRecordSet().getLength(); if (nRows > 0) { this._dt.deleteRows(0,nRows); } }; // pds query FIRSTCLASS.apps.Documents.prototype.query = function(column, query, caseIns, compare) { var rows = []; var search = (caseIns) ? query.toLowerCase() : query; if (this._pds) { for (var i in this._pds) { var key = this._pds[i][column]; if (key) { if(caseIns) { key = key.toLowerCase(); } var comp = false; if (compare) { comp = compare(key, search); } else if (typeof key == "string") { comp = (key.indexOf(search) >= 0); } else { comp = ((""+key) == search); } if (comp) { rows.push([this._pds[i][column],this._pds[i]]); } } } } return rows; }; FIRSTCLASS.apps.Documents.prototype.getColumns = function() { return this._dataSource.getColumns(); }; // return row for given element id FIRSTCLASS.apps.Documents.prototype.rowFromID = function(id) { var row = null; var start = id.indexOf("_") + 1; if (start > 0) { var msgid = id.substr(start); var rows = this.query("messageid",msgid,true); if (rows.length > 0) { row = rows[0][1]; } } return row; }; // return element id for given row FIRSTCLASS.apps.Documents.prototype.idForRow = function(row) { var id = "doc"+this._instance+"_"+row.messageid; return id; }; FIRSTCLASS.apps.Documents.prototype.activate = function () { this._dataSource.activate(); this._masterDS.activate(); FIRSTCLASS.session.setActiveApplication(this, "documents"); FIRSTCLASS.ui.rightSideBar.updateBoxContents(FIRSTCLASS.locale.community.actions.lbl, this._actionsEl); FIRSTCLASS.ui.Dom.reparentNode(this._listEl, this._domElement); }; FIRSTCLASS.apps.Documents.prototype.deactivate = function(internal) { if (!internal) { this._dataSource.deactivate(); this._masterDS.deactivate(); FIRSTCLASS.ui.skin.clear(); this._community.deactivate(internal); } FIRSTCLASS.ui.Dom.reparentNode(this._listEl, this._offlineEl); }; YAHOO.register("fcDocuments", FIRSTCLASS.apps.Documents, {version: "0.0.1", build: "1"});