// Blog.js - implementation of the blogging sub-application FIRSTCLASS.apps.Blog = function(config) { this._domElement = config.domElement; this._dataSource = config.dataSource; this._theProfile = config.theProfile; this._userCID = config.userCID; this._instance = FIRSTCLASS.apps.Blog._nInstances++; this._editor = null; this._unreadItem = []; var that = this; if (!FIRSTCLASS.apps.Blog.prototype._rowSubElement) { FIRSTCLASS.apps.Blog.prototype._rowSubElement = document.createElement("div"); FIRSTCLASS.apps.Blog.prototype._rowSubElement.setAttribute('fcid','feedrow'); FIRSTCLASS.apps.Blog.prototype._rowSubElement.setAttribute('fcevents','click'); FIRSTCLASS.apps.Blog.prototype._rowSubElement.innerHTML = "
"; } this._currentEditElem = null; this._blogEntryElem = document.createElement("div"); YAHOO.util.Dom.addClass(this._blogEntryElem, 'fcEditorContainer'); this._domElement.appendChild(this._blogEntryElem); this._lvDomElement = document.createElement("div"); this._domElement.appendChild(this._lvDomElement); YAHOO.util.Dom.addClass(this._lvDomElement, "fcDiscloseBodies"); var lvConfig = { rowHandler: this, domElement: this._lvDomElement, dataSource: this._dataSource, fillOnScroll: true, selectionFollowsScroll: true, padHeight: true, threading: { format: "bythread", originRowIsHeader: true, originRowIsSort: true, hideThreadBody: false, handleClicks: false, collapseRead: true, displayThreadContributors: true, blogThreading: true, sortfunc: function(row1, row2) { if (row1.typedef.objtype == FIRSTCLASS.objTypes.odocument && row2.typedef.objtype != FIRSTCLASS.objTypes.odocument) { return -1; } if (row2.typedef.objtype == FIRSTCLASS.objTypes.odocument && row1.typedef.objtype != FIRSTCLASS.objTypes.odocument) { return 1; } if (row1.parsedDate > row2.parsedDate) { return 1; } else if (row1.parsedDate == row2.parsedDate) { return 0; } else { return -1; } //return row1.parsedDate > row2.parsedDate; }, threadsortfunc: function(row1, row2) { if (row1.parsedDate < row2.parsedDate) { return 1; } else if (row1.parsedDate == row2.parsedDate) { return 0; } else { return -1; } //return row1.parsedDate < row2.parsedDate; } }, listenForNavKeys: true, rowFilter: this.rowFilter }; var blogBtn = document.getElementById('fcProfileNewBlogBtn'); if (blogBtn !== null) { YAHOO.util.Event.addListener(blogBtn, 'click', function(evt) { YAHOO.util.Event.stopPropagation(evt); if (FIRSTCLASS.session.canNavigateAway() && that._myFeed) { that._myFeed.clearEmailMsg(); that._myFeed.clearBlogEdit(); that.newPage(); } }); } this._listView = new FIRSTCLASS.layout.ListView(lvConfig); this._listView.scrollDetector = function () { that.scrollDetector(); }; this._myFeed = new FIRSTCLASS.layout.BlogFeed( {listView:this._listView, dataSource:config.dataSource, theBlog: this}); if (config.singleThreadView) { this._listView.updatePadText("

" + FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.blog.viewsingleblog,{fcid:"",fcidend:""}) + "

