// Wiki.js - implements the Wiki application // ---- Wiki Application ---- FIRSTCLASS.apps.Wiki = function(config) { this._domEl = config.domElement; this._masterDataSource = config.dataSource; this._dataSource = config.dataSource.createSlave({}); this._view = "none"; this._currentRow = null; this._community = config.community; this._config = config; this._commentEl = null; this._commEditor = null; this._firstPageEl = null; this._savePageName = null; var that = this; var html = []; // HTML elements this._offlineEl = document.createElement("div"); // bag for out-of-page things this._summEl = document.createElement("div"); // wiki summary section // summary bar html.push(""); html.push(""); html.push(""); html.push("
"); html.push(""); html.push(""); html.push("
 "); html.push(""); html.push(""); html.push("
"); html.push("
"); // navigator html.push(""); html.push("
"); html.push("
"); // bottom bar html.push(""); html.push(""); html.push("
"); this._summEl.innerHTML = html.join(""); // this._summEl = this._summEl.firstChild; YAHOO.util.Dom.addClass(this._summEl, "fcWikiMain"); this._offlineEl.appendChild(this._summEl); this._navCellEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiNavCell", this._summEl); // nav cell YAHOO.util.Dom.addClass(this._navCellEl, 'fcWikiNavFilter'); this._countEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageCount", this._summEl); this._pgEl = document.createElement("div"); // page section YAHOO.util.Dom.addClass(this._pgEl, "fcWikiPage"); this._navShade = FIRSTCLASS.ui.Dom.getChildByIdName("fcWikiNavShade", this._summEl); html = []; // page header html.push(""); html.push(""); html.push(""); html.push(""); html.push(""); // info bar html.push(""); html.push(""); html.push(""); // toolbar/footer html.push(""); html.push(""); html.push(""); // the page html.push(""); html.push(""); html.push(""); // footer bar with tags again html.push(""); html.push(""); html.push(""); html.push(""); html.push(""); html.push(""); html.push("
"); html.push(""); html.push("
"); // html.push("
"); html.push("
"); html.push("

