// Documents.js - implementation of the Documents sub-application
FIRSTCLASS.apps.Documents = function(config) {
var that = this;
this._enableFill = false;
this._acceptTypes = [];
this._acceptTypes[FIRSTCLASS.objTypes.file] = true;
this._acceptTypes[FIRSTCLASS.objTypes.odocument] = true;
this._acceptTypes[FIRSTCLASS.objTypes.formdoc] = true;
this._acceptTypes[FIRSTCLASS.objTypes.fcfile] = true;
this._domElement = config.domElement;
// create docs data source and deactivate community ds
config.dataSource.deactivate();
this._dataSource = config.dataSource.createClone({ name: "Documents"});
this._communityACL = config.dataSource.getAcl();
this._community = config.community;
this._config = config;
this._commenting = false;
this._tagging = false;
this._postedAComment = false;
this._commEditor = false;
this._selectedComment = false;
// components
this._history = false;
this._preViewer = false;
this._firstPageEl = false;
this._tableView = false;
// header bar
var html = [];
this._headerEl = document.createElement("div");
YAHOO.util.Dom.addClass(this._headerEl, "fcDocsHeader");
this._domElement.appendChild(this._headerEl);
html.push("
");
html.push(" | ");
html.push("");
html.push("");
html.push(" | ");
html.push(" |
| ");
html.push(" | ");
html.push("
");
html.push("");
this._headerEl.innerHTML = html.join("");
this._pluginEl = FIRSTCLASS.ui.Dom.getChildByClassName('fcOfficePlugin', this._headerEl);
if (FIRSTCLASS.ui.webdav.hasOfficePlugin()) {
FIRSTCLASS.ui.webdav.loadOfficePlugin(this._pluginEl);
}
this._filterEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocPick", this._headerEl);
this._filterCell = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocsFilterCell", this._headerEl);
this._countCell = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocsCountCell", this._headerEl);
this._countEl = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocCounter", this._headerEl);
var udiv = document.createElement('div');
html = [];
html.push("" + FIRSTCLASS.locale.community.docs.showlist + "");
udiv.innerHTML = html.join("");
this._listButton = udiv.firstChild;
// application frame
this._appFrame = document.createElement('div');
this._appFrame.setAttribute('width','100%');
YAHOO.util.Dom.addClass(this._appFrame, 'fcDocsAppFrame');
html = [];
html.push(" | ");
html.push("");
html.push("");
html.push("");
html.push(" | |
");
this._appFrame.innerHTML = html.join('');
this._titleBar = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocsTitleBar", this._appFrame);
this._infoBar = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocsInfoBar", this._appFrame);
this._infoBar2 = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocsInfoBar2", this._appFrame);
this._controlBar = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocsControlBar", this._appFrame);
this._body = FIRSTCLASS.ui.Dom.getChildByClassName("fcDocsBody", this._appFrame);
// component elements
this._titleEl = document.createElement('span');
YAHOO.util.Dom.addClass(this._titleEl, 'fcDocSelTitle');
this._sizeEl = document.createElement('span');
YAHOO.util.Dom.addClass(this._sizeEl, 'fcDocSelFilesize');
this._infoEl = document.createElement('div');
YAHOO.util.Dom.addClass(this._infoEl, 'fcDocsInfo');
this._descriptionEl = document.createElement('div');
YAHOO.util.Dom.addClass(this._descriptionEl, 'fcDocsDescription');
this._selTBEl = document.createElement('div');
this._viewerEl = document.createElement('div');
// row maps
this._versions = []; // versions, by thread
this._comments = []; // comments, by thread
this._histEl = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocSelHistory', this._selPanel);
this._listEl = document.createElement("div");
// initialize selection and associated elements
this._selRow = false;
var addUnreadBlobToMenu = function(el, flagState, button) {
var fmt = "$content$";
if (flagState) {
fmt = "$content$";
}
// keep existing HTML along with tooltip
var str = button.label;
var parts = str.split('|');
if (el.innerHTML && el.innerHTML.indexOf('fcWikiUnreadHist') < 0) {
parts[0] = el.innerHTML;
}
str = parts.join('|');
FIRSTCLASS.locale.setElementString(str, el, fmt);
};
var selTBCfg = {
domElement: this._selTBEl,
buttons: [
// { id: "fcDocItemApprove",
// label: "approve",
// fcid: 'docapprove',
// condition: function(row) {
// var show = false;
// if (that._selRow && that._selRow.status.unapproved && FIRSTCLASS.permissions.hasPriv(that._selRow.acl, FIRSTCLASS.permissions.ACL.APPROVE)) {
// show = true;
// }
// return show;
// }
// },
{ id: "fcDocItemView",
label: FIRSTCLASS.locale.toolbars.documents.open,
isLink: true,
fcid: "docopen",
condition: function(row) {
return row && row.status.unapproved === 0;
},
customizer: function(el) {
if (that._selRow) {
var itemUrl = that.createDownloadUrl(that._selRow);
var title;
if ((typeof that._selRow.subject !== 'undefined') && (that._selRow.subject !== "")) {
title = that._selRow.subject;
} else {
title = that._selRow.col8010;
}
var label = this.label;
if (label.indexOf("|") >= 0) {
label = label.split("|")[0];
title += ": " + label;
}
var fmt = "$content$";
FIRSTCLASS.locale.setElementString(this.label, el, fmt);
}
}
},
{ id: "fcDocItemUpdate",
label: FIRSTCLASS.locale.toolbars.documents.update,
condition: function(row) {
return row ? true : false;
},
priv: FIRSTCLASS.permissions.ACL.CREATE,
fcid: "docupdate"
},
{ id: "fcDocItemEdit",
label: FIRSTCLASS.locale.toolbars.documents.edit,
fcid: "docedit",
priv: FIRSTCLASS.permissions.ACL.CREATE,
condition: function(row) {
var enable = false;
if (row) {
if ((FIRSTCLASS.ui.webdav.osPlatform() === "windows") && FIRSTCLASS.util.Display.isEditableOfficeFile(row.name)) {
if (YAHOO.env.ua.ie || YAHOO.env.ua.gecko) {
enable = true;
}
}
if (row.linkinfo) {
enable = false;
}
if (row.status.unapproved) {
enable = false;
}
}
return enable;
}
},
{ id: "fcDocItemHistory",
label: FIRSTCLASS.locale.toolbars.documents.history,
type: "popup",
customizer: function(el) {
if (that._selRow) {
var f = that.getUnreadState(that._selRow, false) ? true : false;
addUnreadBlobToMenu(el, f, this);
}
},
popup: {
width: 400,
height: 200,
callbacks: {
onRender: function(evt, el) {
that.showHistory(el);
},
onClose: function() {
that.hideHistory();
}
}
}
},
{ id: "fcDocItemComment",
label: FIRSTCLASS.locale.toolbars.documents.comment,
type: "popup",
popup: {
width: 350,
height: 300,
callbacks: {
onRender: function(evt, el) {
that.showComments(evt, el);
},
onClose: function() {
that.hideComments();
}
}
},
customizer: function(el) {
if (that._selRow && that._navigator) {
var f = that.getUnreadState(that._selRow, true);
addUnreadBlobToMenu(el, f.comments, this);
}
},
condition: function() {
var show = true;
if (that._selRow && that._selRow.status.backversion) {
show = false;
} else {
var canCreate = FIRSTCLASS.permissions.hasPriv(that._selRow.acl, FIRSTCLASS.permissions.ACL.CREATE);
var comm = that._comments[that._selRow.threadid];
if (!canCreate && !comm) {
show = false;
}
}
return show;
}
},
{ id: "fcDocTag",
label: FIRSTCLASS.locale.toolbars.documents.tag,
type: "popup",
popup: {
width: 400,
height: 200,
callbacks: {
onRender: function(evt, el) {
that.showTags(evt, el);
},
onClose: function() {
that.hideTags();
}
}
},
condition: function(row) {
var show;
if (row) {
show = row.threadid !== "0";
if (show) {
show = row.status.unapproved ? false : true;
}
}
return show;
}
},
{ id: "fcDocItemWatch",
label: FIRSTCLASS.locale.toolbars.documents.watch,
fcid: "docwatch",
condition: function(row) {
return row ? true : false;
},
customizer: function(el) {
var fmt = "$content$";
if (that._selRow && that._selRow.watched) {
fmt = "$content$
";
}
FIRSTCLASS.locale.setElementString(this.label, el, fmt);
}
},
{ id: "fcDocItemDelete",
label: FIRSTCLASS.locale.toolbars.documents.del,
fcid: "docdelete",
condition: function(row) {
if (row) {
if (row.threadid === "0") {
return false;
}
var delown = FIRSTCLASS.permissions.hasPriv(row.acl, FIRSTCLASS.permissions.ACL.DELETEOWN);
var del = FIRSTCLASS.permissions.hasPriv(row.acl, FIRSTCLASS.permissions.ACL.DELETE);
if (del) {
return true;
} else if (delown && FIRSTCLASS.session.user.cid === row.creatorcid) {
return true;
}
}
return false;
}
},
{ id: "fcDocsShare",
label: FIRSTCLASS.locale.toolbars.documents.share,
fcid: 'share',
type: "popup",
popup: {
width: 320,
height: 500,
callbacks: {
onRender: function(evt, el) {
var clickEl = evt.target ? evt.target.parentNode : evt.srcElement.parentNode;
FIRSTCLASS.ui.sharePopup.showShareDialog(clickEl,el,that._selRow,that._dataSource,"document");
},
onClose: function() {
}
}
},
condition: function(row) {
return row.threadid !== "0";
}
},
{ id: "fcDocSendTo" + this.instance,
label: FIRSTCLASS.locale.toolbars.feed.sendto,
fcid: 'docsendto',
condition: function(row) {
if (FIRSTCLASS.apps.Integration && FIRSTCLASS.apps.Integration.getRepositories() && FIRSTCLASS.apps.Integration.getRepositories().length > 0) {
return row.threadid !== "0";
} else {
return false;
}
}
}
]
};
this._selTB = new FIRSTCLASS.ui.toolBar(selTBCfg);
// actions bar
this._actionsEl = document.createElement("div"); // actions
var actionTBCfg = {
domElement: this._actionsEl,
vertical: true,
buttons: [
{ id: "fcDocUpload",
label: FIRSTCLASS.locale.community.docs.actions.upload,
fcid: "docupload",
priv: FIRSTCLASS.permissions.ACL.CREATE
}
]
};
if (FIRSTCLASS.apps.Integration) {
var buildCustomizer = function(repo) {
return function(el) {
el.setAttribute('fcattrs', repo.name);
};
};
var repositories = FIRSTCLASS.apps.Integration.getRepositories();
var button;
var repo,i;
for (i in repositories) {
if (repositories.hasOwnProperty(i) && repositories[i]) {
repo = repositories[i];
if (repo.capabilities.browse && repo.capabilities.download) {
button = {
id: 'fcDocImportFromRepo'+i,
label: FIRSTCLASS.locale.toolbars.importfromrepo.doSub(repo),
fcid: 'docimportfromrepo',
priv: FIRSTCLASS.permissions.ACL.CREATE,
customizer: buildCustomizer(repo)
};
actionTBCfg.buttons.push(button);
}
}
}
}
actionTBCfg.buttons.push({ id: "fcDocClearUnread",
label: FIRSTCLASS.locale.toolbars.readall,
fcid: "cleardocflags"
});
this._actionsTB = new FIRSTCLASS.ui.toolBar(actionTBCfg);
FIRSTCLASS.ui.rightSideBar.updateBoxContents(FIRSTCLASS.locale.community.actions.lbl, this._actionsEl);
FIRSTCLASS.ui.leftSideBar.updateBoxContents(FIRSTCLASS.locale.community.actions.lbl, this._actionsEl);
this._actionsTB.reconfigure(false, this._communityACL);
this.myResizeEvent();
// comments
this._commentFrame = document.createElement("div");
html = [];
html.push("");
html.push("");
html.push("");
this._commentFrame.innerHTML = html.join("");
this._commentEditFrame = FIRSTCLASS.ui.Dom.getChildByIdName('fcWikiNewComment', this._commentFrame);
this._commentListFrame = FIRSTCLASS.ui.Dom.getChildByIdName('fcWikiCommentList', this._commentFrame);
this._commentProto = document.createElement("div");
html = [];
html.push("");
html.push(" |
");
html.push("");
html.push("
");
html.push("
");
html.push("
");
html.push("
");
this._commentProto.innerHTML = html.join("");
YAHOO.util.Dom.addClass(this._commentProto, 'fcCommentBlock');
this._commentProto.setAttribute('fcid','fcpopupcomment');
// filter
var qfCfg = {
domEl: this._filterEl,
callback: {
filter: function(str) { that._tableView.quickFilterRows(str); },
reset: function() { that._tableView.unQuickFilter(); }
}
};
this._quickFilter = new FIRSTCLASS.util.quickFilter(qfCfg);
YAHOO.util.Dom.addClass(this._domElement, 'fcDocsTab');
YAHOO.util.Dom.setStyle(this._listEl, 'background-color', '#FFFFFF');
FIRSTCLASS.session.setActiveApplication(this, "documents");
// set up view map
var viewMap = [
{ element: this._appFrame,
views: {
select: this._domElement
}
},
{ element: this._listEl,
views: {
list: this._domElement
}
},
{ element: this._viewerEl,
views: {
select: this._body
}
},
{ element: this._listButton,
views: {
select: this._countCell
}
},
{ element: this._filterEl,
views: {
list: this._filterCell
}
},
{ element: this._titleEl,
views: {
select: this._titleBar
}
},
{ element: this._sizeEl,
views: {
select: this._titleBar
}
},
{ element: this._infoEl,
views: {
select: this._infoBar
}
},
{ element: this._descriptionEl,
views: {
select: this._infoBar2
}
},
{ element: this._selTBEl,
views: {
select: this._controlBar
}
}
];
this._viewMapper = new FIRSTCLASS.ui.viewMapper(viewMap);
if (this._viewMapper._offlineEl) {
this._offlineEl = this._viewMapper._offlineEl;
}
// open passed-in row if any
if (config.rowToOpen) {
this.setView('select');
// decouple from initial thread
window.setTimeout(function() {
that.showRowInContext(config.rowToOpen);
}, 100);
} else {
this.setView('list');
}
this._enableFill = true;
};
// class methods
FIRSTCLASS.apps.Documents.prototype.__fcAppName = "FIRSTCLASS.apps.Documents";
FIRSTCLASS.apps.Documents.prototype.createTableView = function() {
var that = this;
var height = (this._listEl.offsetHeight - 27);
if (height < 0) {
height = 0;
}
var tvConfig = {
dataSource: this._dataSource,
domEl: this._listEl,
width: this._listEl.offsetWidth,
height: height,
columns: this._config.dataSource.getColumns(),
defaultSort: {
key: "name",
dir: YAHOO.widget.DataTable.CLASS_ASC
},
colDefs: [
{ label: FIRSTCLASS.locale.community.docs.columns.type,
key: "suffix",
pcWidth: 4,
formatter: function(elCell, oRow, oColumn, oData) { that.formatType(elCell, oRow, oColumn, oData); },
className: "fcDocsIcon",
sortable: true
},
{ label: FIRSTCLASS.locale.community.docs.columns.name,
key: "name",
pcWidth: 32,
abbr: "file name",
formatter: function(elCell, oRow, oColumn, oData) { that.formatName(elCell, oRow, oColumn, oData); },
className: "fcDocsTitle",
sortable: true
},
{ label: FIRSTCLASS.locale.community.docs.columns.size + " ",
abbr: "file size",
key: "bytesize",
pcWidth: 6,
formatter: function(elCell, oRow, oColumn, oData) { that.formatSize(elCell, oRow, oColumn, oData); },
className: "fcDocsFilesize",
sortable: true
},
{ label: FIRSTCLASS.locale.community.docs.columns.version,
abbr: "version",
key: "col8090",
pcWidth: 4,
formatter: function(elCell, oRow, oColumn, oData) { that.formatVersion(elCell, oRow, oColumn, oData); },
className: "fcDocsVersion",
sortable: true
},
{ label: FIRSTCLASS.locale.community.docs.columns.author,
key: "col8082",
pcWidth: 15,
formatter: function(elCell, oRow, oColumn, oData) { that.formatAuthor(elCell, oRow, oColumn, oData); },
className: "fcDocsAuthor",
sortable: true
},
{ label: FIRSTCLASS.locale.community.docs.columns.lastmod,
key: "parsedDate",
pcWidth: 14,
formatter: function(elCell, oRow, oColumn, oData) { that.formatDate(elCell, oRow, oColumn, oData); },
className: "fcDocsDate",
sortable: true
},
{ label: FIRSTCLASS.locale.community.docs.columns.comments,
abbr: "comments",
key: "comments",
pcWidth: 10,
formatter: function(elCell, oRow, oColumn, oData) { that.formatComments(elCell, oRow, oColumn, oData); },
sortable: true
},
{ label: FIRSTCLASS.locale.community.docs.columns.tags,
key: "tags",
pcWidth: 15,
formatter: function(elCell, oRow, oColumn, oData) { that.formatTags(elCell, oRow, oColumn, oData); },
className: "fcDocsTags",
sortable: true
}
],
totalPad: 61,
objtypes: [FIRSTCLASS.objTypes.file, FIRSTCLASS.objTypes.odocument, FIRSTCLASS.objTypes.message],
callback: this
};
this._tableView = new FIRSTCLASS.layout.TableView(tvConfig);
this._tableView.activate();
};
FIRSTCLASS.apps.Documents.prototype.isRelatedApp = function(app) {
return this._community.isSubApp(app);
};
FIRSTCLASS.apps.Documents.prototype.setView = function(view) {
this._view = view;
if (this._viewMapper) {
if (view !== 'list' && this._tableView) {
this._tableView.hide();
}
if (view === 'list') {
YAHOO.util.Dom.removeClass(this._filterCell, 'fcDocsFilterFiller');
} else {
YAHOO.util.Dom.addClass(this._filterCell, 'fcDocsFilterFiller');
}
if (view === 'list' && !this._tableView) {
this.createTableView();
}
this._viewMapper.selectView(view);
if (view === 'list' && this._tableView) {
this._tableView.show();
}
this.myResizeEvent();
}
};
// show and hide comments
FIRSTCLASS.apps.Documents.prototype.showComments = function(event, element) {
this._commentListFrame.innerHTML = "";
this._commentEditFrame.innerHTML = "";
YAHOO.util.Dom.setStyle(element, 'background-color', '#FFFFFF');
if (FIRSTCLASS.permissions.hasPriv(this._dataSource.getAcl(), FIRSTCLASS.permissions.ACL.SEND)) {
// show it
element.appendChild(this._commentFrame);
// create the comment editor
var msgCfg = {
callback: {
owner: this,
onDisplay: function () {
var btn = document.getElementById("fcDocFormCancel");
if (btn) {
YAHOO.util.Dom.setStyle(btn,'display','none');
}
btn = document.getElementById("fcDocFormClear");
if (btn) {
YAHOO.util.Dom.setStyle(btn,'display','none');
}
this.owner.clearComment();
if (this.owner._commEditor && this.owner._commEditor._editForm && this.owner._commEditor._editForm.BODY) {
this.owner._commEditor._editForm.BODY.focus();
}
},
onCancel: function () { this.owner.clearComment(); },
onSave: function () {
this.owner.clearComment();
this.owner._postedAComment = true;
this.owner._dataSource.fetchNewRows();
},
validate: function() {
var hasData = false;
if (this.owner._commEditor && this.owner._commEditor._editForm) {
var data = this.owner._commEditor._editForm.BODY.value;
if (data && data.length > 0) {
hasData = true;
}
}
return hasData;
}
},
element: this._commentEditFrame,
op: FIRSTCLASS.opCodes.Reply,
params: "Quote=0",
baseURL: FIRSTCLASS.lang.removeSlashUrl(this._dataSource.getItemUrl(this._selRow)),
objType: FIRSTCLASS.objTypes.message,
formID: 21003,
formElId: "fcDocForm",
bodyType: "plain",
// tbType: "reply",
// maxImage: 720,
initHeight: "80px",
quoteText: false,
sendTo: false,
showAddr: false
};
this._commEditor = new FIRSTCLASS.util.Message(msgCfg);
}
// add the list of comments
if (this._comments) {
var comments = this._comments[this._selRow.threadid];
if (comments) {
var newCommentEl, idx, currVersion = -1, showVersion = false;
for (idx in comments) {
if (comments.hasOwnProperty(idx) && comments[idx].messageid) {
if (!comments[idx].replyToVersion) {
this.setReplyToVersion(comments[idx]);
}
showVersion = false;
if (comments[idx].replyToVersion !== currVersion) {
currVersion = comments[idx].replyToVersion;
showVersion = true;
}
if (!comments[idx].status.deleted) {
newCommentEl = this.renderComment(comments[idx], showVersion);
this._commentListFrame.appendChild(newCommentEl);
}
}
}
}
}
// create comment toolbar
this._commentTBEl = document.createElement('div');
var TBCfg = {
domElement: this._commentTBEl,
buttons: [
{ id: "fcDocCommentDelete",
label: FIRSTCLASS.locale.toolbars.documents.del,
fcid: "doccommentdelete"
}
]
};
this._commentTB = new FIRSTCLASS.ui.toolBar(TBCfg);
this._commenting = true;
};
// set the version number that this comment is in reply to
FIRSTCLASS.apps.Documents.prototype.setReplyToVersion = function(row) {
var versions = false;
var theVersion = 1;
if (row && this._versions) {
versions = this._versions[row.threadid];
}
if (versions) {
var doc = false,
lastDoc = false;
for (doc in versions) {
if (versions.hasOwnProperty(doc) && versions[doc].lastmods) {
if (versions[doc].lastmods < row.lastmods) {
if (!lastDoc || versions[doc].lastmods > versions[lastDoc].lastmods) {
// save newest version prior to the comment
lastDoc = doc;
}
}
}
}
if (lastDoc) {
theVersion = versions[lastDoc].col8090;
}
}
row.replyToVersion = theVersion;
};
FIRSTCLASS.apps.Documents.prototype.renderComment = function(row, showVersion) {
var commentEl = this._commentProto.cloneNode(true);
var html = [];
var el = false;
var nm = false;
// set the row onto the outer element
commentEl.row = row;
// show the version on this comment
if (showVersion) {
el = FIRSTCLASS.ui.Dom.getChildByClassName('fcCommentVersion', commentEl);
if (el) {
el.innerHTML = FIRSTCLASS.locale.comments.version + " " + row.replyToVersion;
}
}
// comment posting details
el = FIRSTCLASS.ui.Dom.getChildByClassName('fcCommentDetails', commentEl);
if (el) {
html = [];
var itemstr = FIRSTCLASS.locale.history.commented;
nm = row.name;
if (row.col8082) {
nm = row.col8082;
}
html.push("");
html.push(nm);
html.push("
");
el.innerHTML = itemstr.replace("$name$",html.join("")).replace("$date$", "" + FIRSTCLASS.util.Date.getFriendlyDateTimeString(row.lastmods) + "
");
}
// show the author's piccie
el = FIRSTCLASS.ui.Dom.getChildByClassName('fcHistProfPic', commentEl);
if (el) {
var picurl = "";
var cid = false;
if (row.itemdata && row.itemdata.from) {
picurl = FIRSTCLASS.util.User.getSmallProfPicUrlByCid(row.itemdata.from[0].cid);
cid = row.itemdata.from[0].cid;
} else if (row.creatorcid) {
picurl = FIRSTCLASS.util.User.getSmallProfPicUrlByCid(row.creatorcid);
cid = row.creatorcid;
} else {
picurl = FIRSTCLASS.util.User.getSmallProfPicUrlByName(nm);
}
picurl += "&WidthAA=20&HeightAA=27";
if (row.status.unread) {
YAHOO.util.Dom.setStyle(el, 'background-image', "url("+picurl+")");
} else {
YAHOO.util.Dom.setStyle(el, 'background-image', "");
var img = document.createElement("img");
img.src = picurl;
img.setAttribute('fcid', 'user');
img.setAttribute('fcattrs', nm);
if (cid) {
img.setAttribute('uid', cid);
}
YAHOO.util.Dom.addClass(img,'fcHistProfPic');
YAHOO.util.Dom.removeClass(img, 'fcHistPicUnread');
el.removeChild(el.lastChild);
el.appendChild(img);
}
}
// text of the comment
el = FIRSTCLASS.ui.Dom.getChildByClassName('fcCommentText', commentEl);
if (el && row.expandedPreview) {
el.innerHTML = row.expandedPreview;
}
return commentEl;
};
FIRSTCLASS.apps.Documents.prototype.showCommentToolbar = function(fcevent) {
var el = fcevent.target;
if (el) {
var row = el.row;
if (row) {
this._selectedComment = el;
var delown = FIRSTCLASS.permissions.hasPriv(row.acl, FIRSTCLASS.permissions.ACL.DELETEOWN);
var del = FIRSTCLASS.permissions.hasPriv(row.acl, FIRSTCLASS.permissions.ACL.DELETE);
if (del || (delown && FIRSTCLASS.session.user.cid === row.creatorcid)) {
var tbCont = FIRSTCLASS.ui.Dom.getChildByClassName('fcCommentToolbar', el);
if (tbCont) {
FIRSTCLASS.ui.Dom.reparentNode(this._commentTBEl, tbCont);
}
}
}
}
};
FIRSTCLASS.apps.Documents.prototype.deleteComment = function(fcevent) {
var el = fcevent.target;
if (el && this._selectedComment) {
this._dataSource.deleteRow(this._selectedComment.row);
FIRSTCLASS.ui.Dom.reparentNode(this._commentTBEl, this._offlineEl);
this._selectedComment.parentNode.removeChild(this._selectedComment);
this._selectedComment = false;
}
};
FIRSTCLASS.apps.Documents.prototype.hideComments = function() {
var wasFlagged = false;
if (this._commEditor) {
this._commEditor.destroy();
this._commEditor = false;
}
FIRSTCLASS.ui.Dom.reparentNode(this._commentFrame, this._offlineEl);
this._commentListFrame.innerHTML = "";
this._commentEditFrame.innerHTML = "";
wasFlagged = this.clearCommentFlags(this._selRow);
if (this._commenting && wasFlagged) {
var that = this;
window.setTimeout(function() { that._selTB.reconfigure(that._selRow, that._dataSource.getAcl()); }, 1000);
}
this._commenting = false;
};
FIRSTCLASS.apps.Documents.prototype.getCommunity = function() {
return this._community;
};
FIRSTCLASS.apps.Documents.prototype.handleEvent = function(evt, fcevent) {
var rc = false;
if (this._community) {
rv = this._config.community.handleEvent(evt, fcevent);
}
if (this._history) {
rc = this._history.handleEvent(evt, fcevent);
}
if (!rc) {
var handlers = this.eventHandlers[evt.type];
if (handlers) {
var handler = handlers[fcevent.fcid];
if (handler) {
rc = handler(this, fcevent, evt);
if (typeof rc === "undefined") {
rc = true;
}
}
}
}
return rc;
};
FIRSTCLASS.apps.Documents.prototype.eventHandlers = {
click: {
// the initial page
docfirstpage: function(that) {
that.uploadDocument(false);
},
// actions bar
docupload: function(that) {
that.uploadDocument(false);
},
cleardocflags: function(that) {
that._dataSource.markAllAsRead(false);
FIRSTCLASS.ui.navBar.setProfileUnread(0);
},
docshowlist: function(that) {
that.clearSelection();
},
// page toolbar
docedit: function(that) {
FIRSTCLASS.ui.webdav.edit(that._pluginEl, that._selRow, that._dataSource);
},
docupdate: function(that) {
that.uploadDocument(true);
},
docwatch: function(that) {
if (that._selRow) {
if (that._selRow.watched) {
FIRSTCLASS.session.desktop.deleteWatch(that._selRow);
that._selRow.watched = false;
} else {
that._dataSource.watchItem(that._selRow);
that._selRow.watched = true;
}
that._selTB.reconfigure(that._selRow, that._dataSource.getAcl());
}
},
docsendto: function(that, fcevent) {
that.sendTo(that._selRow, fcevent);
},
docdelete: function(that) {
that.deleteDocument(that._selRow);
},
docapprove: function(that) {
if (that._selRow && that._selRow.status.unapproved) {
that._dataSource.approveItem(that._selRow);
that._selTB.reconfigure(that._selRow, that._dataSource.getAcl());
that.updateSelectPanel(that._selRow);
}
},
// history toolbar
fcDocHistMakeCurrent: function(that) {
that.revertToVersion();
},
dochistsendto: function(that, fcevent) {
that.sendTo(that._history._selRow, fcevent);
},
dochistdel: function(that) {
that._dataSource.deleteRow(that._history._selRow);
// delete from UI
var deleteNode = document.getElementById('fcListView' + that._history._lv._ListViewID + 'Thread' + that._history._selRow.col8090);
if (deleteNode !== null) {
deleteNode.parentNode.removeChild(deleteNode);
}
},
// tag cloud
search: function(that, fcevent) {
that.filterByTag(fcevent.fcattrs);
},
// comment toolbar
fcpopupcomment: function(that, fcevent) {
that.showCommentToolbar(fcevent);
},
doccommentdelete: function(that, fcevent) {
that.deleteComment(fcevent);
}
},
mouseup: {
dochistview: function(that) {
if (that._history._selRow.status.unread) {
that._dataSource.toggleUnRead(that._history._selRow, false);
}
},
docopen: function(that) {
if (that._selRow.status.unread) {
that._dataSource.toggleUnRead(that._selRow, false);
}
},
// select panel
docselpanel: function(that, fcevent) {
if (that._history) {
that._history.onSelectionChange(that._history._lv._currentSelection, null, null);
that._history._lv.clearSelection();
that._selTB.reconfigure(that._selRow, that._dataSource.getAcl());
}
}
}
};
FIRSTCLASS.apps.Documents.prototype.dispose = function() {
if (this._tableView) {
this._tableView.dispose();
this._tableView = false;
}
if (this._dataSource) {
this._dataSource.dispose();
this._dataSource = false;
}
};
FIRSTCLASS.apps.Documents.prototype.onNewRow = function(row) {
// selection updated
if (this._selRow && this._selRow.threadid === row.threadid) {
this.selectItem(row);
}
};
FIRSTCLASS.apps.Documents.prototype.onRowUpdate = function(oldRow, newRow) {
// selection updated
if (this._selRow && this._selRow.threadid === newRow.threadid && !this._tagging && !this._commenting && !this._history) {
this.selectItem(newRow);
}
};
FIRSTCLASS.apps.Documents.prototype.onRowDelete = function(row) {
};
// upload or update a document
FIRSTCLASS.apps.Documents.prototype.uploadDocument = function(isUpdate) {
if (!this._uploading) {
var that = this;
var uploadConfig = {
ds: this._dataSource,
dsr: isUpdate ? this._selRow : false,
dlgBaseEl: this._domElement,
callbacks: {
onComplete: function() {
that._uploading = false;
that._dataSource.activate();
},
onCancel: function() {
that._uploading = false;
that._dataSource.activate();
}
}
};
if (isUpdate) {
var label = FIRSTCLASS.locale.getStringParts(FIRSTCLASS.locale.toolbars.documents.update);
uploadConfig.labels = {
upload: label.content
};
}
this._uploading = true;
this._dataSource.deactivate();
FIRSTCLASS.apps.Workflows.uploadDocument.reconfigure(uploadConfig);
}
};
FIRSTCLASS.apps.Documents.prototype.resizeEvent = function(event) {
this._community.resizeEvent(event);
};
// instantiate tagger and insert into passed-in element
FIRSTCLASS.apps.Documents.prototype.showTags = function(event, element) {
var row = this._selRow;
this._tagging = true;
var config = {
domElement:element,
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
};
FIRSTCLASS.apps.Workflows.Tags.reconfigure(config);
};
FIRSTCLASS.apps.Documents.prototype.hideTags = function() {
this._tagging = false;
FIRSTCLASS.apps.Workflows.Tags.cleanup();
};
FIRSTCLASS.apps.Documents.prototype.showShare = function(event, element) {
};
FIRSTCLASS.apps.Documents.prototype.hideShare = function(event, element) {
};
FIRSTCLASS.apps.Documents.prototype.myResizeEvent = function(lockScroll) {
// detect first call
if (!this._tableView || !this._tableView._dt) {
var scroller = YAHOO.util.Dom.getElementsByClassName("fcTabContentPane");
if (scroller[0]) {
scroller[0] = scroller[0].parentNode;
if (scroller[0]) {
YAHOO.util.Dom.setStyle(scroller[0], "overflow", "hidden");
YAHOO.util.Dom.setStyle(scroller[0], "height", "auto");
}
}
YAHOO.util.Dom.setStyle(this._domElement, "overflow", "hidden");
YAHOO.util.Dom.setStyle(this._domElement, "height", "auto");
}
// calculate available real estate
var viewport = FIRSTCLASS.ui.Dom.getViewportBounds();
var listY = false, paneY = false;
listY = YAHOO.util.Dom.getY($('fcChatOverlayContainer'));
paneY = viewport.ht;
if (!listY) {
listY = viewport.ht;
}
listY -= YAHOO.util.Dom.getY(this._domElement) + this._headerEl.offsetHeight;
paneY -= YAHOO.util.Dom.getY(this._domElement) + this._headerEl.offsetHeight;
var docsX = false;
var minDocsX = 400;
var sbX = viewport.wd * 0.2;
if (sbX < 180) {
sbX = 180;
}
docsX = viewport.wd - (YAHOO.util.Dom.getX(this._domElement) + sbX);
if (docsX < minDocsX) { docsX = minDocsX; }
if (listY < 0) { listY = 0; }
if (paneY < 0) { paneY = 0; }
// apply
if (!isNaN(listY)) {
YAHOO.util.Dom.setStyle(this._domElement, "width", docsX + "px");
if (this._view === 'list') {
YAHOO.util.Dom.setStyle(this._listEl, "height", paneY + "px");
YAHOO.util.Dom.setStyle(this._listEl, "overflow", "hidden");
if (this._tableView) {
this._tableView.setSize(docsX, listY, paneY, lockScroll);
}
} else {
YAHOO.util.Dom.setStyle(this._appFrame, "height", paneY + "px");
}
}
};
FIRSTCLASS.apps.Documents.prototype.rowFilter = function(row) {
// it's a document
var acceptIt = this._acceptTypes[row.typedef.objtype] ? true : false,
mapIt = acceptIt;
// it's a comment
if (!acceptIt && row.replyobjtype) {
mapIt = this._acceptTypes[row.replyobjtype] ? true : false;
}
// weird transitional cases
if (row.name.indexOf(".tmp") !== -1) {
mapIt = acceptIt = false;
} else if (row.icon.id === 70) {
mapIt = acceptIt = true;
}
// if it's a document, only accept if it has linkinfo or is wrapped
if (row.typedef.objtype === FIRSTCLASS.objTypes.odocument && !row.linkinfo) {
mapIt = acceptIt = false;
}
if (row.lformid === 20503) {
mapIt = acceptIt = true;
}
// blanket disablers
if (row.status.deleted || !this._enableFill) {
mapIt = acceptIt = false;
}
if (mapIt) {
this.mapNewRow(row);
}
if (mapIt && this._commenting && this._postedAComment && row.threadid === this._selRow.threadid && this._commentFrame && this._commentFrame.parentNode) {
this._postedAComment = false;
this.showComments(false, this._commentFrame.parentNode);
}
return acceptIt;
};
FIRSTCLASS.apps.Documents.prototype.mapNewRow = function(row) {
if (row.replyobjtype) { // a comment
this.addToCommentMap(row);
} else { // a version
this.addToVersionMap(row);
}
};
FIRSTCLASS.apps.Documents.prototype.removePlaceholder = function() {
if (this._firstPageEl && this._firstPageEl.parentNode) {
this._firstPageEl.parentNode.removeChild(this._firstPageEl);
this._firstPageEl = false;
}
};
FIRSTCLASS.apps.Documents.prototype.insertPlaceholder = function(domEl) {
if (!this._firstPageEl) {
this._firstPageEl = document.createElement("div");
this._firstPageEl.setAttribute('width','100%');
YAHOO.util.Dom.setStyle(this._firstPageEl,'padding-top','8px');
YAHOO.util.Dom.setStyle(this._firstPageEl,'padding-left','8px');
var TBCfg = { domElement: this._firstPageEl,
buttons: [
{ id: "makefirstdocpage",
label: FIRSTCLASS.locale.community.docs.initial,
fcid: "docfirstpage"
}
]
};
var tb = new FIRSTCLASS.ui.toolBar(TBCfg);
domEl.appendChild(this._firstPageEl);
}
// header update
if (this._countEl) {
this._countEl.innerHTML = "0 " + FIRSTCLASS.locale.community.docs.count;
}
};
FIRSTCLASS.apps.Documents.prototype.fillComplete = function() {
var nItems = 0;
if (this._tableView && this._tableView._nItems > 0) {
nItems = this._tableView._nItems;
this.removePlaceholder();
} else if (FIRSTCLASS.permissions.hasPriv(this._communityACL, FIRSTCLASS.permissions.ACL.CREATE)) {
this.insertPlaceholder(this._listEl);
}
if (this._countEl) {
this._countEl.innerHTML = nItems + " " + FIRSTCLASS.locale.community.docs.count;
}
};
// delete entire thread
FIRSTCLASS.apps.Documents.prototype.deleteDocument = function(row) {
var that = this;
// put up dialog
var delDlg = new YAHOO.widget.SimpleDialog("dlg", {
width: '320px',
fixedcenter: true,
postmethod: 'none',
visible: false,
draggable: false
});
var str = FIRSTCLASS.locale.community.docs.del.header.replace("$name$",row.name);
delDlg.setHeader(str);
str = FIRSTCLASS.locale.community.docs.del.prompt.replace("$name$",row.name);
delDlg.setBody(str);
delDlg.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_WARN);
var doContinue = function() {
that._dataSource.deleteThread(row);
delDlg.destroy();
that.clearSelection();
};
var doCancel = function() {
delDlg.destroy();
};
delDlg.cfg.queueProperty('buttons', [
{ text: FIRSTCLASS.locale.community.docs.del.cancel,
handler: doCancel
},
{ text: FIRSTCLASS.locale.community.docs.del.cont,
handler: doContinue
}
]);
delDlg.render(document.body);
delDlg.show();
};
// show icon based on filename, with flag
FIRSTCLASS.apps.Documents.prototype.formatType = function(elCell, oRow, oColumn, oData) {
var row = oRow._oData;
var fileUrl = this.createDownloadUrl(row);
var icon = this.getIcon(row);
var html = "
";
if (row.status.unread) {
YAHOO.util.Dom.addClass(elCell,'fcDocsUnreadCell');
}
elCell.innerHTML = html;
};
// show name
FIRSTCLASS.apps.Documents.prototype.formatName = function(elCell, oRow, oColumn, oData) {
elCell.innerHTML = "" + oData + "";
var row = oRow._oData;
if (row.col8101) {
elCell.title = row.col8101;
}
};
// logical file size
FIRSTCLASS.apps.Documents.prototype.formatSize = function(elCell, oRow, oColumn, oData) {
elCell.innerHTML = FIRSTCLASS.util.Display.getFileSizeString(oData);
};
FIRSTCLASS.apps.Documents.prototype.formatAuthor = function(elCell, oRow) {
var row = oRow._oData;
var name = row.col8082;
var mds = this._community._memberlistds;
if (mds) {
var author = mds.query("uid", row.creatorcid.toString());
if (author && author.length) {
author = author[0][1];
name = author.name;
}
}
elCell.innerHTML = name;
};
FIRSTCLASS.apps.Documents.prototype.formatDate = function(elCell, oRow, oColumn, oData) {
var row = oRow._oData;
elCell.innerHTML = FIRSTCLASS.util.Date.getFriendlyShortDateString(row.lastmods);
};
FIRSTCLASS.apps.Documents.prototype.formatVersion = function(elCell, oRow, oColumn, oData) {
var vers = 1;
if (typeof oData === "number") {
vers = oData;
}
elCell.innerHTML = vers.toString();
};
FIRSTCLASS.apps.Documents.prototype.formatTags = function(elCell, oRow, oColumn, oData) {
var tags = "";
if (oData) {
tags = oData;
tags = FIRSTCLASS.ui.generateTagDisplayList(FIRSTCLASS.ui.parseServerTags(tags, {clickable:false, weight:1}));
if (tags.length > 45) {
tags = tags.substring(0,45) + "...";
}
}
elCell.innerHTML = "" + tags + "";
};
FIRSTCLASS.apps.Documents.prototype.formatComments = function(elCell, oRow, oColumn, oData) {
var row = oRow._oData,
unread = this.getUnreadState(row, true),
comments = 0;
if (this._comments[row.threadid]) {
comments = this._comments[row.threadid].length + " ";
}
if (unread && unread.comments > 0) {
var str = FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.community.wiki.ncomments, {count: unread.comments});
comments += "";
}
YAHOO.util.Dom.addClass(elCell, 'fcWikiListComments');
elCell.innerHTML = comments.toString();
};
// returns an object of the form { versions, comments } or false if none.
FIRSTCLASS.apps.Documents.prototype.getUnreadState = function(row, includelatest) {
var rc = false,
newVersions = 0,
newComments = 0;
var comments = this._comments[row.threadid],i;
for (i in comments) {
if (comments.hasOwnProperty(i) && comments[i].status.unread) {
newComments++;
}
}
var versions = this._versions[row.threadid],j;
for (j in versions) {
if (versions.hasOwnProperty(j) && versions[j].status.unread && (versions[j].status.backversion || includelatest)) {
newVersions++;
}
}
if (newVersions > 0 || newComments > 0) {
rc = {
versions: newVersions,
comments: newComments
};
}
return rc;
};
// add a new version from the given row; replace if already there
FIRSTCLASS.apps.Documents.prototype.addToVersionMap = function(row) {
var threadVers = this._versions[row.threadid];
if (!threadVers) {
threadVers = [];
this._versions[row.threadid] = threadVers;
}
var found = false,i;
for (i in threadVers) {
if (threadVers.hasOwnProperty(i) && 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.Documents.prototype.addToCommentMap = function(row) {
var threadComm = this._comments[row.threadid];
if (!threadComm) {
threadComm = [];
this._comments[row.threadid] = threadComm;
}
var found = false, i;
for (i in threadComm) {
if (threadComm.hasOwnProperty(i) && threadComm[i].uid === row.uid) {
found = true;
threadComm.splice(i,1,row);
break;
}
}
if (threadComm && !found) {
if (threadComm[0] && threadComm[0].lastmods && row.lastmods && row.lastmods > threadComm[0].lastmods) {
threadComm.splice(0,0,row);
} else {
threadComm.push(row);
}
}
return;
};
// remove passed-in version from map
FIRSTCLASS.apps.Documents.prototype.removeFromVersionMap = function(row) {
var threadVers = this._versions[row.threadid], i;
if (threadVers) {
for (i in threadVers) {
if (threadVers.hasOwnProperty(i) && 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.Documents.prototype.removeFromCommentMap = function(row) {
var threadComm = this._comments[row.threadid], i;
for (i in threadComm) {
if (threadComm.hasOwnProperty(i) && threadComm[i].uid === row.uid) {
threadComm.splice(i,1);
break;
}
}
return;
};
// clear comment red flags for thread of passed-in row
FIRSTCLASS.apps.Documents.prototype.clearCommentFlags = function(row) {
var threadComm = this._comments[row.threadid], i;
for (i in threadComm) {
if (threadComm.hasOwnProperty(i) && threadComm[i].status && threadComm[i].status.unread) {
this._dataSource.toggleUnRead(threadComm[i], 0);
}
}
return;
};
FIRSTCLASS.apps.Documents.prototype.getIcon = function(row) {
var icon = {};
// thumbnail
if (row.col8065) {
icon.url = this._dataSource.getContainerUrl() + row.col8065;
icon.type = "thumbnail";
} else {
var iconID = FIRSTCLASS.util.Display.getIconID(row.name);
icon.url = "/icons/"+iconID;
icon.type = "icon";
}
return icon;
};
FIRSTCLASS.apps.Documents.prototype.updateSelectPanel = function(row) {
var fileUrl = this._dataSource.getItemUrl(row, true, true, true);
var icon = this.getIcon(row);
// doc title
var name = row.name;
/* FIXME: hack for HDSRC RFP Response */
if (row.status.unapproved) {
name += FIRSTCLASS.locale.community.docs.info.needapprove;
}
this._titleEl.innerHTML = name;
// file size
this._sizeEl.innerHTML = " (" + FIRSTCLASS.util.Display.getFileSizeString(row.col6) + ")";
// version info
this.setFileInfo(row, this._infoEl);
// description
var desc = "";
if (row.linkinfo) {
// imported from a repository
desc = FIRSTCLASS.locale.integrations.importedfrom.doSub({name: row.linkinfo.repository});
desc += "
";
}
desc += FIRSTCLASS.locale.community.docs.info.desc;
desc += row.col8101 ? row.col8101 : FIRSTCLASS.locale.community.docs.info.nodesc;
this._descriptionEl.innerHTML = desc;
// slide viewer
var slideCfg = {
domEl: this._viewerEl,
ds: this._dataSource,
dsr: row,
theApp: this
};
this._slideViewer = new FIRSTCLASS.apps.Documents.slideViewer(slideCfg);
};
// set displayable file info from passed-in row
FIRSTCLASS.apps.Documents.prototype.setFileInfo = function(row, el) {
if (el) {
var html = "";
var version = 1;
if (row.col8090) {
version = row.col8090;
}
html = FIRSTCLASS.locale.community.docs.info.version + version;
if (row.status.backversion) {
html += FIRSTCLASS.locale.community.docs.info.old;
YAHOO.util.Dom.addClass(el,'fcWikiOldVersion');
} else {
html += FIRSTCLASS.locale.community.docs.info.latest;
YAHOO.util.Dom.removeClass(el,'fcWikiOldVersion');
}
html += FIRSTCLASS.locale.community.docs.info.moddate;
var dt = new Date();
dt.setTime(row.lastmods*1000);
var date = FIRSTCLASS.util.Date.getFriendlyDateTimeString(dt);
var name = row.col8082;
var mds = this._community._memberlistds;
if (!name && mds && row.creatorcid) {
var author = mds.query("uid",row.creatorcid.toString());
if (author && author.length) {
author = author[0][1];
name = author.name;
}
}
html += date + FIRSTCLASS.locale.community.docs.info.auth + name;
el.innerHTML = html;
}
};
FIRSTCLASS.apps.Documents.prototype.onRowClick = function(row) {
this.selectItem(row);
};
FIRSTCLASS.apps.Documents.prototype.selectItem = function(row, oncomplete) {
if (row.status.unread) {
row.wasUnread = row.status.unread;
this._dataSource.toggleUnRead(row, false);
}
if (row !== this._selRow) {
FIRSTCLASS.session.addHistoryEntry(this._community.generateHistoryEntry('Documents', this, row));
this._selRow = row;
}
this.updateSelectPanel(row);
this._selTB.reconfigure(row, this._dataSource.getAcl());
this.setView('select');
if (oncomplete) {
oncomplete();
}
};
FIRSTCLASS.apps.Documents.prototype.clearSelection = function() {
this._selRow = false;
this.setView('list');
this._slideViewer.dispose();
};
FIRSTCLASS.apps.Documents.prototype.showRowInContext = function(row, oncomplete) {
this.selectItem(row, oncomplete);
};
FIRSTCLASS.apps.Documents.prototype.sendTo = function(row, fcevent) {
var rgn = YAHOO.util.Dom.getRegion(fcevent.target);
var xy = [rgn.left + rgn.width, rgn.top];
var config = {
xy: xy,
row: row,
dataSource: this._dataSource,
community: {
uri: this._config.dataSource.getContainerUrl(),
name: this._config.dataSource._data.name,
cid: this._config.dataSource._data.cid
},
permalink: this._config.dataSource.getPermalink(row)
};
FIRSTCLASS.apps.Workflows.SendTo.draw(config);
};
FIRSTCLASS.apps.Documents.prototype.showHistory = function(el) {
var that = this;
// create the history object if there is none
if (!this._history) {
if (this._selRow) {
var histCfg = {
domElement: el,
dataSource: this._dataSource,
dsRow: this._selRow,
scrolling: true,
owner: this,
toolbar: [
{ id: "fcDocItemView",
label: FIRSTCLASS.locale.toolbars.documents.open,
fcid: "docopen",
condition: function(row) {
return row && row.status.unapproved === 0;
},
customizer: function(el) {
if (that._history && that._history._myFeed && that._history._myFeed._selectedRow) {
var itemUrl = that.createDownloadUrl(that._history._myFeed._selectedRow);
var fmt = "$content$";
FIRSTCLASS.locale.setElementString(this.label, el, fmt);
}
}
},
{ id: "fcDocHistDelete",
label: FIRSTCLASS.locale.toolbars.documents.deletevers,
fcid: 'dochistdel',
priv: FIRSTCLASS.permissions.ACL.DELETE & FIRSTCLASS.permissions.ACL.DELETEOWN,
condition: function(row) {
if (row.threadid === "0") {
return false;
}
var delown = FIRSTCLASS.permissions.hasPriv(row.acl, FIRSTCLASS.permissions.ACL.DELETEOWN);
var del = FIRSTCLASS.permissions.hasPriv(row.acl, FIRSTCLASS.permissions.ACL.DELETE);
if (del) {
return true;
} else if (delown && FIRSTCLASS.session.user.cid === row.creatorcid) {
return true;
}
return false;
}
}
]
};
this._history = new FIRSTCLASS.apps.history(histCfg);
}
}
};
FIRSTCLASS.apps.Documents.prototype.hideHistory = function() {
this._history.dispose();
this._history = false;
};
// create a downloadable file url
FIRSTCLASS.apps.Documents.prototype.createDownloadUrl = function(row) {
var itemUrl = "";
var uriParts = [];
if (this._acceptTypes[row.typedef.objtype]) {
if (row.linkinfo && row.linkinfo.url && row.lsubform !== 1) {
itemUrl = row.linkinfo.url.substr(1);
} else if (row.typedef.objtype === FIRSTCLASS.objTypes.formdoc || row.typedef.objtype === FIRSTCLASS.objTypes.odocument) {
itemUrl = this._dataSource.getItemUrl(row);
if (row.lformid === 20503) {
uriParts = itemUrl.split('?');
itemUrl = FIRSTCLASS.lang.removeSlashUrl(uriParts[0]) + ".0/" + encodeURI(row.name);
}
} else {
uriParts = row.uri.split('?');
var fName = uriParts[0];
if (row.col8090 && (row.status.backversion !== 0)) {
var dotPos = uriParts[0].lastIndexOf(".");
var name = uriParts[0].slice(0,dotPos) + "_v" + row.col8090 + uriParts[0].slice(dotPos);
uriParts[0] = name;
}
itemUrl = FIRSTCLASS.lang.ensureSlashUrl(this._dataSource.getContainerUrl());
itemUrl += uriParts[0] + "/" + encodeURI(row.name);
}
}
return itemUrl;
};
FIRSTCLASS.apps.Documents.prototype.hideHistory = function() {
// clear pending comment if any
this.clearComment();
// clean up history objects
if (this._history) {
this._history.dispose();
this._history = false;
}
if (this._histEl) {
this._histEl.innerHTML = "";
}
};
FIRSTCLASS.apps.Documents.prototype.isSafeToNavigate = function() {
if (this._commentEl) {
return false;
}
FIRSTCLASS.ui.ToolbarPopup.closePopup();
return true;
};
FIRSTCLASS.apps.Documents.prototype.clearComment = function() {
if (this._commEditor) {
this._commEditor.clearContent();
}
};
FIRSTCLASS.apps.Documents.prototype.filterByTag = function(tag) {
if (this._quickFilter) {
var lTag = tag.toLowerCase();
if (lTag !== this._filterStr) {
this._quickFilter._inputEl.value = lTag;
this._quickFilter.doFilter(lTag);
} else {
this._quickFilter.doFilter("");
}
}
};
FIRSTCLASS.apps.Documents.prototype.activate = function() {
FIRSTCLASS.session.setActiveApplication(this, "documents");
FIRSTCLASS.ui.rightSideBar.updateBoxContents(FIRSTCLASS.locale.community.actions.lbl, this._actionsEl);
FIRSTCLASS.ui.leftSideBar.updateBoxContents(FIRSTCLASS.locale.community.actions.lbl, this._actionsEl);
if (this._config.dataSource.isActive()) {
this._config.dataSource.deactivate();
}
if (this._tableView) {
if (this._view === "list") {
this._tableView.show();
}
this._tableView.activate();
}
};
FIRSTCLASS.apps.Documents.prototype.deactivate = function(internal) {
if (!internal) {
FIRSTCLASS.ui.skin.clear();
this._community.deactivate(internal);
}
if (this._tableView) {
this._tableView.hide();
this._tableView.deactivate();
}
};
// ---- SlideViewer class implements the slide viewer/picker for the selected document
//
// Configuration is:
// domEl - element to insert the viewer into
// ds - data source
// dsr - ds row for the document object
// theApp - owner app
//
FIRSTCLASS.apps.Documents.slideViewer = function(config) {
this._config = config;
this._currSlideIdx = 1;
this._nSlides = 0;
if (this._config.dsr && this._config.dsr.lnumpages && (this._config.dsr.lnumpages > 0)) {
this._nSlides = this._config.dsr.lnumpages;
}
// build the component frame
var html = [];
// outer table
html.push("");
html.push(FIRSTCLASS.locale.community.docs.slideview.all + " | ");
html.push(" | ");
html.push(" |
| ");
html.push(" | ");
html.push("");
html.push(" | ");
html.push(" | ");
html.push(" | ");
html.push(" | ");
html.push(" | ");
html.push(" |
");
this._config.domEl.innerHTML = html.join("");
// content boxes
this._slideList = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocSlideList',this._config.domEl);
this._slideSorter = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocSlideScroller',this._config.domEl);
this._discloser = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocsSlideListDiscloser',this._config.domEl);
this._protoContainer = document.createElement('table');
this._previewProto = this._slideSorter.firstChild.firstChild;
FIRSTCLASS.ui.Dom.reparentNode(this._previewProto, this._protoContainer);
this._slideTitle = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocsSlideListTitle',this._config.domEl);
this._previewCell = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocSlidePreviewCell',this._config.domEl);
this._previewContainer = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocSlidePreviewContainer',this._config.domEl);
this._slideIndexInput = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocsIndexChoose',this._config.domEl);
this._slideIndexMax = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocsMaxIndex',this._config.domEl);
this._slideControls = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocsSlideControls',this._config.domEl);
if (this._nSlides > 0) {
this.showSlideList();
} else {
this.hideSlideList();
}
this.showSlide(1);
};
FIRSTCLASS.apps.Documents.slideViewer.prototype.dispose = function() {
YAHOO.util.Event.purgeElement(this._config.domEl, true);
this._config.domEl.innerHTML = "";
};
FIRSTCLASS.apps.Documents.slideViewer.prototype.eventHandlers = {
click: {
docsshowslidelist: function(that, fcevent) {
that.showSlideList();
},
docshideslidelist: function(that, fcevent) {
that.hideSlideList();
},
docsnextslide: function(that, fcevent) {
that.showSlide(that._currSlideIdx + 1);
},
docsprevslide: function(that, fcevent) {
that.showSlide(that._currSlideIdx - 1);
},
docsfirstslide: function(that, fcevent) {
that.showSlide(1);
},
docslastslide: function(that, fcevent) {
that.showSlide(that._nSlides);
},
docsstartshow: function(that, fcevent) {
},
docsendshow: function(that, fcevent) {
}
},
change: {
docschooseslide: function(that, fcevent) {
var newIdx = fcevent.target.value;
that.showSlide(newIdx);
}
}
};
FIRSTCLASS.apps.Documents.slideViewer.prototype.trimImageContainer = function() {
var width;
var img = this._previewCell.firstChild;
if (img && img.tagName && img.tagName === 'IMG') {
width = img.offsetWidth;
if (width > 0) {
if (width > 640) { width = 640; }
YAHOO.util.Dom.setStyle(img, 'max-width', width + 'px');
YAHOO.util.Dom.setStyle(img, 'width', width + 'px');
YAHOO.util.Dom.setStyle(this._previewContainer, 'width', width + 'px');
}
YAHOO.util.Event.removeListener(img, 'load');
}
};
FIRSTCLASS.apps.Documents.slideViewer.prototype.showSlideList = function() {
this.buildSlideList();
YAHOO.util.Dom.removeClass(this._slideSorter, 'fcHidden');
YAHOO.util.Dom.removeClass(this._slideTitle, 'fcHidden');
this._discloser.setAttribute('title', FIRSTCLASS.locale.community.docs.slideview.hide);
YAHOO.util.Dom.addClass(this._discloser, 'fcDocsCloseSlideList');
YAHOO.util.Dom.removeClass(this._discloser, 'fcDocsOpenSlideList');
this._slideList.setAttribute('width','200px');
this._discloser.setAttribute('fcid','docshideslidelist');
};
FIRSTCLASS.apps.Documents.slideViewer.prototype.hideSlideList = function() {
this._discloser.setAttribute('title', FIRSTCLASS.locale.community.docs.slideview.show);
YAHOO.util.Dom.addClass(this._slideSorter, 'fcHidden');
YAHOO.util.Dom.addClass(this._slideTitle, 'fcHidden');
this.clearSlideList();
YAHOO.util.Dom.removeClass(this._discloser, 'fcDocsCloseSlideList');
YAHOO.util.Dom.addClass(this._discloser, 'fcDocsOpenSlideList');
this._slideList.setAttribute('width','15px');
this._discloser.setAttribute('fcid','docsshowslidelist');
};
FIRSTCLASS.apps.Documents.slideViewer.prototype.clearSlideList = function() {
var tbody = this._slideSorter.firstChild;
while (tbody.childNodes.length > 0) {
tbody.removeChild(tbody.firstChild);
}
};
FIRSTCLASS.apps.Documents.slideViewer.prototype.buildSlideList = function() {
var tile = false,
el = false, index;
this.clearSlideList();
for (index = 1; index < this._nSlides; index++) {
tile = this._previewProto.cloneNode(true);
el = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocsSlideListTile', tile);
el.href = this.getSlideUrl(index);
el = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocsSlideListNumber', tile);
el.innerHTML = index.toString();
this._slideSorter.firstChild.appendChild(tile);
}
};
FIRSTCLASS.apps.Documents.slideViewer.prototype.handleEvent = function(evt, fcevent) {
var rc = false;
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;
};
// calculate the url for the 1-based logical indexed preview
FIRSTCLASS.apps.Documents.slideViewer.prototype.getSlideUrl = function(index) {
var attachIdx = index + 1,
url = false;
if (index >= 2 && index <=(this._nSlides + 2)) {
// get item url
url = this._config._ds.getItemUrl(this._config.dsr);
// replace parameter list with index
url = url.slice(0,url.indexOf('?'));
url += "." + (index+2);
}
return url;
};
// display the selected slide (index is logical)
FIRSTCLASS.apps.Documents.slideViewer.prototype.showSlide = function(index) {
var icon = this._config.theApp.getIcon(this._config.dsr);
if (this._nSlides > 0 || icon.type === 'thumbnail' || FIRSTCLASS.util.Display.isImageFile(this._config.dsr.name)) { // some kind of image
var url = false;
if (this._nSlides > 0) {
url = this.getSlideUrl(index); // preview
YAHOO.util.Dom.removeClass(this._slideControls, 'fcHidden');
} else {
url = this._config.theApp.createDownloadUrl(this._config.dsr); // the file itself
YAHOO.util.Dom.addClass(this._slideControls, 'fcHidden');
YAHOO.util.Dom.addClass(this._slideList, 'fcHidden');
}
this._previewCell.innerHTML = "
";
YAHOO.util.Event.addListener(this._previewCell.firstChild, 'load', function() {
var that = this;
window.setTimeout(function() {
that.trimImageContainer.call(that);
}, 100);
}, this, true);
this._previewCell.firstChild.setAttribute('src',url);
} else { // we got nothin'
var imghtml = "
";
this._previewCell.innerHTML = imghtml + "" + FIRSTCLASS.locale.community.docs.nopre + "
";
YAHOO.util.Dom.setStyle(this._previewContainer, 'text-align', 'center');
YAHOO.util.Dom.setStyle(this._previewContainer, 'width', '480px');
YAHOO.util.Dom.setStyle(this._previewContainer, 'height', '320px');
YAHOO.util.Dom.addClass(this._slideList, 'fcHidden');
YAHOO.util.Dom.addClass(this._slideControls, 'fcHidden');
}
this._slideIndexInput.value = this._currSlideIdx;
this._slideIndexMax.innerHTML = FIRSTCLASS.locale.community.docs.slideview.total.replace('$count$', (this._nSlides > 0 ? this._nSlides : 1));
};
// resize the preview if the available area is too small (maybe not)
FIRSTCLASS.apps.Documents.slideViewer.prototype.myResizeEvent = function() {
};
YAHOO.register("fcDocuments", FIRSTCLASS.apps.Documents, {version: "0.0.1", build: "1"});