",true); } else { this._listView.updatePadText(FIRSTCLASS.locale.community.nomore); } }; // class variables FIRSTCLASS.apps.Blog._nInstances = 0; FIRSTCLASS.apps.Blog.prototype._dataSource = null; FIRSTCLASS.apps.Blog.prototype._domElement = null; FIRSTCLASS.apps.Blog.prototype._listView = null; FIRSTCLASS.apps.Blog.prototype._myFeed = null; FIRSTCLASS.apps.Blog.prototype._rowSubElement = null; FIRSTCLASS.apps.Blog.prototype._editor = null; // class methods FIRSTCLASS.apps.Blog.prototype._resizeBlog = function () { var ypos = 30; var newheight = YAHOO.util.Dom.getViewportHeight()-ypos-1; if (newheight > 0) { this._listView.updatePadHeight(newheight); } }; FIRSTCLASS.apps.Blog.prototype.handleEvent = function(evt, fcevent) { return this._myFeed.handleEvent(evt, fcevent); }; FIRSTCLASS.apps.Blog.prototype.scrollDetector = function () { if (this._dataSource.hasMoreRows() && !this._dataSource.isLoading() && this._dataSource.isActive() && (this._dataSource._config.fetchThreadID===false)) { this._dataSource.fetchRows(); } for (var unreadCircle in this._unreadItem) { if ((this._unreadItem[unreadCircle] !== null) && (this._unreadItem[unreadCircle].offsetTop > 0) && (this._unreadItem[unreadCircle].offsetHeight > 0)) { if (this._unreadItem[unreadCircle].offsetTop + this._unreadItem[unreadCircle].offsetHeight < window.scrollY + 150) { var theRow = this._listView.findRowElementFromElement(this._unreadItem[unreadCircle]); if (theRow !== null) { if (theRow.row.typedef.objtype != FIRSTCLASS.objTypes.odocument) { this._myFeed.reduceNumComments(theRow.row.threadid); } this._dataSource.toggleUnRead(theRow.row, 0); this._unreadItem[unreadCircle] = null; } } } } }; FIRSTCLASS.apps.Blog.prototype.emptyBlogCheck = function (myProfile,singleThread) { var blogContent = document.getElementById('fcProfileBlogContent'); if (blogContent) { var hasItems = false; for (var a in this._listView._rowmap) { hasItems = true; break; } if (!hasItems) { if (myProfile) { YAHOO.util.Dom.setStyle(document.getElementById('fcProfileCreateFirstBlog'),'display','inline'); } else { FIRSTCLASS.ui.Dom.setInnerHTML(blogContent,"
" + FIRSTCLASS.locale.blog.noentries + "
"); } } else { this._resizeBlog(); } } }; FIRSTCLASS.apps.Blog.prototype.createRow = function(row) { var that = this; var myRowElement = null; var myRowContents = document.createElement("div"); YAHOO.util.Dom.generateId(myRowContents); var table = this._myFeed.createRow(row); myRowContents.appendChild(table); myRowContents.yId = myRowContents.id; // if (row.status.unread) { YAHOO.util.Dom.addClass(myRowContents, "unread"); } YAHOO.util.Dom.addClass(myRowContents, "fcBlogItem"); if (row.lformid == 21008 || row.icon.id == 9626) { YAHOO.util.Event.addListener(myRowContents, 'click', function(evt) { that._myFeed.onSelectionChange(evt,this); } ); } else if (row.typedef.objtype == FIRSTCLASS.objTypes.confitem) { // YAHOO.util.Dom.setStyle(myRowContents,"padding-left","60px"); YAHOO.util.Dom.setStyle(myRowContents,"padding-top","15px"); YAHOO.util.Dom.setStyle(myRowContents,"padding-left","40px"); YAHOO.util.Event.addListener(myRowContents, 'click', function(evt) { that._myFeed.onSelectionChange(evt,this); } ); } myRowElement = FIRSTCLASS.apps.Blog.prototype._rowSubElement.cloneNode(true); myRowElement.firstChild.id = ((row.typedef.objtype == FIRSTCLASS.objTypes.odocument) ? "blog[" : "comment[") + row.uri + "]"; var child = myRowElement.childNodes[0].childNodes[0].childNodes[0].childNodes[1]; child.appendChild(myRowContents); myRowElement.row = myRowContents.row; myRowElement.table = table; if (row.status.unread) { YAHOO.util.Dom.addClass(myRowElement,"unread"); } else { YAHOO.util.Dom.addClass(myRowElement,"read"); } this.updateRow(row,myRowElement,null); return myRowElement; }; FIRSTCLASS.apps.Blog.prototype.updateRow = function(row, element, oldRow) { if (typeof oldRow == "undefined") oldRow = null; if (this._myFeed) { if (typeof element.table == "undefined") { this._myFeed.updateRow(row,element,oldRow); } else { this._myFeed.updateRow(row,element.table,oldRow); } if (row.status.unread) { var circle; if (row.typedef.objtype == FIRSTCLASS.objTypes.odocument) { circle = FIRSTCLASS.ui.Dom.getChildByClassName("fclvrowpicunreadblog",element); } else { circle = FIRSTCLASS.ui.Dom.getChildByClassName("fclvrowpicunreadblogcomment",element); } this._unreadItem[row.uri] = circle; } } }; FIRSTCLASS.apps.Blog.prototype.generateUniqueId = function(row) { return row.messageid; // + "C"; }; // sort thread items in reverse chrono FIRSTCLASS.apps.Blog.prototype.rowSort = function(row1, row2) { var result = true; if (row1 && row2) { result = row1.parsedDate <= row2.parsedDate; } return result; }; FIRSTCLASS.apps.Blog.prototype.activate = function () { this._listView.activate(); this._dataSource.activate(); }; FIRSTCLASS.apps.Blog.prototype.deactivate = function() { this._listView.deactivate(); this._dataSource.deactivate(); }; FIRSTCLASS.apps.Blog.prototype.rowFilter = function(row) { if (row.status.deleted || ((row.typedef.objtype == FIRSTCLASS.objTypes.formdoc || row.typedef.objtype == FIRSTCLASS.objTypes.odocument) && (row.col8010 == "FCXResume"))) { return false; } return (row.typedef.objtype == FIRSTCLASS.objTypes.odocument) || (row.typedef.objtype == FIRSTCLASS.objTypes.confitem); }; FIRSTCLASS.apps.Blog.prototype.newPage = function() { if (this._editor === null) { var createText = document.getElementById('fcProfileCreateFirstBlog'); YAHOO.util.Dom.setStyle(createText,'display','none'); this._dataSource.deactivate(); var editCfg = { row: null, domElement: this._blogEntryElem, blogEntry: this, currentEdit: null }; this._editor = new FIRSTCLASS.apps.Blog.editor(editCfg); } }; FIRSTCLASS.apps.Blog.prototype.editPage = function(theRow,blogElement,editElement) { if (this._editor === null) { var editCfg = { row: theRow, domElement: editElement, blogEntry: this, currentEdit: blogElement }; this._editor = new FIRSTCLASS.apps.Blog.editor(editCfg); } }; FIRSTCLASS.apps.Blog.editor = function(config) { this._domElement = config.domElement; this._dsRow = config.row || null; this._dataSource = config.blogEntry._dataSource; this._currentEditElem = config.currentEdit; this._itemURL = null; this._theBlog = config.blogEntry; // fire up the editor var msgCfg = { callback: this, element: config.domElement, objType: FIRSTCLASS.objTypes.odocument, body: "HTML", formID: 20500, formElId: "fcDocForm", bodyType: "HTML", quoteText: null, sendTo: null, initHeight: "300px", tbType: "blog", maxImage: 480 }; if (this._dsRow) { // edit an existing one this._itemURL = config.blogEntry._dataSource.getItemUrl(this._dsRow); msgCfg.baseURL = this._itemURL; msgCfg.op = FIRSTCLASS.opCodes.FormEdit; msgCfg.params = "Close=-1"; msgCfg.row = this._dsRow; } else { // create a new one msgCfg.baseURL = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL) + '__Open-Item/SharedDocuments/'; // config.blogEntry._dataSource.getContainerUrl(); msgCfg.op = FIRSTCLASS.opCodes.FormNew; msgCfg.inMemory = false; msgCfg.params = "InitialText="; } this._editor = new FIRSTCLASS.util.Message(msgCfg); }; FIRSTCLASS.apps.Blog.editor.prototype.onDisplay = function() { var docName = document.getElementById('blogSubject'); if (docName) { docName.focus(); docName.select(); } var container = document.getElementById('BODY_container'); if (container !== null) { YAHOO.util.Dom.setStyle(container, 'width', '98%'); } }; FIRSTCLASS.apps.Blog.editor.prototype.onLoaded = function(isEditable) { if (!isEditable) { // got back read only form if (this._editor !== null) { this._editor.destroy(); this._editor = null; } this._theBlog._editor = null; this._currentEditElem.removeChild(this._domElement); this._currentEditElem = null; alert(FIRSTCLASS.locale.blog.notEditable); return; } }; FIRSTCLASS.apps.Blog.editor.prototype.onCancel = function() { var tbcontainer = null; if (this._editor !== null) { this._editor.destroy(); this._editor = null; } this._theBlog._editor = null; if (this._currentEditElem !== null) { var itemURL; var questionMark = this._itemURL.indexOf('?',0); if (questionMark > 0) { itemURL = FIRSTCLASS.lang.ensureSlashUrl(this._itemURL.substr(0,questionMark)); } else { itemURL = FIRSTCLASS.lang.ensureSlashUrl(this._itemURL); } FIRSTCLASS.util.net.asyncRequest('POST',itemURL+"__FormSave?Close=1", null); this._currentEditElem.removeChild(this._domElement); tbcontainer = FIRSTCLASS.ui.Dom.getChildByClassName("fclvrowtoolbar",this._currentEditElem); if (tbcontainer) { YAHOO.util.Dom.removeClass(tbcontainer, "fcHidden"); } this._currentEditElem = null; } else { this._dataSource.activate(); this._domElement.innerHTML = ""; } tbcontainer = FIRSTCLASS.ui.Dom.getChildByClassName("fclvrowtoolbar",this._theBlog._selectedElement); if (tbcontainer) { YAHOO.util.Dom.removeClass(tbcontainer, "fcHidden"); } }; FIRSTCLASS.apps.Blog.editor.prototype.onSave = function() { if (this._editor !== null) { this._editor.destroy(); this._editor = null; } if (this._currentEditElem !== null) { this._currentEditElem.removeChild(this._domElement); YAHOO.util.Dom.setStyle(this._currentEditElem.firstChild,'display',''); this._dataSource.fetchItem(this._dsRow); var tbcontainer = FIRSTCLASS.ui.Dom.getChildByClassName("fclvrowtoolbar",this._currentEditElem); if (tbcontainer) { YAHOO.util.Dom.removeClass(tbcontainer, "fcHidden"); } this._currentEditElem = null; } else { this._dataSource.activate(); this._dataSource.fetchNewRows(); this._domElement.innerHTML = ""; } this._theBlog._editor = null; }; FIRSTCLASS.apps.Blog.editor.prototype.onFail = function(obj) { if (this._editor !== null) { this._editor.destroy(); this._editor = null; } var del = this._domElement; if (this._currentEditElem !== null) { del = this._currentEditElem; this._currentEditElem = null; } del.innerHTML = ""; if (obj && obj.error) { FIRSTCLASS.ui.navBar.updateShoutBox(FIRSTCLASS.locale.errors.getErrorString(obj.error)); } this._theBlog._editor = null; }; YAHOO.register("fcBlog", FIRSTCLASS.apps.Blog, {version: "0.0.1", build: "1"});