/**
* Class Description
* @namespace FIRSTCLASS.apps
* @module Community
* @requires
* @optional
* @title Community base Application
*/
/**
* Constructor definition
* @class Community
* @constructor
* @param {Object} config (required) the configuration object
* @param {string|HTMLElement} config.div (required) the div to load into
* @param {string} config.baseUrl (required) the container base url
*/
FIRSTCLASS.apps.Pulse = function(config) {
/**
* Private member variables
*
* Private variables are identified by the convention of naming them with a leading underscore.
* i.e. this._privateVariable
*/
if (config.logTime) {
config.logTime("Pulse App Init");
}
var that = this;
this._domElement = document.createElement("div");
this._config = config;
if (!config.baseUrl) {
config.baseUrl = this.uri;
}
var dsconfig = {
containerBaseUrl: config.baseUrl,
autoLoad: false,
watchForNew: true,
messagebodies: false,
nosymbiomainfetch: true,
sortFirstFetch: false,
serversort: "&Table=-3_9",
fetchThreads: true,
initialRequestGranularity: 5,
requestGranularity: 10,
pollInterval: 1000,
objtypefilter: FIRSTCLASS.objTypes.message
};
if (this._config.logTime) {
dsconfig.logTime = this._config.logTime;
}
this._dataSource = new FIRSTCLASS.util.DataSource(dsconfig);
/*this.app = this;*/
/* set up the listview */
this._containerDomElement = document.createElement("div");
this._lvDomElement = document.createElement("div");
this._newMessageInlineElement = document.createElement("div");
this._setupInstantSend(this._newMessageInlineElement);
this._containerDomElement.appendChild(this._newMessageInlineElement);
this._containerDomElement.appendChild(this._lvDomElement);
//YAHOO.util.Dom.addClass(this._lvDomElement, "fcAppScrollingContent");
//YAHOO.util.Dom.addClass(this._lvDomElement, "fcMailbox");
this._contentPane = FIRSTCLASS.ui.widgets.buildContentBox(this._containerDomElement, 'fcWhiteContentBox');
this._domElement.appendChild(this._contentPane);
var lvConfig = {
domElement: this._lvDomElement,
dataSource: this._dataSource,
fillOnScroll:true,
threading: {
format: "bythread",
sortfunc: this._rowSort,
threadsortfunc: this._threadSort,
originRowIsHeader: true,
collapseRead: true,
displayThreadContributors: true
},
listenForNavKeys: false,
selectionFollowsScroll: true,
padHeight: true,
padText: FIRSTCLASS.locale.community.loading,
drawOffScreen: false,
rowFilter: this.rowFilter,
scrollContainer: document.body.parentNode,
feedConfig: {
inlineReplyFormID: 21008,
replyMode: "All"
}
};
this._listView = new FIRSTCLASS.layout.ListView(lvConfig);
this._listView.updatePadText({top:"All|My People|Me|Filter", align:"right"})
this._dataSource.addRowListener(this);
this._dataSource.addDataListener(this._dataListener);
FIRSTCLASS.session.addHistoryEntry(this);
this.setupDiscover();
this.activate();
};
FIRSTCLASS.apps.Pulse.prototype.setupDiscover = function() {
var discoverdsconfig = {
containerBaseUrl: FIRSTCLASS.whatshot({returnurl: true, what:"Both"}),
autoLoad: false,
watchForNew: false,
messagebodies: false,
nosymbiomainfetch: true,
useobjid: true,
requestGranularity: 50,
serversort: ""
};
this._discoverDataSource = new FIRSTCLASS.util.DataSource(discoverdsconfig);
this._communitylist = document.createElement("div");
var communitylistcfg = {
domElement: this._communitylist,
dataSource: this._discoverDataSource,
threading: {
format: FIRSTCLASS.layout.ThreadHandler.types.NONE
},
compareRows:function(row1,row2) {
},
rowFilter: function(row) {
if (row.col8092 && (row.col8092 != 0 && row.col8092 != 3)) {
return false;
}
if (row.typedef.objtype == FIRSTCLASS.objTypes.conference) {
return true;
}
// fix this to check the dir rooted field for type
switch (row.icon.id) {
case 11138:
return false;
default:
return row.status.view == 1;
}
},
keepRowsSorted: false,
rowHandler: FIRSTCLASS.apps.Search.handlers.communities
};
this._communitylistlv = new FIRSTCLASS.layout.ListView(communitylistcfg);
this._peoplelist = document.createElement("div");
var communitylistcfg = {
domElement: this._peoplelist,
dataSource: this._discoverDataSource,
threading: {
format: FIRSTCLASS.layout.ThreadHandler.types.NONE
},
compareRows:function(row1,row2) {
},
rowFilter: function(row) {
if (row.col8108 && (row.col8108 == 1 || row.col8108 == 5)) {
return true;
}
return false;
if (row.col8092 && row.col8092 != 0) {
return false;
}
switch (row.icon.id) {
case 11138:
return row.status.view == 1;
default:
return false;
}
},
keepRowsSorted: false,
rowHandler: FIRSTCLASS.apps.Search.handlers.people
};
this._peoplelistlv = new FIRSTCLASS.layout.ListView(communitylistcfg);
};
FIRSTCLASS.apps.Pulse.prototype._dataListener = {
onHeaderData: function(data, contents) {
switch (data) {
case "stats":
var str = contents.lConfSubscribers
+ " " + FIRSTCLASS.locale.community.summ.subscribers + ", "
+ contents.lConfPosts
+ " " + FIRSTCLASS.locale.community.summ.posts + ", "
+ contents.lConfHits
+ " " + FIRSTCLASS.locale.community.summ.views;
FIRSTCLASS.ui.navBar.setBottomText(str);
break;
default:
return;
}
},
filter: function(dataname) {
switch (dataname) {
case "stats":
return true;
default:
return false;
}
}
}
/** HISTORY MANAGEMENT VARIABLES **/
FIRSTCLASS.apps.Pulse.prototype.uri = FIRSTCLASS.session.baseURL + "The+Pulse";
FIRSTCLASS.apps.Pulse.prototype.cacheable = true;
/** HISTORY MANAGEMENT VARIABLES END **/
FIRSTCLASS.apps.Pulse.prototype._setupInstantSend = function(element) {
var html = ["
"];
element.innerHTML = html.join("");
YAHOO.util.Dom.addClass(element, 'fcInstantSendContainer');
};
FIRSTCLASS.apps.Pulse.prototype._updateInstantSendAutoComplete = function(hashtag, endindex) {
$('instantSendACHidden').value = hashtag;
if (this._autoComplete) {
this._autoComplete.sendQuery(hashtag);
}
this._autoCompleteConfig.endindex = endindex;
};
FIRSTCLASS.apps.Pulse.prototype._hideInstantSendAutoComplete = function() {
this._trackingHashTag = false;
if (this._autoComplete) {
this._autoComplete.collapseContainer();
}
};
FIRSTCLASS.apps.Pulse._autoCompleteSelectHandler = function(oself, oitem, odata) {
var tag = oitem[2][1].tag;
var input = $('instantsend');
var fakeevt = {target:input, keyCode:32, type:'keyup', hashtag: tag};
FIRSTCLASS.events.handler(fakeevt)
this._autoCompleteConfig = false;
};
FIRSTCLASS.apps.Pulse.prototype._showInstantSendAutoComplete = function(type, atindex) {
//var tags = item: FIRSTCLASS.ui.parseServerTags(row.tags),
this._autoCompleteConfig = {
atindex: atindex,
endindex: atindex
};
var input = $('instantsend');
var textToIndex = input.value.substr(0, atindex);
var tmp = $('instantsendwidthcalc');
tmp.innerHTML = textToIndex;
YAHOO.util.Dom.setStyle($('instantSendACHidden'), 'left', "" + (tmp.offsetWidth-15) + "px");
if (type == "hashtag") {
if (!this._autoComplete) {
$('instantSendACHidden').value = "";
var that = this;
var personaltags = FIRSTCLASS.session.desktop.personaltags;
var containertags = FIRSTCLASS.ui.parseServerTags(this._dataSource.getTags());
var tags = FIRSTCLASS.ui.mergeTagClouds(personaltags, containertags);
//var tags = personaltags;
var func = function(string) {
var tag;
var lstring = string.toLowerCase();
var rows = [];
for (var j in tags) {
var tag = tags[j];
var ltag = tag.tag.toLowerCase();
if (ltag.indexOf(lstring) == 0 || lstring == "") {
rows.push(tag);
}
}
return rows;
};
var datasource = new YAHOO.widget.DS_JSFunction(func);
var ac = $('instantSendAutoComplete');//FIRSTCLASS.ui.Dom.getChildByClassName("fcNameValAutoComplete", that._editForm);
this._autoComplete = new YAHOO.widget.AutoComplete($('instantSendACHidden'),ac,datasource);
this._autoComplete.maxResultsDisplayed = 100;
this._autoComplete.minQueryLength = 0;
//this._autoComplete.alwaysShowContainer = true;
//that._autoComplete.typeAhead = true;
//that._autoComplete.useShadow = true;
this._autoComplete.formatResult = function(result, query) {
return result[1].tag;
};
this._autoComplete.itemSelectEvent.subscribe(FIRSTCLASS.apps.Pulse._autoCompleteSelectHandler);
}
}
if (this._autoComplete) {
this._autoComplete.sendQuery("");
}
}
FIRSTCLASS.apps.Pulse.prototype.onRow = function(row, dataSource, atEnd, hasMore, isNewDelivery) {
if (isNewDelivery) {
this._listView.selectRow(row);
}
};
FIRSTCLASS.apps.Pulse.prototype.rowFilter = function(row) {
return true;
};
FIRSTCLASS.apps.Pulse.prototype.activate = function () {
this.activateSideBars();
FIRSTCLASS.util.revealContents();
FIRSTCLASS.ui.Dom.replaceContentsWithElement(this._config.parentDiv, this._domElement);
this.resizeEvent();
FIRSTCLASS.session.setActiveApplication(this, "pulse");
FIRSTCLASS.ui.setDocumentTitle("The Pulse");
FIRSTCLASS.ui.navBar.setTitle("The Pulse");
FIRSTCLASS.ui.navBar.setProfileStatus(false);
YAHOO.util.Dom.setStyle(document.body, "height", "100%");
YAHOO.util.Dom.setStyle(document.body, "overflow-x", "hidden");
YAHOO.util.Dom.setStyle(document.body, "overflow-y", "auto");
document.body.scrollTop = 0;
};
FIRSTCLASS.apps.Pulse.prototype.__fcAppName = "FIRSTCLASS.apps.Pulse";
FIRSTCLASS.apps.Pulse.prototype._clearFilter = function() {
this._filterType = false;
this._dataSource.reset();
this._listView.reLoadFromDataSource();
};
FIRSTCLASS.apps.Pulse.prototype._doFilter = function(cfg) {
if (this._filterType != cfg.type) {
var handled = false;
var ft = false;
switch(cfg.type) {
case "mypeople":
this._dataSource.reconfigure({tackon:"&AuthorGFilter=MyPeople;Me", containerBaseUrl: this._config.baseUrl});
handled = true;
break;
case "me":
this._dataSource.reconfigure({tackon:"&AuthorGFilter=Me", containerBaseUrl: this._config.baseUrl});
handled = true;
break;
case "quickfilter":
//var uri = FIRSTCLASS.search({key:cfg.pattern, scope: this._config.baseUrl, doquickfilter:true, justreturnsearchurl: true});
//this._dataSource.reconfigure({tackon:"", containerBaseUrl: uri, useobjid: true});
var fields = [
"8063",
"8",
"7"
];
var tackon = "&ColGFilter=";
for (var i in fields) {
if (i != 0) {
tackon += "|";
}
tackon += fields[i] + "$_[.*" + cfg.pattern + ".*]";
}
this._dataSource.reconfigure({tackon:tackon, containerBaseUrl: this._config.baseUrl});
handled = true;
ft = cfg.type + cfg.pattern;
break;
default:
}
if (!ft) {
ft = cfg.type;
}
if (handled) {
this._filterType = ft;
this._listView.reLoadFromDataSource();
}
}
};
FIRSTCLASS.apps.Pulse.prototype.deactivate = function() {
FIRSTCLASS.ui.MiniProfile.hideBoxNow();
YAHOO.util.Dom.setStyle(document.body, "height", "");
YAHOO.util.Dom.setStyle(document.body, "overflow", "");
this._dataSource.deactivate();
};
FIRSTCLASS.apps.Pulse.prototype.dispose = function() {
if (this._config.logTime) {
this._config.logTime("Pulse app dispose called");
}
this._dataSource.deactivate();
this._dataSource.dispose();
};
FIRSTCLASS.apps.Pulse.prototype.activateSideBars = function() {
FIRSTCLASS.ui.leftSideBar.hide();
FIRSTCLASS.ui.leftSideBar.resetApplicationBoxContents();
FIRSTCLASS.ui.rightSideBar.show();
FIRSTCLASS.ui.rightSideBar.resetApplicationBoxContents();
FIRSTCLASS.ui.rightSideBar.addApplicationBox(this._peoplelist, "PEOPLE");
FIRSTCLASS.ui.rightSideBar.addApplicationBox(this._communitylist, FIRSTCLASS.locale.desktop.communities);
};
FIRSTCLASS.apps.Pulse.prototype.resizeEvent = function(event) {
var viewport = FIRSTCLASS.ui.Dom.getViewportBounds();
if (!this.sbTop) {
this.sbTop = YAHOO.util.Dom.getY($("fcRightSideBar"));
}
/* these are hard coded values, change them if the ui changes */
var ypos2 = 115;
var xpos2 = 20;
var ypos = 114;
var sbTop = this.sbTop;
if (FIRSTCLASS.skin && FIRSTCLASS.skin.community && FIRSTCLASS.skin.community.sidebars && FIRSTCLASS.skin.community.sidebars.right && FIRSTCLASS.skin.community.sidebars.right.bottompad) {
sbTop += FIRSTCLASS.skin.community.sidebars.right.bottompad;
}
FIRSTCLASS.ui.rightSideBar.adjustBoxHeights(viewport.ht-sbTop);
var sbwid = viewport.wd*.02;
if (sbwid < 180) {
sbwid = 180;
}
FIRSTCLASS.session.RuntimeCSS.updateRule('.fcListViewRow .fcBody', "max-width: " + (viewport.wd - sbwid - 300) + "px;overflow-x:auto;");
var newheight = viewport.ht-ypos-1;
/* if (ypos) {
var appContent = FIRSTCLASS.ui.Dom.getChildByClassName("fcAppScrollingContent", this._domElement);
if (appContent) {
newheight = viewport.ht - ypos2 - 1;
if (newheight <= 0) {
return;
}
var newwidth = viewport.wd - xpos2 - 1;
if (YAHOO.env.ua.ie) {
YAHOO.util.Dom.setStyle(appContent, "overflow-y", "scroll");
YAHOO.util.Dom.setStyle(appContent, "overflow-x", "hidden");
} else {
YAHOO.util.Dom.setStyle(appContent, "overflow", "auto");
}
YAHOO.util.Dom.setStyle(appContent, "height", newheight+"px");
}
}*/
var fcMain = $("fcMain");
if (fcMain) {
YAHOO.util.Dom.setStyle(fcMain, "height", viewport.ht+"px");
}
};
FIRSTCLASS.apps.Pulse.eventHandlers = {
focus: {
instantsend: function(that, fcevent) {
if (fcevent.target.value == "What's on your mind?") {
fcevent.target.value = "";
YAHOO.util.Dom.addClass(fcevent.target, 'focussed');
YAHOO.util.Dom.removeClass(fcevent.target.parentNode.nextSibling.nextSibling, 'fcHidden');
YAHOO.util.Dom.removeClass($('instantsendimg'), 'fcHidden');
// YAHOO.util.Dom.removeClass($('instantsendimg').parentNode, 'fcHidden');
YAHOO.util.Dom.setStyle($('instantsendimg').parentNode, 'display', '');
}
}
},
blur: {
instantsend: function(that, fcevent) {
if (fcevent.target.value == "") {
fcevent.target.value = "What's on your mind?";
YAHOO.util.Dom.removeClass(fcevent.target, 'focussed');
YAHOO.util.Dom.addClass(fcevent.target.parentNode.nextSibling.nextSibling, 'fcHidden');
YAHOO.util.Dom.addClass($('instantsendimg'), 'fcHidden');
YAHOO.util.Dom.setStyle($('instantsendimg').parentNode, 'display', 'none');
}
}
},
keyup: {
instantsend: function(that, fcevent, evt) {
YAHOO.log("key");
if (YAHOO.env.ua.ie) {
var range = document.selection.createRange();
var stored_range = range.duplicate();
stored_range.moveToElementText(fcevent.target);
stored_range.setEndPoint('EndToEnd', range);
fcevent.target.selectionStart = stored_range.text.length - range.text.length;
fcevent.target.selectionEnd = fcevent.target.selectionStart + range.text.length;
}
if (evt.keyCode == 27) {
that._hideInstantSendAutoComplete();
fcevent.target.blur();
} else if (evt.keyCode == 13) {
if (that._trackingHashTag) {
var currentSelection = that._autoComplete.getListItemData(that._autoComplete.getListEl().childNodes[0]);
if (currentSelection) {
var input = fcevent.target;
var curvalue = input.value;
var lastindex = fcevent.target.selectionStart-1;
var newvalue = curvalue.substr(0, lastindex);
var tail;
if (YAHOO.env.ua.ie) {
tail = curvalue.substr(fcevent.target.selectionStart+2);
} else {
tail = curvalue.substr(fcevent.target.selectionStart);
}
newvalue += (tail);
input.value = newvalue;
if (!YAHOO.env.ua.ie) {
input.setSelectionRange(lastindex, lastindex);
} else {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', lastindex);
range.moveStart('character', lastindex);
range.select();
}
FIRSTCLASS.apps.Pulse._autoCompleteSelectHandler(false, [false, false, currentSelection], false);
}
} else {
that._hideInstantSendAutoComplete();
FIRSTCLASS.apps.Desktop.instance.saveProfileStatus($('instantsend').value);
$('instantsend').value = "";
$('instantsend').blur();
}
} else if (!that._trackingHashTag && (evt.keyCode == 51)) {
that._trackingHashTag = true;
that._showInstantSendAutoComplete("hashtag", fcevent.target.selectionStart);
} else if (that._trackingHashTag) {
if (evt.keyCode == 32) {
// done, this is a space
if(evt.hashtag) {
var input = fcevent.target;
var curvalue = input.value;
var lastindex = that._autoCompleteConfig.atindex;
var newvalue = curvalue.substr(0, lastindex);
var tail;
if (YAHOO.env.ua.ie) {
tail = curvalue.substr(that._autoCompleteConfig.endindex-1);
} else {
tail = curvalue.substr(that._autoCompleteConfig.endindex);
}
newvalue += (evt.hashtag + tail);
input.value = newvalue;
if (!YAHOO.env.ua.ie) {
input.setSelectionRange(that._autoCompleteConfig.atindex + evt.hashtag.length, that._autoCompleteConfig.atindex + evt.hashtag.length);
} else {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', that._autoCompleteConfig.atindex + evt.hashtag.length);
range.moveStart('character', that._autoCompleteConfig.atindex + evt.hashtag.length);
range.select();
}
input.focus();
}
that._hideInstantSendAutoComplete();
that._trackingHashTag = false;
} else {
var tagstart = that._autoCompleteConfig.atindex;
if (fcevent.target.selectionStart < that._autoCompleteConfig.atindex) {
that._hideInstantSendAutoComplete();
that._trackingHashTag = false;
} else {
that._hashtag = fcevent.target.value.substr(tagstart, fcevent.target.selectionStart - tagstart);
that._updateInstantSendAutoComplete(that._hashtag, fcevent.target.selectionStart);
}
}
}
}
},
click: {
doinstantsend: function(that, fcevent, evt) {
var fakeevt = {keyCode:13};
var fakefcevt = {target: fcevent.target.parentNode.previousSibling.firstChild};
FIRSTCLASS.apps.Pulse.eventHandlers.keyup.instantsend(that, fakefcevt, fakeevt);
},
filter: function(that, fcevent, evt) {
if (fcevent.fcattrs == "all") {
that._clearFilter();
} else if (fcevent.fcattrs == "mypeople") {
that._doFilter({type:'mypeople'});
} else if (fcevent.fcattrs == "me") {
that._doFilter({type:'me'});
} else if (fcevent.fcattrs == "quickfilter") {
var quickfilter = $('quickfilter');
if (quickfilter) {
that._doFilter({type:"quickfilter", pattern: quickfilter.value});
}
}
}
}
};
FIRSTCLASS.apps.Pulse.prototype.handleEvent = function(evt, fcevent) {
var rv = this._listView.handleEvent(evt, fcevent);
if (!rv) {
var handlers = FIRSTCLASS.apps.Pulse.eventHandlers[evt.type];
if (handlers) {
var handler = handlers[fcevent.fcid];
if (handler) {
rv = handler(this, fcevent, evt);
if (typeof rv == "undefined") {
rv = true;
}
}
}
}
return rv;
};
FIRSTCLASS.apps.Pulse.prototype._rowSort = function(row1, row2) {
var result = true;
if (!row1.status.backversion
&& (row1.typedef.objtype == FIRSTCLASS.objTypes.fcfile
|| row1.typedef.objtype == FIRSTCLASS.objTypes.file
|| row1.typedef.objtype == FIRSTCLASS.objTypes.odocument)) {
return -1;
} else if (!row2.status.backversion
&& (row2.typedef.objtype == FIRSTCLASS.objTypes.fcfile
|| row2.typedef.objtype == FIRSTCLASS.objTypes.file
|| row2.typedef.objtype == FIRSTCLASS.objTypes.odocument)) {
return 1;
}
if (row1.col8090 && row2.col8090
&& (row1.typedef.objtype == FIRSTCLASS.objTypes.fcfile
|| row1.typedef.objtype == FIRSTCLASS.objTypes.file
|| row1.typedef.objtype == FIRSTCLASS.objTypes.odocument)
&& (row2.typedef.objtype == FIRSTCLASS.objTypes.fcfile
|| row2.typedef.objtype == FIRSTCLASS.objTypes.file
|| row2.typedef.objtype == FIRSTCLASS.objTypes.odocument)) {
//return row1.col8090 < row2.col8090;
if (row1.col8090 < row2.col8090) {
return -1;
} else if (row1.col8090 == row2.col8090) {
return 0;
} else {
return 1;
}
}
/*if (row1 && row2) {
result = row1.parsedDate >= row2.parsedDate;
}*/
if (row1.parsedDate < row2.parsedDate) {
return -1;
} else if (row1.parsedDate == row2.parsedDate) {
return 0;
} else {
return 1;
}
return result;
};
FIRSTCLASS.apps.Pulse.prototype._threadSort = function(row1, row2) {
/* var result = true;
if (row1 && row2) {
result = row1.parsedDate <= row2.parsedDate;
}*/
if (row1 && row2) {
if (row1.parsedDate < row2.parsedDate) {
return 1;
} else if (row1.parsedDate == row2.parsedDate) {
return 0;
} else {
return -1;
}
}
return 1;
// return result;
};
YAHOO.register("fcPulse", FIRSTCLASS.apps.Pulse, {version: "0.0.1", build: "1"});