FIRSTCLASS.apps.Workflows = {}; FIRSTCLASS.apps.Workflows.CreateCommunity = function(config) { var that = this; this._config = config; if (!this._config) { this._config = {}; } if (!this._config.root) { this._config.root = FIRSTCLASS.session.baseURL; } if (!this._config.datasource) { this._config.datasource = FIRSTCLASS.session.desktop._dataSource; } FIRSTCLASS.apps.Workflows.CreateCommunity.instance = this; var domElem = document.createElement("div"); this._dialog = new FIRSTCLASS.apps.FormDialog({ baseUrl: FIRSTCLASS.lang.ensureSlashUrl(this._config.root)+FIRSTCLASS.opCodes.Create+"?Templates=CreateCommunity&How=Picker&What=1&Type=66&Close=-1&KeepNames=1", domElement:domElem, owner: this, title: FIRSTCLASS.locale.workflows.community.create, buttons: [ { text:FIRSTCLASS.locale.workflows.community.create, isDefault:true, type:"submit"}, { text:FIRSTCLASS.locale.workflows.community.cancel, type:"cancel" } ], submit: function() { that._currentStep(); }, cancel: function() { that._cancel(); }, hide: function() { that.cleanup(); }, onDomInserted:function() { that._elements = { toolbar: FIRSTCLASS.ui.Dom.getChildByClassName("fcCommunityWorkflowToolBar", domElem), body: FIRSTCLASS.ui.Dom.getChildByClassName("fcCommunityWorkflowBody", domElem), buttons: that._dialog.getButtons(), stepOne: { name: $("fcCommunityNameInput"), namestatus: $("fcCommunityNameStatus"), description: $("fcCommunityDescriptionInput"), type: $("fcCommunityType"), allowExternal: $("fcCommunityAllowExternal"), email: $("fcCommunityEmailAddy") } }; that._elements.stepOne.name.select(); FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.buttons[0].set('disabled', true); var form2 = $('fcPickerForm'); that._attlist = form2.getAttribute('attlist'); that._objurl = form2.getAttribute('objurl'); YAHOO.util.Event.addListener(that._elements.stepOne.name, 'keydown', FIRSTCLASS.apps.Workflows.Tags.eatKeys); YAHOO.util.Event.addListener(that._elements.stepOne.name, 'keyup', that.watchForNameAndDescription); YAHOO.util.Event.addListener(that._elements.stepOne.description, 'keyup', that.watchForNameAndDescription); }, hideaftersubmit: false, hideaftercancel: false }); this._currentStep = this.stepOne; this._cancel = this.finish; }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.verifyName = function(name) { if (name.length > 0) { var callback = this.verifyNameCallbacks, options = 2, allowgroups = false, params = false, ignorelast = true; FIRSTCLASS.util.Form.validateName(FIRSTCLASS.session.baseURL, name, 9, 0, callback, options, allowgroups, params, ignorelast); } else { var status = FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.stepOne.namestatus; status.innerHTML = ""; FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.buttons[0].set('disabled', true); } }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.displayNameValidationError = function(isError, msg) { var status = FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.stepOne.namestatus; if (isError) { status.innerHTML = msg ? msg : FIRSTCLASS.locale.workflows.community.exists; FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.buttons[0].set('disabled', true); } else { status.innerHTML = ""; if (FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.stepOne.description.value.length > 0) { FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.buttons[0].set('disabled', false); } } }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.verifyNameCallbacks = { onComplete: function(obj) { var found = false, records = false, r; if (obj.match) { switch(obj.match) { case "single": if(obj.pattern.toLowerCase() === obj.item.name.toLowerCase()) { found = true; } break; case "multi": records = obj.dataSource._data.records; for (r in records) { if (obj.pattern.toLowerCase() === records[r].name.toLowerCase()) { found = true; } } break; default: } } FIRSTCLASS.apps.Workflows.CreateCommunity.instance.displayNameValidationError(found); }, onFailure: function(obj) { //var status = FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.stepOne.namestatus; //status.innerHTML = YAHOO.lang.JSON.stringify(obj); } }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.watchForNameAndDescription = function(evt) { var valid = true; // filter out any nasty characters from the typed-in string var name = FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.stepOne.name.value; var name2 = name.replace(/[\[\]\(\)<>\.\$#@\?\/\\\:;,&\*\=\'\"\+\-\_\{\}\|\`\~\!\%\^]/g,""); if (name2.length < name.length) { valid = false; } else if (name.charAt(0) === " ") { valid = false; } if (name.length === 0) { FIRSTCLASS.apps.Workflows.CreateCommunity.instance.displayNameValidationError(true, ""); } else if (valid) { FIRSTCLASS.apps.Workflows.CreateCommunity.instance.verifyName(name); } else { FIRSTCLASS.apps.Workflows.CreateCommunity.instance.displayNameValidationError(true, FIRSTCLASS.locale.workflows.community.invalid); } /* if (FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.stepOne.name.value.length > 0 && FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.stepOne.description.value.length > 0) { FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.buttons[0].set('disabled', false); } else { FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.buttons[0].set('disabled', true); }*/ }; // an excellent function FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.performNameValidation = function() { }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.getCommunityEmail = function() { }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.stepOne = function() { FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.buttons[1].set('disabled', true); FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.buttons[0].set('disabled', true); var that = this; var name = FIRSTCLASS.lang.uesc(this._elements.stepOne.name.value); this._values = { name: this._elements.stepOne.name.value, description: this._elements.stepOne.description.value }; var form = $("fcCommunityCreateForm"); var url = form.action; var form2 = $('fcPickerForm'); this._objurl = form2.getAttribute('objurl'); var cb1 = { success: function(o) { var callback = { success: function(o) { var url1 = form2.getAttribute('attlist') + "?Templates=CreateCommunity&KeepNames=1&Quit=1"; var url2 = form2.getAttribute('objurl') + "?Templates=CreateCommunity&KeepNames=1&Quit=1"; FIRSTCLASS.util.net.asyncRequest('GET', url2); that._config.datasource.addRowListener(that); that._config.datasource.activate(); that._config.datasource.fetchRows(); if (that._config.root !== FIRSTCLASS.session.baseURL) { that._config.datasource.fetchNewRows({ completed: function() { that._config.datasource.fetchNewRows(); } }); } else { that._config.datasource.watchForTinkle({ success: function() { that._config.datasource.watchForTinkle(); } }); } }, failure: function(o) { var obj = o.responseJSON; if (obj && obj.error && obj.error.code === 1080) { // name mismatch var nm = FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.stepOne.name; that.verifyNameCallbacks.onComplete({match: "single", item: {name: nm.value}, pattern: nm.value}); nm.select(); that._currentStep = that.stepOne; } else { alert(FIRSTCLASS.locale.workflows.community.failed); } } }; FIRSTCLASS.util.net.doAsyncPost({form: form, upload: false, callbacks: callback}); /* YAHOO.util.Connect.setForm(form, false); FIRSTCLASS.util.net.asyncRequest('POST', url, callback); */ } }; var u2 = form2.action + "&KeepNames=1&FieldID:8087%3DSTRING=" + FIRSTCLASS.lang.uesc($('fcCommunityNameInput').value); FIRSTCLASS.util.net.asyncRequest('GET', u2, cb1); }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.onRow = function(row) { var that = this, url, body, cb, formcontainer, html; if (row.name === this._values.name) { // found the community body = that._elements.stepOne.description.value; //var post = "BodyType=TEXT&Close=0&Body="+body; url = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.lang.ensureSlashUrl(this._config.root)+row.uri)+"__ACL/__OPENNDX3/"+FIRSTCLASS.opCodes.FormSave+"?Clear=0&Templates=JS&Close=0&Quit=1"; cb = { success: function(o) { that.nextStep(1); }, failure: function(o) { that.nextStep(1); } }; formcontainer = document.createElement("DIV"); //var uri = FIRSTCLASS.session.baseURL + "Send?FormID=21006"; html = ["
"]; html.push(""); html.push(""); html.push(""); html.push(""); html.push("
"); formcontainer.innerHTML = html.join(""); formcontainer.firstChild.childNodes[3].value = body; // FIRSTCLASS.util.net.asyncRequest('POST', url, cb, post); FIRSTCLASS.util.submitForm(formcontainer.firstChild, false, cb); this._values.dsrow = row; } }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.fillFinished = function() { if (this._values.dsrow) { this._config.datasource.removeRowListener(this); } }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.stepTwo = function() { var that = this; var form = document.forms.fcCommunityCustomizeForm; FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.buttons[1].set('disabled', false); FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.buttons[0].set('disabled', false); // disabled, because we don't rename the item yet var burl = FIRSTCLASS.lang.ensureSlashUrl(this._config.root) + this._values.dsrow.uri; this._dataSource = new FIRSTCLASS.util.DataSource({ containerBaseUrl: burl, autoLoad: true, watchForNew: false, loadUnreadImmediate: false, messagebodies: false, nosymbiomainfetch: false }); this._dataSource.addDataListener({ onHeaderData:function(key, data) { if (key === "objid") { that._loadInvitationStep(that._dataSource, data); } }, filter:function(key) { return key === "objid"; } }); /* set the icon on the desktop */ if (this._values.dsrow) { this._values.dsrow.icon.uri="/Icons/"+$("fcIconInput").value; this._values.dsrow.icon.id = parseInt($("fcIconInput").value, 10); this._config.datasource.notifyRowChanged(this._values.dsrow); } // YAHOO.util.Connect.setForm(form); var cb = { success: function(evt) { that.nextStep(2); }, failure: function(evt) { that.nextStep(2); } }; FIRSTCLASS.util.net.doAsyncPost({form: form, upload: false, callbacks: cb}); // FIRSTCLASS.util.net.asyncRequest('POST', form.action, cb); // this.nextStep(2); }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype._loadInvitationStep = function(dataSource, objid) { // perform namevals to get cids, and store list of cids/email addresses to invite // on click of "invite", send the invitation. }; FIRSTCLASS.apps.Workflows.CreateCommunity.pickIcon = function(evt) { var input = $("fcIconInput"); var target = YAHOO.util.Event.getTarget(evt); if (YAHOO.util.Dom.hasClass(target,'fcIcon')) { var id = target.attributes.iconid; if (id) { input.value = id.nodeValue; YAHOO.util.Dom.addClass(target, 'selected'); if (FIRSTCLASS.apps.Workflows.CreateCommunity.instance._values.selectedIcon) { YAHOO.util.Dom.removeClass(FIRSTCLASS.apps.Workflows.CreateCommunity.instance._values.selectedIcon, 'selected'); } FIRSTCLASS.apps.Workflows.CreateCommunity.instance._values.selectedIcon = target; FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.buttons[0].set('disabled', false); } } }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.stepThree = function() { // members.innerHTML = invited member names this.nextStep(3); }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.cleanup = function() { if (this._dialog) { var dlg = this._dialog; window.setTimeout(function() { dlg.destroy(); dlg = false; }, 100); // this._dialog.destroy(); this._dialog = false; } if (this._attlist) { FIRSTCLASS.util.net.asyncRequest('GET', this._attlist + "?Templates=CreateCommunity&Quit=1"); } if (this._objurl) { FIRSTCLASS.util.net.asyncRequest('GET', this._objurl + "?Templates=CreateCommunity&Quit=1"); } }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.finish = function() { this._dialog.hide(); }; FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.nextStep = function(stepno) { var that = this; // FIXME: disabled skinning step, need to implement if (stepno === 2) { stepno = 3; } var url = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL) + "__MemForm?Templates=CreateCommunity&FormID=1100" + stepno; if (stepno === 1) { url = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.lang.ensureSlashUrl(this._config.root)+this._values.dsrow.uri)+"__GetInfo?Templates=CreateCommunity"; } var cb = { success: function(o) { var div = document.createElement("DIV"); div.innerHTML = o.responseText; that._elements.body.innerHTML = div.lastChild.innerHTML; that._elements.toolbar.innerHTML = div.firstChild.innerHTML; div.innerHTML = ""; switch (stepno) { case 1: that._elements.buttons[0].set('label', FIRSTCLASS.locale.workflows.community.dosave); that._elements.buttons[0].set('disabled', true); that._elements.buttons[1].set('label', FIRSTCLASS.locale.workflows.community.skip); that._elements.buttons[1].set('disabled', false); that._currentStep = that.stepTwo; that._cancel = function() { that.nextStep(2); }; break; case 2: that._elements.buttons[0].set('label', FIRSTCLASS.locale.workflows.community.invite); that._elements.buttons[1].set('label', FIRSTCLASS.locale.workflows.community.skip); that._currentStep = that.stepThree; that._cancel = that._currentStep; break; case 3: that._elements.buttons[0].set('disabled', false); that._elements.buttons[0].set('label', FIRSTCLASS.locale.workflows.community.doclose); that._elements.buttons[1].destroy(); var namebox = $('fcCommunityWorkflowNameVer'); //var members = $('fcCommunityWorkflowMembersVer'); namebox.innerHTML = that._values.name; var iconbox = $('fcCommunityWorkflowIconVer'); iconbox.src = "/Icons/"+that._values.dsrow.icon.id; that._currentStep = that.finish; that._cancel = that.finish; break; } } }; FIRSTCLASS.util.net.asyncRequest('GET', url, cb); }; YAHOO.register("fcWorkflows", FIRSTCLASS.apps.Workflows, {version: "0.0.1", build: "1"}); FIRSTCLASS.apps.Members = function(config) { this._config = config; this.startWorkflow(); }; FIRSTCLASS.apps.Members.prototype.isVisible = function() { if (this._dialog && this._dialog.getDialog && this._dialog.getDialog().cfg) { return this._dialog.getDialog().cfg.getProperty('visible'); } return false; }; FIRSTCLASS.apps.Members.prototype.startWorkflow = function() { var that = this; if (this.cancelfunc === this.startWorkflow) { this.cancelfunc = false; } if (!this._dialog) { this._dialog = new FIRSTCLASS.apps.FormDialog({ baseUrl: FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL)+"__MemForm?FormID=10001&Templates=Members&Step=1", domElement:this._config.domElement, title:FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.workflows.members.invite, {title:this._config.title}), buttons: [ { text:FIRSTCLASS.locale.workflows.members.add, isDefault:true, type:"submit" }, { text:FIRSTCLASS.locale.uploader.cancel, type: "cancel" } ], submit: function() { that.currentStep(); }, cancel: function() { that.close(); }, onDomInserted: function() { that.setButtonState({invite: false, close: true}); var patternEl = FIRSTCLASS.ui.Dom.getChildByIdName('pattern', that._config.domElement); if (patternEl) { YAHOO.util.Event.addListener(patternEl, "keydown", FIRSTCLASS.apps.Workflows.Tags.eatKeys); } }, hideaftersubmit: false, hideaftercancel: false }); } else { var requestUrl = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL) + "__MemForm?FormID=10001&Templates=Members&Step=1"; var connManagerRequest = FIRSTCLASS.util.net.asyncRequest("GET", requestUrl, { success:function(response) { that._config.domElement.innerHTML = response.responseText; that._dialog.getDialog().cfg.setProperty("buttons", [ { text:FIRSTCLASS.locale.workflows.members.add, isDefault:true, type:"submit", handler: function() { that.currentStep(); } }, { text:FIRSTCLASS.locale.uploader.cancel, type: "cancel", handler: function() { that.close(); } } ]); that._dialog.getDialog().show(); that.setButtonState({invite: false, close: true}); }, failure: function(response) { that._config.domElement.innerHTML = response.responseText; that._dialog.getDialog().cfg.setProperty("buttons", [ { text:FIRSTCLASS.locale.workflows.members.add, isDefault:true, type:"submit", handler: function() { that.currentStep(); } }, { text:FIRSTCLASS.locale.uploader.cancel, type: "cancel", handler: function() { that.close(); } } ]); that._dialog.getDialog().show(); that.setButtonState({invite: false, close: true}); } }); } this.currentStep = this.doValidation; FIRSTCLASS.apps.Members.instance = this; }; FIRSTCLASS.apps.Members.prototype.doValidation = function() { var input = FIRSTCLASS.ui.Dom.getChildByClassName("fcAddSubscriberNameField", this._config.domElement); if (FIRSTCLASS.lang.isEmailAddress(input.value.trim())) { this.setAndOrShowContainer('noticecontainer', FIRSTCLASS.locale.workflows.members.emailname); input.select(); return; } var url = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL) + "__MemForm?FormID=11215&Templates=JS&Close=-1"; var that = this; var cbs = { success: function(response) { var o = {}; try { o = FIRSTCLASS.lang.JSON.parse(response.responseText); } catch(x){ o = false; } if (o) { that.doingValidation = false; that._objid = o.objid; that.doValidationStep2(); } }, failure: function(response) { } }; var buttons = this._dialog.getButtons(); buttons[1].set('label',FIRSTCLASS.locale.uploader.cancel); FIRSTCLASS.util.net.asyncRequest('GET', url, cbs); }; FIRSTCLASS.apps.Members.prototype.doValidationStep2 = function() { var input = FIRSTCLASS.ui.Dom.getChildByClassName("fcAddSubscriberNameField", this._config.domElement); // do some cleanup of text then provide some affordance that we're doing something var callback = this; if (input && !this.doingValidation) { this.doingValidation = true; /* if (FIRSTCLASS.lang.isEmailAddress(input.value.trim())) { var obj = { match: "none", pattern: input.value.trim() }; this.onComplete(obj); } else { */ var url = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL) + "__OBJID_" + this._objid; FIRSTCLASS.util.Form.validateName(url, input.value.trim(), 9, 1000, callback, false, false, false, true); /* } */ } }; FIRSTCLASS.apps.Members.prototype.addUser = function(cfg) { var that = this; cfg.folderid = this._config.folderid; cfg.objid = false ;//this._config.objid; var func = function() { that.lockAllInputs(); that.setAndOrShowContainer('noticecontainer',FIRSTCLASS.locale.workflows.members.sending); var formobj = {elements: [], action: FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL) + "__MemForm/"+FIRSTCLASS.opCodes.FormSave+"?FormID=11215&Clear=0&Templates=JS"}; if (cfg.messagesrc) { cfg.message = cfg.messagesrc.value; } if (cfg.cid) { formobj.elements.push({name:'To', value:cfg.cid}); } else { formobj.elements.push({name:'FieldID:1201=STRING', value:cfg.userid}); } if (cfg.first) { formobj.elements.push({name:'FieldID:1202=STRING', value:cfg.first}); } if (cfg.last) { if (cfg.last.length === 0) { cfg.last = " "; } formobj.elements.push({name:'FieldID:1204=STRING', value:cfg.last}); } formobj.elements.push({name:'FieldID:1501=SHORT', value:cfg.objid}); formobj.elements.push({name:'FieldID:1502=STRING', value:cfg.message}); formobj.elements.push({name:'FieldID:1503=LONG', value:cfg.folderid.siteid}); formobj.elements.push({name:'FieldID:1504=LONG', value:cfg.folderid.msgid}); var cb = { success: function(obj) { var handled = false; if (obj && obj.responseText) { var o = false; try { o = FIRSTCLASS.lang.JSON.parse(obj.responseText); } catch (e) {} if (o && o.error && o.httpcode === 500) { that.setAndOrShowContainer('noticecontainer', FIRSTCLASS.locale.errors.getErrorString(o.error)); handled = true; } } if (!handled) { that.setAndOrShowContainer('noticecontainer', FIRSTCLASS.locale.workflows.members.added); var buttons = that._dialog.getButtons(); buttons[1].set('label',FIRSTCLASS.locale.workflows.members.doclose); } that.currentStep = that.doValidation; that.resetAllContainers(); that.unlockAllInputs(); }, failure: function(obj) { var handled = false; if (obj && obj.responseText) { var o = false; try { o = FIRSTCLASS.lang.JSON.parse(obj.responseText); } catch (e) {} if (o && o.error) { that.setAndOrShowContainer('noticecontainer', FIRSTCLASS.locale.errors.getErrorString(o.error)); handled = true; } } that.currentStep = that.doValidation; if (!handled) { that.setAndOrShowContainer('noticecontainer', FIRSTCLASS.locale.workflows.members.failed); } that.resetAllContainers(); that.unlockAllInputs(); } }; var conn = FIRSTCLASS.util.net.doAsyncPost({form: formobj, action: FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL) + "__MemForm/"+FIRSTCLASS.opCodes.FormSave+"?FormID=11215&Clear=0&Templates=JS", upload: false, callbacks: cb}); that.cancelfunc = false; }; if (!cfg.objid) { return function() { that.lockAllInputs(); var cb = { success: function(response) { var obj = {}; try { obj = FIRSTCLASS.lang.JSON.parse(response.responseText); } catch (e) { } if (obj.objid) { cfg.objid = obj.objid; func(); } }, failure: function(obj) { var handled = false; if (obj && obj.responseText) { var o = false; try { o = FIRSTCLASS.lang.JSON.parse(obj.responseText); } catch (e) {} if (o && o.error) { cfg.domElement.innerHTML = FIRSTCLASS.locale.errors.getErrorString(o.error); handled = true; } } that.currentStep = that.doValidation; if (!handled) { that.setAndOrShowContainer('noticecontainer', FIRSTCLASS.locale.workflows.members.failed); } that.unlockAllInputs(); } }; var url = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL, true) + that._config.community + "?Templates=JS&Both=0-1&Close=-1"; if (that._config.community.indexOf(FIRSTCLASS.session.baseURL) >= 0) { url = that._config.community + "?Templates=JS&Both=0-1&Close=-1"; } var conn = FIRSTCLASS.util.net.asyncRequest('GET', url, cb); }; } else { return func; } }; FIRSTCLASS.apps.Members.prototype.setButtonState = function(buttons) { var thebuttons = this._dialog.getDialog().getButtons(); var disabled = false; if (typeof buttons.invite !== "undefined") { disabled = !buttons.invite; thebuttons[0].set('disabled', disabled); } if (typeof buttons.close !== "undefined") { disabled = !buttons.close; thebuttons[1].set('disabled', disabled); } }; FIRSTCLASS.apps.Members.prototype.resetAllContainers = function() { this.resetContainer("messagecontainer"); this.resetContainer("hitlistcontainer"); this.resetContainer("nohitscontainer"); this.resetContainer("miniprofilecontainer"); this.resetContainer("namevalidationcontainer"); $('pattern').value = ""; $('pattern').select(); this.setButtonState({invite:false, close:true}); }; FIRSTCLASS.apps.Members.prototype.lockAllInputs = function() { var ids = ['pattern', 'searchbutton', 'emailinput', 'firstnameinput', 'lastnameinput', 'invitationmessage'], i; for (i in ids) { $(ids[i]).disabled = "disabled"; } }; FIRSTCLASS.apps.Members.prototype.unlockAllInputs = function() { var ids = ['pattern', 'searchbutton', 'emailinput', 'firstnameinput', 'lastnameinput', 'invitationmessage'], i; for (i in ids) { $(ids[i]).disabled = false; } }; FIRSTCLASS.apps.Members.prototype.resetContainer = function(id, html) { var el = false; if (typeof id === "string") { el = $(id); } else { el = id; } if (el) { YAHOO.util.Dom.addClass(el, 'hidden'); if (typeof html === "string") { el.innerHTML = ""; } } }; FIRSTCLASS.apps.Members.prototype.setAndOrShowContainer = function(id, html) { var el = false; if (typeof id === "string") { el = $(id); } else { el = id; } if (el) { YAHOO.util.Dom.removeClass(el, 'hidden'); if (typeof html === "string") { el.innerHTML = html; } } }; FIRSTCLASS.apps.Members.prototype.noMatch = function() { var pattern = FIRSTCLASS.ui.Dom.getChildByIdName("pattern", this._config.domElement).value; this.onComplete({type:"none", pattern:pattern}); }; FIRSTCLASS.apps.Members.prototype.onComplete = function(obj) { var messagecontainer = FIRSTCLASS.ui.Dom.getChildByIdName("messagecontainer", this._config.domElement); var hitlistcontainer = FIRSTCLASS.ui.Dom.getChildByIdName("hitlistcontainer", this._config.domElement); var nohitscontainer = FIRSTCLASS.ui.Dom.getChildByIdName("nohitscontainer", this._config.domElement); var miniprofilecontainer = FIRSTCLASS.ui.Dom.getChildByIdName("miniprofilecontainer", this._config.domElement); var namevalidationcontainer = FIRSTCLASS.ui.Dom.getChildByIdName("namevalidationcontainer", this._config.domElement); var noticecontainer = FIRSTCLASS.ui.Dom.getChildByIdName("noticecontainer", this._config.domElement); var message = FIRSTCLASS.ui.Dom.getChildByIdName('invitationmessage', messagecontainer); this.resetContainer(noticecontainer, ""); var that = this; switch (obj.match) { case "single": // single match, and added to list, we can return var now = new Date(); var miniprofhtml = "
"; miniprofhtml += "
" + FIRSTCLASS.locale.workflows.members.userselect4.doSub({hash:top.location.hash, onclick:"FIRSTCLASS.apps.Members.instance.noMatch();"}) + "
"; miniprofilecontainer.innerHTML = miniprofhtml; //+FIRSTCLASS.locale.workflows.members.message+"
"; FIRSTCLASS.ui.widgets.showMiniProfile(miniprofilecontainer.firstChild, obj.item,false,false,false, false, false); this.setAndOrShowContainer(miniprofilecontainer); this.setAndOrShowContainer(messagecontainer); this.resetContainer(hitlistcontainer); this.resetContainer(nohitscontainer); this.resetContainer(noticecontainer, ''); this.resetContainer(namevalidationcontainer); this.setButtonState({invite: true, close: true}); that.currentStep = that.addUser({cid:obj.item.cid, messagesrc:message}); break; case "multi": // multimatch, we got a DataSource var guidetext = FIRSTCLASS.ui.Dom.getChildByClassName("guidetext", hitlistcontainer); var guidetext2 = FIRSTCLASS.ui.Dom.getChildByClassName("guidetext2", hitlistcontainer); var list = FIRSTCLASS.ui.Dom.getChildByClassName("list", hitlistcontainer); list.innerHTML = ""; guidetext.innerHTML = FIRSTCLASS.locale.workflows.members.userselect; guidetext2.innerHTML = FIRSTCLASS.locale.workflows.members.userselect2.doSub({hash:top.location.hash, onclick:"FIRSTCLASS.apps.Members.instance.noMatch();"}); this.setAndOrShowContainer(hitlistcontainer); this.setAndOrShowContainer(miniprofilecontainer); this.setAndOrShowContainer(messagecontainer); this.resetContainer(nohitscontainer); this.resetContainer(noticecontainer, ''); this.resetContainer(namevalidationcontainer); var dt = new Date(); this.miniprofid = "fcMembersMiniProfile" + dt.getTime(); miniprofilecontainer.innerHTML = "
"; var lvcfg = { noHover: true, domElement: list, dataSource: obj.dataSource, threading: { format: FIRSTCLASS.layout.ThreadHandler.types.NONE }, rowHandler: new FIRSTCLASS.layout.UserListHandler(obj.dataSource,false,false), onFillFinished: function() { that._dialog.getDialog().center(); } }; that.listView = new FIRSTCLASS.layout.ListView(lvcfg); that.setButtonState({invite: true, close: true}); that.currentStep = function() { var msg = message; if (msg && msg.value.length > 0) { msg = msg.value; } else { msg = ""; } if (that.userselection) { that.addUser({cid:that.userselection.row.cid, /*objid:that._config.objid,*/ message:msg})(); } else { this.setAndOrShowContainer(noticecontainer,FIRSTCLASS.locale.workflows.members.userselect3); } }; break; //case "none": default: this.setAndOrShowContainer(nohitscontainer); this.setAndOrShowContainer(messagecontainer); this.resetContainer(hitlistcontainer); this.resetContainer(miniprofilecontainer); this.resetContainer(namevalidationcontainer); this.resetContainer(noticecontainer, ''); var uidField = FIRSTCLASS.ui.Dom.getChildByIdName("emailinput", nohitscontainer); uidField.value = ""; var names = obj.pattern.split(" "); var namevalshown = false; if (names.length <= 1) { this.setAndOrShowContainer(namevalidationcontainer); var firstname = FIRSTCLASS.lang.upperCaseFirstLetter(names[0]); $('firstnameinput').value = firstname; $('lastnameinput').value = ""; namevalshown = true; } this.setAndOrShowContainer(messagecontainer); that._dialog.getDialog().center(); uidField.focus(); that.setButtonState({invite: true, close: true}); that.currentStep = function() { var userid = uidField.value; if (FIRSTCLASS.lang.isEmailAddress(userid.trim())) { names = obj.pattern.split(" "); var firstname = FIRSTCLASS.lang.upperCaseFirstLetter(names[0]); var lastname = ""; if (names.length > 1) { lastname = FIRSTCLASS.lang.upperCaseFirstLetter(names[names.length-1]); } if (namevalshown) { firstname = $('firstnameinput').value; lastname = $('lastnameinput').value; } that.addUser({userid:userid, first: firstname, last: lastname, messagesrc:message})(); } else { this.setAndOrShowContainer(noticecontainer,FIRSTCLASS.locale.workflows.members.invalidemail); uidField.select(); } }; } this.doingValidation = false; }; FIRSTCLASS.apps.Members.prototype.submit = function() { if (this.submitFunc) { this.submitFunc(); } }; FIRSTCLASS.apps.Members.prototype.rowclick = function (element, row) { if (this.userselection) { YAHOO.util.Dom.removeClass(this.userselection.element, "selected"); } YAHOO.util.Dom.addClass(element, "selected"); this.userselection = {"element":element,"row":row}; FIRSTCLASS.ui.widgets.showMiniProfile($(this.miniprofid) /*$('fcMembersMiniProfile')*/, row,false,false,false,true, false, false); this._dialog.getDialog().center(); var message = $('invitationmessage'); message.select(); message.focus(); }; FIRSTCLASS.apps.Members.prototype.close = function() { if (this.cancelfunc) { this.cancelfunc(); } else { if (this._dialog) { this._dialog.hide(); this._dialog.destroy(); this._dialog = false; } } }; FIRSTCLASS.apps.Members.prototype.eventHandlers = { click: { user: function(that, fcevent, row) { that.rowclick(fcevent.target, row); }, userClick: function(that, fcevent, row) { that.rowclick(fcevent.target, row); } } }; FIRSTCLASS.apps.Members.prototype.handleEvent = function(event, fcevent) { var rv = false; var handlers = this.eventHandlers[event.type]; if (handlers) { var handler = handlers[fcevent.fcid]; if (handler) { //var tg = fcevent.target; var row = this.listView._rowmap[fcevent.target.id]; if (row) { rv = handler(this, fcevent, row); if (typeof rv === "undefined") { rv = true; } } } } return rv; }; FIRSTCLASS.apps.Members.prototype.onFailure = function(obj) { this.doingValidation = false; var domElement = FIRSTCLASS.ui.Dom.getChildByClassName("fcNameValContainer", this._config.domElement); domElement.innerHTML = obj.response.responseText; }; FIRSTCLASS.apps.Workflows.Invitation = function(config) { var that = this; var accept = function() { FIRSTCLASS.apps.Desktop.instance.acceptItem(config.row.uri); /* var joinurl = FIRSTCLASS.session.baseURL + '?LFieldID_8092.'+FIRSTCLASS.lang.removeSlashUrl(config.row.uri)+'_LONG=0&Templates=JS'; FIRSTCLASS.util.net.asyncRequest('GET', joinurl); config.row.col8092 = 0; config.dataSource.notifyRowDeleted(config.row); config.dataSource.notifyRowChanged(config.row);*/ }; var dialog = false; var decline = function() { config.dataSource.deleteRow(config.row); config.domElement.innerHTML = ''; dialog.hide(); dialog.destroy(); }; dialog = new FIRSTCLASS.apps.FormDialog({ baseUrl: FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL)+FIRSTCLASS.lang.ensureSlashUrl(config.row.uri)+"__Resume?FormID=10002&Invitation=1&Templates=Invitation", domElement:config.domElement, title:FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.workflows.invitation.title, {name:config.row.name}), buttons: [ { text:FIRSTCLASS.locale.workflows.invitation.accept, isDefault:true, type:"submit"}, { text:FIRSTCLASS.locale.workflows.invitation.decline, type: "cancel", handler: decline } ], submit: function() { accept(); dialog.hide(); dialog.destroy(); }, cancel: function() { decline(); // dialog.hide(); // dialog.destroy(); }, onDomInserted: function() { var del = dialog.mySimpleDialog.body; var inviter = FIRSTCLASS.ui.Dom.getChildByClassName('fcCommunityInviter', del); inviter.innerHTML = config.row.author; var invitemsg = FIRSTCLASS.ui.Dom.getChildByClassName('fcCommunityInviteMessage', del); var communityimg = FIRSTCLASS.ui.Dom.getChildByClassName('fcCommunityImage', del); communityimg.src = config.row.icon.uri; var communityemail = FIRSTCLASS.ui.Dom.getChildByClassName('fcCommunityEmail', del); var communitydesc = FIRSTCLASS.ui.Dom.getChildByClassName('fcCommunityType', del); var names = YAHOO.util.Dom.getElementsByClassName('fcCommunityName', false, del); var i; for (i in names) { names[i].innerHTML = config.row.name; } }, hideaftersubmit: true, hideaftercancel: true }); //YAHOO.util.Event.onContentReady('fcCommunityInviteForm', this.updateHTML); FIRSTCLASS.apps.Workflows.Invitation.instance = this; }; FIRSTCLASS.apps.Workflows.Upload = function(config) { var that = this; var domEl = document.createElement("div"); this.oncomplete = function() { this._dialog.hide(); this._dialog.destroy(); }; var widget = new FIRSTCLASS.ui.widgets.upload({baseUrl: config.baseUrl, domElement: domEl, callbacks: this}); var onsubmit = function() { widget.submit(); // that._dialog.getButtons()[1].destroy(); that._dialog.getButtons()[0].destroy(); }; widget.setChangeHandler(onsubmit); var oncancel = function() { widget.cancel(); that.oncomplete(); }; var buttons = [ /* {text:"Upload", handler:onsubmit, isDefault: true},*/ {text:FIRSTCLASS.locale.workflows.upload.docancel, handler:oncancel, isDefault: true} ]; this._dialog = new YAHOO.widget.SimpleDialog("upload", { width: "30em", visible: true, draggable: false, fixedcenter: true, buttons: buttons }); this._dialog.setHeader(FIRSTCLASS.locale.workflows.upload.title); this._dialog.setBody(domEl); this._dialog.render(document.body); this._dialog.show(); }; FIRSTCLASS.apps.Workflows.AboutCommunity = function(config) { this._config = config; if (!FIRSTCLASS.apps.Integration._isInitialized) { // do init first FIRSTCLASS.apps.Integration._onInit.push({func: FIRSTCLASS.apps.Workflows.AboutCommunity.finishBootStrap, config:this}); FIRSTCLASS.apps.Integration.init(); } else { this.startWorkflow(); } }; FIRSTCLASS.apps.Workflows.AboutCommunity.finishBootStrap = function(config) { config.startWorkflow(); }; FIRSTCLASS.apps.Workflows.AboutCommunity.prototype.getRepositoryHandler = function(cfg) { var that = this, func, repositories = cfg.repositories, i = cfg.index; func = function() { that.close(); FIRSTCLASS.apps.Integration.ECM.Browse.doBrowse({ 'xuid': '', 'title':FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.integrations.ecm.archiveto, {repository:repositories[i].name}), showleaves: false, mode:"archive", callbacks: { archive: FIRSTCLASS.apps.Integration.ECM.Browse.Actions.archive, community: { name: that._config.title } }, repository:repositories[i].name}); }; return func; }; FIRSTCLASS.apps.Workflows.AboutCommunity.prototype.startWorkflow = function(edit) { var that = this; this._defaultButtons = [ { text:FIRSTCLASS.locale.workflows.aboutcommunity.close, isDefault:true, handler:function () {that.close();} } ]; this._config.domElement = document.createElement("div"); var requestUrl, connManagerRequest, i; if (!this._dialog) { if (!that._config.prefsmode && ((FIRSTCLASS.permissions.hasPriv(this._config.acl, FIRSTCLASS.permissions.ACL.MODERATOR) || (typeof this._config.isalias !== "undefined" && parseInt(this._config.isalias, 10) === 0)) && that._config.baseUrl.indexOf("Open-Conf") < 0)) { this._defaultButtons.push({ text:FIRSTCLASS.locale.workflows.aboutcommunity.edit, handler: function() { that.startWorkflow(true); } }); var repositories = FIRSTCLASS.apps.Integration.getRepositories(); for (i in repositories) { var repository = repositories[i]; if (repository.capabilities.sendarchive) { this._defaultButtons.push({ text:FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.integrations.ecm.archiveto, {repository:repositories[i].name}), handler: this.getRepositoryHandler({repositories: repositories, index: i}) }); } } } var baseurl = FIRSTCLASS.lang.ensureSlashUrl(that._config.baseUrl)+"__Resume?Templates=AboutCommunity&Title="+escape(that._config.title)+"&Icon="+that._config.icon+"&Quit=1"; if (that._config.prefsmode) { baseurl += "&Mode=1"; } else { baseurl += "&Mode=2"; } if (that._config.baseUrl.indexOf("Open-Conf") >=0) { baseurl = FIRSTCLASS.session.templatebase + "/AboutCommunity/error301.html"; } this._dialog = new FIRSTCLASS.apps.FormDialog({ baseUrl: baseurl, domElement:this._config.domElement, title:that._config.title, buttons: this._defaultButtons, hideaftersubmit: false, hideaftercancel: true, modal: false, onDomInserted: function() { var title = FIRSTCLASS.ui.Dom.getChildByClassName("fcCommunityTitle", that._config.domElement); if (title) { title.innerHTML = that._config.title; } if (that._config.baseUrl.indexOf("Open-Conf") < 0) { var watched = FIRSTCLASS.session.desktop.isContainerBeingWatched(that._config.baseUrl); var watchPicker = $('fcWatchPicker'); if (!watchPicker) { return; } var html = []; html.push("
" + FIRSTCLASS.locale.workflows.aboutcommunity.subscribetitle + "
"); html.push("
" + FIRSTCLASS.locale.workflows.aboutcommunity.subscribenone + "
"); html.push("
" + FIRSTCLASS.locale.workflows.aboutcommunity.subscribefeed + "
"); html.push("
" + FIRSTCLASS.locale.workflows.aboutcommunity.subscribedigest + "
"); watchPicker.innerHTML = html.join(""); var pickers = [ FIRSTCLASS.ui.Dom.getChildByIdName('watchpickerradio1', watchPicker), FIRSTCLASS.ui.Dom.getChildByIdName('watchpickerradio2', watchPicker), FIRSTCLASS.ui.Dom.getChildByIdName('watchpickerradio3', watchPicker) ]; var picker, i; var whandler = function() { var watched = FIRSTCLASS.session.desktop.isContainerBeingWatched(that._config.baseUrl); if (!watched) { watched = {type:0}; } var pvalue = parseInt(this.value,10); if (watched.type !== pvalue) { if (watched.type !== 0) { FIRSTCLASS.session.desktop.stopContainerBeingWatched(that._config.baseUrl); } if (pvalue !== 0) { var mode = pvalue; if (pvalue === 4) { mode = 3; } FIRSTCLASS.util.net.asyncRequest('GET',that._config.baseUrl+"?Watch=" + mode + "&Templates=JS&JSON=2", { success: function(response) { FIRSTCLASS.apps.Desktop.instance._dataSource.fetchRows(false, false, false, false, true, true); }, failure: function(response) { } }); } } }; for (i in pickers) { picker = pickers[i]; YAHOO.util.Event.on(picker, 'change', whandler); } } } }); } else { if (edit) { that.originalSkin = FIRSTCLASS.ui.skin.get(); requestUrl = FIRSTCLASS.lang.ensureSlashUrl(that._config.baseUrl)+"__ACL/__OPENNDX3/"+FIRSTCLASS.opCodes.FormEdit+"?Templates=AboutCommunity&Clear=0&Title="+escape(that._config.title)+"&Icon="+that._config.icon+"&Quit=1"; if (that._config.prefsmode) { requestUrl += "&Mode=1"; } else { requestUrl += "&Mode=2"; } connManagerRequest = FIRSTCLASS.util.net.asyncRequest("GET", requestUrl, { success:function(response) { that._dialog.getDialog().setBody(response.responseText.replace("COMMUNITYTITLE", that._config.title)); //that._message = new FIRSTCLASS.util.Message() that._dialog.getDialog().cfg.setProperty("buttons", [ { text:FIRSTCLASS.locale.workflows.aboutcommunity.dosave, isDefault:true, type:"submit", handler: function() { var skintext = []; var picker = $('fcCommunityLayoutPicker'); var hasembed = false; var layout = "0"; if (picker) { layout = picker.value; hasembed = $('fcCommunityEditEmbedInput').value; if (that._editor) { var value = that._editor.getData(); that._editor.destroy(); delete that._editor; hasembed = value; } //$('fcCommunityEditEmbedInput').type = "hidden"; var embedcode = hasembed; if (hasembed !== "") { hasembed = 1; } else { hasembed = 0; } } var savecb = { success: function() { var keys = [ {key: "layout", id: "13084", type:"SHORT", value:parseInt(layout, 10)}, {key: "skin", id: "13083", type:"STRING", value:FIRSTCLASS.ui.skin.get()} ]; if (hasembed) { keys.push({key: "hasembed", id: "13085", type:"SHORT", value:parseInt(hasembed, 10)}); keys.push({key:"embedcode", id: 13086, type:"TEXT", value: embedcode}); } that._config.dataSource.updateContainerFieldData(keys); }, failure: function() { var keys = [ {key: "layout", id: "13084", type:"SHORT", value:parseInt(layout, 10)}, {key: "skin", id: "13083", type:"STRING", value:FIRSTCLASS.ui.skin.get()} ]; if (hasembed) { keys.push({key: "hasembed", id: "13085", type:"SHORT", value:parseInt(hasembed, 10)}); keys.push({key:"embedcode", id: 13086, type:"TEXT", value: embedcode}); } that._config.dataSource.updateContainerFieldData(keys); } }; that.save(savecb); } }, { text:FIRSTCLASS.locale.workflows.aboutcommunity.docancel, type: "cancel", handler: function() { FIRSTCLASS.ui.skin.set(that.originalSkin); that.close(); } } ]); var picker = $('fcSkinPicker'); that.picker = picker; var skins = ["default", "aqua", "army", "bills", "bizbldg", "bluecloud", "bluegrass", "bluegrid", "blueoak", "bricks", "chess", "copper", "cotton", "dots", "flowers", "gears_blue", "graffiti", "gravel", "globe", "legal", "mathletes", "mesh", "metal", "military", "network", "paper", "pei", "rocks", "stalactites", "teachers", "tech", "waterdrop"]; var html = ["
"); picker.innerHTML = html.join(""); YAHOO.util.Event.addListener(picker.firstChild.firstChild, 'change', function(evt) { var skinname = picker.firstChild.firstChild.value; FIRSTCLASS.ui.skin.set(skinname); YAHOO.util.Event.stopPropagation(evt); }); if (that._config.layout) { var layoutin = $('fcCommunityLayoutPicker'); if (that._config.layout !== layoutin.value) { layoutin.value = that._config.layout; } } YAHOO.util.Event.addListener($('fcCommunityEmbedRich'), 'click', function(evt) { if ($('fcCommunityEmbedRich').value === 'rich text') { var ckc = { startupFocus: true, resize_enabled: false, dialog_backgroundCoverOpacity: 0.4, dialog_backgroundCoverColor: 'rgb(160,160,160)', colorButton_enableMore: true, skin: 'bf1_1,../cke_skins/bf1_1/', undoStackSize : 50, removePlugins: 'flash,newpage,pagebreak,save,scayt,templates,wsc,image,link', extraPlugins : 'bfimage,bflink,bfembed', baseFloatZIndex: 100000, toolbar_reply: [ ['Undo','Redo'], ['Cut','Copy','Paste','PasteText','PasteFromWord'], ['Bold','Italic','Underline','Strike','Subscript','Superscript'], ['NumberedList','BulletedList'], ['Outdent','Indent','Blockquote'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['Table','Smiley'], ['SelectAll','RemoveFormat'] ], toolbar: 'reply' }; CKEDITOR.plugins.addExternal('bfimage', '../cke_plugins/bfimage/', 'bfimage.js'); CKEDITOR.plugins.addExternal('bflink', '../cke_plugins/bflink/', 'bflink.js'); CKEDITOR.plugins.addExternal('bfembed', '../cke_plugins/bfembed/', 'bfembed.js'); that._editor = CKEDITOR.replace($('fcCommunityEditEmbedInput'), ckc); $('fcCommunityEmbedRich').value = 'plain'; } else { var value = ''; if (that._editor) { value = that._editor.getData(); that._editor.destroy(); delete that._editor; } $('fcCommunityEmbedRich').value = 'rich text'; } }); that._dialog.getDialog().center(); }, failure: function(response) { that._dialog.getDialog().setBody(response.responseText.replace("COMMUNITYTITLE", that._config.title)); that._dialog.getDialog().center(); that._dialog.getDialog().cfg.setProperty("buttons", that._defaultButtons); /* that._dialog.getDialog().cfg.setProperty("buttons", [ { text:"Save", isDefault:true, type:"submit", handler: function() { that.save(); } }, { text:"Cancel", type: "cancel", handler: function() { that.close(); FIRSTCLASS.ui.skin.set(that.originalSkin); } } ]);*/ } }); } else { requestUrl = FIRSTCLASS.lang.ensureSlashUrl(that._config.baseUrl)+"__Resume?Templates=AboutCommunity&Title="+escape(that._config.title)+"&Icon="+that._config.icon+"&Quit=1"; if (that._config.prefsmode) { requestUrl += "&Mode=1"; } else { requestUrl += "&Mode=2"; } connManagerRequest = FIRSTCLASS.util.net.asyncRequest("GET", requestUrl, { success:function(response) { that._dialog.getDialog().setBody(response.responseText.replace("COMMUNITYTITLE", that._config.title)); that._dialog.getDialog().center(); that._dialog.getDialog().cfg.setProperty("buttons", that._defaultButtons); }, failure: function(response) { that._dialog.getDialog().setBody(response.responseText.replace("COMMUNITYTITLE", that._config.title)); that._dialog.getDialog().center(); that._dialog.getDialog().cfg.setProperty("buttons", that._defaultButtons); } }); } } }; FIRSTCLASS.apps.Workflows.AboutCommunity.prototype.save = function (callback) { var form = document.forms.CommunityEditForm; var that = this; FIRSTCLASS.util.net.doAsyncPost({form: form, upload: false, callbacks: { success:function(response) { window.setTimeout(function() { that.startWorkflow(false); if (callback && callback.success) { callback.success(); } }, 40); }, failure: function(response) { /* FIXME: sometimes we drop in here for some reason */ window.setTimeout(function() { that.startWorkflow(false); if (callback && callback.failure) { callback.failure(); } }, 40); } }}); /* YAHOO.util.Connect.setForm(form); FIRSTCLASS.util.net.asyncRequest("POST", form.action, { success:function(response) { window.setTimeout(function() { that.startWorkflow(false); if (callback && callback.success) { callback.success(); } }, 40); }, failure: function(response) { window.setTimeout(function() { that.startWorkflow(false); if (callback && callback.failure) { callback.failure(); } }, 40); } }); */ }; FIRSTCLASS.apps.Workflows.AboutCommunity.prototype.close = function () { this._dialog.hide(); this._dialog.destroy(); delete this._dialog; if (this._editor) { this._editor.destroy(); delete this._editor; } }; FIRSTCLASS.apps.Workflows.Tags = { }; FIRSTCLASS.apps.Workflows.Tags.reconfigure = function (config) { // config options: // personal: personal tag cloud // container: container tag cloud // domElement: dom element to draw into // itemtags: tags of the item // dataSource: dataSource to receive tag updates (optional) // row: row to update if hooked to a datasource (optional) // destField: form field to receive the tag data (optional alternative to ds/row) this.cleanup(); this._config = config; if (!config.personal) { config.personal = FIRSTCLASS.session.desktop.personaltags; } if (!config.container && FIRSTCLASS.session.getActiveApplication()._dataSource) { config.container = FIRSTCLASS.ui.parseServerTags(FIRSTCLASS.session.getActiveApplication()._dataSource.getTags()); } this._selectedTags = {}; this._availableTags = []; if (this._config.showonconfig) { this.drawWidget(); } }; FIRSTCLASS.apps.Workflows.Tags.getTags = function (plain) { // get the parsed tag string that the user selected var buf = [], i; for (i in this._selectedTags) { buf.push(i); } if (plain) { return buf.join(","); } else { return FIRSTCLASS.ui.tags.arrayToServerTags(buf); } }; FIRSTCLASS.apps.Workflows.Tags.getClickFunctionText = function(tag) { return "FIRSTCLASS.apps.Workflows.Tags.addTag(\"" + tag + "\");"; }; FIRSTCLASS.apps.Workflows.Tags.drawWidget = function () { // draw tagger var that = this, i; var ht = [ "
" ]; if (typeof this._config.editable === "undefined" || this._config.editable) { ht.push(""); ht.push(""); ht.push(" "); ht.push(""); ht.push("
" + FIRSTCLASS.locale.workflows.tags.main + "
" + FIRSTCLASS.locale.workflows.tags.click + "
"); if (this._config.personal || this._config.container) { var suggestedtags = FIRSTCLASS.ui.condenseTagClouds(this._config.personal, this._config.container); if (suggestedtags.length) { ht.push("
"); ht.push(FIRSTCLASS.ui.generateTagDisplayList(suggestedtags, "tag")); ht.push("" + FIRSTCLASS.locale.community.feed.more + ""); ht.push("" + FIRSTCLASS.locale.community.feed.less + ""); ht.push("
"); for (i in suggestedtags) { this._availableTags.push(suggestedtags[i].tag); } } } ht.push("
" + FIRSTCLASS.locale.workflows.tags.newtag + ""); ht.push(""); ht.push("
" + FIRSTCLASS.locale.workflows.tags.add + "
"); ht.push("
"); } ht.push("
"); this._config.domElement.innerHTML = ht.join(""); this._config.domElements = { selection: FIRSTCLASS.ui.Dom.getChildByClassName('fcSelectedTags', this._config.domElement), selected: FIRSTCLASS.ui.Dom.getChildByClassName('fcSelectedTags', this._config.domElement), autocontainer: FIRSTCLASS.ui.Dom.getChildByClassName('autocontainer', this._config.domElement), input: FIRSTCLASS.ui.Dom.getChildByClassName('fcTagInputBox', this._config.domElement), suggested: FIRSTCLASS.ui.Dom.getChildByClassName('suggested', this._config.domElement) //container: FIRSTCLASS.ui.Dom.getChildByClassName('container', this._config.domElement) }; for (i in this._config.item) { this.addTag(this._config.item[i].tag, true); } YAHOO.util.Event.addListener(this._config.domElements.input, 'keyup', this.handleTextInput); YAHOO.util.Event.addListener(this._config.domElement, "keyup", this.eatKeys); YAHOO.util.Event.addListener(this._config.domElement, "keydown", this.eatKeys); }; FIRSTCLASS.apps.Workflows.Tags.showAll = function() { if (this._config.domElements.suggested) { YAHOO.util.Dom.removeClass(this._config.domElements.suggested,'fcPartialCloud'); YAHOO.util.Dom.addClass(this._config.domElements.suggested,'fcFullCloud'); } }; FIRSTCLASS.apps.Workflows.Tags.showPartial = function() { if (this._config.domElements.suggested) { YAHOO.util.Dom.removeClass(this._config.domElements.suggested,'fcFullCloud'); YAHOO.util.Dom.addClass(this._config.domElements.suggested,'fcPartialCloud'); } }; FIRSTCLASS.apps.Workflows.Tags.handleTextInput = function(evt) { // if enter, parse the string into tags (comma separated) - if comma, put the tag in // check for enter(13), comman(188), period(190) if(evt.keyCode === 13 || evt.keyCode === 188) { /// || evt.keyCode == 190 period FIRSTCLASS.apps.Workflows.Tags._config.domElements.input.value = FIRSTCLASS.apps.Workflows.Tags._config.domElements.input.value.replace(/,/g,''); FIRSTCLASS.apps.Workflows.Tags.parseInputTags(); // enter or comma YAHOO.util.Event.stopEvent(evt); } YAHOO.util.Event.stopPropagation(evt); }; FIRSTCLASS.apps.Workflows.Tags.eatKeys = function(evt) { if (evt.keyCode === 13) { YAHOO.util.Event.stopEvent(evt); } YAHOO.util.Event.stopPropagation(evt); }; FIRSTCLASS.apps.Workflows.Tags.parseInputTags = function() { // strip commas from tag, they're a user interface control character var str = this._config.domElements.input.value; if (str !== "") { var tags = FIRSTCLASS.ui.parseServerTags(str+FIRSTCLASS.ui.tags.defines.separator), i; for (i in tags) { this.addTag(tags[i].tag.trim()); } this._config.domElements.input.value = ""; this._config.domElements.input.focus(); } }; FIRSTCLASS.apps.Workflows.Tags.removeTag = function (tag) { var el = this._selectedTags[tag]; if (el) { this._config.domElements.selection.removeChild(el); delete this._selectedTags[tag]; } var theTags = this.getTags(); if (this._config.dataSource && this._config.row) { this._config.dataSource.updateFieldData(this._config.row, [{id:8021, type:"STRING", value:theTags}]); var oldRow = {}; FIRSTCLASS.lang.deepCopyObjData(oldRow, this._config.row); this._config.row.tags = theTags; this._config.dataSource.notifyRowChanged(this._config.row, oldRow); /* add tags to container in-memory taglist (merge tag clouds) */ var mergecloud = FIRSTCLASS.ui.mergeTagClouds(FIRSTCLASS.ui.parseServerTags(theTags), FIRSTCLASS.ui.parseServerTags(this._config.dataSource.getTags())); var mergestr = FIRSTCLASS.ui.cloudToServerTags(mergecloud); this._config.dataSource.setTags(mergestr); } else if (this._config.destField) { /* embedded case */ this._config.destField.value = theTags; } var j = 0, i; for (i in this._selectedTags) { j++; } if (j === 0) { YAHOO.util.Dom.setStyle(this._config.domElements.selected, 'display', 'none'); } }; FIRSTCLASS.apps.Workflows.Tags.addTag = function (tag, suppress) { if (!this._selectedTags[tag] && tag !== "") { var ht = [ "" ]; if (typeof this._config.editable === "undefined" || this._config.editable) { ht.push(tag); ht.push(""); } else { ht.push(""); ht.push(tag); ht.push(""); } ht.push(""); var tmpdom = document.createElement("div"); tmpdom.innerHTML = ht.join(""); this._selectedTags[tag] = tmpdom.firstChild; this._config.domElements.selection.appendChild(tmpdom.firstChild); if (!suppress) { var theTags = this.getTags(); if (this._config.dataSource && this._config.row) { // standalone case - update the server and the ds using a "form" post var form = {}; var field = {}; form.elements = []; form.action = FIRSTCLASS.lang.ensureSlashUrl(this._config.dataSource.getContainerUrl()) + FIRSTCLASS.opCodes.FormSave; var row = FIRSTCLASS.lang.removeSlashUrl(this._config.row.uri); if (this._config.row.typedef.objtype === FIRSTCLASS.objTypes.file) { if (row.indexOf("FCItemURL=") > 0) { row = row.slice(row.indexOf("FCItemURL=") + 10); } } if (row.indexOf("?") > 0) { row = row.slice(0, row.indexOf("?")); } field.name = "Charset"; field.value = "UTF-8"; form.elements.push(field); /* send tag list */ field = {}; field.name = "LFieldID_8021." + row + "=STRING"; field.value = theTags; form.elements.push(field); /* post it */ FIRSTCLASS.util.submitForm(form); /* save tags and update row */ var oldRow = {}; FIRSTCLASS.lang.deepCopyObjData(oldRow, this._config.row); this._config.row.tags = theTags; this._config.dataSource.notifyRowChanged(this._config.row, oldRow); /* merge tags into container cloud */ var mergecloud = FIRSTCLASS.ui.mergeTagClouds(FIRSTCLASS.ui.parseServerTags(theTags), FIRSTCLASS.ui.parseServerTags(this._config.dataSource.getTags())); var mergestr = FIRSTCLASS.ui.cloudToServerTags(mergecloud); this._config.dataSource.setTags(mergestr); } else if (this._config.destField) { /* embedded case */ this._config.destField.value = theTags; } } if (this._config.handlers && this._config.handlers.onchange && !suppress) { this._config.handlers.onchange({newtag:tag, tags:this.getTags()}); } YAHOO.util.Dom.setStyle(this._config.domElements.selected, 'display', 'inline'); } }; FIRSTCLASS.apps.Workflows.Tags.cleanup = function() { if (this._config && this._config.domElement) { YAHOO.util.Event.purgeElement(this._config.domElement, true); this._config.domElement.innerHTML = ""; } this._config = false; }; /* upload document workflow * * - will use flash uploader if available * - can either create it's own YUI dialog or can be installed into a provided DIV * * config: * ds dataSource object * dsr optional row pointer - if present, the upload is an update to said row, and should be single-file * dlgBaseEl if requesting a dialog, base element for dialog (this one wins if both elements are set, otherwise just pick one) * contentEl if not requesting a dialog, container element for ui * enableMulti allow multi-file uploading if available * callbacks { * onUploadReady upload is/can be enabled * onUpload(oFileInfo, oResponse) successfully uploaded a file * onError(sError) file upload failed (if no callback, will post error alerts) * onComplete all uploads done * onCancel user cancelled * } * labels { button labels * upload * cancel * } */ FIRSTCLASS.apps.Workflows.uploadDocument = { initVars: function() { // flash related this._uploader = false; this._useFlash = FIRSTCLASS.flashdetector.hasFlash(); // if (YAHOO.env.ua.ie && (YAHOO.env.ua.ie < 8)) { // this._useFlash = false; // } this._ticket = false; // base state this._uploaderReady = false; this._uploadEnabled = false; this._isUploading = false; this._isUpdate = false; this._dupRow = false; this._displayState = false; // components/elements this._config = false; this._dialog = false; this._dialogEl = false; this._el = false; this._comment = false; this._tags = false; this._uploadForm = false; this._metaForm = false; this._fcount = false; this._bcount = false; this._status = false; // progress bar this._progressBar = false; this._progressTimer = false; this._totalBytes = false; this._progBytes = false; // file data this._fileList = []; this._fileIdx = false; }, reconfigure: function(config) { var that = this; this.cleanup(); this._config = config; this._isUpdate = (config.dsr && typeof config.dsr === "object"); if (this._config.dlgBaseEl) { // create the dialog this.openDialog(); this._dialog.setBody(this.getContent()); this._el = this._dialog.body; } else { this._config.contentEl.innerHTML = this.getContent(); this._el = this._config.contentEl; } // uploader controls this._uploadForm = FIRSTCLASS.ui.Dom.getChildByIdName('upload_browse', this._el); var action = FIRSTCLASS.lang.ensureSlashUrl(this._config.ds.getContainerUrl()) + FIRSTCLASS.opCodes.Attach; this._uploadForm.setAttribute("action", action); this._uploadForm.setAttribute("enctype", "multipart/form-data"); this._uploadForm.setAttribute("autocomplete", "off"); // conflict controls this._conflictForm = { form: FIRSTCLASS.ui.Dom.getChildByIdName('upload_conflict', this._el), prompt: FIRSTCLASS.ui.Dom.getChildByIdName('upload_conflict_prompt', this._el), rename: FIRSTCLASS.ui.Dom.getChildByIdName('upload_rename', this._el), newname: FIRSTCLASS.ui.Dom.getChildByIdName('upload_newname', this._el), update: FIRSTCLASS.ui.Dom.getChildByIdName('upload_update', this._el), skip: FIRSTCLASS.ui.Dom.getChildByIdName('upload_skip', this._el), proceed: FIRSTCLASS.ui.Dom.getChildByIdName('upload_conflict_proceed', this._el) }; var TBCfg = { domElement: this._conflictForm.proceed, buttons: [ { id: "fcUploadConflictProceed", label: FIRSTCLASS.locale.uploader.proceed, click: function(evt) { that.resolveUploadConflict(); } } ] }; this._conflictTB = new FIRSTCLASS.ui.toolBar(TBCfg); // callback object for duplicate check this._dupCallback = { // success - item already exists success: function(o) { if (o.responseJSON && o.responseJSON.records && o.responseJSON.records[0]) { that._dupRow = o.responseJSON.records[0]; that.displayUploadConflict(); } else { that.proceedWithUpload(); } }, // failure - name unique failure: function(o) { that.proceedWithUpload(); } }; // metadata controls this._metaForm = FIRSTCLASS.ui.Dom.getChildByIdName('upload_metadata', this._el); this._comment = FIRSTCLASS.ui.Dom.getChildByIdName('upload_meta_cmt', this._el); this._metaForm.setAttribute("autocomplete", "off"); // tagger controls var tagContainer = FIRSTCLASS.ui.Dom.getChildByIdName('fcTagger', this._el); this._tags = FIRSTCLASS.ui.Dom.getChildByIdName('fcTags', this._el); if (this._isUpdate && this._config.dsr.tags && (this._config.dsr.tags.length > 0)) { this._tags.value = this._config.dsr.tags; } this._tagcfg = { domElement: tagContainer, item: FIRSTCLASS.ui.parseServerTags(this._tags.value), hidesuggestions: true, destField: this._tags, showonconfig: true }; FIRSTCLASS.apps.Workflows.Tags.reconfigure(this._tagcfg); // status fields this._fcount = $('upload_nfiles'); this._bcount = $('upload_nbytes'); this._filename = $('upload_fname'); // progress bar var pbconfig = { anim: false, height: 8, width: 290, value: 0 }; this._progressBar = new YAHOO.widget.ProgressBar(pbconfig).render('upload_progress'); // on picker data change, initiate duplicate check if (this._useFlash) { this.initFlash(); } else { // hook up file select event YAHOO.util.Event.on('upload_choose', 'change', function(ev) { YAHOO.util.Event.stopEvent(ev); that.onFileSelect(ev); return false; }); } this.enableUpload(false); this.displayUploadStatus('initial'); }, getContent: function() { var html = []; var pickWidth = "56", descWidth = "71"; if (YAHOO.env.ua.mac && YAHOO.env.ua.gecko) { pickWidth = "42"; descWidth = "62"; } else if (YAHOO.env.ua.webkit) { descWidth = "54"; } // file input form html.push("
"); html.push("
"); html.push(""); html.push(""); html.push(""); if (this._useFlash) { html.push(""); html.push(""); html.push("
" + FIRSTCLASS.locale.uploader.file + ""); html.push("
"); html.push("
"); } else { html.push("
"); html.push(""); } html.push("
"); // sub-form for conflict resolution html.push("
"); html.push(""); html.push(""); html.push(""); html.push(""); html.push(""); html.push("
" + FIRSTCLASS.locale.uploader.rename); html.push("
" + FIRSTCLASS.locale.uploader.update + "
" + FIRSTCLASS.locale.uploader.skip + "
"); // sub-form for meta-data - description and tags html.push("
"); html.push(""); html.push(""); html.push("
"); if (this._isUpdate) { html.push(FIRSTCLASS.locale.uploader.notes); } else { html.push(FIRSTCLASS.locale.uploader.description); } html.push("
"); html.push("
"); return html.join(''); }, cleanup: function() { if (this._dialog) { this.closeDialog(); } if (this._progressBar) { this._progressBar.destroy(); } if (this._progressTimer) { window.clearInterval(this._progressTimer); } this.initVars(); }, openDialog: function() { var that = this; if (this._dialog) { this.closeDialog(); } this._dialogEl = document.createElement('div'); this._dialogEl.setAttribute('style', 'visibility:hidden'); this._dialogEl.setAttribute('id', 'fcDocsDialog'); this._config.dlgBaseEl.appendChild(this._dialogEl); // create the dialog var buttons = []; buttons.push({ text: (this._config.labels && this._config.labels.cancel) ? this._config.labels.cancel : FIRSTCLASS.locale.uploader.cancel, handler: function() { that.uploadCancel(); }, isDefault: true }); buttons.push({ text: (this._config.labels && this._config.labels.upload) ? this._config.labels.upload : FIRSTCLASS.locale.uploader.upload, handler: function() { that.uploadFiles(); }, isDefault: false, isDisabled: true }); this._dialog = new YAHOO.widget.Dialog('fcDocsDialog', { width: '500px', draggable: true, visible: false, constraintoviewport: true, postmethod: "none", close: false, hideaftersubmit: false, xy: [this._config.dlgBaseEl.offsetHeight / 2 - 100, this._config.dlgBaseEl.offsetWidth / 2 - 200], shim: (navigator.userAgent.toLowerCase().indexOf("msie") > -1), buttons: buttons, zIndex: 1000 }); this._dialog.setHeader(this._isUpdate ? FIRSTCLASS.locale.uploader.uptitle : FIRSTCLASS.locale.uploader.title); this._dialog.render(); this._dialog.show(); }, closeDialog: function() { if (this._dialog) { this._dialog.destroy(); this._dialog = false; } }, enableUpload: function(enable) { if (this._dialog) { var buttons = this._dialog.getButtons(), i; for (i in buttons) { if (typeof buttons[i] === 'object') { var button = buttons[i]; var label = button.get('label'); if (label === FIRSTCLASS.locale.uploader.upload) { if (enable) { button._button.removeAttribute("disabled"); button.removeStateCSSClasses("disabled"); button._button.setAttribute("default", "default"); button.addStateCSSClasses("default"); } else { button._button.setAttribute("disabled", "disabled"); button.addStateCSSClasses("disabled"); button._button.removeAttribute("default"); button.removeStateCSSClasses("default"); } } else if (label === FIRSTCLASS.locale.uploader.cancel) { if (enable) { button._button.removeAttribute("default", "default"); button.removeStateCSSClasses("default"); } else { button._button.setAttribute("default", "default"); button.addStateCSSClasses("default"); } } } } } if (enable) { this._uploadEnabled = true; if (this._config.callbacks && this._config.callbacks.onUploadReady) { this._config.callbacks.onUploadReady(); } this.displayUploadStatus('ready'); } }, // trap selection and enable upload onFileSelect: function(event) { this._fileList = []; var file; if (this._useFlash) { for (file in event.fileList) { event.fileList[file].name = FIRSTCLASS.lang.limitFilenameLength(event.fileList[file].name); this._fileList.push(event.fileList[file]); } } else { var names = FIRSTCLASS.lang.removeSlashUrl(this._uploadForm.Attachment.value), fileRec = {}; names = names.match(/[^\/\\]+$/); if (this._isUpdate) { fileRec.name = this._config.dsr.name; } else { fileRec.name = FIRSTCLASS.lang.limitFilenameLength(names[0]); } fileRec.id = 'singleton'; fileRec.size = 0; fileRec.loaded = 0; this._fileList.push(fileRec); } this._totalBytes = this._progBytes = 0; for (file in this._fileList) { if (this._fileList[file].size) { this._totalBytes += this._fileList[file].size; } } this.enableUpload(true); }, flashBacks: { onContentReady: function(event) { var doMulti = true; if (this._config.enableMulti === false) { doMulti = false; } if (this._isUpdate) { doMulti = false; } this._uploader.setAllowMultipleFiles(doMulti); this._uploaderReady = true; }, onUploadStart: function(event) { this._fileList[this._fileIdx].loaded = 0; this.displayUploadStatus('upload'); }, onUploadProgress: function(evt) { this._fileList[this._fileIdx].loaded = evt.bytesLoaded; this.displayUploadStatus('upload'); }, // call uploadComplete() on last of complete and completeData onUploadComplete: function(event) { var file = false; for (file in this._fileList) { if (this._fileList[file].id === event.id) { this._fileList[file].complete = true; if (this._fileList[file].data) { this.uploadComplete(); } break; } } }, // call uploadComplete() on last of complete and completeData onUploadCompleteData: function(event) { if (event.data) { var response = {}; try { response = FIRSTCLASS.lang.JSON.parse(event.data); } catch (e) { } var file = false; for (file in this._fileList) { if (this._fileList[file].id === event.id) { this._fileList[file].response = response; if (this._fileList[file].complete) { this.uploadComplete(); } break; } } } }, onUploadError: function(event) { // skip status display if return code is a non-messageable one from Flash if (typeof event.status !== "number" || event.status < 200 || event.status > 400) { this.displayUploadStatus('error'); } this.uploadComplete(); } }, initFlash: function() { YAHOO.widget.Uploader.SWFURL = FIRSTCLASS.session.domain + FIRSTCLASS.session.templatebase + "/" + FIRSTCLASS.session.ui.yuifolder + "/build/uploader/assets/uploader.swf"; this._uploader = new YAHOO.widget.Uploader('uploadOverlay', FIRSTCLASS.session.ui.fcbase.absolute + '/sprites/BROWSE-button-states.png', true); this._uploader.addListener('contentReady', this.flashBacks.onContentReady, this, true); this._uploader.addListener('fileSelect', this.onFileSelect, this, true); this._uploader.addListener('uploadStart', this.flashBacks.onUploadStart, this, true); this._uploader.addListener('uploadProgress', this.flashBacks.onUploadProgress, this, true); this._uploader.addListener('uploadCancel', this.uploadCancel, this, true); this._uploader.addListener('uploadComplete', this.flashBacks.onUploadComplete, this, true); this._uploader.addListener('uploadCompleteData', this.flashBacks.onUploadCompleteData, this, true); this._uploader.addListener('uploadError', this.flashBacks.onUploadError, this, true); }, // Called in response to uploadComplete (flash), uploadCompleteData(flash) or any non-flash response // Response data already stored in fileList object for current file. Calls onUpload callback. uploadComplete: function() { var that = this; // function to handle upload sequence var nextUpload = function() { if (that._config.callbacks && that._config.callbacks.onUpload) { that._config.callbacks.onUpload(that._fileList[that._fileIdx]); } that._fileIdx++; if (that._fileIdx < that._fileList.length) { that.driveUpload(); } else { that.displayUploadStatus('done'); if (that._config.callbacks && that._config.callbacks.onComplete) { that._config.callbacks.onComplete(); } that.cleanup(); } }; var metacb = { success: function() { nextUpload(); }, failure: function() { if (that._config.callbacks && that._config.callbacks.onError) { that._config.callbacks.onError(FIRSTCLASS.locale.uploader.errors.meta); } else { alert(FIRSTCLASS.locale.uploader.errors.meta); } nextUpload(); } }; this.postMetadata(metacb); }, uploadCancel: function() { if (this._useFlash) { if (this._uploaderReady) { this._uploader.cancel(); } } if (this._dialog) { this.closeDialog(); } if (this._config.callbacks && this._config.callbacks.onCancel) { this._config.callbacks.onCancel(); } this.cleanup(); }, // callback: { success(), failure() } postMetadata: function(callback) { if ((this._comment.value !== "") || (this._tags.value !== "")) { var url = FIRSTCLASS.lang.ensureSlashUrl(this._config.ds.getContainerUrl()) + FIRSTCLASS.opCodes.FormSave; this._metaForm.setAttribute("action",url); this._metaForm.setAttribute("enctype","multipart/form-data"); var itemSpec = this._fileList[this._fileIdx].name; if (this._config.dsr && this._config.dsr.threadid) { itemSpec = "TD-" + this._config.dsr.threadid; } else if (this._dupRow && this._dupRow.threadid) { itemSpec = "TD-" + this._dupRow.threadid; } if (this._tags.value !== "") { this._tags.setAttribute("name",'LFieldID:8021."' + itemSpec + '"=STRING'); } else { this._tags.setAttribute("name",""); } if (this._comment.value !== "") { this._comment.setAttribute("name",'LFieldID:8101."' + itemSpec + '"=LITERALSTRING'); } else { this._comment.setAttribute("name",""); } var form = { elements: [this._tags, this._comment] }; FIRSTCLASS.util.net.doAsyncPost({form: form, action:url, upload: false, callbacks: callback}); } else if (typeof callback.success === 'function') { callback.success(); } }, // upload the current file from the file list uploadAFile: function() { var that = this, action = this._uploadForm.action; if (this._useFlash) { var paramStr = action.indexOf("?")>=0 ? "&" : "?"; paramStr +="Templates=JS&Close=1"; if (this._ticket) { paramStr += "&SKey="+this._ticket; } var vkey = this._fileList[this._fileIdx].vkey; if (vkey) { paramStr += "&VKey=" + vkey; } action += encodeURI(paramStr); var vars = { Charset: 'UTF-8', AttName: this._isUpdate ? this._config.dsr.name : this._fileList[this._fileIdx].name, AttOptions: 'WRAP' }; this._uploader.upload(this._fileList[this._fileIdx].id, action, "POST", vars, 'Attachment'); } else { // fake up a progress indicator this.displayUploadStatus('upload'); var val = 0; this._progressTimer = window.setInterval(function() { if (that._progressBar) { if (val < 100) { val += 5; that._progressBar.set('value',val); that._progressBar.redraw(); } else { window.clearInterval(that._progressTimer); that._progressTimer = false; } } }, 1000); // set attach name field this._uploadForm.AttName.value = this._fileList[this._fileIdx].name; action = this._uploadForm.action + "?Templates=JS"; this._uploadForm.action = action; var callback = { success: function(obj) { this.upload(obj); }, upload: function(obj) { if (obj && obj.responseText) { var o = {}; try { o = FIRSTCLASS.lang.JSON.parse(obj.responseText); } catch (e) { } if (o && o.httpcode && o.httpcode >= 400) { this.failure(); return; } that._fileList[that._fileIdx].response = o; that._fileList[that._fileIdx].complete = true; that.uploadComplete(); } }, failure: function(obj) { if (that._config.callbacks && that._config.callbacks.onError) { that._config.callbacks.onError(FIRSTCLASS.locale.uploader.errors.file); } else { alert(FIRSTCLASS.locale.uploader.errors.file); } that._fileList[that._fileIdx].response = false; that._fileList[that._fileIdx].complete = false; that.uploadComplete(); }, abort: function(evt) { this.failure(); } }; // do the upload var conn = FIRSTCLASS.util.submitForm(this._uploadForm, true, callback); } }, proceedWithUpload: function() { // on to the next step if (FIRSTCLASS.session.server.requiresvkeys) { this.getVKeyAndUpload(); } else { this.uploadAFile(); } }, // get vkey and proceed to upload getVKeyAndUpload: function() { var that = this, vkeycb = function(vkey) { that._fileList[that._fileIdx].vkey = vkey; that.uploadAFile(); }; FIRSTCLASS.util.net.getVKey(vkeycb); }, // display a form to help the user resolve an upload name conflict displayUploadConflict: function() { // format the prompt string var conStr = FIRSTCLASS.locale.uploader.dup; conStr = conStr.replace("^1",this._fileList[this._fileIdx].name); conStr = conStr.replace("^2",this._config.ds._data.name); this._conflictForm.prompt.innerHTML = conStr; // pre-fill new name var newName = FIRSTCLASS.lang.createFilenameVariant(this._fileList[this._fileIdx].name); this._conflictForm.newname.value = newName; // show the form YAHOO.util.Dom.removeClass(this._conflictForm.form, 'fcHidden'); }, // take requested action to resolve upload name conflict resolveUploadConflict: function() { if (this._conflictForm.rename.checked) { // back around the loop with a new name var newName = this._conflictForm.newname.value; this._fileList[this._fileIdx].name = newName; this.testForDuplicateName(newName); } else if (this._conflictForm.update.checked) { // just leave the name this.proceedWithUpload(); } else if (this._conflictForm.skip.checked) { // skip it this.uploadComplete(); } YAHOO.util.Dom.addClass(this._conflictForm.form, 'fcHidden'); }, // test if file exists and choose a callback testForDuplicateName: function(name) { var url = FIRSTCLASS.lang.ensureSlashUrl(this._config.ds.getContainerUrl()); url += "?Templates=JS&JSON=2&Show=0&Files=1&ColFilter=8010_(" + name + ")"; var connObj = FIRSTCLASS.util.net.asyncRequest('GET',url,this._dupCallback); }, // function to initiate upload sequence for a file driveUpload: function() { if (this._fileList[this._fileIdx].id) { // test for duplicates if (this._isUpdate) { this.proceedWithUpload(); } else { this.testForDuplicateName(this._fileList[this._fileIdx].name); } } }, uploadFiles: function() { var that = this; // block re-entry if (this._isUploading) { return; } this._isUploading = true; this._fileIdx = 0; this._ticket = YAHOO.util.Cookie.get('fcisac'); this.driveUpload(); }, /* refresh uploader status display * states: initial - prompt user to pick a file * ready - file(s) selected * upload - update display from state of current file * error - display an error message * done - all done */ displayUploadStatus: function(newState, errmsg) { switch (newState) { case 'initial': // initial - set prompt if (!this._useFlash) { YAHOO.util.Dom.addClass(this._fcount, 'fcHidden'); YAHOO.util.Dom.addClass(this._bcount, 'fcHidden'); YAHOO.util.Dom.addClass($('upload_pb'), 'fcHidden'); YAHOO.util.Dom.addClass(this._filename, 'fcHidden'); YAHOO.util.Dom.removeClass($('upload_choose'),'fcHidden'); } this._fcount.innerHTML = FIRSTCLASS.locale.uploader.choose; this._bcount.innerHTML = ''; this._filename.innerHTML = ''; this._progressBar.set('value', 0); this._progressBar.redraw(); break; case 'ready': // ready - display file count if (this._fileList.length > 0) { var statstr = FIRSTCLASS.locale.uploader.count.doSub([this._fileList.length]); this._fcount.innerHTML = statstr; } this._bcount.innerHTML = ''; this._filename.innerHTML = this._fileList[0].name + (this._fileList.length > 1 ? ',...' : ''); this._progressBar.set('value', 0); this._progressBar.redraw(); break; case 'upload': // upload - set fill, byte count, file count and filename if ((this._displayState !== 'upload') && (!this._useFlash)) { // show hidden fields, hide file picker YAHOO.util.Dom.removeClass(this._fcount, 'fcHidden'); YAHOO.util.Dom.removeClass($('upload_pb'), 'fcHidden'); YAHOO.util.Dom.removeClass(this._filename, 'fcHidden'); YAHOO.util.Dom.addClass($('upload_choose'), 'fcHidden'); if (this._progressBar) { this._progressBar.set('width','392px'); } } this._progBytes = 0; var file; for (file in this._fileList) { if (this._fileList[file].loaded) { this._progBytes += this._fileList[file].loaded; } } var info = this._fileList[this._fileIdx]; if (info) { this._fcount.innerHTML = 'Uploading file ' + (this._fileIdx + 1) + ' of ' + this._fileList.length; this._bcount.innerHTML = FIRSTCLASS.util.Display.getFileSizeString(this._progBytes) + ' / ' + FIRSTCLASS.util.Display.getFileSizeString(this._totalBytes); this._filename.innerHTML = info.name; this._progressBar.set('value', 100.0 * (this._progBytes/this._totalBytes)); this._progressBar.redraw(); } break; case 'error': // error - display message this._fcount.innerHTML = errmsg ? errmsg : 'Error uploading files.'; break; case 'done': this._fcount.innerHTML = 'All uploads complete.'; this._bcount.innerHTML = ''; this._filename.innerHTML = ''; this._progressBar.set('value', 100); this._progressBar.redraw(); break; } this._displayState = newState; } }; FIRSTCLASS.apps.Workflows.SendTo = {}; FIRSTCLASS.apps.Workflows.SendTo.draw = function(config) { this.start(config); }; FIRSTCLASS.apps.Workflows.SendTo.start = function(config) { var repository, i; if (!FIRSTCLASS.apps.Integration._isInitialized) { // do init first FIRSTCLASS.apps.Integration._onInit.push({func: FIRSTCLASS.apps.Workflows.SendTo.start, config:config}); FIRSTCLASS.apps.Integration.init(); } else { if (FIRSTCLASS.apps.Workflows.SendTo._menu) { FIRSTCLASS.apps.Workflows.SendTo._menu.destroy(); } FIRSTCLASS.apps.Workflows.SendTo._menu = new YAHOO.widget.Menu('fcDropDownMenu', {xy: config.xy}); FIRSTCLASS.apps.Workflows.SendTo._currentConfig = config; var menu = FIRSTCLASS.apps.Workflows.SendTo._menu; var items = []; var handled = false; var repositories = FIRSTCLASS.apps.Integration.getRepositories(); var row = config.row; /** FIXME: MAKING UP FOR JEFF's INADEQUACIES in CS1 demo, this is CRAP **/ if (!row.linkinfo) { var rows = config.dataSource.query("threadid", row.threadid, false, false); for (i = 0; i < rows.length; i++) { if (rows[i][1].linkinfo) { row = rows[i][1]; break; } } } if (row.linkinfo && !config.row.linkinfo) { config.row.linkinfo = row.linkinfo; } if (config.row.linkinfo) { repository = false; for (i in repositories) { if (repositories[i].name === config.row.linkinfo.repository) { repository = i; break; } } if (repository) { handled = FIRSTCLASS.apps.Workflows.SendTo.sendTo("click", false, {type:"ECM", repository:repository, row:config.row, direct: true}); } } if (!handled) { if ((config.row.typedef.objtype === FIRSTCLASS.objTypes.odocument && config.row.lformid === FIRSTCLASS.formids.filewrapper) || config.row.typedef.objtype === FIRSTCLASS.objTypes.file) { var ritems = []; for (i in repositories) { repository = repositories[i]; if (repository.capabilities.saveto) { ritems.push({ text:repository.name, onclick: { fn:FIRSTCLASS.apps.Workflows.SendTo.sendTo, obj: {type:"ECM", repository:i, row:config.row} } }); } } if (ritems.length) { items.push(ritems); } } menu.addItems(items); menu.render(document.body); menu.show(); menu.focus(); } } }; FIRSTCLASS.apps.Workflows.SendTo.sendTo = function(type, event, object) { if (type === "click") { if (object.type.indexOf("ECM") === 0) { var repositories = FIRSTCLASS.apps.Integration.getRepositories(); var repository = repositories[object.repository]; var xuid = ""; var reserved = false; if (object.direct) { if (!repository) { return false; } xuid = object.row.linkinfo.xuid; reserved = object.row.linkinfo.lRepositoryReserved; } FIRSTCLASS.apps.Integration.ECM.Browse.doBrowse({ 'xuid':xuid, 'title':FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.workflows.sendto.ecmtitle, {name: object.row.name, repository: repository.name}), showleaves: false, fname:object.row.name, community:FIRSTCLASS.apps.Workflows.SendTo._currentConfig.community, mode:"sendto", repository:repository.name, reserved: reserved}); } else if (object.type.indexOf("email") === 0) { // open form, attach document FIRSTCLASS.apps.Workflows.SendTo.doEmailNoDlg(object); } else if (object.type.indexOf("document") === 0) { // open form, attach document FIRSTCLASS.apps.Workflows.SendTo.doEmailNoDlg(object); } else if (object.type.indexOf("community") === 0) { // copy FIRSTCLASS.apps.Workflows.SendTo.doEmailNoDlg(object); // FIRSTCLASS.apps.Workflows.SendTo.doCopy(object); } else if (object.type.indexOf("blog") === 0) { // make blog post //FIRSTCLASS.apps.Workflows.SendTo.doBlog(object); FIRSTCLASS.apps.Workflows.SendTo.doEmailNoDlg(object); } // else do something else } return true; }; FIRSTCLASS.apps.Workflows.SendTo.doEmail = function(object) { var baseurl = false; FIRSTCLASS.apps.Workflows.SendTo._email = {object: object}; var callback = false; switch (object.row.typedef.objtype) { case FIRSTCLASS.objTypes.message: case FIRSTCLASS.objTypes.confitem: // forward message baseurl = FIRSTCLASS.lang.ensureSlashUrl(this._currentConfig.dataSource.getItemUrl(object.row, true, false))+FIRSTCLASS.opCodes.Forward+"?FormID=141&Templates=SendTo"; callback = FIRSTCLASS.apps.Workflows.SendTo.doSendCB; break; /* case FIRSTCLASS.objTypes.odocument: case FIRSTCLASS.objTypes.form: case FIRSTCLASS.objTypes.fcfile: */ default: // create new message and attach // donewmessage baseurl = FIRSTCLASS.session.baseURL + "__Open-Item/Mailbox/__Send?FormID=141&Templates=SendTo&InitialText="; callback = FIRSTCLASS.apps.Workflows.SendTo.doAttachCB; } var domElem = document.createElement("div"); FIRSTCLASS.apps.Workflows.SendTo._email.domElem = domElem; FIRSTCLASS.apps.Workflows.SendTo._email.dialog = new FIRSTCLASS.apps.FormDialog({ baseUrl: baseurl, domElement:domElem, owner: FIRSTCLASS.apps.Workflows.SendTo, title:FIRSTCLASS.locale.workflows.sendto.email.title,//"Send to Email", /* buttons: [ { text:FIRSTCLASS.locale.workflows.sendto.email.send, isDefault:true, type:"submit" }, { text:FIRSTCLASS.locale.workflows.sendto.email.cancel, type:"cancel" } ], */ submit: FIRSTCLASS.apps.Workflows.SendTo.doSendSaveCB, cancel: FIRSTCLASS.apps.Workflows.SendTo.doSendCancelCB, hide: FIRSTCLASS.apps.Workflows.SendTo.doSendCancelCB, width:"540px", onDomInserted:callback, hideaftersubmit: false, hideaftercancel: false }); }; FIRSTCLASS.apps.Workflows.SendTo.doAttachCB = function() { // initialize editor, do copy YAHOO.util.Dom.removeClass(FIRSTCLASS.apps.Workflows.SendTo._email.dialog.mySimpleDialog.element, 'yui-dialog'); var domElem = FIRSTCLASS.apps.Workflows.SendTo._email.domElem; var form = domElem.firstChild; var object = { row: FIRSTCLASS.apps.Workflows.SendTo._email.object.row, to: form.getAttribute('fcUrl'),// url to message callbacks: { success: FIRSTCLASS.apps.Workflows.SendTo.doSendAttachDoneCB } }; FIRSTCLASS.apps.Workflows.SendTo.doSendCB(function() { FIRSTCLASS.apps.Workflows.SendTo.doCopy(object); }); }; FIRSTCLASS.apps.Workflows.SendTo.doSendAttachDoneCB = function() { var domElem = FIRSTCLASS.apps.Workflows.SendTo._email.domElem; var attlist = FIRSTCLASS.ui.Dom.getChildByIdName('fcAttachmentContainer', domElem); if (attlist) { var iconid = FIRSTCLASS.util.Display.getIconID(FIRSTCLASS.apps.Workflows.SendTo._email.object.row.name); attlist.innerHTML = "
 " + FIRSTCLASS.apps.Workflows.SendTo._email.object.row.name + "
"; YAHOO.util.Dom.setStyle(attlist.parentNode, 'display',''); YAHOO.util.Dom.setStyle(attlist.parentNode.previousSibling, 'display',''); } var subject = FIRSTCLASS.ui.Dom.getChildByIdName('fcDocSubject', domElem); if (subject) { subject.value = FIRSTCLASS.apps.Workflows.SendTo._email.object.row.name; } if (FIRSTCLASS.apps.Workflows.SendTo._currentConfig.permalink) { var permalink = FIRSTCLASS.session.baseURL + FIRSTCLASS.apps.Workflows.SendTo._currentConfig.permalink + "'>"+FIRSTCLASS.locale.workflows.sendto.email.permalink+""; //FIRSTCLASS.apps.Workflows.SendTo._email.message.insertHTML(permalink); } }; FIRSTCLASS.apps.Workflows.SendTo.doSendDoneCB = function() { // FIRSTCLASS.apps.Workflows.SendTo._email.domElem.firstChild.elements["ValidateTo"].focus(); FIRSTCLASS.apps.Workflows.SendTo._email.message.destroy(); if (FIRSTCLASS.apps.Workflows.SendTo._currentConfig.emailDoneCB) { FIRSTCLASS.apps.Workflows.SendTo._currentConfig.emailDoneCB(); } // FIRSTCLASS.apps.Workflows.SendTo._email.dialog.destroy(); }; FIRSTCLASS.apps.Workflows.SendTo.doSendCancelCB = function() { try { $('fcSearchInput').focus(); $('fcSearchInput').blur(); } catch(e) { } FIRSTCLASS.apps.Workflows.SendTo._email.message.onCancel(); FIRSTCLASS.apps.Workflows.SendTo._email.message.destroy(); }; FIRSTCLASS.apps.Workflows.SendTo.doSendSaveCB = function() { try { $('fcSearchInput').focus(); $('fcSearchInput').blur(); } catch(e) { } FIRSTCLASS.apps.Workflows.SendTo._email.message.onSubmit(false, { onSave: function(response) { FIRSTCLASS.apps.Workflows.SendTo._email.message.destroy(); }, onFail: function(response) { //debugger; } }); }; FIRSTCLASS.apps.Workflows.SendTo.doSendValidateCB = function(updateBody) { var fakeBody = document.getElementById('fakeBody'); var realBody = document.getElementById('BODY'); if (fakeBody && realBody) { realBody.value = fakeBody.value + "\n\n" + realBody.value + "\n\n" + FIRSTCLASS.languages.en.workflows.sendto.email.permalink + ": " + FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.domain + FIRSTCLASS.session.baseURL) + FIRSTCLASS.apps.Workflows.SendTo._currentConfig.permalink + ""; fakeBody.value = ""; } return (FIRSTCLASS.apps.Workflows.SendTo._email.message._validatedNames.length > 0); }; FIRSTCLASS.apps.Workflows.SendTo.doSendNameValidateCB = function() { var sendBtn = document.getElementById('fcDocFormSave'); if (sendBtn !== null) { if (FIRSTCLASS.apps.Workflows.SendTo._email.message._validatedNames.length > 0) { YAHOO.util.Dom.setStyle(sendBtn,'color',''); // FIRSTCLASS.apps.Workflows.SendTo._email.dialog.getButtons()[0].set('disabled', false); } else { YAHOO.util.Dom.setStyle(sendBtn,'color','#bbbbbb'); // FIRSTCLASS.apps.Workflows.SendTo._email.dialog.getButtons()[0].set('disabled', true); } } }; FIRSTCLASS.apps.Workflows.SendTo.doSendCB = function(onloaded) { // YAHOO.util.Dom.removeClass(FIRSTCLASS.apps.Workflows.SendTo._email.dialog.mySimpleDialog.element, 'yui-dialog'); // FIRSTCLASS.apps.Workflows.SendTo._email.dialog.getButtons()[0].set('disabled', true); var domElem = FIRSTCLASS.apps.Workflows.SendTo._email.domElem; var form = domElem.firstChild; YAHOO.util.Dom.addClass(domElem, 'fcSendToEmail'); var url = form.getAttribute('fcUrl'); if (!onloaded) { onloaded = function() { //FIRSTCLASS.apps.Workflows.SendTo._email.message.insertQuote(false, FIRSTCLASS.apps.Workflows.SendTo._email.object.row.name); }; } var msgCfg = { callback: { onCancel: FIRSTCLASS.apps.Workflows.SendTo.doSendDoneCB, onSave: FIRSTCLASS.apps.Workflows.SendTo.doSendDoneCB, validate: FIRSTCLASS.apps.Workflows.SendTo.doSendValidateCB, onLoaded: onloaded, onNameValidate: FIRSTCLASS.apps.Workflows.SendTo.doSendNameValidateCB }, element: domElem, op: "", params: "Templates=SendTo&InitialText=", baseURL: url, objType: FIRSTCLASS.objTypes.message, formID: 141, formElId: "fcDocForm", bodyType: "PLAIN", quoteText: null, sendTo: null, tbType: "sendto", initHeight: "240px", autoHeight: false, showAddr: true, nvoptions: 28, overrideForms: "&Templates=SendTo" }; FIRSTCLASS.apps.Workflows.SendTo._email.message = new FIRSTCLASS.util.Message(msgCfg); }; FIRSTCLASS.apps.Workflows.SendTo.doBlog = function(object) { // docopy with coercion /* this._currentConfig.dataSource.fetchItem(object.row, { completed: FIRSTCLASS.apps.Workflows.SendTo.doBlogPostCB });*/ }; FIRSTCLASS.apps.Workflows.SendTo.doBlogPostCB = function(row) { if (row && row.itemdata.expandedBody) { var name = row.col14; if (!row.col14) { name = row.col8010; } var html = ["
", "", "", "", "", ""]; var tmpdom = document.createElement("div"); tmpdom.innerHTML = html.join(""); /* YAHOO.util.Connect.setForm(tmpdom.firstChild); FIRSTCLASS.util.net.asyncRequest("POST", tmpdom.firstChild.action);*/ FIRSTCLASS.util.net.doAsyncPost({form: tmpdom.firstChild, upload: false}); } }; FIRSTCLASS.apps.Workflows.SendTo.doCopy = function(object) { var itemuri = FIRSTCLASS.lang.ensureSlashUrl(object.row.uri); if (itemuri.indexOf("FCItemURL=") >= 0) { itemuri = itemuri.substr(itemuri.indexOf("FCItemURL=")+10); } var to = ""; if (object.to) { to = object.to; } else if (object.community && object.community.uri) { if (object.baseurl) { to = FIRSTCLASS.lang.ensureSlashUrl(object.baseurl) + object.community.uri; } else { to = FIRSTCLASS.session.baseURL + object.community.uri; } } /*else { debugger; } */ var theURI = FIRSTCLASS.lang.ensureSlashUrl((this._currentConfig) ? this._currentConfig.community.uri : object.fromURI); var html = ["", "", "", "", ""]; var tmpdom = document.createElement("div"); tmpdom.innerHTML = html.join(""); FIRSTCLASS.util.net.doAsyncPost({form: tmpdom.firstChild, upload: false, callbacks: object.callbacks}); }; FIRSTCLASS.apps.Workflows.MemberList = { init: function(communityuri, canedit) { if (!FIRSTCLASS.apps.Workflows.MemberList._rowTemplate) { FIRSTCLASS.apps.Workflows.MemberList._rowTemplate = document.createElement("div"); FIRSTCLASS.apps.Workflows.MemberList._rowTemplate.innerHTML = "" + "" + "" + "" + "" + "" + "
"; } FIRSTCLASS.apps.Workflows.MemberList._communityuri = FIRSTCLASS.lang.ensureSlashUrl(communityuri); if (FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource) { FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource.dispose(); FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource = false; } FIRSTCLASS.apps.Workflows.MemberList._initialized = true; }, cleanup: function() { if (FIRSTCLASS.apps.Workflows.MemberList._initialized === true) { if (typeof FIRSTCLASS.apps.Workflows.MemberList._dialog === "object") { FIRSTCLASS.apps.Workflows.MemberList._dialog.hide(); FIRSTCLASS.apps.Workflows.MemberList._dialog.destroy(); FIRSTCLASS.apps.Workflows.MemberList._dialog = false; } FIRSTCLASS.apps.Workflows.MemberList._ACL = null; if (typeof FIRSTCLASS.apps.Workflows.MemberList._listView === "object") { FIRSTCLASS.apps.Workflows.MemberList._listView.dispose(); FIRSTCLASS.apps.Workflows.MemberList._listView = false; } if (typeof FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource === "object") { FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource.dispose(); FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource = false; } FIRSTCLASS.apps.Workflows.MemberList._canedit = false; FIRSTCLASS.apps.Workflows.MemberList._initialized = false; } }, doShow: function(communityuri, canedit, externalonly, creatorcid) { FIRSTCLASS.apps.Workflows.MemberList._canedit = canedit; FIRSTCLASS.apps.Workflows.MemberList._externalonly = externalonly; FIRSTCLASS.apps.Workflows.MemberList._creatorcid = creatorcid; // show a dialog with a members list, merged with the ACL FIRSTCLASS.apps.Workflows.MemberList.init(communityuri, canedit); // get members list var membersurl = FIRSTCLASS.lang.ensureSlashUrl(communityuri) + "__ListSubscribers"; var cfg = { containerBaseUrl:membersurl, itemrequest: false, loadFull: true }; FIRSTCLASS.apps.Workflows.MemberList.communityuri = FIRSTCLASS.lang.ensureSlashUrl(communityuri); FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource = new FIRSTCLASS.util.DataSource(cfg); //FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource.addRowListener(FIRSTCLASS.apps.Workflows.MemberList); // get acl and augment the datasource rows if (FIRSTCLASS.apps.Workflows.MemberList._ACL) { FIRSTCLASS.apps.Workflows.MemberList._ACL = null; } // show the dialog with loading... in it var domElem = document.createElement("div"); this._dialog = new FIRSTCLASS.apps.FormDialog({ baseUrl: FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL)+"__MemForm?FormID=12103&Templates=MemberList", domElement:domElem, owner: this, title: FIRSTCLASS.locale.workflows.memberlist.title, buttons: [ { text:FIRSTCLASS.locale.workflows.memberlist.close, isDefault:true, type:"submit" } ], submit: FIRSTCLASS.apps.Workflows.MemberList.cleanup, hide: FIRSTCLASS.apps.Workflows.MemberList.cleanup, onDomInserted: function() { FIRSTCLASS.apps.Workflows.MemberList.requestACL(); FIRSTCLASS.apps.Workflows.MemberList._elements = { wait: FIRSTCLASS.ui.Dom.getChildByClassName("fcMemberListWaitContainer", domElem), list: FIRSTCLASS.ui.Dom.getChildByClassName("fcMemberListContainer", domElem), frm: FIRSTCLASS.ui.Dom.getChildByClassName("fcMemberListForm", domElem) }; FIRSTCLASS.apps.Workflows.MemberList._dialog.getDialog().cfg.setProperty('close', false); }, hideaftersubmit: false, hideaftercancel: false }); }, reload: function() { FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource.reFill(); }, onRow: function(row) { }, onRowDeleted: function(row) { }, fillFinished: function() { // if (FIRSTCLASS.apps.Workflows.MemberList._ACL }, requestACL: function(enableonreceived, callback) { var aclurl = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.apps.Workflows.MemberList.communityuri) + "__ACL?Templates=JS&JSON=2&NS=1"; FIRSTCLASS.util.net.asyncRequest('GET', aclurl, { enableonreceived: enableonreceived, callback: callback, success: FIRSTCLASS.apps.Workflows.MemberList.onACLReceived, failure: FIRSTCLASS.apps.Workflows.MemberList.onACLFailure }); }, onACLReceived: function(response) { try { FIRSTCLASS.apps.Workflows.MemberList._ACL = FIRSTCLASS.lang.JSON.parse(response.responseText); } catch (e) { // there was an error in the json } /*var data = FIRSTCLASS.apps.Workflows.MemberList._ACL; if (data.records) { for (var i in data.records) { // do something } }*/ // show the members list now if (!FIRSTCLASS.apps.Workflows.MemberList._listView) { var lvcfg = { noHover: true, domElement: FIRSTCLASS.apps.Workflows.MemberList._elements.list, dataSource: FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource, threading: { format: FIRSTCLASS.layout.ThreadHandler.types.NONE }, rowHandler: FIRSTCLASS.apps.Workflows.MemberList, rowFilter: function(row) { if (FIRSTCLASS.apps.Workflows.MemberList._externalonly) { return row.userclass === 5; } else { return true; } }, onFillFinished: function() { FIRSTCLASS.apps.Workflows.MemberList._dialog.getDialog().center(); } }; YAHOO.util.Dom.setStyle(FIRSTCLASS.apps.Workflows.MemberList._elements.wait, 'display', 'none'); FIRSTCLASS.apps.Workflows.MemberList._listView = new FIRSTCLASS.layout.ListView(lvcfg); } if (this.enableonreceived) { FIRSTCLASS.apps.Workflows.MemberList.enableAfterSaving(); } if (this.callback) { this.callback(); } }, onACLFailure: function(response) { YAHOO.util.Dom.setStyle(FIRSTCLASS.apps.Workflows.MemberList._elements.wait, 'display', 'none'); FIRSTCLASS.apps.Workflows.MemberList._elements.list.innerHTML = FIRSTCLASS.locale.workflows.memberlist.errors.failure; FIRSTCLASS.apps.Workflows.MemberList.enableAfterSaving(); if (this.callback) { this.callback(); } }, getButtons: function() { if(!this._buttons) { this._buttons = FIRSTCLASS.apps.Workflows.MemberList._dialog.getButtons(); } return this._buttons; }, deleteMember: function(cid, acl, subscription, overridedisabled) { if (this._disabled && !overridedisabled) { return; } FIRSTCLASS.apps.Workflows.MemberList.disableWhileSaving(); // issue a delete to the acl if the user exists there var aclurl = FIRSTCLASS.lang.ensureSlashUrl(this.communityuri) + "__ACL"; var subscribersurl = FIRSTCLASS.lang.ensureSlashUrl(this.communityuri) + "__ListSubscribers"; var data = FIRSTCLASS.apps.Workflows.MemberList._ACL; var found = false, i; for (i in data.records) { if (data.records[i].cid === cid) { found = i; break; } } if (typeof subscription === "undefined" || subscription) { var r = false; for (i in FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource._data.records) { r = FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource._data.records[i]; if (r.uid === cid) { r.status.deleted = true; FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource.notifyRowDeleted(r); } } } if (typeof acl === "undefined" || acl) { FIRSTCLASS.util.Form.deleteName(aclurl, 9, found, cid, FIRSTCLASS.apps.Workflows.MemberList.deleteMemberCB); } if (typeof subscription === "undefined" || subscription) { FIRSTCLASS.util.Form.deleteName(subscribersurl, 11, false, cid, FIRSTCLASS.apps.Workflows.MemberList.deleteMemberCB); } }, deleteMemberCB: { onComplete: function() { FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource.reFill(); FIRSTCLASS.apps.Workflows.MemberList.requestACL(true); }, onFailure: function() { FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource.reFill(); FIRSTCLASS.apps.Workflows.MemberList.requestACL(true); } }, onComplete: function(param) { FIRSTCLASS.apps.Workflows.MemberList.enableAfterSaving(); }, onFailure: function(param) { FIRSTCLASS.apps.Workflows.MemberList.enableAfterSaving(); }, changeACL: function(cid, acl) { FIRSTCLASS.apps.Workflows.MemberList.disableWhileSaving(); var url = FIRSTCLASS.lang.ensureSlashUrl(this.communityuri) + "__ACL"; var data = FIRSTCLASS.apps.Workflows.MemberList._ACL; var found = false, i; for (i in data.records) { if (data.records[i].cid.toString(10) === cid) { found = i; if (data.records[i].rights.toString(10) === acl) { FIRSTCLASS.apps.Workflows.MemberList.enableAfterSaving(); return; } } } FIRSTCLASS.apps.Workflows.MemberList.changeACLCB.cid = cid; FIRSTCLASS.apps.Workflows.MemberList.changeACLCB.newacl = acl; if (!found) { FIRSTCLASS.util.Form.add(url, "CID"+cid, 9, data.records.length, FIRSTCLASS.apps.Workflows.MemberList.changeACLCB, false, false, true); data.records[data.records.length] = {cid: cid, rights: 0}; } else { if (acl === "-1") { FIRSTCLASS.apps.Workflows.MemberList.deleteMember(cid, true, false, true); } else { FIRSTCLASS.apps.Workflows.MemberList.changeACLCB.onComplete(); } } }, changeACLCB: { onComplete: function(param) { var callback2 = function() { var cid = FIRSTCLASS.apps.Workflows.MemberList.changeACLCB.cid; var newacl = FIRSTCLASS.apps.Workflows.MemberList.changeACLCB.newacl; var url = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.apps.Workflows.MemberList.communityuri) + "__ACL/" + FIRSTCLASS.opCodes.FormSave + "?Clear=0&Close=0"; var data = FIRSTCLASS.apps.Workflows.MemberList._ACL; var found = false, i; if (data && data.records) { for (i in data.records) { if (data.records[i].cid.toString(10) === cid) { found = i; } } } var html = [""]; html.push(""); html.push(""); html.push("
"); var el = document.createElement("div"); el.innerHTML = html.join(""); var cb = { success: function() { FIRSTCLASS.apps.Workflows.MemberList.requestACL(true); } }; FIRSTCLASS.util.submitForm(el.firstChild, false, cb); }; var callback = function() { // if the requested cid is not yet in the list, try again, otherwise proceed to the second callback to save the change var cid = FIRSTCLASS.apps.Workflows.MemberList.changeACLCB.cid; var data = FIRSTCLASS.apps.Workflows.MemberList._ACL; var found = false, i; if (data && data.records) { for (i in data.records) { if (data.records[i].cid.toString(10) === cid) { found = i; } } } if (found) { FIRSTCLASS.apps.Workflows.MemberList.requestACL(false, callback2); } else { window.setTimeout(function() { FIRSTCLASS.apps.Workflows.MemberList.requestACL(false, callback); }, 1000); } }; FIRSTCLASS.apps.Workflows.MemberList.requestACL(false, callback); }, onFailure: function(param) { FIRSTCLASS.apps.Workflows.MemberList.enableAfterSaving(); } }, createRow: function(row) { return FIRSTCLASS.apps.Workflows.MemberList.updateRow(row, FIRSTCLASS.apps.Workflows.MemberList._rowTemplate.cloneNode(true)); }, disableWhileSaving: function() { var buttons = FIRSTCLASS.apps.Workflows.MemberList.getButtons(); var i, el; buttons[0].set('disabled', true); for (i in FIRSTCLASS.apps.Workflows.MemberList._elements.frm.elements) { el = FIRSTCLASS.apps.Workflows.MemberList._elements.frm.elements[i]; if (el) { try { el.disabled = true; } catch (e) {} } } this._disabled = true; }, enableAfterSaving: function() { var buttons = FIRSTCLASS.apps.Workflows.MemberList.getButtons(); var i, el; buttons[0].set('disabled', false); for (i in FIRSTCLASS.apps.Workflows.MemberList._elements.frm.elements) { el = FIRSTCLASS.apps.Workflows.MemberList._elements.frm.elements[i]; if (el) { try { el.disabled = false; } catch (e) {} } } this._disabled = false; }, updateRow: function(row, element) { var that = this; var isowner = false; var prof = element.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[1]; var img = element.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0]; var text = element.childNodes[0].childNodes[0].childNodes[0].childNodes[1]; var message = element.childNodes[0].childNodes[0].childNodes[0].childNodes[3]; YAHOO.util.Dom.addClass(element, 'fcUser' + row.cid); var nameHtml = "" + row.name + ""; if (row.userclass === 5) { nameHtml += " (" + FIRSTCLASS.locale.general.external + ")"; } text.innerHTML = nameHtml; FIRSTCLASS.util.User.setTinyProfPicUrlByCid(prof, row.cid, false,false,false,{width:20, height:27}); var data = FIRSTCLASS.apps.Workflows.MemberList._ACL; var found = false, i; if (data && data.records) { for (i in data.records) { if (row.uid === data.records[i].cid) { found = data.records[i]; break; } } } isowner = (row.uid === FIRSTCLASS.apps.Workflows.MemberList._creatorcid); if (!isowner && FIRSTCLASS.apps.Workflows.MemberList._canedit) { var html = [""); html.push(" " + FIRSTCLASS.locale.workflows.memberlist.del + ""); message.innerHTML = html.join(""); } else { var rights = -1; if (found) { rights = found.rights; } if (isowner) { rights = "owner"; } message.innerHTML = FIRSTCLASS.apps.Workflows.MemberList.rightsToString(rights); } return element; }, onRightsChange: function(el) { var cid = el.getAttribute("cid"); var newvalue = el.value; FIRSTCLASS.apps.Workflows.MemberList.changeACL(cid,newvalue); }, generateUniqueId: function(row) { return "MemberListRow" + row.uid; }, rightsTrans: { "owner": FIRSTCLASS.locale.workflows.memberlist.rights.owner, 122735: FIRSTCLASS.locale.workflows.memberlist.rights.moderator, 122664: FIRSTCLASS.locale.workflows.memberlist.rights.contributor, 120320: FIRSTCLASS.locale.workflows.memberlist.rights.reader }, rightsToString: function(rights) { if (FIRSTCLASS.apps.Workflows.MemberList.rightsTrans[rights]) { return FIRSTCLASS.apps.Workflows.MemberList.rightsTrans[rights]; } else { return FIRSTCLASS.locale.workflows.memberlist.rights.def; } } }; FIRSTCLASS.apps.Workflows.SendTo.doEmailNoDlg = function(object) { var baseurl = false; FIRSTCLASS.apps.Workflows.SendTo._email = {object: object}; var config = {row: object.row, dataSource: object._dataSource,emailDisplayCB:object.displayCB,emailDoneCB: object.doneCB,permalink: object._dataSource.getPermalink(object.row), community: { uri:object._dataSource.getContainerUrl(), name: object._dataSource._dataname, cid: object._dataSource._data.cid } }; FIRSTCLASS.apps.Workflows.SendTo._currentConfig = config; var callback = false; var that = this; switch (object.row.typedef.objtype) { case FIRSTCLASS.objTypes.message: case FIRSTCLASS.objTypes.confitem: // forward message baseurl = FIRSTCLASS.lang.ensureSlashUrl(this._currentConfig.dataSource.getItemUrl(object.row, true, false))+FIRSTCLASS.opCodes.Forward+"?FormID=141&Templates=SendTo"; // callback = FIRSTCLASS.apps.Workflows.SendTo.doSendCB; break; /* case FIRSTCLASS.objTypes.odocument: case FIRSTCLASS.objTypes.form: case FIRSTCLASS.objTypes.fcfile: */ default: // create new message and attach // donewmessage baseurl = FIRSTCLASS.session.baseURL + "__Open-Item/Mailbox/__Send?FormID=141&Templates=SendTo&InitialText="; // callback = FIRSTCLASS.apps.Workflows.SendTo.doAttachCB; } var handleSuccess = function(o) { var domElem = document.getElementById("emailForm"); FIRSTCLASS.apps.Workflows.SendTo._email.domElem = domElem; FIRSTCLASS.apps.Workflows.SendTo._email.object.row = object.row; domElem.innerHTML = o.responseText; if (FIRSTCLASS.apps.Workflows.SendTo._currentConfig.emailDisplayCB) { FIRSTCLASS.apps.Workflows.SendTo._currentConfig.emailDisplayCB(); } FIRSTCLASS.apps.Workflows.SendTo.doAttachNoDlgCB(object.type); }; var handleFailure = function(o) { alert ("Cannot create email and attachment"); }; callback = { success:handleSuccess, failure: handleFailure }; FIRSTCLASS.util.net.asyncRequest('GET', baseurl, callback); }; FIRSTCLASS.apps.Workflows.SendTo.doAttachNoDlgCB = function(theType) { // initialize editor, do copy var domElem = FIRSTCLASS.apps.Workflows.SendTo._email.domElem; var form = domElem.firstChild; var object = { type: theType, row: FIRSTCLASS.apps.Workflows.SendTo._email.object.row, to: form.getAttribute('fcUrl'),// url to message callbacks: { success: FIRSTCLASS.apps.Workflows.SendTo.doSendAttachDoneNoDlgCB, failure: function(o) { alert(o.responseText); } } }; switch (object.row.typedef.objtype) { case FIRSTCLASS.objTypes.message: case FIRSTCLASS.objTypes.confitem: FIRSTCLASS.apps.Workflows.SendTo.doSendCB(function() { FIRSTCLASS.apps.Workflows.SendTo.doSendAttachDoneNoDlgCB(); }); break; default: FIRSTCLASS.apps.Workflows.SendTo.doSendCB(function() { FIRSTCLASS.apps.Workflows.SendTo.doCopy(object); }); } }; FIRSTCLASS.apps.Workflows.SendTo.doSendAttachDoneNoDlgCB = function() { var domElem = FIRSTCLASS.apps.Workflows.SendTo._email.domElem; var theRow = FIRSTCLASS.apps.Workflows.SendTo._email.object.row; var realSubject = (theRow.col8091 === FIRSTCLASS.objTypes.odocument) ? theRow.col8010 : theRow.subject; var attlist = FIRSTCLASS.ui.Dom.getChildByIdName('fcAttachmentContainer', domElem); if (attlist) { var iconid = FIRSTCLASS.util.Display.getIconID(FIRSTCLASS.apps.Workflows.SendTo._email.object.row.name); attlist.innerHTML = "
 " + realSubject + "
"; YAHOO.util.Dom.setStyle(attlist.parentNode, 'display',''); YAHOO.util.Dom.setStyle(attlist.parentNode.previousSibling, 'display',''); } var subject = FIRSTCLASS.ui.Dom.getChildByIdName('fcDocSubject', domElem); if (subject) { subject.value = realSubject; } }; YAHOO.register("fcWorkflows", FIRSTCLASS.apps.Workflows, {version: "0.0.1", build: "1"});