"); html.push("
"); html.push("
"); html.push("
"); html.push("
"); html.push("
"); html.push(""); html.push(""); html.push("
"); html.push("
"); html.push("
"); html.push("
"); html.push("
"); html.push("
" + FIRSTCLASS.locale.community.wiki.tags + " 
"); html.push("
"); this._pgEl.innerHTML = html.join(""); this._offlineEl.appendChild(this._pgEl); this._pgHdrEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageHeader", this._pgEl); // page header this._pgInfoBar = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiInfoBar", this._pgEl); // page info bar // this._pgInfoBtn = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageInfoBtn", this._pgEl); // page info button // this._pgInfoBtn.setAttribute('fcid','pginfo'); this._contentPaneEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiContent", this._pgEl); // table enclosing content area this._pageTableEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageTable", this._pgEl); // page table this._bodyCell = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageCell", this._pgEl); // page body cell this._bodyEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageBody", this._pgEl); // page body this._tocCell = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiTOCCell", this._pgEl); // table of contents cell this._tocEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiTOC", this._pgEl); // table of contents this._tocEl.setAttribute('fcid', 'wikitoc'); this._tocBtnEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiTOCBtn", this._pgEl); // toc toggle this._tocBtnEl.setAttribute('fcid', 'wikitocbtn'); this._pickerEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcQF", this._summEl); // page finder this._pickerInEl = FIRSTCLASS.ui.Dom.getChildByIdName("fcQFP", this._summEl); // page finder input field this._pickerConEl = FIRSTCLASS.ui.Dom.getChildByIdName("fcQFC", this._summEl); // page finder list container this._pageTBEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageToolbar", this._pgEl); // page toolbar this._editTBCont = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiEditTB", this._pgEl); // edit toolbar this._tagEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageTags", this._pgEl); // tags this._tagBar = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiTagBar", this._pgEl); this._tagList = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiTagList", this._pgEl); this._tocTitle = document.createElement("div"); YAHOO.util.Dom.addClass(this._tocTitle, 'fcWikiContentsTitle'); this._tocTitle.innerHTML = "
" + FIRSTCLASS.locale.community.wiki.contents + "
"; this._tocOrigin = 0; this._nTocRows = 0; this._scrollToc = false; this._tocHeight = this._tocEl.offsetHeight; this._taggerEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiTagEditor", this._pgEl); // toolbars & controls this._actionsEl = document.createElement("div"); // actions var actionTBCfg = { domElement: this._actionsEl, vertical: true, buttons: [ { id: "fcWikiNewPage", label: FIRSTCLASS.locale.community.wiki.actions.wikinew, fcid: 'newwikipage', priv: FIRSTCLASS.permissions.ACL.CREATE }, { id: "fcWikiUpload" + this._instance, label: FIRSTCLASS.locale.community.docs.actions.upload, fcid: "upload", priv: FIRSTCLASS.permissions.ACL.CREATE }, { id: "fcWikiClearUnread" + this._instance, label: FIRSTCLASS.locale.toolbars.readall, fcid: 'clearwikiflags' } ] }; this._actionsTB = new FIRSTCLASS.ui.toolBar(actionTBCfg); this._actionsTB.reconfigure(null, this._dataSource.getAcl()); FIRSTCLASS.ui.rightSideBar.updateBoxContents(FIRSTCLASS.locale.community.actions.lbl, this._actionsEl); this._showNavTBEl = document.createElement("div"); // show list var TBCfg = { domElement: this._showNavTBEl, buttons: [ { id: "fcDocsListPages", label: FIRSTCLASS.locale.community.wiki.show, fcid: 'showwikinav' } ] }; this._showNavTB = new FIRSTCLASS.ui.toolBar(TBCfg); this._showNavTB.setButtonLabel("fcDocsListPages", FIRSTCLASS.locale.community.wiki.show + "
"); this._offlineEl.appendChild(this._showNavTBEl); this._hideNavTBEl = document.createElement("div"); // hide list TBCfg = { domElement: this._hideNavTBEl, buttons: [ { id: "fcDocsListPages", label: FIRSTCLASS.locale.community.wiki.hide, fcid: 'hidewikinav' } ] }; this._hideNavTB = new FIRSTCLASS.ui.toolBar(TBCfg); this._hideNavTB.setButtonLabel("fcDocsListPages", FIRSTCLASS.locale.community.wiki.hide + "
"); this._offlineEl.appendChild(this._hideNavTBEl); this._viewTBEl = document.createElement("div"); // viewing toolbar TBCfg = { domElement: this._viewTBEl, buttons: [ { id: "fcWikiEditPage", label: FIRSTCLASS.locale.toolbars.wiki.edit, priv: FIRSTCLASS.permissions.ACL.CREATE & FIRSTCLASS.permissions.ACL.EDIT & FIRSTCLASS.permissions.ACL.DELETEOWN, condition: function() { var show = (that._view == "page") ? true : false; if (show) { if (!that._currentRow) { show = false; } else if (that._currentRow.status.backversion) { show = false; } } return show; }, fcid: 'wikiedit' }, { id: "fcWikiAddAComment", label: FIRSTCLASS.locale.toolbars.wiki.comment, condition: function() { var show = ((that._view == "history") || (that._view == "page")); if (that._currentRow && that._currentRow.status.backversion) { show = false; } return show; }, fcid: 'wikicomment' }, { id: "fcWikiShowHistory", label: FIRSTCLASS.locale.toolbars.wiki.history, condition: function() { return (that._view != "history"); }, customizer: function(el) { if (that._currentRow && that._navigator) { var f = that._navigator.getUnreadState(that._currentRow); var fmt = "$content$"; if (f) { fmt = "
$content$"; } FIRSTCLASS.locale.setElementString(this.label, el, fmt); } }, fcid: 'wikihistory' }, { id: "fcWikiSend", label: FIRSTCLASS.locale.toolbars.wiki.sendto, fcid: 'wikisend' }, { id: "fcWikiDelete", label: FIRSTCLASS.locale.toolbars.wiki.del, fcid: 'wikideletepage', condition: function(row) { if (row !== null) { if (row.threadid === "0") { return false; } if (row.status.backversion) { return false; } if (that._view !== "page") { 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: "fcWikiWatch", label: FIRSTCLASS.locale.toolbars.wiki.watch, customizer: function(el) { var l = this.label; var fmt = "$content$"; if (that._currentRow && that._currentRow.status.watched) { fmt += "
"; } FIRSTCLASS.locale.setElementString(this.label, el, fmt); }, fcid: 'wikiwatch' }, { id: "fcWikiTag" + this.instance, label: FIRSTCLASS.locale.toolbars.wiki.tags, fcid: 'dotag', condition: function(row) { var show = (that._view === "page") && that._currentRow && !that._currentRow.status.backversion; if (show) { if (row !== null) { show = row.threadid != "0"; } } return show; } }, { id: "fcWikiPrint" + this.instance, label: FIRSTCLASS.locale.toolbars.wiki.print, fcid: 'print', condition: function(row) { return (that._view === "page"); } }, { id: "fcWikiPermaLink" + this.instance, label: FIRSTCLASS.locale.toolbars.wiki.permalink, fcid: 'permalink', condition: function(row) { return (that._view === "page") && that._currentRow && !that._currentRow.status.backversion; }, customizer: function(el) { if (that._currentRow) { FIRSTCLASS.locale.setElementString(FIRSTCLASS.locale.toolbars.wiki.permalink, el, "$content$"); } } }, { id: "fcWikiViewLatest", label: FIRSTCLASS.locale.toolbars.wiki.back, condition: function() { var show = (that._view == "page"); if (that._currentRow && !that._currentRow.status.backversion) { show = false; } return show; }, fcid: 'wikiviewlatest' }, { id: "fcWikiViewPage", label: FIRSTCLASS.locale.toolbars.wiki.back, condition: function() { var show = (that._view != "edit") && (that._view != "page"); return show; }, fcid: 'wikiview' } ] }; this._viewTB = new FIRSTCLASS.ui.toolBar(TBCfg); this._offlineEl.appendChild(this._viewTBEl); this._editTBEl = document.createElement("div"); // editing toolbar this._editTBEl.setAttribute('align', 'right'); TBCfg = { domElement: this._editTBEl, buttons: [ { id: "fcWikiCancelEdits", label: FIRSTCLASS.locale.community.wiki.cancel, fcid: 'wikieditcancel' }, { id: "fcWikiSaveEditsBtn", label: FIRSTCLASS.locale.community.wiki.savebtn, fcid: 'wikieditsave' } ] }; this._editTB = new FIRSTCLASS.ui.toolBar(TBCfg); this._offlineEl.appendChild(this._editTBEl); // dialogs this._saveDlg = null; // edit-complete dialog this._sendDlg = null; // send-to dialog this._infoDlg = null; // page info dialog // init this._navigator = null; this._history = null; this._editor = null; this._tocTick = null; this.hideContents(); this._navHidden = true; this._navigator = new FIRSTCLASS.apps.Wiki.navigator({ domElement: this._navCellEl, dataSource: this._dataSource, wiki: this }); FIRSTCLASS.session.setActiveApplication(this, "wiki"); this._navigator.closePicker(); this.setView("page"); this._editsSaved = false; // un-skin the top bar of the tab var mainEl = document.getElementById('fcContent'); var theEl = FIRSTCLASS.ui.Dom.getChildByClassName('tm', mainEl); YAHOO.util.Dom.setStyle(theEl, 'background-image', 'url(' + FIRSTCLASS.session.templatebase + '/firstclass/images/ContentPane_100W_T.png)'); YAHOO.util.Dom.setStyle(theEl, 'background-repeat', 'repeat-x'); theEl = FIRSTCLASS.ui.Dom.getChildByClassName('trc', mainEl); YAHOO.util.Dom.setStyle(theEl, 'background-image', 'url(' + FIRSTCLASS.session.templatebase + '/firstclass/images/ContentPane_100W_TRC.png)'); this._dataSource.fetchRowsByObjType(FIRSTCLASS.objTypes.odocument, false); }; // class methods FIRSTCLASS.apps.Wiki.prototype.__fcAppName = "FIRSTCLASS.apps.Wiki"; FIRSTCLASS.apps.Wiki.prototype.isRelatedApp = function(app) { return this._community.isSubApp(app); }; FIRSTCLASS.apps.Wiki.prototype.getCommunity = function() { return this._community; }; FIRSTCLASS.apps.Wiki.prototype.eventHandlers = { click: { // actions bar newwikipage: function(that) { if (that._view !== 'edit') { if (FIRSTCLASS.session.canNavigateAway()) { that.newPage(); } } }, clearwikiflags: function(that) { that._dataSource.markAllAsRead(false); FIRSTCLASS.ui.navBar.setProfileUnread(0); }, upload: function(that) { var uploadConfig = { ds: that._dataSource, dsr: null, paneEl: that._domEl }; var workflow = new FIRSTCLASS.apps.Workflows.uploadDocument(uploadConfig); }, // nav show/hide wikinavshade: function(that) { if (that._navHidden) { that.showPageList(); } else { that.hidePageList(); } }, // table of contents wikitoc: function(that, fcevent) { that.scrollToContentsItem(fcevent.target); }, // page information pginfo: function(that) { that.showPageInfo(); }, // page toolbar wikiview: function(that) { that.setView("page"); }, wikiviewlatest: function(that) { that.openPageByName(that._currentRow.col8010); }, wikiedit: function(that) { that.editPage(); }, wikicomment: function(that) { if (that._view != "history") { that.setView("history"); } that.addComment(); }, wikihistory: function(that) { that.setView("history"); }, wikiwatch: function(that) { if (that._currentRow) { if (that._currentRow.status.watched) { FIRSTCLASS.session.desktop.deleteWatch(that._currentRow); that._currentRow.status.watched = false; that._viewTB.reconfigure(that._currentRow); } else { that._dataSource.watchItem(that._currentRow); that._currentRow.status.watched = true; that._viewTB.reconfigure(that._currentRow); } } }, wikisend: function(that, fcevent) { that.sendTo(that._currentRow, fcevent); }, wikideletepage: function(that) { that.deletePage(that._currentRow); }, print: function(that, fcevent) { if (that._currentRow.threadid == "0") { return false; } window.open(FIRSTCLASS.session.domain + FIRSTCLASS.session._activeObject + that._currentRow.uri + "?Templates=Print"); }, dotag: function(that, fcevent) { that.editTags(); }, // edit toolbar wikieditcancel: function(that) { if (that._editor && (that._editor._saveState === "none")) { that.cancelEdits(); that.setView("page"); } }, wikieditsave: function(that) { if (that._editor && (that._editor._saveState === "none")) { that.saveEdits(); } }, // body links fcwl: function(that, fcevent, evt) { return that.openLinkedPage(evt); }, // show/hide toc wikitocbtn: function(that) { if (that._tocHidden) { that.showContents(); } else { that.hideContents(); } }, //scroll toc wikitocup: function(that) { that.setTocOrigin(that._tocOrigin - 1); }, wikitocdown: function(that) { that.setTocOrigin(that._tocOrigin + 1); }, // show version wikihistshowversion: function(that, fcevent) { var tg = that._history.rowFromEvent(fcevent); if (tg) { that.viewSelectedVersion(tg.row); } }, // embeds fcestart: function(that, fcevent) { var attrs = fcevent.fcattrs.split(";"); var url = FIRSTCLASS.lang.ensureSlashUrl(that._dataSource.getItemUrl(that._currentRow, true, false, true)); url += "embed" + attrs[0] + ".html"; FIRSTCLASS.ui.embeds.handleClick(fcevent, url); }, // navigator navtable: function(that, fcevent, evt) { that._navigator.handleClick(evt); }, // history wikihistview: function(that, fcevent) { that.viewSelectedVersion(that._history._selRow); }, wikihistsendto: function(that, fcevent) { that.sendTo(that._history._selRow, fcevent); }, wikihistdel: function(that, fcevent) { that._dataSource.deleteRow(that._history._selRow); } }, mouseover: { navtable: function(that, fcevent, evt) { that._navigator.handleHover(evt, true); } }, mouseout: { navtable: function(that, fcevent, evt) { that._navigator.handleHover(evt, false); } }, mouseup: { // select panel wikipanel: function(that, fcevent) { if (that._history !== null) { that._history.onSelectionChange(that._history._lv._currentSelection, null, null); that._history._lv.clearSelection(); } } } }; FIRSTCLASS.apps.Wiki.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.Wiki.prototype.dispose = function() { this._dataSource.dispose(); }; // delete entire page thread FIRSTCLASS.apps.Wiki.prototype.deletePage = 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.wiki.del.header.replace("$name$", row.name); delDlg.setHeader(str); str = FIRSTCLASS.locale.community.wiki.del.prompt.replace("$name$", row.name); delDlg.setBody(str); delDlg.cfg.setProperty("icon", YAHOO.widget.SimpleDialog.ICON_WARN); var doContinue = function() { that._dataSource.deleteThread(row); // remove immediately from nav's version map and row map var n = that._navigator; if (n._versions[row.threadid]) { delete n._versions[row.threadid]; } for (var idx = 0; idx < n._rowMap.length; idx++) { if (row.threadid == n._rowMap[idx].threadid) { n._rowMap.splice(idx, 1); n.nItems = n._rowMap.length; n.reDrawTable(); break; } } delDlg.destroy(); var pageOpened = false; if (n && n._rowMap && n._rowMap.length > 0) { if (row.threadid != n._rowMap[0].threadid) { that.openPage(n._rowMap[0]); pageOpened = true; } else if (n._rowMap.length > 1) { that.openPage(n._rowMap[1]); pageOpened = true; } } if (!pageOpened) { that._firstFill = true; that.fillFinished(); } }; var doCancel = function() { delDlg.destroy(); }; delDlg.cfg.queueProperty('buttons', [ { text: FIRSTCLASS.locale.community.wiki.del.cancel, handler: doCancel }, { text: FIRSTCLASS.locale.toolbars.wiki.del, handler: doContinue } ]); delDlg.render(document.body); delDlg.show(); }; // configure page components for selected view FIRSTCLASS.apps.Wiki.prototype.setView = function(view) { // hide page title var thePage = this._pgEl; // set row data into page view var titleEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageTitle", this._pgEl); if (titleEl) { titleEl.innerHTML = ""; } // hide current view switch (this._view) { case "page": this.hidePage(); break; case "edit": this.hideEditor(); this._editsSaved = false; break; case "history": this.hideHistory(); break; case "none": // initial setup // install summary assembly FIRSTCLASS.ui.Dom.reparentNode(this._summEl, this._domEl); // install page assembly FIRSTCLASS.ui.Dom.reparentNode(this._pgEl, this._domEl); break; default: break; } this._view = view; // sync navigation menu if (view != "edit") { this.showPageList(); } else { this.hidePageList(); } // show new view switch (view) { case "page": // reading view // show wiki summary YAHOO.util.Dom.removeClass(this._summEl, 'fcHidden'); // show page header YAHOO.util.Dom.removeClass(this._pgEl, 'fcHidden'); YAHOO.util.Dom.removeClass(this._pgHdrEl, 'fcHidden'); YAHOO.util.Dom.removeClass(this._tagBar, 'fcHidden'); // insert viewing menu if (this._navigator.nItems > 0) { FIRSTCLASS.ui.Dom.reparentNode(this._viewTBEl, this._pageTBEl); } FIRSTCLASS.ui.Dom.reparentNode(this._editTBEl, this._offlineEl); // show page info bar YAHOO.util.Dom.removeClass(this._pgInfoBar, 'fcHidden'); // show page body and toc YAHOO.util.Dom.addClass(this._bodyEl, 'fcWikiBodyView'); FIRSTCLASS.ui.Dom.reparentNode(this._bodyEl, this._bodyCell); FIRSTCLASS.ui.Dom.reparentNode(this._pageTableEl, this._contentPaneEl); this.showPage(); if (titleEl && this._currentRow) { titleEl.innerHTML = FIRSTCLASS.lang.mlesc(this._currentRow.col8010); } break; case "edit": // hide wiki summary YAHOO.util.Dom.addClass(this._summEl, 'fcHidden'); // show page header YAHOO.util.Dom.removeClass(this._pgEl, 'fcHidden'); YAHOO.util.Dom.removeClass(this._pgHdrEl, 'fcHidden'); YAHOO.util.Dom.removeClass(this._tagBar, 'fcHidden'); // insert editing menu FIRSTCLASS.ui.Dom.reparentNode(this._editTBEl, this._editTBCont); FIRSTCLASS.ui.Dom.reparentNode(this._viewTBEl, this._offlineEl); // hide page info bar YAHOO.util.Dom.addClass(this._pgInfoBar, 'fcHidden'); // show empty page body, no toc for now this._bodyEl.innerHTML = ""; YAHOO.util.Dom.removeClass(this._bodyEl, 'fcWikiBodyView'); FIRSTCLASS.ui.Dom.reparentNode(this._bodyEl, this._bodyCell); FIRSTCLASS.ui.Dom.reparentNode(this._pageTableEl, this._contentPaneEl); this.showEditor(); break; case "history": titleEl.innerHTML = FIRSTCLASS.lang.mlesc(this._currentRow.col8010); // show wiki summary YAHOO.util.Dom.removeClass(this._summEl, 'fcHidden'); // show page header YAHOO.util.Dom.removeClass(this._pgEl, 'fcHidden'); YAHOO.util.Dom.removeClass(this._pgHdrEl, 'fcHidden'); // insert viewing menu FIRSTCLASS.ui.Dom.reparentNode(this._viewTBEl, this._pageTBEl); FIRSTCLASS.ui.Dom.reparentNode(this._editTBEl, this._offlineEl); // show page info bar YAHOO.util.Dom.removeClass(this._pgInfoBar, 'fcHidden'); // remove page body and toc FIRSTCLASS.ui.Dom.reparentNode(this._bodyEl, this._bodyCell); FIRSTCLASS.ui.Dom.reparentNode(this._pageTableEl, this._offlineEl); this._contentPaneEl.innerHTML = ""; this.showHistory(); break; default: break; } this._viewTB.reconfigure(this._currentRow); this.resizeEvent(); }; FIRSTCLASS.apps.Wiki.prototype.resizeEvent = function(event) { this._community.resizeEvent(event); }; FIRSTCLASS.apps.Wiki.prototype.myResizeEvent = function(event, recursive) { // detect first call if (YAHOO.util.Dom.hasClass(this._domEl, "fcContentWrapper")) { YAHOO.util.Dom.removeClass(this._domEl, "fcContentWrapper"); 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"); } } } var viewport = FIRSTCLASS.ui.Dom.getViewportBounds(); var yPos = null; var newHeight = null; var underhead = 21; switch (this._view) { case "page": yPos = YAHOO.util.Dom.getY(this._bodyEl); if (this._tagBar) { yPos += this._tagBar.offsetHeight; } newHeight = viewport.ht - (yPos + underhead); YAHOO.util.Dom.setStyle(this._contentPaneEl, "overflow", "hidden"); YAHOO.util.Dom.setStyle(this._contentPaneEl, "height", "auto"); YAHOO.util.Dom.setStyle(this._bodyEl, "overflow", "auto"); if (!isNaN(newHeight) && newHeight >= 0) { YAHOO.util.Dom.setStyle(this._bodyEl, "height", newHeight+"px"); if (!this._tocHidden) { this.setTocBounds(newHeight); } } break; case "edit": var editBodyEl = FIRSTCLASS.ui.Dom.getChildByClassName("yui-editor-editable-container",this._pgEl); if (editBodyEl) { yPos = YAHOO.util.Dom.getY(editBodyEl); newHeight = viewport.ht - yPos - underhead; YAHOO.util.Dom.setStyle(this._contentPaneEl, "overflow", "hidden"); YAHOO.util.Dom.setStyle(this._contentPaneEl, "height", "auto"); YAHOO.util.Dom.setStyle(this._bodyEl, "overflow", "hidden"); YAHOO.util.Dom.setStyle(this._bodyEl, "height", "auto"); YAHOO.util.Dom.setStyle(editBodyEl, "overflow", "auto"); if (!isNaN(newHeight) && newHeight >= 0) { YAHOO.util.Dom.setStyle(editBodyEl, "height", newHeight+"px"); if (!this._tocHidden) { YAHOO.util.Dom.setStyle(this._tocCell, "height", newHeight+"px"); } } } break; case "history": yPos = YAHOO.util.Dom.getY(this._contentPaneEl); newHeight = viewport.ht - yPos - underhead; YAHOO.util.Dom.setStyle(this._bodyEl, "overflow", "hidden"); YAHOO.util.Dom.setStyle(this._bodyEl, "height", "auto"); YAHOO.util.Dom.setStyle(this._contentPaneEl, "overflow", "auto"); if (!isNaN(newHeight) && newHeight >= 0) { YAHOO.util.Dom.setStyle(this._contentPaneEl, "height", newHeight+"px"); } break; } }; FIRSTCLASS.apps.Wiki.prototype.showPicker = function() { if (this._pickerEl) { YAHOO.util.Dom.removeClass(this._pickerEl, "fcHidden"); } }; FIRSTCLASS.apps.Wiki.prototype.hidePicker = function() { if (this._pickerEl) { YAHOO.util.Dom.addClass(this._pickerEl, "fcHidden"); } }; FIRSTCLASS.apps.Wiki.prototype.openLinkedPage = function(evt) { var tg = evt.target; if (!tg) { tg = evt.srcElement; } if (tg.tagName != "A") { if (tg.parentNode.tagName == "A") { tg = tg.parentNode; } else { tg = null; } } if (tg !== null && tg.className.indexOf("fcwl") >= 0) { var path = tg.pathname; if (path) { var slash = path.lastIndexOf("/"); if (slash >= 0) { path = path.slice(slash+1); } path = decodeURI(path); this.openPageByName(path); } return true; } return false; }; FIRSTCLASS.apps.Wiki.prototype.openPageByName = function(pageName) { var row = this._navigator.rowFromPageName(pageName); if (row) { this.openPage(row); } }; FIRSTCLASS.apps.Wiki.prototype.openItem = function(row) { this.openPage(row); }; FIRSTCLASS.apps.Wiki.prototype.showRowInContext = function(row, oncomplete) { this.openPage(row, false, oncomplete); }; FIRSTCLASS.apps.Wiki.prototype.openPage = function(row, isOld, oncomplete) { if (this._config.logTime) { this._config.logTime("openPage called"); this._config.logTime(YAHOO.lang.JSON.stringify(row)); } var that = this; // squirrel the row var oldRow = this._currentRow; this._currentRow = row; // initialize flag state if (typeof row.status.watched === "undefined") { row.status.watched = FIRSTCLASS.session.desktop.isThreadBeingWatched(row.threadid); } // get the new page var openCB = { success: function(o) { that.setView("page"); if (that._navigator) { that._navigator.syncSelection(oldRow, row); } that.constructPage(o.responseText, isOld); if (row.status.unread) { that._dataSource.toggleUnRead(row, false); } that._history = null; that._editor = null; if (oncomplete) { oncomplete(); } FIRSTCLASS.session.addHistoryEntry(that._community.generateHistoryEntry('Wiki', that, row)); that._navigator.closePicker(); }, failure: function(o) { that.constructPage(o.responseText); } }; var url = this._dataSource.getItemUrl(row); var qm = "?"; if (url.indexOf(qm) < 0) { url += "?"; } else { url += "&"; } url += "FormID=20501"; YAHOO.util.Connect.asyncRequest('GET', url, openCB); }; // set page info from passed-in specifier - object or string FIRSTCLASS.apps.Wiki.prototype.setPageInfo = function(spec) { var el = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageDetails",this._pgInfoBar); if (el) { if ((typeof spec == "object") && (spec !== null)) { if (el) { var details = FIRSTCLASS.locale.community.wiki.details; var version = 1; if (spec.col8090) { version = this._currentRow.col8090; } var old = ""; if (spec.status.backversion) { old = FIRSTCLASS.locale.community.wiki.oldver; YAHOO.util.Dom.addClass(el,'fcWikiOldVersion'); } else { YAHOO.util.Dom.removeClass(el,'fcWikiOldVersion'); } var dt = new Date(); dt.setTime(spec.lastmods*1000); var date = FIRSTCLASS.util.Date.getFriendlyDateTimeString(dt); el.innerHTML = details.replace("$version$",version).replace("$old$",old).replace("$date$",date).replace("$author$",spec.col8082); } } else if (typeof spec == "string") { el.innerHTML = spec; } else { el.innerHTML = ""; } } }; FIRSTCLASS.apps.Wiki.prototype.constructPage = function(pageText) { // rebuild page if new text is passed in if (pageText) { // swap the body out of the DOM FIRSTCLASS.ui.Dom.reparentNode(this._bodyEl,this._offlineEl); var thePage = this._pgEl; // set row data into page view var theElement = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageTitle",thePage); if (theElement) { theElement.innerHTML = FIRSTCLASS.lang.mlesc(this._currentRow.col8010); } this.setPageInfo(this._currentRow); var tags = this._currentRow.tags || ""; var title = FIRSTCLASS.ui.Dom.getChildByClassName('fcWikiTagsTitle', this._pgEl); if (title) { if (tags.length > 0) { this._showTags = true; YAHOO.util.Dom.removeClass(title,'fcHidden'); } else { this._showTags = false; YAHOO.util.Dom.addClass(title,'fcHidden'); } } var cloud = FIRSTCLASS.ui.parseServerTags(tags, {clickable:true}); tags = FIRSTCLASS.ui.generateTagDisplayList(cloud); this._tagEl.innerHTML = tags; this._bodyEl.innerHTML = this._dataSource.expandContent(this._currentRow,pageText); FIRSTCLASS.ui.Dom.reparentNode(this._bodyEl, this._bodyCell); this.processContentNodes(); this.updateContents(); if (this._TOC.length > 2) { this.showContents(); } else { this.hideContents(); } } }; FIRSTCLASS.apps.Wiki.prototype.processContentNodes = function() { // functions for various kinds of nodes var processAnchor = function(node) { if ((node.className == "fcwl") && (this._view != 'edit')) { node.setAttribute('fcid', 'fcwl'); } }; var processDiv = function(node) { if ((node.className == 'fcEmbed') && (this._view == 'edit')) { node.innerHTML = ""; } }; var process = function (node) { switch (node.tagName) { case 'A': processAnchor(node); break; case 'DIV': processDiv(node); break; } for (var c = 0; c < node.childNodes.length; c++) { process(node.childNodes[c]); } }; // find base node var baseEl = this._bodyEl; if (this._view == "edit") { if (this._editor && this._editor._editor && this._editor._editor._editor && this._editor._editor._editor._getDoc) { var doc = this._editor._editor._editor._getDoc(); if (doc.body) { baseEl = doc.body; } } } process(baseEl); }; FIRSTCLASS.apps.Wiki.prototype.showPageList = function() { if (this._navHidden) { FIRSTCLASS.ui.Dom.reparentNode(this._navigator._navTable,this._navCellEl); YAHOO.util.Dom.removeClass(this._navCellEl,'fcHidden'); YAHOO.util.Dom.removeClass(this._navShade, 'fcWikiShowNav'); YAHOO.util.Dom.addClass(this._navShade, 'fcWikiHideNav'); this._navShade.setAttribute('title',FIRSTCLASS.locale.community.wiki.tooltips.hidenav); this._navHidden = false; this.resizeEvent(); } }; FIRSTCLASS.apps.Wiki.prototype.hidePageList = function() { if (!this._navHidden) { FIRSTCLASS.ui.Dom.reparentNode(this._navigator._navTable,this._offlineEl); YAHOO.util.Dom.addClass(this._navCellEl,'fcHidden'); YAHOO.util.Dom.removeClass(this._navShade, 'fcWikiHideNav'); YAHOO.util.Dom.addClass(this._navShade, 'fcWikiShowNav'); this._navShade.setAttribute('title',FIRSTCLASS.locale.community.wiki.tooltips.shownav); this._navHidden = true; this.resizeEvent(); } }; FIRSTCLASS.apps.Wiki.prototype.updateContents = function() { // function to walk nodes and scrape headings var addToTOC = function (node, list) { if (node.tagName == "H2" || node.tagName == "H3") { var e = {}; if (YAHOO.env.ua.ie) { e.text = "" + node.innerText; } else { e.text = "" + node.textContent; } e.el = node; list.push(e); } for (var c = 0; c < node.childNodes.length; c++) { addToTOC(node.childNodes[c],list); } }; this._TOC = []; // find base node var baseEl = this._bodyEl; if (this._view == "edit") { if (this._editor && this._editor._editor && this._editor._editor._editor && this._editor._editor._editor._getDoc) { var doc = this._editor._editor._editor._getDoc(); if (doc.body) { baseEl = doc.body; } } } addToTOC(baseEl, this._TOC); this.setTocBounds(this._tocCell.offsetHeight); }; // insert the contents data into the contents pane, with optional scroller buttons FIRSTCLASS.apps.Wiki.prototype.drawContents = function() { var row = this._tocOrigin, end = row + this._nTocRows; var text, title; this._tocEl.innerHTML = ""; var html = []; if (this._scrollToc) { html.push("
"); } for (; row < end; row++) { html.push(" 32) { text = text.slice(0,29) + "..."; } html.push(" id='fcWikiTOC" + row + "' fcid='wikitoc' title='" + title + "'>" + text + ""); } if (this._scrollToc) { html.push("
"); html.push("
"); } this._tocEl.innerHTML = html.join(""); // set up event handler keys if (this._scrollToc) { var that = this; var btn = FIRSTCLASS.ui.Dom.getChildByIdName('fcWikiTocUp',this._tocEl); btn.setAttribute('fcid','wikitocup'); btn = FIRSTCLASS.ui.Dom.getChildByIdName('fcWikiTocDown',this._tocEl); btn.setAttribute('fcid','wikitocdown'); } return; }; // set the ordinal origin for the top TOC item FIRSTCLASS.apps.Wiki.prototype.setTocOrigin = function(origin) { if (this._scrollToc && this._TOC && this._TOC.length > 0) { if (origin != this._tocOrigin && this._scrollToc) { this._tocOrigin = origin; if (this._tocOrigin < 0) { this._tocOrigin = 0; } if (this._tocOrigin > (this._TOC.length - this._nTocRows)) { this._tocOrigin = this._TOC.length - this._nTocRows; } if (!this._tocHidden) { this.drawContents(); } } } else { this._tocOrigin = 0; } return; }; // set TOC visible row count FIRSTCLASS.apps.Wiki.prototype.setTocBounds = function(height) { var yRow = 20, yTitle = 25, yScroll = 42; var available = height - yTitle; if ((available < (yRow * this._TOC.length)) && (this._TOC.length > 0)) { this._scrollToc = true; available -= yScroll; if (available > yRow) { this._nTocRows = Math.floor(available/yRow); this._tocSlop = available - (this._nTocRows * yRow); } else { this._nTocRows = 1; } } else { this._scrollToc = false; this._nTocRows = this._TOC.length; } this.drawContents(); }; FIRSTCLASS.apps.Wiki.prototype.showContents = function() { this._tocCell.setAttribute('width','15%'); this._bodyCell.setAttribute('width','85%'); YAHOO.util.Dom.removeClass(this._tocCell,'fcHidden'); YAHOO.util.Dom.removeClass(this._tocBtnEl, 'fcWikiOpenToc'); YAHOO.util.Dom.addClass(this._tocBtnEl, 'fcWikiCloseToc'); this._tocBtnEl.setAttribute('title',FIRSTCLASS.locale.community.wiki.tooltips.hidetoc); FIRSTCLASS.ui.Dom.reparentNode(this._tocTitle,this._tocCell); FIRSTCLASS.ui.Dom.reparentNode(this._tocEl,this._tocCell); this._tocOrigin = 0; this.setTocBounds(this._tocCell.offsetHeight); this._tocHidden = false; return; }; FIRSTCLASS.apps.Wiki.prototype.hideContents = function() { YAHOO.util.Dom.addClass(this._tocCell,'fcHidden'); YAHOO.util.Dom.removeClass(this._tocBtnEl, 'fcWikiCloseToc'); YAHOO.util.Dom.addClass(this._tocBtnEl, 'fcWikiOpenToc'); this._tocBtnEl.setAttribute('title',FIRSTCLASS.locale.community.wiki.tooltips.showtoc); this._tocHidden = true; return; }; FIRSTCLASS.apps.Wiki.prototype.scrollToContentsItem = function(target) { if (target) { var id = target.id; var prefix = "fcWikiTOC"; id = id.slice(id.indexOf(prefix) + prefix.length); var scroller = null; if (this._view == "edit") { if (this._editor && this._editor._editor && this._editor._editor._editor && this._editor._editor._editor._getDoc) { scroller = this._editor._editor._editor._getDoc().body.parentNode; } } else if (this._view == "page") { scroller = this._bodyEl; } if (scroller !== null) { FIRSTCLASS.ui.scrollChildrenIntoView(scroller, this._TOC[id].el); } } return; }; FIRSTCLASS.apps.Wiki.prototype.showPage = function() { FIRSTCLASS.ui.Dom.reparentNode(this._bodyEl, this._bodyCell); this.setPageInfo(this._currentRow); }; FIRSTCLASS.apps.Wiki.prototype.hidePage = function() { FIRSTCLASS.ui.Dom.reparentNode(this._bodyEl, this._offlineEl); }; FIRSTCLASS.apps.Wiki.prototype.isSafeToNavigate = function() { return (this._editor === null && this._commEditor == null); }; FIRSTCLASS.apps.Wiki.prototype.hideEditor = function() { if (this._editor) { if (this._editor && this._editor._editor) { this._editor._editor.destroy(); } this._editor.hideEditor(); this._editor = null; this._masterDataSource.activate(); } if (this._saveDlg) { this._saveDlg.cancel(); this._saveDlg.destroy(); this._saveDlg = null; } }; FIRSTCLASS.apps.Wiki.prototype.showEditor = function() { if (this._editor) { this._editor.showEditor(); this._masterDataSource.deactivate(); } }; FIRSTCLASS.apps.Wiki.prototype.cancelEdits = function() { if (this._editor && this._editor._editor) { this._editor._editor.onCancel(); } }; FIRSTCLASS.apps.Wiki.prototype.saveEdits = function() { if (this._editor) { this._editor._saveState = "saving"; } var that = this; var pageName = FIRSTCLASS.locale.community.wiki.save.defname; var comment = FIRSTCLASS.locale.community.wiki.save.defcomm; var tags = ""; var namewidth = "74", commwidth = "71", tagwidth = "97%"; if (YAHOO.env.ua.webkit) { namewidth = "63"; commwidth = "61"; tagwidth = "97%"; } else if (YAHOO.env.ua.mac && YAHOO.env.ua.gecko) { namewidth = "71"; commwidth = "69"; } if (this._currentRow && !this._editor._isACreate) { pageName = this._currentRow.col8010; tags = this._currentRow.tags; comment = ""; } // create and post dialog if (this._saveDlgEl) { var saveCont = document.getElementById("fcWikiSaveDlg_c"); if (saveCont) { this._pgHdrEl.removeChild(saveCont); } this._saveDlgEl = null; this._saveDlg = null; } this._saveDlgEl = document.createElement("div"); this._saveDlgEl.setAttribute("style", "visibility:hidden"); this._saveDlgEl.setAttribute("id", "fcWikiSaveDlg"); var html = []; html.push("
"); html.push(FIRSTCLASS.locale.community.wiki.save.title); html.push(" " + pageName + "
"); html.push("
"); html.push(""); html.push(""); html.push(""); html.push("
"); html.push("
"); html.push("
"); this._saveDlgEl.innerHTML = html.join(""); this._pgHdrEl.appendChild(this._saveDlgEl); this._saveDlg = new YAHOO.widget.Dialog("fcWikiSaveDlg", { width: "525px", draggable: false, visible: false, constraintoviewport: true, postmethod: "manual", close: false, shim: (navigator.userAgent.toLowerCase().indexOf("msie") > -1), buttons: [ { text: FIRSTCLASS.locale.community.wiki.save.cancel, handler: function() { that._editor._saveState = "none"; this.cancel(); } }, { text: FIRSTCLASS.locale.community.wiki.save.save, handler: function() { if (that._editor && that._editor._editor && that._editor._editor._editForm) { var data = this.getData(); if (data.name) { // page name var pageName = FIRSTCLASS.lang.strTruncUTF8(data.name, 60); that._editor._editor._editForm["FieldID:8010=STRING"].value = pageName; // comment that._editor._editor._editForm["FieldID:8101=LITERALSTRING"].value = data.comment; // tags that._editor._editor._editForm["FieldID:8021=STRING"].value = data.tags; // save name for matching that._savePageName = pageName; var elements = that._editor._editor._editForm.elements; for (var i in elements) { var el = elements[i]; if (typeof el == "object" && el !== null && el.tagName && el.tagName == "INPUT") { YAHOO.util.Dom.setAttribute(el, 'disabled', 'disabled'); } } FIRSTCLASS.apps.Workflows.Tags.cleanup(); YAHOO.util.Dom.setStyle(that._tagContainer, 'display', 'none'); var buttons = this.getButtons(); buttons[0].set('disabled', true); buttons[0].addClass('fcHidden'); buttons[1].set('disabled', true); buttons[1].set('label', FIRSTCLASS.locale.editor.insertimage.prog); that._editor._editor.onSubmit(false, { completed: function() { buttons[1].set('label', FIRSTCLASS.locale.community.feed.loading); } }); that._editsSaved = true; } } }, isDefault: true } ] }); this._tagContainer = FIRSTCLASS.ui.Dom.getChildByIdName('fcTagger', this._saveDlgEl); this._tags = FIRSTCLASS.ui.Dom.getChildByIdName('fcTags', this._saveDlgEl); this._tagcfg = { domElement: this._tagContainer, item: FIRSTCLASS.ui.parseServerTags(tags), hidesuggestions: true, destField: this._tags, showonconfig: true }; FIRSTCLASS.apps.Workflows.Tags.reconfigure(this._tagcfg); this._saveDlg.render(); this._saveDlg.show(); if (this._editor._isACreate) { this._saveDlg.form.name.value = ''; this._saveDlg.form.name.focus(); } else { this._saveDlg.form.comment.focus(); } if (this._tocTick !== null) { window.clearInterval(this._tocTick); this._tocTick = null; } return; }; FIRSTCLASS.apps.Wiki.prototype.showPageInfo = function() { var that = this; // create and post dialog if (this._infoDlgEl) { this._infoDlgEl.parentNode.removeChild(this._infoDlgEl); this._infoDlgEl = null; this._infoDlg = null; } if (this._currentRow) { this._infoDlgEl = document.createElement("div"); this._infoDlgEl.setAttribute("style","visibility:hidden"); this._infoDlgEl.setAttribute("id","fcWikiPageInfoDlg"); var html = []; html.push("
"); html.push(FIRSTCLASS.locale.community.wiki.pginfo.title); html.push(" " + this._currentRow.col8010 + "
"); html.push("
"); html.push(""); html.push(""); html.push("
"); this._infoDlgEl.innerHTML = html.join(""); YAHOO.util.Dom.insertAfter(this._infoDlgEl, this._pgInfoBtn); this._infoDlg = new YAHOO.widget.Dialog("fcWikiPageInfoDlg", { width: "400px", draggable: false, visible : false, constraintoviewport : true, postmethod : "manual", shim: (navigator.userAgent.toLowerCase().indexOf("msie") > -1), buttons : [ { text: FIRSTCLASS.locale.community.wiki.pginfo.cancel, handler: function() { this.cancel(); } }, { text: FIRSTCLASS.locale.community.wiki.pginfo.save, handler: function() {}, isDefault:true } ] }); this._infoDlg.render(); this._infoDlg.show(); } return; }; FIRSTCLASS.apps.Wiki.prototype.hideHistory = function() { if (this._history) { this._contentPaneEl.innerHTML = ""; if (this._commentEl) { this.clearComment(); } this._history.dispose(); this._history = null; } if (this._pgInfoBar) { YAHOO.util.Dom.removeClass(this._pgInfoBar, 'fcHidden'); } }; FIRSTCLASS.apps.Wiki.prototype.showHistory = function() { var that = this; if (this._currentRow) { var histCfg = { domElement: this._contentPaneEl, dataSource: this._dataSource, dsRow: this._currentRow, owner: this, toolbar: [ { id: "fcWikiHistView", label: FIRSTCLASS.locale.toolbars.wiki.view, fcid: 'wikihistview', condition: function() { return (that._history._selRow.typedef.objtype == FIRSTCLASS.objTypes.odocument); } }, { id: "fcWikiHistSendTo", label: FIRSTCLASS.locale.toolbars.wiki.sendto, fcid: 'wikihistsendto', condition: function() { var show = (that._history._selRow.typedef.objtype == FIRSTCLASS.objTypes.odocument); return ; } }, { id: "fcWikiHistDelete", label: FIRSTCLASS.locale.toolbars.wiki.del, fcid: 'wikihistdel', 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; } } ] }; this._history = new FIRSTCLASS.apps.history(histCfg); if (this._navigator) { this._navigator.clearCommentFlags(this._currentRow); } if (this._pgInfoBar) { YAHOO.util.Dom.addClass(this._pgInfoBar, 'fcHidden'); } } }; FIRSTCLASS.apps.Wiki.prototype.addComment = function() { if (FIRSTCLASS.permissions.hasPriv(this._dataSource.getAcl(), FIRSTCLASS.permissions.ACL.SEND) && this._commEditor == null) { var that = this; // insert the receiving element into the dom this._commentEl = document.createElement('div'); YAHOO.util.Dom.addClass(this._commentEl, 'fcEditorContainer'); if (this._contentPaneEl.hasChildNodes()) { YAHOO.util.Dom.insertBefore(this._commentEl, this._contentPaneEl.firstChild); } else { this._contentPaneEl.appendChild(this._commentEl); } // 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(); } }, element: this._commentEl, op: FIRSTCLASS.opCodes.Reply, params: "Quote=0", baseURL: FIRSTCLASS.lang.ensureSlashUrl(this._dataSource.getItemUrl(this._currentRow)), objType: FIRSTCLASS.objTypes.message, formID: 21003, formElId: "fcDocForm", bodyType: "HTML", tbType: "reply", maxImage: 720, initHeight: "180px", quoteText: null, sendTo: null, showAddr: false }; this._commEditor = new FIRSTCLASS.util.Message(msgCfg); } }; FIRSTCLASS.apps.Wiki.prototype.clearComment = function() { if (this._commEditor !== null) { this._commEditor.destroy(); this._commEditor = null; } if (this._commentEl) { if (this._commentEl.parentNode) { this._commentEl.parentNode.removeChild(this._commentEl); } this._commentEl = null; } }; FIRSTCLASS.apps.Wiki.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.Wiki.prototype.viewSelectedVersion = function(row) { this.openPage(row); }; FIRSTCLASS.apps.Wiki.prototype.editPage = function() { if (this._config.logTime) { this._config.logTime("Wiki editPage called!"); } if (this._currentRow) { if (this._config.logTime) { this._config.logTime(YAHOO.lang.JSON.stringify(this._currentRow)); } var editCfg = { row: this._currentRow, domElement: this._bodyEl, wiki: this }; this._editor = new FIRSTCLASS.apps.Wiki.editor(editCfg); this.processContentNodes(); this._editsSaved = false; } }; FIRSTCLASS.apps.Wiki.prototype.editTags = function() { var el = this._taggerEl; var row = this._currentRow; 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; FIRSTCLASS.ui.Dom.reparentNode(this._tagList,this._taggerEl); } else { FIRSTCLASS.ui.Dom.reparentNode(this._tagList,this._offlineEl); 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.Wiki.prototype.newPage = function() { if (this._config.logTime) { this._config.logTime("Wiki newPage called!"); } this._masterDataSource.deactivate(); var editCfg = { row: null, domElement: this._bodyEl, wiki: this }; this._editor = new FIRSTCLASS.apps.Wiki.editor(editCfg); this.updateContents(); this.hideContents(); }; FIRSTCLASS.apps.Wiki.prototype.activate = function () { if (this._config.logTime) { this._config.logTime("Wiki Activating"); } this._dataSource.activate(); this._masterDataSource.activate(); FIRSTCLASS.session.setActiveApplication(this, "wiki"); FIRSTCLASS.ui.rightSideBar.updateBoxContents(FIRSTCLASS.locale.community.actions.lbl, this._actionsEl); }; FIRSTCLASS.apps.Wiki.prototype.deactivate = function(internal) { if (!internal) { this._dataSource.deactivate(); this._masterDataSource.deactivate(); FIRSTCLASS.ui.skin.clear(); this._community.deactivate(internal); } }; // Show error dialog, with config options: // .header string dialog title bar // .body string dialog message // .width number pixel width of dialog // .onCancel function callback when dialog dismissed // FIRSTCLASS.apps.Wiki.prototype.showErrorDialog = function(config) { var width = "320px"; if (config.width) { width = config.width + "px"; } var failDlg = new YAHOO.widget.SimpleDialog("dlg", { width: '320px', fixedcenter: true, postmethod: 'none', visible: false, draggable: false }); if (config.header) { failDlg.setHeader(config.header); } if (config.body) { failDlg.setBody(config.body); } failDlg.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_WARN); var doCancel = function() { if (typeof config.onCancel === "function") { config.onCancel(); } failDlg.destroy(); }; failDlg.cfg.queueProperty('buttons', [ { text: FIRSTCLASS.locale.community.wiki.del.cancel, handler: doCancel } ]); failDlg.render(document.body); failDlg.show(); }; // -- wiki url handler callbacks // callback to make full url from clicked-on content URLs FIRSTCLASS.apps.Wiki.prototype.getCurrentPageUrl = function() { return this._dataSource.getItemUrl(this._currentRow); }; YAHOO.register("fcWiki", FIRSTCLASS.apps.Wiki, {version: "0.0.1", build: "1"}); // ---- Wiki navigation control ---- // navigator configuration: // domElement - element to install in // dataSource // wiki - parent object pointer FIRSTCLASS.apps.Wiki.navigator = function(config) { this._domElement = config.domElement; this._dataSource = config.dataSource; this._wiki = config.wiki; // initialize dimensions this.orgCol = 0; this.nRows = 0; this.nCols = 0; this.nItems = 0; this.nDrawnItems = 0; this.nUndrawnItems = 0; this._firstFill = true; // initialize row maps this._rowMap = []; // active rows for navigator keyed on name this._versions = []; // old versions keyed on thread this._comments = []; // comments keyed on thread var that = this; // create source dom elements var html = []; if (!FIRSTCLASS.apps.Wiki.navigator.prototype._mainTbl) { var el = document.createElement("div"); var max = FIRSTCLASS.apps.Wiki.navigator.prototype.MAXCOLS; YAHOO.util.Dom.addClass(FIRSTCLASS.apps.Wiki.navigator.prototype._mainTbl,"fcWikiNavTable"); html.push(""); html.push(""); html.push(""); html.push("
"); for (var col=0; col < max; col++) { html.push("
"); } html.push("
"); html.push("
"); el.innerHTML = html.join(""); FIRSTCLASS.apps.Wiki.navigator.prototype._mainTbl = el.firstChild; } if (!FIRSTCLASS.apps.Wiki.navigator.prototype._colTbl) { FIRSTCLASS.apps.Wiki.navigator.prototype._colTbl = FIRSTCLASS.apps.Wiki.navigator.prototype._mainTbl.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0].childNodes[0].cloneNode(true); } // install nav table this._navTable = FIRSTCLASS.apps.Wiki.navigator.prototype._mainTbl.cloneNode(true); this._domElement.appendChild(this._navTable); // register this as a row listener this._dataSource.addRowListener(this, true); this._quickFind = null; }; // navigator vars FIRSTCLASS.apps.Wiki.navigator.prototype._domElement = null; FIRSTCLASS.apps.Wiki.navigator.prototype._dataSource = null; FIRSTCLASS.apps.Wiki.navigator.prototype._wiki = null; FIRSTCLASS.apps.Wiki.navigator.prototype._mainTbl = null; FIRSTCLASS.apps.Wiki.navigator.prototype._colTbl = null; FIRSTCLASS.apps.Wiki.navigator.prototype.MAXROWS = 4; FIRSTCLASS.apps.Wiki.navigator.prototype.MAXCOLS = 3; // navigator functions FIRSTCLASS.apps.Wiki.navigator.prototype.syncSelection = function(oldRow, newRow) { if (newRow) { var el; if (oldRow) { el = document.getElementById("fcWikiNav_" + oldRow.messageid); if (el) { YAHOO.util.Dom.removeClass(el,"fcWikiNavHilite"); el = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiNavItem",el); if (el) { YAHOO.util.Dom.removeClass(el, "fcWikiNavHilite"); } } } var rowToSelect = this.rowFromPageName(newRow.col8010); if (rowToSelect) { this.shiftIntoView(rowToSelect); el = document.getElementById("fcWikiNav_" + rowToSelect.messageid); if (el) { YAHOO.util.Dom.addClass(el,"fcWikiNavHilite"); var itemEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiNavItem",el); if (itemEl) { YAHOO.util.Dom.addClass(el, "fcWikiNavHilite"); } var iconEl = FIRSTCLASS.ui.Dom.getChildByClassName('fcWikiNavIconBlock',el); if (iconEl) { var flagEl = FIRSTCLASS.ui.Dom.getChildByClassName('fcWikiIconFlag',el); var unread = this.getUnreadState(rowToSelect); if (flagEl && !unread) { // remove the flag flagEl.parentNode.removeChild(flagEl); } else if (unread && !flagEl) { // create a flag flagEl = document.createElement('div'); flagEl.setAttribute('style', 'display:block;'); YAHOO.util.Dom.addClass(flagEl,'fcWikiIconFlag'); iconEl.parentNode.appendChild(flagEl); } } } } } }; FIRSTCLASS.apps.Wiki.navigator.prototype.shiftIntoView = function(row) { if (row) { for (var idx=0; idx < this._rowMap.length; idx++) { if (this._rowMap[idx].messageid == row.messageid) { var showCol = Math.floor(idx/this.nRows); var newOrg = this.orgCol; if (this.orgCol > showCol) { newOrg = showCol; } if (showCol > (this.orgCol + this.MAXCOLS)) { newOrg = showCol - (this.MAXCOLS-1); } if (newOrg != this.orgCol) { this.scrollTable(newOrg); } break; } } } }; FIRSTCLASS.apps.Wiki.navigator.prototype.handleClick = function(evt) { var tg = evt.target; if (!tg) { tg = evt.srcElement; } while (tg && !tg.id && (tg !== this._navTable)) { tg = tg.parentNode; } if (tg && tg.id) { switch (tg.id) { case "fcWikiNavHome": this.scroll(true,true); break; case "fcWikiNavLeftArrow": this.scroll(true,false); break; case "fcWikiNavRightArrow": this.scroll(false,false); break; case "fcWikiNavEnd": this.scroll(false,true); break; default: var row = this.rowFromElement(tg); if (row) { this._wiki.openPage(row); break; } return false; } } return true; }; FIRSTCLASS.apps.Wiki.navigator.prototype.handleHover = function(evt, hoverOn) { var tg = evt.target; if (!tg) { tg = evt.srcElement; } while (tg && !tg.id && (tg !== this._navTable)) { tg = tg.parentNode; } if (tg.id) { if (this._hoverEl) { if ((tg != this._hoverEl) || !hoverOn) { YAHOO.util.Dom.removeClass(this._hoverEl, "fcWikiNavHover"); this._hoverEl = null; } } if (hoverOn && (!this._hoverEl || (this._hoverEl != tg))) { this._hoverEl = tg; YAHOO.util.Dom.addClass(this._hoverEl, "fcWikiNavHover"); } } }; FIRSTCLASS.apps.Wiki.navigator.prototype.rowFromElement = function(element){ var id = element.id.toString(); var theRow = null; id = id.slice(id.lastIndexOf("_") + 1); if (id) { for (var idx = 0; idx < this.nItems; idx++) { if (this._rowMap[idx].messageid == id) { theRow = this._rowMap[idx]; break; } } } return theRow; }; FIRSTCLASS.apps.Wiki.navigator.prototype.rowFromPageName = function(pageName) { var ucPage = pageName.toUpperCase(); for (var idx = 0; idx < this.nItems; idx++) { if (this._rowMap[idx].col8010.toUpperCase() == ucPage) { return this._rowMap[idx]; } } }; FIRSTCLASS.apps.Wiki.navigator.prototype.onRow = function(row, dataSource, atEnd, hasMore, suppressRedraw) { if (this._wiki._config.logTime) { this._wiki._config.logTime("Wiki navigator onRow"); } var insertAt = -1; var threadAt = -1; var discarded = false; var nameMatch = false; var delNew = true; if (row.typedef.objtype == FIRSTCLASS.objTypes.odocument) { // a version this.addToVersionMap(row); // insertion sort item into list for (var idx = 0; idx < this._rowMap.length; idx++) { if ((insertAt < 0) && (row.col8010.toUpperCase() <= this._rowMap[idx].col8010.toUpperCase())) { // insert the new item this._rowMap.splice(idx, 0, row); insertAt = idx++; // on match, delete older version if (row.col8010.toUpperCase() == this._rowMap[idx].col8010.toUpperCase()) { nameMatch = true; delNew = true; if (row.col8090 >= 0) { if (!(this._rowMap[idx].col8090 >= 0) || (row.col8090 > this._rowMap[idx].col8090)) { this._rowMap.splice(idx, 1); delNew = false; idx--; } } if (delNew) { this._rowMap.splice(insertAt, 1); discarded = true; idx--; } } } // on thread id match with name change, toss the older version if (row.threadid == this._rowMap[idx].threadid) { threadAt = idx; if (!nameMatch) { delNew = true; if (row.col8090) { if ((!this._rowMap[idx].col8090) || (row.col8090 > this._rowMap[idx].col8090)) { this._rowMap.splice(idx, 1); delNew = false; } } if (delNew) { if (insertAt >= 0) { this._rowMap.splice(insertAt, 1); } discarded = true; } insertAt = threadAt; } } // if item inserted and thread found, we are done if ((threadAt >= 0) && (insertAt >= 0)) { break; } } // append it if not inserted and thread not found if ((insertAt < 0) && (threadAt < 0)) { insertAt = this._rowMap.length; this._rowMap[this._rowMap.length] = row; } // recalc this.nItems = this._rowMap.length; this.nUndrawnItems++; if (((this.nUndrawnItems > 10) || !this._firstFill) && !suppressRedraw) { this.reDrawTable(); } // someone else's update to current document if (!discarded && this._wiki._currentRow && row.messageid != this._wiki._currentRow.messageid) { if ((row.threadid == this._wiki._currentRow.threadid) && ((this._wiki._view == "page") || this._wiki._editsSaved)) { this._wiki.openPage(row); } } if (this._wiki._config.logTime) { this._wiki._config.logTime("Wiki navigator onRow(discarded: \"" + discarded + "\", savePageName: \"" + this._wiki._savePageName + "\", col8010: \"" + row.col8010+ "\""); } // a new edit just completed if (!discarded && this._wiki._savePageName && (row.col8010 == this._wiki._savePageName)) { this._wiki.openPage(row); this._wiki._savePageName = null; } } else { // a comment this.addToCommentMap(row); } }; FIRSTCLASS.apps.Wiki.navigator.prototype.onRows = function(rows, dataSource, atEnd, hasMore) { if (this._wiki._config.logTime) { this._wiki._config.logTime("Wiki navigator onRows"); } for (var i in rows) { this.onRow(rows[i],dataSource,atEnd, true, true); } this.reDrawTable(); }; // add a new version from the given row; replace if already there FIRSTCLASS.apps.Wiki.navigator.prototype.addToVersionMap = function(row) { var threadVers = this._versions[row.threadid]; if (!threadVers) { threadVers = []; this._versions[row.threadid] = threadVers; } var found = false; for (var i in threadVers) { if (threadVers[i].uid == row.uid) { found = true; threadVers.splice(i,1,row); break; } } if (threadVers && !found) { threadVers.push(row); } return; }; // add a new comment from the given row; replace if already there FIRSTCLASS.apps.Wiki.navigator.prototype.addToCommentMap = function(row) { var threadComm = this._comments[row.threadid]; if (!threadComm) { threadComm = []; this._comments[row.threadid] = threadComm; } var found = false; for (var i in threadComm) { if (threadComm[i].uid == row.uid) { found = true; threadComm.splice(i,1,row); break; } } if (threadComm && !found) { threadComm.push(row); } return; }; // remove passed-in version from map FIRSTCLASS.apps.Wiki.navigator.prototype.removeFromVersionMap = function(row) { var threadVers = this._versions[row.threadid]; if (threadVers) { for (var i in threadVers) { if (threadVers[i].uid == row.uid) { threadVers.splice(i, 1); break; } } if (threadVers.length == 0) { delete this._versions[row.threadid]; } } return; }; // remove passed-in comment from map FIRSTCLASS.apps.Wiki.navigator.prototype.removeFromCommentMap = function(row) { var threadComm = this._comments[row.threadid]; for (var i in threadComm) { if (threadComm[i].uid == row.uid) { threadComm.splice(i,1); break; } } return; }; // clear comment red flags for thread of passed-in row FIRSTCLASS.apps.Wiki.navigator.prototype.clearCommentFlags = function(row) { var threadComm = this._comments[row.threadid]; for (var i in threadComm) { if (threadComm[i].status) { this._dataSource.toggleUnRead(threadComm[i], 0); } } return; }; FIRSTCLASS.apps.Wiki.navigator.prototype.getUnreadState = function(row, filter) { var flagState = false; var onVers = true; var onComm = true; if (filter) { if (filter == "version") { onComm = false; } if (filter == "comment") { onVers = false; } } if (onComm) { var comments = this._comments[row.threadid]; for (var i in comments) { if (comments[i].status.unread) { flagState = true; break; } } } if (onVers && !flagState) { var versions = this._versions[row.threadid]; for (var j in versions) { if (versions[j].status.unread) { flagState = true; break; } } } return flagState; }; FIRSTCLASS.apps.Wiki.navigator.prototype.onFillCompleted = function() { var that = this; if (this.nItems == 0) { if (!this._wiki._firstPageEl) { // empty wiki - insert a control to create the first page this._wiki._firstPageEl = document.createElement("div"); this._wiki._firstPageEl.setAttribute('width', '100%'); YAHOO.util.Dom.setStyle(this._wiki._firstPageEl, 'padding-top', '8px'); YAHOO.util.Dom.setStyle(this._wiki._firstPageEl, 'padding-top', '8px'); var TBCfg = { domElement: this._wiki._firstPageEl, buttons: [ { id: "makefirstpage", label: FIRSTCLASS.locale.community.wiki.initial, click: function(evt) { YAHOO.util.Event.stopPropagation(evt); that._wiki.newPage(); } } ] }; var tb = new FIRSTCLASS.ui.toolBar(TBCfg); this._wiki._bodyEl.appendChild(this._wiki._firstPageEl); FIRSTCLASS.ui.Dom.reparentNode(this._wiki._viewTBEl, this._wiki._offlineEl); } } else { if (this._wiki._countEl) { this._wiki._countEl.innerHTML = this.nItems + " " + FIRSTCLASS.locale.community.wiki.count; } } }; FIRSTCLASS.apps.Wiki.navigator.prototype.fillFinished = function() { var that = this; this.reDrawTable(); if (!this._wiki._editor) { // auto-open most recent item if any if (this.nItems > 0 && (this._firstFill || this._wiki._firstPageEl) && !this._wiki._currentRow) { this._wiki.openPage(this._rowMap[0]); if (this._wiki._firstPageEl) { FIRSTCLASS.ui.Dom.reparentNode(this._wiki._firstPageEl, this._wiki._offlineEl); FIRSTCLASS.ui.Dom.reparentNode(this._wiki._viewTBEl, this._wiki._pageTBEl); } } } this._firstFill = false; }; FIRSTCLASS.apps.Wiki.navigator.prototype.onRowChanged = function(row, dataSource, suppressRedraw) { if (row.typedef.objtype == FIRSTCLASS.objTypes.odocument) { this.addToVersionMap(row); /* replace row in list; if its name changes, remove it from the list and replace it with the new one */ for (var idx=0; idx < this._rowMap.length; idx++) { if (row.uid == this._rowMap[idx].uid) { if (row.col8010 == this._rowMap[idx].col8010) { var isCurrent = false; if (this._wiki._currentRow) { isCurrent = (this._rowMap[idx].threadid == this._wiki._currentRow.threadid && this._rowMap[idx].messageid != this._wiki._currentRow.messageid); } this._rowMap[idx] = row; if ((isCurrent) && this._wiki._view == "page") { this._wiki.openPage(row); } } else { this._rowMap.splice(idx,1); this.onRow(row,dataSource,true,false); if (!suppressRedraw) { this.reDrawTable(); } } break; } } } else { this.addToCommentMap(row); } }; FIRSTCLASS.apps.Wiki.navigator.prototype.onRowsChanged = function(rows, dataSource) { for (var i in rows) { this.onRowChanged(rows[i], dataSource, true); } this.reDrawTable(); }; FIRSTCLASS.apps.Wiki.navigator.prototype.onRowDeleted = function(row, dataSource) { if (row.typedef.objtype == FIRSTCLASS.objTypes.odocument) { this.removeFromVersionMap(row); if (!this._versions[row.threadid]) { // if last version, delete row from list; if it was visible, update the display for (var idx = 0; idx < this._rowMap.length; idx++) { if (row.threadid == this._rowMap[idx].threadid) { this._rowMap.splice(idx, 1); this.nItems = this._rowMap.length; this.reDrawTable(); break; } } } } else { this.removeFromCommentMap(row); } }; // create a column table for the nth "logical" column FIRSTCLASS.apps.Wiki.navigator.prototype.createColumn = function(logColIdx) { var colTbl = FIRSTCLASS.apps.Wiki.navigator.prototype._colTbl.cloneNode(true); var html = []; html.push(""); for (var row = 0; row < this.nRows; row++) { html.push(""); var idx = (logColIdx * this.nRows) + row; if (idx < this.nItems) { html.push(""); } else { html.push(""); } } html.push("
"); // outer cell html.push(""); // sub-table html.push("
"); // icon/flag html.push("
"); if (this.getUnreadState(this._rowMap[idx])) { html.push("
"); } html.push("
" + FIRSTCLASS.lang.mlesc(this._rowMap[idx].col8010) + "
"); // name html.push("
"); colTbl.innerHTML = html.join(""); return colTbl; }; // replace the nth visible column with the passed-in one FIRSTCLASS.apps.Wiki.navigator.prototype.replaceColumn = function(visColIdx, colTable) { // install column var theRow = this._navTable.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0]; if (theRow.childNodes[visColIdx]) { theRow.replaceChild(colTable, theRow.childNodes[visColIdx]); } }; // set the table's scroll origin FIRSTCLASS.apps.Wiki.navigator.prototype.scrollTable = function(newOrigin) { if (newOrigin < 0) { newOrigin = 0; } if (newOrigin >= (this.nCols - this.MAXCOLS)) { newOrigin = this.nCols - this.MAXCOLS; } var goRightBy = newOrigin - this.orgCol; var newCol; if (Math.abs(goRightBy) >= this.MAXCOLS) { this.orgCol = newOrigin; this.reDrawTable(); } else { if (goRightBy !== 0) { if (goRightBy > 0) { this.deleteColumns(0,goRightBy-1); for (var col=0; col < goRightBy; col++) { newCol = this.createColumn(newOrigin + this.MAXCOLS + col - goRightBy); this.addColumn(false,newCol); } } else { this.deleteColumns(this.MAXCOLS + goRightBy, this.MAXCOLS - 1); for (col=0; col > goRightBy; col--) { newCol = this.createColumn(this.orgCol + col - 1); this.addColumn(true,newCol); } } } this.orgCol = newOrigin; this.setScrollArrows(); } }; // add a new column on one side or the other FIRSTCLASS.apps.Wiki.navigator.prototype.addColumn = function(atLeft, column) { var theRow = this._navTable.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0]; if (theRow.hasChildNodes()) { if (atLeft) { theRow.insertBefore(column, theRow.childNodes[0]); } else { theRow.appendChild(column, theRow.lastChild); } } }; // delete 1 or more visible columns FIRSTCLASS.apps.Wiki.navigator.prototype.deleteColumns = function(fromCol, toCol) { var theRow = this._navTable.childNodes[0].childNodes[0].childNodes[1].childNodes[0].childNodes[0].childNodes[0]; for (var column = fromCol; column <= toCol; column++) { theRow.removeChild(theRow.childNodes[fromCol]); } }; FIRSTCLASS.apps.Wiki.navigator.prototype.reDrawTable = function() { // recalc table dimensions var rowCount = Math.floor(this.nItems/this.MAXCOLS); if ((rowCount * this.MAXCOLS) < this.nItems) { rowCount++; } if (rowCount > this.MAXROWS) {rowCount = this.MAXROWS; } if (rowCount != this.nRows) { this.nRows = rowCount; } var colCount = Math.floor(this.nItems/this.nRows); if (colCount < this.MAXCOLS) { colCount = this.MAXCOLS; } if ((colCount * this.nRows) < this.nItems) { colCount++; } if (colCount != this.nCols) { this.nCols = colCount; } if (this.orgCol > (this.nCols - this.MAXCOLS)) { this.orgCol = this.nCols - this.MAXCOLS; } // replace all visible columns var endCol = this.orgCol + this.MAXCOLS - 1; for (var column = this.orgCol; column <= endCol; column++) { var colTbl = this.createColumn(column); this.replaceColumn(column - this.orgCol, colTbl); } // reset bounds this.nDrawnItems = this.nItems; this.nUndrawnItems = 0; this.setScrollArrows(); this.syncSelection(null,this._wiki._currentRow); }; FIRSTCLASS.apps.Wiki.navigator.prototype.setScrollArrows = function() { var showRight = false; var showLeft = false; if (this.nCols > this.MAXCOLS) { if (this.orgCol > 0) { showLeft = true; } if (this.orgCol < (this.nCols - this.MAXCOLS)) { showRight = true; } } var arrow = FIRSTCLASS.ui.Dom.getChildByIdName("fcWikiNavRightArrow", this._navTable); if (arrow) { if (showRight) { YAHOO.util.Dom.removeClass(arrow,"fcHidden"); arrow.setAttribute('title',FIRSTCLASS.locale.community.wiki.tooltips.scrollnav); } else { YAHOO.util.Dom.addClass(arrow,"fcHidden"); arrow.setAttribute('title',""); } } arrow = FIRSTCLASS.ui.Dom.getChildByIdName("fcWikiNavLeftArrow", this._navTable); if (arrow) { if (showLeft) { YAHOO.util.Dom.removeClass(arrow,"fcHidden"); arrow.setAttribute('title',FIRSTCLASS.locale.community.wiki.tooltips.scrollnav); } else { YAHOO.util.Dom.addClass(arrow,"fcHidden"); arrow.setAttribute('title',""); } } }; FIRSTCLASS.apps.Wiki.navigator.prototype.filter = function(row) { // it's a wiki page var accept = row.typedef.objtype == FIRSTCLASS.objTypes.odocument; // it's a wiki comment if (row.replyobjtype && (row.replyobjtype == FIRSTCLASS.objTypes.odocument)) { accept = true; } // it's not deleted if (row.status.deleted) { accept = false; } // it's not a half-formed new page if ((row.typedef.objtype == FIRSTCLASS.objTypes.odocument) && !row.col8082) { accept = false; } // it's not an external document if (row.linkinfo) { accept = false; } if (this._wiki._config.logTime) { this._wiki._config.logTime("wiki filter returning: " + accept); } return accept; }; FIRSTCLASS.apps.Wiki.navigator.prototype.scroll = function(goLeft, toEnd) { var newOrg = this.orgCol; if (toEnd) { if (goLeft) { newOrg = 0; } else if (this.nCols > this.MAXCOLS) { newOrg = this.nCols - this.MAXCOLS; } } else { if (goLeft) { if (newOrg > 0) { newOrg--; } } else if (this.nCols > this.MAXCOLS) { if (newOrg < (this.nCols - this.MAXCOLS)) { newOrg++; } } } if (newOrg != this.orgCol) { this.scrollTable(newOrg); } }; FIRSTCLASS.apps.Wiki.navigator.prototype.openPicker = function() { var that = this; var wiki = this._wiki; if (!this._quickFind) { this._quickFind = new FIRSTCLASS.util.quickFind( { ds: this._dataSource, col: "col8010", inEl: wiki._pickerInEl, contEl: wiki._pickerConEl, onSelect: function(row) { YAHOO.util.Event.removeBlurListener(wiki._pickerInEl); wiki.openPage(row); }, filter: function(rows, qStr) { var keep; // get rid of non-docs and old versions for (var i = rows.length - 1; i >= 0; i--) { keep = true; if (rows[i].typedef.objtype != FIRSTCLASS.objTypes.odocument) { keep = false; } if (rows[i].status.backversion !== 0) { keep = false; } if (keep) { rows[i].qStr = qStr; } else { rows.splice(i,1); } } // get rid of repeats var killIdx = -1; for (i = rows.length - 1; i > 0; i--) { if (rows[i].col8010 == rows[i-1].col8010) { killIdx = (rows[i].lastmod <= rows[i-1].lastmod) ? i : i-1; rows.splice(killIdx,1); } } // sort the results rows.sort(function(rowA, rowB) { var posA = rowA.col8010.toLowerCase().indexOf(rowA.qStr); var posB = rowB.col8010.toLowerCase().indexOf(rowB.qStr); return posA - posB; }); // get rid of bogo-property for (i = rows.length-1; i >= 0; i--) { delete rows[i].qStr; } }, format: function(title) { return "
" + title + "
"; } }); } }; FIRSTCLASS.apps.Wiki.navigator.prototype.closePicker = function() { var that = this; if (this._quickFind !== null) { this._quickFind.dispose(); this._quickFind = null; this._wiki._pickerConEl.innerHTML = ""; this.closePicker(); this._wiki._pickerInEl.value = FIRSTCLASS.locale.community.wiki.find; YAHOO.util.Dom.removeClass(this._wiki._pickerInEl, "focussed"); } YAHOO.util.Event.addListener(this._wiki._pickerInEl, "blur", function(evt) { window.setTimeout( function() { that.closePicker(); that._wiki._pickerInEl.value = FIRSTCLASS.locale.community.wiki.find; YAHOO.util.Dom.removeClass(that._wiki._pickerInEl, "focussed"); }, 500); }); YAHOO.util.Event.addListener(this._wiki._pickerInEl, "focus", function(evt) { if (that._wiki._pickerInEl.value == FIRSTCLASS.locale.community.wiki.find) { that._wiki._pickerInEl.value = ""; } YAHOO.util.Dom.addClass(that._wiki._pickerInEl, "focussed"); that.openPicker(); }); this._wiki._pickerInEl.blur(); this._wiki._pickerInEl.value = FIRSTCLASS.locale.community.wiki.find; }; // ---- Wiki editor ---- // editor configuration: // domElement // wiki FIRSTCLASS.apps.Wiki.editor = function(config) { this._domElement = config.domElement; this._wiki = config.wiki; this._dsRow = config.row || null; var that = this; // create editor socket and page container this._view = {}; this._view.socketEl = document.createElement("div"); // holder div for editor this._view.editEl = document.createElement("div"); YAHOO.util.Dom.addClass(this._view.editEl, "fcWikiPage"); this._view.socketEl.appendChild(this._view.editEl); this._view.isOffscreen = true; this._isACreate = false; // fire up the editor var msgCfg = { callback: this, dataSource: this._wiki._dataSource, row: this._dsRow, element: this._view.editEl, objType: FIRSTCLASS.objTypes.odocument, body: "HTML", formID: 20501, formElId: "fcDocForm", bodyType: "HTML", quoteText: null, sendTo: null, tbType: "wiki", initHeight: this._domElement.offsetHeight, initWidth: this._domElement.offsetWidth }; if (this._dsRow) { // edit vs create msgCfg.baseURL = this._wiki._dataSource.getItemUrl(this._dsRow); msgCfg.op = FIRSTCLASS.opCodes.FormEdit; msgCfg.params = "Close=-1"; } else { this._isACreate = true; msgCfg.baseURL = this._wiki._dataSource.getContainerUrl(); msgCfg.op = FIRSTCLASS.opCodes.FormNew; msgCfg.params = "Close=-1&InitialText="; } this._editor = new FIRSTCLASS.util.Message(msgCfg); // set up interval timer to refresh contents during editing this._contentChange = false; this._tocTick = window.setInterval(function() { that.checkTOCUpdate(); }, 5000); this._saveState = "none"; }; // editor vars // editor functions FIRSTCLASS.apps.Wiki.editor.prototype.onFail = function(obj) { var that = this; var cfg = { header: FIRSTCLASS.locale.community.wiki.noedhd, body: FIRSTCLASS.locale.community.wiki.noedit, onCancel: function() { that._wiki.hideEditor(); } }; if (obj && obj.error) { cfg.body = FIRSTCLASS.locale.errors.getErrorString(obj.error); } this._wiki.showErrorDialog(cfg); }; FIRSTCLASS.apps.Wiki.editor.prototype.onLoaded = function(success) { if (success) { this._wiki.setView("edit"); } else { var that = this; var cfg = { header: FIRSTCLASS.locale.community.wiki.noedhd, body: FIRSTCLASS.locale.community.wiki.noedit, onCancel: function() { that._wiki.hideEditor(); } }; this._wiki.showErrorDialog(cfg); } }; FIRSTCLASS.apps.Wiki.editor.prototype.onDisplay = function() { var titEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcWikiPageTitle", this._wiki._pgHdrEl); if (titEl) { var contents = ""; if (this._editor && this._editor._editForm) { contents = this._editor._editForm["FieldID:8010=STRING"].value; } titEl.innerHTML = contents; } this._wiki.resizeEvent(); this.onCommand(); }; FIRSTCLASS.apps.Wiki.editor.prototype.showEditor = function() { if (this._view.isOffscreen) { FIRSTCLASS.ui.Dom.reparentNode(this._view.editEl, this._domElement); this._view.isOffscreen = false; } }; FIRSTCLASS.apps.Wiki.editor.prototype.onCancel = function() { this._wiki.hideEditor(); if (this._wiki._currentRow) { this._wiki.openPage(this._wiki._currentRow); } }; FIRSTCLASS.apps.Wiki.editor.prototype.onSave = function() { this._saveState = "done"; // if (this._wiki._currentRow && !this._isACreate) { // this._wiki.openPage(this._wiki._currentRow); // } else { // var that = this; // var cb = { // completed: function() { // if (that._wiki._savePageName !== null) { // that._wiki._masterDataSource.fetchNewRows(this); // } // } // }; if (this._wiki._config.logTime) { this._wiki._config.logTime("Wiki calling fetchNewRows from editor.onSave"); } this._wiki._masterDataSource.activate(); this._wiki._masterDataSource.fetchNewRows(); // this._wiki._masterDataSource.fetchNewRows(cb); // } }; FIRSTCLASS.apps.Wiki.editor.prototype.onSubmit = function() { }; FIRSTCLASS.apps.Wiki.editor.prototype.onCommand = function() { this._contentChange = true; }; FIRSTCLASS.apps.Wiki.editor.prototype.onTyping = function() { this._contentChange = true; }; FIRSTCLASS.apps.Wiki.editor.prototype.hideEditor = function() { if (!this._view.isOffscreen) { FIRSTCLASS.ui.Dom.reparentNode(this._view.editEl,this._view.socketEl); this._view.isOffscreen = true; } }; FIRSTCLASS.apps.Wiki.editor.prototype.checkTOCUpdate = function() { if (this._contentChange) { this._wiki.updateContents(); this._contentChange = false; var that = this; if (this._editor && this._editor._editor) { this._editor._editor.on('afterExecCommand', function() { that.onCommand(); }, this, true); } } };