FIRSTCLASS.apps.Integration = { _repositories: false, _isInitialized: false, _onInit: [], _baseUrl: FIRSTCLASS.session.baseURL + "BlueField Applications", _templatePart: "?Templates=JS&Close=-1&JSON=2", _commands: { search: 5000, getInfo: 5001, copy: 5002, link: 5003, view: 5004, browse: 5005, save: 5006, archive: 5007, close: 5999 } }; FIRSTCLASS.apps.Integration.init = function() { if (FIRSTCLASS.apps.Integration._isInitialized) { return; } var url = FIRSTCLASS.apps.Integration._baseUrl + FIRSTCLASS.apps.Integration._templatePart + "&Both=1"; //"?Templates=JS&Close=-1"; var callbacks = { success: FIRSTCLASS.apps.Integration._parseInitResponse, failure: FIRSTCLASS.apps.Integration._parseInitResponse }; YAHOO.util.Connect.asyncRequest("GET", url, callbacks); }; FIRSTCLASS.apps.Integration._parseInitResponse = function (response) { var obj = false; if (response.status == 200) { try { obj = FIRSTCLASS.lang.JSON.parse(response.responseText); var repositories = []; for (var i in obj.records) { repositories[i] = { name: obj.records[i].name, uri: obj.records[i].uri, handler: FIRSTCLASS.apps.Integration.ECM }; } FIRSTCLASS.apps.Integration._repositories = repositories; } catch (e) { // an error occurred //debugger; } } FIRSTCLASS.apps.Integration._isInitialized = true; for (var i in FIRSTCLASS.apps.Integration._onInit) { FIRSTCLASS.apps.Integration._onInit[i].func(FIRSTCLASS.apps.Integration._onInit[i].config); } FIRSTCLASS.apps.Integration._onInit = []; }; FIRSTCLASS.apps.Integration.initRepository = function(repositoryname) { var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(repositoryname); if (repository == 0 || repository == -1) { // no such repository return; } else { var baseurl = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.apps.Integration._baseUrl) + repository.uri + FIRSTCLASS.apps.Integration._templatePart; var callbacks = { success: FIRSTCLASS.apps.Integration._parseInitRepositoryResponse, failure: FIRSTCLASS.apps.Integration._parseInitRepositoryResponse }; FIRSTCLASS.apps.Integration._initingRepository = repository; YAHOO.util.Connect.asyncRequest('GET', baseurl, callbacks); } }; FIRSTCLASS.apps.Integration._parseInitRepositoryResponse = function (response) { var obj = false; if (response.status == 200) { try { obj = FIRSTCLASS.lang.JSON.parse(response.responseText); } catch (e) { FIRSTCLASS.apps.Integration._initingRepository.objid = -1; //debugger; return; } FIRSTCLASS.apps.Integration._initingRepository.objid = obj.objid; } else { FIRSTCLASS.apps.Integration._initingRepository.objid = -1; } for (var i in FIRSTCLASS.apps.Integration._onInit) { FIRSTCLASS.apps.Integration._onInit[i].func(FIRSTCLASS.apps.Integration._onInit[i].config); } FIRSTCLASS.apps.Integration._onInit = []; }; FIRSTCLASS.apps.Integration.getRepositories = function() { if (FIRSTCLASS.apps.Integration._isInitialized) { return FIRSTCLASS.apps.Integration._repositories; } else { FIRSTCLASS.apps.Integration.init(); return false; } }; FIRSTCLASS.apps.Integration.getRepositoryByName = function(name) { if (FIRSTCLASS.apps.Integration._isInitialized) { for (var i in FIRSTCLASS.apps.Integration._repositories) { if (FIRSTCLASS.apps.Integration._repositories[i].name == name) { return FIRSTCLASS.apps.Integration._repositories[i]; } } return 0; } else { return -1; } }; FIRSTCLASS.apps.Integration.getRepositoryByObjid = function(objid) { if (FIRSTCLASS.apps.Integration._isInitialized) { for (var i in FIRSTCLASS.apps.Integration._repositories) { if (FIRSTCLASS.apps.Integration._repositories[i].objid == objid) { return FIRSTCLASS.apps.Integration._repositories[i]; } } return 0; } else { return -1; } }; FIRSTCLASS.apps.Integration.ECM = { }; FIRSTCLASS.apps.Integration.ECM.search = function(config) { // config = {key, domElement, repository} this._searchconfig = config var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(config.repository); if (repository == 0) { // no such repository } else if (repository == -1) { // not init'ed, init then run again FIRSTCLASS.apps.Integration._onInit.push({func: FIRSTCLASS.apps.Integration.ECM.search, config:config}); FIRSTCLASS.apps.Integration.init(); } else { // got repository if (repository.objid) { FIRSTCLASS.apps.Integration.ECM._searchStep2(repository.objid); } else { FIRSTCLASS.apps.Integration._onInit.push({func: FIRSTCLASS.apps.Integration.ECM.search, config:config}); FIRSTCLASS.apps.Integration.initRepository(config.repository); } } }; FIRSTCLASS.apps.Integration.ECM._searchStep2 = function(objid) { var that = this; if (objid == -1) { this._searchconfig.domElement.innerHTML = "
"+FIRSTCLASS.locale.integrations.ecm.search.unavailable+"
"; return; } if (!this._searchconfig.repository) { this._searchconfig.repository = FIRSTCLASS.apps.Integration.getRepositories()[0].name; } var form = document.createElement("DIV"); var html = ['
']; form.innerHTML = html.join(""); for (var i in form.firstChild.childNodes) { if (form.firstChild.childNodes[i].name && form.firstChild.childNodes[i].name.indexOf("4000") > 0) { form.firstChild.childNodes[i].value = this._searchconfig.key; } else if (form.firstChild.childNodes[i].name && form.firstChild.childNodes[i].name.indexOf("7000") > 0) { var repositories = FIRSTCLASS.apps.Integration.getRepositories(); for (var j in repositories) { if (repositories[j].name == this._searchconfig.repository) { form.firstChild.childNodes[i].value = j; break; } } } } var callbacks = { success: function(response) { var url = form.firstChild.action; var idx = url.indexOf("/"+FIRSTCLASS.opCodes.FormSave); url = url.substr(0,idx)+"?FormID=10223"; that._ECMsearchurl = url; that.lldatasource = new FIRSTCLASS.util.DataSource({ containerBaseUrl: url, autoLoad: false, requestGranularity: 100, messagebodies: false, docbodies: false, paramStr: "&DoWait=1", isSameRow: function(row1, row2) { return row1.uid == row2.uid; }, isRadForm: true }); var lllvconfig = { domElement: that._searchconfig.domElement, dataSource: that.lldatasource, fillOnScroll: false, loadByPage: false, threading: { format: "none", sortfunc: false }, rowHandler: FIRSTCLASS.apps.Search.handlers.ECM, padText: "
"+ FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.integrations.ecm.search.searching, {repository:that._searchconfig.repository})+"
", padHeight: true }; that._ECMListView = new FIRSTCLASS.layout.ListView(lllvconfig); that._ECMListView.updatePadHeight(FIRSTCLASS.ui.Dom.getViewportHeight()); that.fetchRows(); //FIRSTCLASS.apps.Integration.ECM.watchForResponseComplete({success:FIRSTCLASS.apps.Integration.ECM._parseResponse, failure:FIRSTCLASS.apps.Integration.ECM._parseResponse}); }, failure: function(response) { that._searchconfig.domElement.innerHTML = "
"+FIRSTCLASS.locale.integrations.ecm.search.unavailable+"
"; }}; YAHOO.util.Connect.setForm(form.firstChild); YAHOO.util.Connect.asyncRequest('POST', form.firstChild.action, callbacks); }; FIRSTCLASS.apps.Integration.ECM.fetchRows = function() { if (this.lldatasource) { this.lldatasource.fetchRows(); var that = this; var listener = { foundRows: false, onRow: function(row) { that.lldatasource.removeRowListener(listener); that._ECMListView.clearPadText(); this.foundRows = true; }, fillFinished: function(isNewDelivery, justadded) { if (!this.foundRows && !justadded) { that._ECMListView.updatePadText(FIRSTCLASS.locale.integrations.ecm.search.noresult); } }, onFillCompleted: function(dsrc) { if (!this.foundRows) { that._ECMListView.updatePadText(FIRSTCLASS.locale.integrations.ecm.search.noresult); } } }; this.lldatasource.addRowListener(listener); } }; FIRSTCLASS.apps.Integration.ECM._parseResponse = function (response) { var obj = false; try { obj = FIRSTCLASS.lang.JSON.parse(response.responseText); } catch (e) { // FIXME: an error occurred, show a message //debugger; } return obj; }; FIRSTCLASS.apps.Integration.ECM.watchForResponseComplete = function(callbacks, objid) { if (objid) { FIRSTCLASS.apps.Integration.ECM._currentObjID = objid; } else if (FIRSTCLASS.apps.Integration.ECM._currentObjID) { objid = FIRSTCLASS.apps.Integration.ECM._currentObjID; } else { return; } var url = FIRSTCLASS.session.baseURL + '__OBJID_' + objid + "?Templates=JS&DoWait=1&" + FIRSTCLASS.ui.Dom.getCurrTimestamp(); YAHOO.util.Connect.asyncRequest('GET', url, callbacks); }; FIRSTCLASS.apps.Integration.ECM.doCommand = function(config) { var form = document.createElement("DIV"); var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(config.repository); if (repository == 0 || repository == -1) { // integration not init'ed or repository doesn't exist -- FIXME } else { if (!repository.objid) { // repository not init'ed, init and try again FIRSTCLASS.apps.Integration._onInit.push({func: FIRSTCLASS.apps.Integration.ECM.doCommand, config:config}); FIRSTCLASS.apps.Integration.initRepository(config.repository); } else { var html = ["
"]; /*if (config.repository) { html.push(''); }*/ if (config.xuid) { html.push(''); } for (var i in config.fields) { var type = "STRING"; switch(i) { case 4006: case 4007: type = "LITERALSTRING"; break; default: type = "STRING"; } html.push(''); } html.push(''); html.push(''); html.push("
"); form.innerHTML = html.join(""); YAHOO.util.Connect.setForm(form.firstChild); YAHOO.util.Connect.asyncRequest('POST', form.firstChild.action, config.callbacks); } } }; FIRSTCLASS.apps.Integration.ECM.copyTo = function(config) { this._copyConfig = config; FIRSTCLASS.apps.Integration.ECM.pickCommunityForCopy(config.repository); }; FIRSTCLASS.apps.Integration.ECM.linkTo = function(config) { this._linkConfig = config; FIRSTCLASS.apps.Integration.ECM.pickCommunityForLink(config.repository); }; FIRSTCLASS.apps.Integration.ECM.getInfo = function(config) { var cmdConfig = { command: 5001, xuid: config.xuid, callbacks: config.callbacks, repository: config.repository }; FIRSTCLASS.apps.Integration.ECM.doCommand(cmdConfig); }; FIRSTCLASS.apps.Integration.ECM.doBrowse = function(config) { FIRSTCLASS.apps.Integration.ECM.Browse.doBrowse(config); }; FIRSTCLASS.apps.Integration.ECM.doView = function(config) { this.doCommand({command: 5004, xuid: config.xuid, repository:config.repository}); }; FIRSTCLASS.apps.Integration.ECM.archiveTo = function(config) { }; FIRSTCLASS.apps.Integration.ECM.pickCommunityForCopy = function(repository) { FIRSTCLASS.apps.Integration.ECM.pickCommunity({ title:FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.integrations.ecm.copy.title, {repository:repository}), submittext: FIRSTCLASS.locale.integrations.ecm.copy.submit, submit:FIRSTCLASS.apps.Integration.ECM.onCommunityPickedForCopy, custombutton: FIRSTCLASS.locale.integrations.ecm.copy.submitcustom }); }; FIRSTCLASS.apps.Integration.ECM.pickCommunityForLink = function(repository) { FIRSTCLASS.apps.Integration.ECM.pickCommunity({ title:FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.integrations.ecm.link.title, {repository:repository}), submittext: FIRSTCLASS.locale.integrations.ecm.link.submit, submit:FIRSTCLASS.apps.Integration.ECM.onCommunityPickedForLink, custombutton: FIRSTCLASS.locale.integrations.ecm.link.submitcustom }); }; FIRSTCLASS.apps.Integration.ECM.pickCommunity = function(config) { var that = this; var domElement = document.createElement("DIV"); this._domElement = domElement; this._dialog = new FIRSTCLASS.apps.FormDialog({ baseUrl: FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL)+"__MemForm?FormID=11001&Templates=ECM", domElement:domElement, title: config.title, buttons: [ { text:FIRSTCLASS.locale.integrations.ecm.cancel, type: "cancel" }, { text:config.submittext, isDefault: true, disabled: true, type: "submit" } ], submit: config.submit, cancel: FIRSTCLASS.apps.Integration.ECM.onCommunityCancel, hide: FIRSTCLASS.apps.Integration.ECM.onCommunityCancel, hideaftersubmit: false, hideaftercancel: false }); FIRSTCLASS.apps.Integration.ECM.buttontext = config.custombutton; YAHOO.util.Event.onAvailable('fcECMDropdown', FIRSTCLASS.apps.Integration.ECM.populateCommunityPicker); }; FIRSTCLASS.apps.Integration.ECM.communityPicked = function() { var domel = $('fcECMDropdown'); var buttons = FIRSTCLASS.apps.Integration.ECM._dialog.getButtons(); buttons[1].set('disabled', false); buttons[1].removeClass('fcHidden'); buttons[1].set('label', FIRSTCLASS.locale.doSub(FIRSTCLASS.apps.Integration.ECM.buttontext, {community: domel.firstChild.value})); }; FIRSTCLASS.apps.Integration.ECM.populateCommunityPicker = function() { var html = [""); var domel = $('fcECMDropdown'); domel.innerHTML = html.join(""); var config = { domElement:$('fcECMTagPicker'), item: false, personal:FIRSTCLASS.session.desktop.personaltags, container: false, editable: true, showonconfig:true }; FIRSTCLASS.apps.Workflows.Tags.reconfigure(config); }; FIRSTCLASS.apps.Integration.ECM.onCommunityPickedForCopy = function() { var config = { command: FIRSTCLASS.apps.Integration._commands.copy, fname: FIRSTCLASS.apps.Integration.ECM._copyConfig.fname, xuid: FIRSTCLASS.apps.Integration.ECM._copyConfig.xuid, progresstext: FIRSTCLASS.locale.integrations.ecm.copy.wait, repository: FIRSTCLASS.apps.Integration.ECM._copyConfig.repository }; FIRSTCLASS.apps.Integration.ECM.onCommunityPicked(config); }; FIRSTCLASS.apps.Integration.ECM.onCommunityPickedForLink = function() { var config = { command: FIRSTCLASS.apps.Integration._commands.link, fname: FIRSTCLASS.apps.Integration.ECM._linkConfig.fname, xuid: FIRSTCLASS.apps.Integration.ECM._linkConfig.xuid, progresstext: FIRSTCLASS.locale.integrations.ecm.link.wait, repository: FIRSTCLASS.apps.Integration.ECM._linkConfig.repository }; FIRSTCLASS.apps.Integration.ECM.onCommunityPicked(config); }; FIRSTCLASS.apps.Integration.ECM.onCommunityPicked = function(config) { var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(config.repository); var communityname = $('fcECMDropdown').firstChild.value; var cmdConfig = { fields: { "4003": communityname, "4005": config.fname, "4007": FIRSTCLASS.apps.Workflows.Tags.getTags(), "4006": $('fcECMDescription').value }, command: config.command, xuid: config.xuid, repository: config.repository }; FIRSTCLASS.apps.Integration.ECM.doCommand(cmdConfig); FIRSTCLASS.apps.Integration.ECM.watchForResponseComplete({ success:FIRSTCLASS.apps.Integration.ECM.onCommunityActionSuccess, failure:FIRSTCLASS.apps.Integration.ECM.onCommunityActionFailure }, repository.objid); var div = $('fcECMPicker'); div.innerHTML = "
" + config.progresstext + "
"; var buttons = FIRSTCLASS.apps.Integration.ECM._dialog.getButtons(); for (var i in buttons) { buttons[i].set('disabled', true); buttons[i].addClass('fcHidden'); } }; FIRSTCLASS.apps.Integration.ECM.doSaveToRepository = function(config) { var cmdConfig = { fields: { "4001": "", "4002": config.parentxuid, //parent xuid "4003": config.community, //community name "4005": config.fname //file name }, command: FIRSTCLASS.apps.Integration._commands.save, repository: config.repository }; if (config.xuid) { cmdConfig.fields["4001"] = config.xuid; } FIRSTCLASS.apps.Integration.ECM.doCommand(cmdConfig); }; FIRSTCLASS.apps.Integration.ECM.doArchiveToRepository = function(config) { var cmdConfig = { fields: { "4001": "", "4002": config.parentxuid, // parent xuid to archive to "4003": config.community.name //community name }, command: FIRSTCLASS.apps.Integration._commands.archive, repository: config.repository }; FIRSTCLASS.apps.Integration.ECM.doCommand(cmdConfig); }; FIRSTCLASS.apps.Integration.ECM.onCommunityActionSuccess = function(response) { var obj = FIRSTCLASS.apps.Integration.ECM._parseResponse(response); var div = $('fcECMPicker'); if (obj && obj.response && obj.response.code == 1) { // success div.innerHTML = "
"+FIRSTCLASS.locale.integrations.ecm.succeeded+"
"; } else { // failure // if it was a timeout, the responseText will be blank if (response.responseText.length == 0) { var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository); FIRSTCLASS.apps.Integration.ECM.watchForResponseComplete({ success: FIRSTCLASS.apps.Integration.ECM.onCommunityActionSuccess , failure: FIRSTCLASS.apps.Integration.ECM.onCommunityActionFailure } /* omit objid because we are reissuing same command */); return; } div.innerHTML = FIRSTCLASS.locale.integrations.ecm.failed+"
" + obj.response.message; } var buttons = FIRSTCLASS.apps.Integration.ECM._dialog.getButtons(); buttons[0].set('disabled', false); buttons[0].set('label', 'Close'); buttons[0].removeClass('fcHidden'); buttons[1].destroy(); }; FIRSTCLASS.apps.Integration.ECM.onCommunityActionFailure = function(response) { // var obj = FIRSTCLASS.apps.Integration.ECM._parseResponse(response.responseText); var div = $('fcECMPicker'); var obj = false; var message = ""; try { obj = FIRSTCLASS.lang.JSON.parse(response.responseText); } catch (e) { // an error occurred // if it was a timeout, //debugger; if (false) { var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository); FIRSTCLASS.apps.Integration.ECM.watchForResponseComplete({ success: FIRSTCLASS.apps.Integration.ECM.onCommunityActionSuccess , failure: FIRSTCLASS.apps.Integration.ECM.onCommunityActionFailure } /* omit objid because we are reissuing same command */); return; } } if (obj && obj.response && obj.response.message) { message = obj.response.message; } else { message = response.responseText; } div.innerHTML = FIRSTCLASS.locale.integrations.ecm.failed+"
" + message; var buttons = FIRSTCLASS.apps.Integration.ECM._dialog.getButtons(); buttons[0].set('disabled', false); buttons[0].set('label', FIRSTCLASS.locale.integrations.ecm.close); buttons[0].removeClass('fcHidden'); buttons[1].destroy(); }; FIRSTCLASS.apps.Integration.ECM.onCommunityCancel = function() { FIRSTCLASS.apps.Integration.ECM._domElement.innerHTML = ""; FIRSTCLASS.apps.Integration.ECM._dialog.destroy(); }; FIRSTCLASS.apps.Integration.ECM.eventHandlers = { click: { ecmview: function(that, fcevent) { //that.doView({xuid: fcevent.fcattrs}); }, ecmcopy: function(that, fcevent) { that.copyTo({xuid: fcevent.fcattrs, fname:fcevent.target.getAttribute('fname'), repository: fcevent.target.getAttribute('repository')}); }, ecmlink: function(that, fcevent) { that.linkTo({xuid: fcevent.fcattrs, fname:fcevent.target.getAttribute('fname'), repository: fcevent.target.getAttribute('repository')}); } } }; FIRSTCLASS.apps.Integration.ECM.handleEvent = function(event, fcevent) { var handlers = this.eventHandlers[event.type]; if (handlers) { var handler = handlers[fcevent.fcid]; if (handler) { rv = handler(this, fcevent); if (typeof rv == "undefined") { rv = true; } } } }; FIRSTCLASS.apps.Integration.ECM.Browse = { selectionModes: { all: 0, leaves: 1, nodes: 2 } }; FIRSTCLASS.apps.Integration.ECM.Browse.doBrowse = function(config) { // config = {repository, xuid, title, savecallbacks, defaultfilename} this._currentconfig = config; this._currentxuid = config.xuid; this._treenodes = []; this._contents = []; if (config.selMode) { this._selectionMode = config.selMode; } else { this._selectionMode = FIRSTCLASS.apps.Integration.ECM.Browse.selectionModes.all; } var domElement = document.createElement("DIV"); FIRSTCLASS.apps.Integration.ECM.Browse._domElement = domElement; var submit = FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSave; if (config.mode == "sendto") { submit = FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSend; } else if (config.mode =="archive") { submit = FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseArchive; } this._dialog = new FIRSTCLASS.apps.FormDialog({ baseUrl: FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL)+"__MemForm?FormID=12001&Templates=ECM", domElement:domElement, title: config.title, buttons: [ { text:FIRSTCLASS.locale.integrations.ecm.cancel, type: "cancel" }, { text:FIRSTCLASS.locale.integrations.ecm.save, isDefault: true, disabled: true, type: "submit" } ], submit: submit, cancel: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseCancel, hideaftersubmit: false, hideaftercancel: false, onHide: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseCancel }); var cmdConfig = { command: FIRSTCLASS.apps.Integration._commands.browse, xuid: config.xuid, repository: config.repository, callbacks: { success: FIRSTCLASS.apps.Integration.ECM.Browse.doCheckForResponse } }; FIRSTCLASS.apps.Integration.ECM.doCommand(cmdConfig); YAHOO.util.Event.onAvailable('fcECMBrowse', FIRSTCLASS.apps.Integration.ECM.Browse._handleFormAvailable); }; FIRSTCLASS.apps.Integration.ECM.Browse.doCheckForResponse = function(response) { var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository); FIRSTCLASS.apps.Integration.ECM.Browse.checkForResponse(repository.objid); }; FIRSTCLASS.apps.Integration.ECM.Browse.checkForResponse = function(objid) { FIRSTCLASS.apps.Integration.ECM.watchForResponseComplete({ success: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseResponse, failure: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseResponse }, objid); }; FIRSTCLASS.apps.Integration.ECM.Browse._handleFormAvailable = function() { FIRSTCLASS.apps.Integration.ECM.Browse._titleDomEl = $('fcECMBrowseTitle'); FIRSTCLASS.apps.Integration.ECM.Browse._treeDomEl = $('fcECMBrowseTree'); FIRSTCLASS.apps.Integration.ECM.Browse._nameDomEl = $('fcECMBrowseNamePicker'); if (FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.fname) { FIRSTCLASS.apps.Integration.ECM.Browse._nameDomEl.value = FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.fname; YAHOO.util.Dom.setStyle('fcECMBrowseContainer', 'display', ''); } else { YAHOO.util.Dom.setStyle('fcECMBrowseContainer', 'display', 'none'); } if (FIRSTCLASS.apps.Integration.ECM.Browse._contentAvailable) { FIRSTCLASS.apps.Integration.ECM.Browse._populateContent(); } }; FIRSTCLASS.apps.Integration.ECM.Browse._setupTreeView = function() { this._treeView = new YAHOO.widget.TreeView(FIRSTCLASS.apps.Integration.ECM.Browse._treeDomEl/*, { singleNodeHighlight: true }*/); this._treeView.singleNodeHighlight = true; this._treenodes[this._currentxuid] = this._treeView.getRoot(); this._treeView.setDynamicLoad(FIRSTCLASS.apps.Integration.ECM.Browse._doNavigate); this._treeView.draw(); this._treeView.subscribe('clickEvent', FIRSTCLASS.apps.Integration.ECM.Browse._handleNodeClick); }; FIRSTCLASS.apps.Integration.ECM.Browse.getSelectionXUID = function() { return this._currentxuid; }; FIRSTCLASS.apps.Integration.ECM.Browse.doesFileNameExistInSelectedFolder = function(fname) { var obj = this._contents[this._currentxuid]; if (typeof obj == "undefined") { return -1; } for (var i in obj.browserecords) { var rec = obj.browserecords[i]; var isleaf = (rec.iscontainer == "false"); if (isleaf && rec.name.indexOf(fname) == 0 && fname.indexOf(rec.name) == 0) { // found file, now you need to do a get info to find out if you can save return rec.xuid; } } return false; }; FIRSTCLASS.apps.Integration.ECM.Browse.doCheckForFileNameInSelectedFolder = function(fname, callback) { FIRSTCLASS.apps.Integration.ECM.Browse._checkFname = fname; FIRSTCLASS.apps.Integration.ECM.Browse._checkCB = callback; FIRSTCLASS.apps.Integration.ECM.Browse._doNavigate(false, FIRSTCLASS.apps.Integration.ECM.Browse.doCheckForFileNameInSelectedFolderDone, FIRSTCLASS.apps.Integration.ECM.Browse._currentxuid); }; FIRSTCLASS.apps.Integration.ECM.Browse.doCheckForFileNameInSelectedFolderDone = function() { var exists = FIRSTCLASS.apps.Integration.ECM.Browse.doesFileNameExistInSelectedFolder(FIRSTCLASS.apps.Integration.ECM.Browse._checkFname); FIRSTCLASS.apps.Integration.ECM.Browse._checkCB({fnamechecked:exists}); }; FIRSTCLASS.apps.Integration.ECM.Browse._doNavigate = function(node, fnLoadComplete, xuid) { var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository); if (repository == 0 || repository == -1) { // error } else { if (node) { xuid = node.data.xuid; } var cmdConfig = { command: FIRSTCLASS.apps.Integration._commands.browse, xuid: xuid, repository: repository.name, callbacks: { success: FIRSTCLASS.apps.Integration.ECM.Browse.doCheckForResponse } }; FIRSTCLASS.apps.Integration.ECM.doCommand(cmdConfig); FIRSTCLASS.apps.Integration.ECM.Browse._onLoadComplete = fnLoadComplete; FIRSTCLASS.apps.Integration.ECM.Browse._currentxuid = xuid; } }; FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseResponse = function(response) { var obj = false; try { obj = FIRSTCLASS.lang.JSON.parse(response.responseText); } catch (e) { // an error occurred } if (obj) { FIRSTCLASS.apps.Integration.ECM.Browse._handleBrowseResponse(obj); } }; FIRSTCLASS.apps.Integration.ECM.Browse._handleBrowseResponse = function(obj) { //this._currentxuid = obj.inputs.xuid; this._contents[this._currentxuid] = obj; if (FIRSTCLASS.apps.Integration.ECM.Browse._titleDomEl) { FIRSTCLASS.apps.Integration.ECM.Browse._populateContent(); } }; FIRSTCLASS.apps.Integration.ECM.Browse._handleNodeClick = function(event) { var rc = false; var doHighlight = false; if (FIRSTCLASS.apps.Integration.ECM.Browse._selectionMode == FIRSTCLASS.apps.Integration.ECM.Browse.selectionModes.all) { doHighlight = true; } else if (FIRSTCLASS.apps.Integration.ECM.Browse._selectionMode == FIRSTCLASS.apps.Integration.ECM.Browse.selectionModes.leaves) { if (event.node.isLeaf) { doHighlight = true; } else { rc = true; } } else //{ FIRSTCLASS.apps.Integration.ECM.Browse.selectionModes.nodes: if (!event.node.isLeaf) { doHighlight = true; } if (doHighlight) { FIRSTCLASS.apps.Integration.ECM.Browse._currentxuid = event.node.data.xuid; event.node.highlight(); event.node.focus(); //event.node.refresh(); } this.render(); return rc; }; FIRSTCLASS.apps.Integration.ECM.Browse._populateContent = function() { if (!this._treeView) { this._setupTreeView(); } var obj = this._contents[this._currentxuid]; //var html = [""]; var record = false; var parent = false; for (var i in obj.browserecords) { record = obj.browserecords[i]; if (!this._treenodes[record.xuid]) { parent = this._treenodes[record.parentxuid]; var isleaf = (record.iscontainer == "false"); if (!isleaf || isleaf && this._currentconfig.showleaves) { var node = new YAHOO.widget.TextNode({ // html:record.name, label:record.name,// + " " +record.xuid, expanded:false, xuid:record.xuid, isLeaf: isleaf, enableHighlight: true // href: "#"+top.location.hash }, parent); this._treenodes[record.xuid] = node; } } } this._treeView.render(); if (this._onLoadComplete) { this._onLoadComplete(); this._onLoadComplete = false; } }; /* // FIXME: Implement me FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseArchive = function() { var config = { parentxuid: FIRSTCLASS.apps.Integration.ECM.Browse._currentxuid, community: FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.community.name, repository: FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository }; FIRSTCLASS.apps.Integration.ECM.doArchiveToRepository(config); };*/ FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSend = function(config) { var fname = FIRSTCLASS.apps.Integration.ECM.Browse._nameDomEl.value;// = $('fcECMBrowseNamePicker'); var xuid = false; var verify = false; if (config && config.fnamechecked) { verify = true; xuid = config.fnamechecked; } else { var exists = FIRSTCLASS.apps.Integration.ECM.Browse.doesFileNameExistInSelectedFolder(fname); if (exists == -1) { // dispatch check FIRSTCLASS.apps.Integration.ECM.Browse.doCheckForFileNameInSelectedFolder(fname, FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSend); return; } else if (exists) { xuid = exists; verify = true; } else { verify = false; } } if (xuid && verify) { var rc = confirm(FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.integrations.ecm.versionconfirm, {fname:fname, repository:FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository})); if (!rc) { return; } // confirm new version //return; } //else { // continue //} var config = { parentxuid: FIRSTCLASS.apps.Integration.ECM.Browse._currentxuid, community: FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.community.name, fname: FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.fname, repository: FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository }; if (xuid) { config.xuid = xuid; } FIRSTCLASS.apps.Integration.ECM.doSaveToRepository(config); var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository); if (repository == 0 || repository == -1) { // error } else { FIRSTCLASS.apps.Integration.ECM.Browse._domElement.innerHTML = "
"+FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.integrations.ecm.send.sending, {repository:repository.name})+"
"; var buttons = FIRSTCLASS.apps.Integration.ECM.Browse._dialog.getButtons(); buttons[0].set('disabled', true); buttons[0].addClass('fcHidden'); buttons[1].set('disabled', true); buttons[1].addClass('fcHidden'); FIRSTCLASS.apps.Integration.ECM.watchForResponseComplete({ success: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSendSuccess , failure: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSendFailure }, repository.objid); } }; FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSendSuccess = function(response) { var rc = 0; try { var o = FIRSTCLASS.lang.JSON.parse(response.responseText); rc = o.response.code; } catch(e) { rc = false; // if it was a timeout, the responseText will be blank if (response.responseText.length == 0) { var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository); FIRSTCLASS.apps.Integration.ECM.watchForResponseComplete({ success: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSendSuccess , failure: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSendFailure } /* omit objid because we are reissuing same command */); return; } } if (rc == 1) { var buttons = FIRSTCLASS.apps.Integration.ECM.Browse._dialog.getButtons(); buttons[0].set('disabled', false); buttons[0].set('label', FIRSTCLASS.locale.integrations.ecm.close); buttons[0].removeClass('fcHidden'); buttons[1].destroy(); FIRSTCLASS.apps.Integration.ECM.Browse._domElement.innerHTML = "
"+FIRSTCLASS.locale.integrations.ecm.succeeded+"
"; } else { FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSendFailure(response); } }; FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSendFailure = function(response) { var buttons = FIRSTCLASS.apps.Integration.ECM.Browse._dialog.getButtons(); buttons[0].set('disabled', false); buttons[0].removeClass('fcHidden'); buttons[0].set('label', FIRSTCLASS.locale.integrations.ecm.close); buttons[1].destroy(); var obj = false; var message = ""; try { obj = FIRSTCLASS.lang.JSON.parse(response.responseText); } catch (e) { // an error occurred // if it was a timeout, //debugger; if (false) { var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository); FIRSTCLASS.apps.Integration.ECM.watchForResponseComplete({ success: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSendSuccess , failure: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSendFailure } /* omit objid because we are reissuing same command that just failed */); return; } } if (obj && obj.response && obj.response.message) { message = obj.response.message; } else { message = response.responseText; } FIRSTCLASS.apps.Integration.ECM.Browse._domElement.innerHTML = "
"+FIRSTCLASS.locale.integrations.ecm.failed+"
" + message + "
"; }; FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSave = function() { if (FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.callbacks && FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.callbacks.save) { var node = FIRSTCLASS.apps.Integration.ECM.Browse._treenodes[FIRSTCLASS.apps.Integration.ECM.Browse._currentxuid]; if (node.isLeaf) { FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.callbacks.save({xuid:node.data.xuid, fname:node.label}); } } FIRSTCLASS.apps.Integration.ECM.Browse.close(); }; FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseArchive = function() { if (FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.callbacks && FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.callbacks.archive) { var node = FIRSTCLASS.apps.Integration.ECM.Browse._treenodes[FIRSTCLASS.apps.Integration.ECM.Browse._currentxuid]; if (!node.isLeaf) { FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.callbacks.archive({parentxuid:node.data.xuid}); } } var repository = FIRSTCLASS.apps.Integration.getRepositoryByName(FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository); if (repository == 0 || repository == -1) { // error } else { FIRSTCLASS.apps.Integration.ECM.Browse._domElement.innerHTML = "
"+FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.integrations.ecm.send.sending, {repository:repository.name})+"
"; var buttons = FIRSTCLASS.apps.Integration.ECM.Browse._dialog.getButtons(); buttons[0].set('disabled', true); buttons[0].addClass('fcHidden'); buttons[1].set('disabled', true); buttons[1].addClass('fcHidden'); FIRSTCLASS.apps.Integration.ECM.watchForResponseComplete({ success: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSendSuccess , failure: FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseSendFailure }, repository.objid); } }; FIRSTCLASS.apps.Integration.ECM.Browse._onBrowseCancel = function() { if (FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.callbacks && FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.callbacks.cancel) { FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.callbacks.cancel(); } window.setTimeout(FIRSTCLASS.apps.Integration.ECM.Browse.close, 10); }; FIRSTCLASS.apps.Integration.ECM.Browse.close = function() { if (FIRSTCLASS.apps.Integration.ECM.Browse._treeView) { FIRSTCLASS.apps.Integration.ECM.Browse._treeView.destroy(); FIRSTCLASS.apps.Integration.ECM.Browse._treeView = false; } if (FIRSTCLASS.apps.Integration.ECM.Browse._dialog) { FIRSTCLASS.apps.Integration.ECM.Browse._dialog.destroy(); FIRSTCLASS.apps.Integration.ECM.Browse._dialog = false; } FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig = false; }; FIRSTCLASS.apps.Integration.ECM.Browse.Actions = { copy: function(config) { var cf = { xuid: config.xuid, fname: config.fname, repository: FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository }; FIRSTCLASS.apps.Integration.ECM.copyTo(cf); }, put: function(config) { alert("uploading file"); }, archive: function(config) { var cf = { parentxuid: config.parentxuid, repository: FIRSTCLASS.apps.Integration.ECM.Browse._currentconfig.repository, community: this.community }; FIRSTCLASS.apps.Integration.ECM.doArchiveToRepository(cf); } }; FIRSTCLASS.apps.Integration.ECM.Browse.eventHandlers = { click: { node: function(that, fcevent) { FIRSTCLASS.apps.Integration.ECM.Browse._currentxuid = fcevent.fcattrs; // FIRSTCLASS.apps.Integration.ECM.Browse._handleNodeClick(fcevent.fcattrs); } } }; FIRSTCLASS.apps.Integration.ECM.Browse.handleEvent = function(event, fcevent) { var handlers = this.eventHandlers[event.type]; if (handlers) { var handler = handlers[fcevent.fcid]; if (handler) { rv = handler(this, fcevent); if (typeof rv == "undefined") { rv = true; } } } }; YAHOO.register("fcIntegration", FIRSTCLASS.apps.Integration, {version: "0.0.1", build: "1"});