FIRSTCLASS.apps.Workflows = {};
FIRSTCLASS.apps.Workflows.CreateCommunity = function() {
var that = this;
FIRSTCLASS.apps.Workflows.CreateCommunity.instance = this;
var domElem = document.createElement("div");
this._dialog = new FIRSTCLASS.apps.FormDialog({
baseUrl: FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL)+FIRSTCLASS.opCodes.Create+"?Templates=CreateCommunity&How=Picker&What=1&Type=66&Close=-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, 'keyup', that.watchForName);
},
hideaftersubmit: false,
hideaftercancel: false
});
this._currentStep = this.stepOne;
this._cancel = this.finish;
};
FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.watchForName = function(evt) {
if (FIRSTCLASS.apps.Workflows.CreateCommunity.instance._elements.stepOne.name.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);
}
};
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&Quit=1";
var url2 = form2.getAttribute('objurl') + "?Templates=CreateCommunity&Quit=1";
YAHOO.util.Connect.asyncRequest('GET', url1);
YAHOO.util.Connect.asyncRequest('GET', url2);
FIRSTCLASS.session.desktop._dataSource.addRowListener(that);
FIRSTCLASS.session.desktop._dataSource.activate();
FIRSTCLASS.session.desktop._dataSource.fetchRows();
FIRSTCLASS.session.desktop._dataSource.watchForTinkle({
success: function() {
FIRSTCLASS.session.desktop._dataSource.watchForTinkle();
}
});
},
failure: function(o) {
alert(FIRSTCLASS.locale.workflows.community.failed);
}
};
YAHOO.util.Connect.setForm(form, false);
YAHOO.util.Connect.asyncRequest('POST', url, callback);
}
};
var u2 = form2.action + "&FieldID:8087%3DSTRING=" + FIRSTCLASS.lang.uesc($('fcCommunityNameInput').value);
YAHOO.util.Connect.asyncRequest('GET', u2, cb1);
};
FIRSTCLASS.apps.Workflows.CreateCommunity.prototype.onRow = function(row) {
var that = this;
if (row.name == this._values.name) {
// found the community
var body = that._elements.stepOne.description.value;
//var post = "BodyType=TEXT&Close=0&Body="+body;
url = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL+row.uri)+"__ACL/__OPENNDX3/"+FIRSTCLASS.opCodes.FormSave+"?Clear=0";
var cb = {
success: function(o) {
that.nextStep(1);
},
failure: function(o) {
that.nextStep(1);
}
};
var formcontainer = document.createElement("DIV");
//var uri = FIRSTCLASS.session.baseURL + "Send?FormID=21006";
var html = ["
");
formcontainer.innerHTML = html.join("");
formcontainer.firstChild.childNodes[3].value = body;
// YAHOO.util.Connect.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) {
FIRSTCLASS.session.desktop._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.session.baseURL + 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) {
switch(key) {
case "objid":
that._loadInvitationStep(that._dataSource, data);
break;
default:
}
},
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);
FIRSTCLASS.session.desktop._dataSource.notifyRowChanged(this._values.dsrow);
}
YAHOO.util.Connect.setForm(form);
var cb = {
success: function(evt) {
that.nextStep(2);
},
failure: function(evt) {
that.nextStep(2);
}
};
YAHOO.util.Connect.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) {
YAHOO.util.Connect.asyncRequest('GET', this._attlist + "?Templates=CreateCommunity&Quit=1");
}
if (this._objurl) {
YAHOO.util.Connect.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.session.baseURL+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;
}
}
}
YAHOO.util.Connect.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.next, isDefault:true, type:"submit" },
{ text:FIRSTCLASS.locale.workflows.members.cancel, type: "cancel" }
],
submit: function() {
that.currentStep();
},
cancel: function() {
that.close();
},
hideaftersubmit: false,
hideaftercancel: false
});
} else {
var requestUrl = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL) + "__MemForm?FormID=10001&Templates=Members&Step=1";
var connManagerRequest = YAHOO.util.Connect.asyncRequest("GET", requestUrl, {
success:function(response) {
that._config.domElement.innerHTML = response.responseText;
that._dialog.getDialog().cfg.setProperty("buttons", [
{ text:FIRSTCLASS.locale.workflows.members.next, isDefault:true, type:"submit", handler: function() {
that.currentStep();
} },
{ text:FIRSTCLASS.locale.workflows.members.cancel, type: "cancel", handler: function() {
that.close();
} }
]);
that._dialog.getDialog().show();
},
failure: function(response) {
that._config.domElement.innerHTML = response.responseText;
that._dialog.getDialog().cfg.setProperty("buttons", [
{ text:FIRSTCLASS.locale.workflows.members.next, isDefault:true, type:"submit", handler: function() {
that.currentStep();
} },
{ text:FIRSTCLASS.locale.workflows.members.cancel, type: "cancel", handler: function() {
that.close();
} }
]);
that._dialog.getDialog().show();
}
});
}
this.currentStep = this.doValidation;
FIRSTCLASS.apps.Members.instance = this;
};
FIRSTCLASS.apps.Members.prototype.doValidation = function() {
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._objid = o.objid;
that.doValidationStep2();
}
},
failure: function(response) {
}
};
YAHOO.util.Connect.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);
}
}
};
FIRSTCLASS.apps.Members.prototype.addUser = function(cfg) {
var that = this;
cfg.folderid = this._config.folderid;
cfg.objid = false ;//this._config.objid;
var func = function() {
var form = document.createElement("div");
if (cfg.messagesrc) {
cfg.message = cfg.messagesrc.value;
}
var html = ["")
form.innerHTML = html.join("");
var msg = FIRSTCLASS.ui.Dom.getChildByClassName('fcInviteMessage', form);
msg.value = cfg.message;
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) {
cfg.domElement.innerHTML = FIRSTCLASS.locale.errors.getErrorString(o.error);
handled = true;
}
}
if (!handled) {
cfg.domElement.innerHTML = FIRSTCLASS.locale.workflows.members.added;
}
that.currentStep = that.close;
that._dialog.getButtons()[0].set('label', FIRSTCLASS.locale.workflows.members.doclose);
that._dialog.getButtons()[1].destroy();
},
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.close;
that._dialog.getButtons()[0].set('label', FIRSTCLASS.locale.workflows.members.doclose);
that._dialog.getButtons()[1].destroy();
if (!handled) {
cfg.domElement.innerHTML = FIRSTCLASS.locale.workflows.members.failed;
}
}
};
YAHOO.util.Connect.setForm(form.firstChild);
var conn = YAHOO.util.Connect.asyncRequest('POST', FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL) + "__MemForm/"+FIRSTCLASS.opCodes.FormSave+"?FormID=11215&Clear=0&Templates=JS", cb);
that.cancelfunc = false;
};
if (!cfg.objid) {
return function() {
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.close;
that._dialog.getButtons()[0].set('label', FIRSTCLASS.locale.workflows.members.doclose);
that._dialog.getButtons()[1].destroy();
if (!handled) {
cfg.domElement.innerHTML = FIRSTCLASS.locale.workflows.members.failed;
}
}
};
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 = YAHOO.util.Connect.asyncRequest('GET', url, cb);
};
} else {
return func;
}
};
FIRSTCLASS.apps.Members.prototype.onComplete = function(obj) {
var domElement = FIRSTCLASS.ui.Dom.getChildByClassName("fcNameValContainer", this._config.domElement);
var input = FIRSTCLASS.ui.Dom.getChildByClassName("fcInputContainer", this._config.domElement);
input.innerHTML = "";
var that = this;
FIRSTCLASS.ui.Dom.clearElementChildren(domElement);
switch (obj.match) {
case "single":
// single match, and added to list, we can return
var now = new Date();
domElement.innerHTML = "
"+FIRSTCLASS.locale.workflows.members.message+" ";
FIRSTCLASS.ui.widgets.showMiniProfile(domElement.firstChild, obj.item,false,false,false);
that._dialog.getButtons()[0].set('label', FIRSTCLASS.locale.workflows.members.add);
that.currentStep = that.addUser({cid:obj.item.cid, /*objid:that._config.objid,*/ messagesrc:domElement.lastChild, domElement:domElement});
break;
case "multi":
// multimatch, we got a DataSource
input.innerHTML = FIRSTCLASS.locale.workflows.members.userselect;//"Did you mean one of these users?";
var dt = new Date();
this.miniprofid = "fcMembersMiniProfile" + dt.getTime();
domElement.innerHTML = "
"+FIRSTCLASS.locale.workflows.members.clickuser+"
"+FIRSTCLASS.locale.workflows.members.message+" "
YAHOO.util.Dom.setStyle(domElement.firstChild.firstChild, "height", "auto");
YAHOO.util.Dom.setStyle(domElement.firstChild.firstChild, "max-height", "200px");
YAHOO.util.Dom.setStyle(domElement.firstChild.firstChild, "overflow", "auto");
var lvcfg = {
noHover: true,
domElement: domElement.firstChild.firstChild,
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._dialog.getDialog().cfg.setProperty('width', '700px');
}
};
that.listView = new FIRSTCLASS.layout.ListView(lvcfg);
that.currentStep = function() {
var msg = FIRSTCLASS.ui.Dom.getChildByClassName('fcMembersMessage', domElement);
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,
domElement:domElement})();
input.innerHTML = "";
} else {
alert("please select a user");
}
};
break;
//case "none":
default:
var requestUrl = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL) + "__MemForm?FormID=11215&Clear=0&Templates=Members&Email=0";
if (!FIRSTCLASS.lang.isEmailAddress(obj.pattern)) {
requestUrl = FIRSTCLASS.lang.ensureSlashUrl(FIRSTCLASS.session.baseURL) + "__MemForm?FormID=11215&Clear=0&Templates=Members&Email=1";
}
// open a new user with custom uif
var connManagerRequest = YAHOO.util.Connect.asyncRequest("GET", requestUrl, {
success:function(response) {
domElement.innerHTML = response.responseText;
var uidField = FIRSTCLASS.ui.Dom.getChildByClassName("fcUserNameField", domElement);
var verifyField = FIRSTCLASS.ui.Dom.getChildByClassName("fcVerifyEmail", domElement);
if (verifyField) {
verifyField.innerHTML = obj.pattern;
}
var objidField = FIRSTCLASS.ui.Dom.getChildByClassName("fcCommunityObjIDField", domElement);
//var aliases = FIRSTCLASS.ui.Dom.getChildByClassName("fcAliasField", domElement);
if (FIRSTCLASS.lang.isEmailAddress(obj.pattern)) {
uidField.value = obj.pattern;
} else {
var names = obj.pattern.split(" ");
$("fcFirstNameField").value = FIRSTCLASS.lang.upperCaseFirstLetter(names[0]);
if (names.length > 1) {
$("fcLastNameField").value = FIRSTCLASS.lang.upperCaseFirstLetter(names[names.length-1]);
}
}
objidField.value = that._config.objid;
//aliases.value = obj.pattern;
//var button = FIRSTCLASS.ui.Dom.getChildByClassName("fcSubmit", domElement);
that._dialog.getButtons()[0].set('label', FIRSTCLASS.locale.workflows.members.sendinvite);
that._dialog.getButtons()[1].set('label', FIRSTCLASS.locale.workflows.members.tryagain);
that._dialog.getDialog().center();
that.cancelfunc = that.startWorkflow;
that.currentStep = that.submit;
that.submitFunc = function() {
var first = $("fcFirstNameField").value;
var last = $("fcLastNameField").value;
var msg = $("fcInvitationMessage").value;
var form = FIRSTCLASS.ui.Dom.getChildByClassName("fcUserForm", domElement);
var email = uidField.value;
if (first.length == 0 || last.length == 0 || email.length == 0) {
domElement.innerHTML = "" + FIRSTCLASS.locale.workflows.members.incomplete + " ";
that._dialog.getButtons()[0].set('label', FIRSTCLASS.locale.workflows.members.doclose);
that._dialog.getDialog().center();
that.currentStep = that.close;
that._dialog.getButtons()[1].destroy();
return;
}
that.addUser({first:first, last:last, message:msg, userid:uidField.value, domElement:domElement})();
that.cancelfunc = false;
};
},
failure:function(err) {
domElement.innerHTML = err.responseText;
}
});
// hmm, nothing found
//domElement.innerHTML = "no results found, this is where we ask you to create the user if we have an email address";
}
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);
};
FIRSTCLASS.apps.Members.prototype.close = function() {
if (this.cancelfunc) {
this.cancelfunc();
} else {
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;
}
} else {
debugger;
}
}
}
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() {
var joinurl = FIRSTCLASS.session.baseURL + '?LFieldID_8092.'+FIRSTCLASS.lang.removeSlashUrl(config.row.uri)+'_LONG=0&Templates=JS';
YAHOO.util.Connect.asyncRequest('GET', joinurl);
config.row.col8092 = 0;
config.dataSource.notifyRowDeleted(config.row);
config.dataSource.notifyRowChanged(config.row);
};
var decline = function() {
config.dataSource.deleteRow(config.row);
config.domElement.innerHTML = '';
this.hide();
this.destroy();
};
var 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() {
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);
for (var 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.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");
if (!this._dialog) {
if ((FIRSTCLASS.permissions.hasPriv(this._config.acl, FIRSTCLASS.permissions.ACL.MODERATOR) || typeof this._config.isalias != "undefined" && parseInt(this._config.isalias) == 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 (var i in repositories) {
this._defaultButtons.push({
text:FIRSTCLASS.locale.doSub(FIRSTCLASS.locale.integrations.ecm.archiveto, {repository:repositories[i].name}),
handler: function() {
that.close();
FIRSTCLASS.apps.Integration.ECM.Browse.doBrowse({
'xuid':2000,
'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});
}
});
}
}
if (that._config.baseUrl.indexOf("Open-Conf") < 0) {
var watched = FIRSTCLASS.session.desktop.isContainerBeingWatched(that._config.baseUrl);
var whandler = function() {
var watched = FIRSTCLASS.session.desktop.isContainerBeingWatched(that._config.baseUrl);
var ttl = "";
if (watched) {
FIRSTCLASS.session.desktop.stopContainerBeingWatched(that._config.baseUrl);
ttl = FIRSTCLASS.locale.community.feed.actions.watch;
} else {
YAHOO.util.Connect.asyncRequest('GET',that._config.baseUrl+"?Watch=1");
ttl = FIRSTCLASS.locale.community.feed.actions.unwatch;
}
that._defaultButtons[that._defaultButtons.length-1].text = ttl;
that._dialog.getDialog().cfg.setProperty("buttons", that._defaultButtons);
};
if (watched) {
this._defaultButtons.push({
text:FIRSTCLASS.locale.community.feed.actions.unwatch,
handler: whandler
});
} else {
this._defaultButtons.push({
text:FIRSTCLASS.locale.community.feed.actions.watch,
handler: whandler
});
}
}
var baseurl = FIRSTCLASS.lang.ensureSlashUrl(that._config.baseUrl)+"__Resume?Templates=AboutCommunity&Title="+escape(that._config.title)+"&Icon="+that._config.icon;
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,
onDomInserted: function() {
var title = FIRSTCLASS.ui.Dom.getChildByClassName("fcCommunityTitle", that._config.domElement);
if (title) {
title.innerHTML = that._config.title;
}
}
});
} else {
if (edit) {
that.originalSkin = FIRSTCLASS.ui.skin.get();
var 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;
var connManagerRequest = YAHOO.util.Connect.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 formhtml = "";
var tmp = document.createElement("div");
tmp.innerHTML = formhtml;
YAHOO.util.Connect.setForm(tmp.firstChild);
var cb = {
success: function(r) {
//alert("success");
},
failure: function(r) {
//alert("failure");
}
};
YAHOO.util.Connect.asyncRequest('POST',tmp.firstChild.action, cb);
that.save();
} },
{ 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 = [""];
for (var i in skins) {
html.push(""+skins[i]+" ");
}
html.push("
");
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);
});
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 {
var requestUrl = FIRSTCLASS.lang.ensureSlashUrl(that._config.baseUrl)+"__Resume?Templates=AboutCommunity&Title="+escape(that._config.title)+"&Icon="+that._config.icon;
var connManagerRequest = YAHOO.util.Connect.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 () {
var form = document.forms["CommunityEditForm"];
var that = this;
YAHOO.util.Connect.setForm(form);
YAHOO.util.Connect.asyncRequest("POST", form.action, {
success:function(response) {
that.startWorkflow(false);
},
failure: function(response) {
alert("FAILED");
that.startWorkflow(false);
}
});
};
FIRSTCLASS.apps.Workflows.AboutCommunity.prototype.close = function () {
this._dialog.hide();
this._dialog.destroy();
};
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 () {
// get the parsed tag string that the user selected
var buf = [];
for (var i in this._selectedTags) {
buf.push(i);
}
return FIRSTCLASS.ui.tags.arrayToServerTags(buf);
//buf.join(FIRSTCLASS.ui.tags.separator);
};
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;
var ht = [ "" ];
if (typeof this._config.editable == "undefined" || this._config.editable) {
ht.push("
" + FIRSTCLASS.locale.workflows.tags.main + " ");
ht.push("
");
ht.push("" + FIRSTCLASS.locale.workflows.tags.click + " ");
ht.push("" + FIRSTCLASS.locale.workflows.tags.newtag + " ");
ht.push("");
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 (var 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
if(evt.keyCode == 13 /* enter */
|| evt.keyCode == 188 /* comma */
/*|| 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);
// var tags = str.split(FIRSTCLASS.ui.tags.separator);
for (var 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;
for (var 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
configuration:
ds dataSource object
dsr optional row pointer - if present, the upload is an update to said row
paneEl host pane
onComplete caller function to be called when done
**/
FIRSTCLASS.apps.Workflows.uploadDocument = function(config) {
if (FIRSTCLASS.apps.Workflows.uploadDocument._isOpen) {
return;
}
FIRSTCLASS.apps.Workflows.uploadDocument._isOpen = true;
var that = this;
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";
}
this._isUpdate = false;
if (config.dsr && typeof config.dsr == "object") {
this._isUpdate = true;
}
this._config = config;
this._instance = ++FIRSTCLASS.apps.Workflows.uploadDocument._instances;
this._dlg = null;
if (FIRSTCLASS.flashdetector.hasFlash() && FIRSTCLASS.session.ui.experimental) {
this._useFlashUploader = true;
}
// put up dialog
var dlgCfg = {};
dlgCfg.title = this._isUpdate ? FIRSTCLASS.locale.uploader.uptitle : FIRSTCLASS.locale.uploader.title;
dlgCfg.cancel = 'uploadCancel';
dlgCfg.done = 'uploadFile';
dlgCfg.doneLabel = FIRSTCLASS.locale.uploader.upload;
dlgCfg.width = '500px';
var html = [];
// file input form
html.push("");
dlgCfg.body = html.join("");
this.openUploadDialog(dlgCfg);
this._uploadForm = FIRSTCLASS.ui.Dom.getChildByIdName('upload_browse', this._el);
this._uploadForm.setAttribute("action", FIRSTCLASS.lang.ensureSlashUrl(this._config.ds.getContainerUrl()) + FIRSTCLASS.opCodes.Attach + "?Templates=JS");
this._uploadForm.setAttribute("enctype", "multipart/form-data");
this._uploadForm.setAttribute("autocomplete", "off");
this._conflictForm = this._isUpdate ? null : FIRSTCLASS.ui.Dom.getChildByIdName('upload_conflict', this._el);
this._renamer = this._isUpdate ? null : FIRSTCLASS.ui.Dom.getChildByIdName('upload_newname', this._el);
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");
this.enableUpload(false);
// form event hooks
// on picker data change, initiate duplicate check
if (this._useFlashUploader) {
this.setupFlashCallbacks();
} else {
YAHOO.util.Event.on('upload_choose', 'change', function(ev) {
YAHOO.util.Event.stopEvent(ev);
var fName = FIRSTCLASS.lang.removeSlashUrl(this.value);
fName = fName.match(/[^\/\\]+$/);
if (that._isUpdate) {
that._fileName = that._config.dsr.name;
that.enableUpload(true);
} else {
that._fileName = FIRSTCLASS.lang.limitFilenameLength(fName[0]);
that.testForDuplicateName();
}
return false;
});
}
// on upload radio, show rename box, disable upload
YAHOO.util.Event.on('upload_rename', 'mouseup', function(ev) {
YAHOO.util.Event.stopEvent(ev);
YAHOO.util.Dom.removeClass(that._renamer, 'fcHidden');
that.enableUpload(false);
});
// on rename, retest for duplicate
if (!this._isUpdate) {
YAHOO.util.Event.on(that._renamer, 'change', function(ev) {
YAHOO.util.Event.stopEvent(ev);
that._fileName = FIRSTCLASS.lang.limitFilenameLength(this.value);
that.testForDuplicateName();
});
}
// on update radio, hide and clear rename box, enable upload with picker name
YAHOO.util.Event.on('upload_update', 'mouseup', function(ev) {
YAHOO.util.Event.stopEvent(ev);
YAHOO.util.Dom.addClass(that._renamer, 'fcHidden');
var fName = FIRSTCLASS.lang.removeSlashUrl(YAHOO.util.Dom.get('upload_choose').value);
var slash = fName.lastIndexOf("/");
if (slash >= 0) {
fName = fName.slice(slash + 1);
}
that._fileName = FIRSTCLASS.lang.limitFilenameLength(fName);
that.enableUpload(true);
});
};
FIRSTCLASS.apps.Workflows.uploadDocument._instances = 0;
FIRSTCLASS.apps.Workflows.uploadDocument._isOpen = false;
FIRSTCLASS.apps.Workflows.uploadDocument._isUploading = false;
// test if file name (from member var) exists in the current container (as a document)
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.testForDuplicateName = function() {
var that = this;
var url = FIRSTCLASS.lang.removeSlashUrl(this._config.ds.getContainerUrl());
var callback = {
// success indicates that the item already exists - show form to resolve
success: function(o) {
that.displayUploadConflict(true);
},
// assume that failure indicates no item - enable the upload button
failure: function(o) {
that.displayUploadConflict(false);
that.enableUpload(true);
}
};
// form the file check url
url += "/" + this._fileName;
var connObj = YAHOO.util.Connect.asyncRequest('HEAD',url,callback);
};
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.enableUpload = function(enable) {
var buttons = this._dlg.getButtons();
for (var 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");
}
}
}
}
};
// display the name conflict resolution form
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.displayUploadConflict = function(showIt) {
// insert file and container names
var el = FIRSTCLASS.ui.Dom.getChildByIdName('fcDocNameConflict',this._el);
if (el) {
if (showIt) {
var conStr = FIRSTCLASS.locale.uploader.dup;
conStr = conStr.replace("^1",this._fileName);
conStr = conStr.replace("^2",this._config.ds._data.name);
el.innerHTML = conStr;
this._renamer.value = this._fileName;
YAHOO.util.Dom.removeClass(this._conflictForm,'fcHidden');
} else {
el.innerHTML = "";
this._renamer.value = "";
YAHOO.util.Dom.addClass(this._conflictForm,'fcHidden');
}
}
};
// do the upload
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.uploadFileWithFlash = function() {
if (FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.uploaderReady && FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.fileID) {
var that = this;
var cb = {
success: function(o) {
window.setTimeout(function() {
var form = that._uploadForm;
var vars = {
// AttName: that._fileName,
Templates: "JS",
FCTicket: o.responseText.trim(),
Close: 1
};
var action = form.action;// + "?Templates=JS&FCTicket=" + o.responseText.trim();
FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader._uploader.upload(FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.fileID,
action, "GET",
vars, 'Attachment');
YAHOO.util.Connect.resetDefaultHeaders();
YAHOO.util.Connect.setDefaultXhrHeader(true);
YAHOO.util.Connect.setDefaultPostHeader(true);
}, 100);
},
failure: function(o) {
YAHOO.util.Connect.resetDefaultHeaders();
YAHOO.util.Connect.setDefaultXhrHeader(true);
YAHOO.util.Connect.setDefaultPostHeader(true);
}
};
YAHOO.util.Connect.resetDefaultHeaders();
YAHOO.util.Connect.setDefaultPostHeader(false);
YAHOO.util.Connect.setDefaultXhrHeader(false);
YAHOO.util.Connect.initHeader('Connection', 'close');
YAHOO.util.Connect.initHeader('Keep-Alive', '0');
YAHOO.util.Connect.asyncRequest('GET', "/Login?Templates=Ticket", cb);
}
};
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.cancelUploadFileWithFlash = function() {
if (FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.uploaderReady && FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.fileID) {
FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader._uploader.cancel(FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.fileID);
}
};
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.setupFlashCallbacks = function() {
FIRSTCLASS.apps.Workflows.uploadDocument._currentInstance = this;
YAHOO.widget.Uploader.SWFURL = FIRSTCLASS.session.templatebase + "/yui_2.7.0/build/uploader/assets/uploader.swf";
FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader._uploader = new YAHOO.widget.Uploader('uploadOverlay');
var uploader = FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader._uploader;
var callbacks = FIRSTCLASS.apps.Workflows.uploadDocument.callbacks;
uploader.addListener('contentReady', callbacks.onContentReady);
uploader.addListener('fileSelect', callbacks.onFileSelect);
uploader.addListener('uploadStart', callbacks.onUploadStart);
uploader.addListener('uploadProgress', callbacks.onUploadProgress);
uploader.addListener('uploadCancel', callbacks.onUploadCancel);
uploader.addListener('uploadComplete', callbacks.onUploadComplete);
uploader.addListener('uploadCompleteData', callbacks.onUploadCompleteData);
uploader.addListener('uploadError', callbacks.onUploadError);
uploader.addListener('rollOver', callbacks.onRollOver);
uploader.addListener('rollOut', callbacks.onRollOut);
uploader.addListener('click', callbacks.handleClick);
};
FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader = {
fileID: false,
fileName: false,
_uploader: false,
uploaderReady: false
};
FIRSTCLASS.apps.Workflows.uploadDocument.callbacks = {
onContentReady: function(event) {
FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader._uploader.setAllowMultipleFiles(false);
FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.uploaderReady = true;
},
onFileSelect: function(event) {
for (var file in event.fileList) {
if (YAHOO.lang.hasOwnProperty(event.fileList, file)) {
FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.fileID = event.fileList[file].id;
}
}
var progress = $('upload_progress');
YAHOO.util.Dom.setStyle(progress, 'display', 'block');
FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.fileName = event.fileList[FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.fileID].name;
progress.innerHTML = FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.fileName;
var that = FIRSTCLASS.apps.Workflows.uploadDocument._currentInstance;
if (that._isUpdate) {
that._fileName = that._config.dsr.name;
that.enableUpload(true);
} else {
that._fileName = FIRSTCLASS.lang.limitFilenameLength(FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.fileName);
that.testForDuplicateName();
}
},
onUploadStart: function(event) {
FIRSTCLASS.apps.Workflows.uploadDocument._currentInstance.setUploadingFormState(true);
FIRSTCLASS.apps.Workflows.uploadDocument._currentInstance.enableUpload(false);
$('upload_progress').innerHTML = "uploading: 0% done";
},
onUploadProgress: function(evt) {
var prog = Math.round(100*(evt.bytesLoaded/evt.bytesTotal));
$('upload_progress').innerHTML = "uploading: " + prog + "% done ("
+ FIRSTCLASS.util.Display.getFileSizeString(evt.bytesLoaded) + " of "
+ FIRSTCLASS.util.Display.getFileSizeString(evt.bytesTotal) + ")";
},
onUploadCancel: function(event) {
$('upload_progress').innerHTML = "upload cancelled";
},
onUploadComplete: function(event) {
$('upload_progress').innerHTML = "File Uploaded, setting tags now";
var that = FIRSTCLASS.apps.Workflows.uploadDocument._currentInstance;
// that.enableUpload(true);
that.setUploadingFormState(false);
// on success, upload metadata
that.postMetadata();
FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader._uploader.clearFileList();
FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.fileID = false;
},
onUploadCompleteData: function(event) {
$('upload_progress').innerHTML = "upload complete data";
},
onUploadError: function(event) {
if (typeof event.status == "number" && event.status >= 200 && event.status < 400) {
FIRSTCLASS.apps.Workflows.uploadDocument.callbacks.onUploadComplete(event);
} else if (FIRSTCLASS.apps.Workflows.uploadDocument._flashUploader.fileID) {
$('upload_progress').innerHTML = "error";
var that = FIRSTCLASS.apps.Workflows.uploadDocument._currentInstance;
that.enableUpload(true);
that.setUploadingFormState(false);
}
},
onRollOver: function(event) {
},
onRollOut: function(event) {
},
handleClick: function(event) {
}
};
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.uploadFile = function() {
if (this._useFlashUploader) {
this.uploadFileWithFlash();
return;
}
if (FIRSTCLASS.apps.Workflows.uploadDocument._isUploading) {
return;
}
FIRSTCLASS.apps.Workflows.uploadDocument._isUploading = true;
var that = this;
// set attach name field
this._uploadForm.AttName.value = this._fileName;
var callback = {
success: function() {
that.setUploadingFormState(false);
// on success, upload metadata
that.postMetadata();
},
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.setUploadingFormState(false);
// on success, upload metadata
that.postMetadata();
},
failure: function() {
// close the upload dialog
that.closeUploadDialog();
// post an error
that.postError(FIRSTCLASS.locale.uploader.errors.file);
},
abort: function(evt) {
// close the upload dialog
that.closeUploadDialog();
// post an error
that.postError(FIRSTCLASS.locale.uploader.errors.file);
}
};
// set form state to "uploading"
this.setUploadingFormState(true);
// do the upload
var conn = FIRSTCLASS.util.submitForm(this._uploadForm, true, callback);
};
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.setUploadingFormState = function(isUploading) {
var iconCell = FIRSTCLASS.ui.Dom.getChildByIdName('uploadprogicon', this._el);
if (iconCell) {
if (isUploading) {
iconCell.innerHTML = " ";
} else {
iconCell.innerHTML = "";
}
}
};
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.postError = function(msg) {
// pop up error dialog
var error = msg || "An error has occurred.";
var err = new YAHOO.widget.SimpleDialog("docUploadErrorDialog", {
width: "300px",
fixedcenter: true,
visible: false,
draggable: false,
close: true,
text: error,
icon: YAHOO.widget.SimpleDialog.ICON_HELP,
constraintoviewport: true,
buttons: [ { text:"OK", handler: function() { err.hide(); }, isDefault:true }]
});
err.render(document.body);
err.show();
};
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.postMetadata = function() {
var that = this;
if ((that._comment.value === "") && (that._tags.value === "")) {
that.closeUploadDialog();
return;
}
var callback = {
success: function() {
that.closeUploadDialog();
},
failure: function() {
that.closeUploadDialog();
that.postError(FIRSTCLASS.locale.uploader.errors.meta);
}
};
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._fileName;
if (this._isUpdate) {
itemSpec = "TF-" + this._config.dsr.threadid;
}
if (this._comment.value !== "") {
this._comment.setAttribute("name",'LFieldID:8101."' + itemSpec + '"=LITERALSTRING');
} else {
this._comment.setAttribute("name","");
}
if (this._tags.value !== "") {
this._tags.setAttribute("name",'LFieldID:8021."' + itemSpec + '"=STRING');
//this._itemTags.setAttribute("name",'LFieldID:8100."' + itemSpec + '"=STRING');
//this._itemTags.value = this._tags.value;
} else {
//this._itemTags.setAttribute("name","");
this._tags.setAttribute("name","");
}
YAHOO.util.Connect.setForm(this._metaForm, false);
var c = YAHOO.util.Connect.asyncRequest('POST', url , callback);
};
// open the upload dialog
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.openUploadDialog = function(config) {
var that = this;
if (this._dlg !== null) { // close current if any
this.closeUploadDialog();
}
this._dConfig = {};
YAHOO.lang.augmentObject(this._dConfig, config);
this._el = document.createElement('div');
this._el.setAttribute('style', 'visibility:hidden');
this._el.setAttribute('id', 'fcDocsDialog' + this._instance);
this._config.paneEl.appendChild(this._el);
// create the dialog
var buttons = [];
if (typeof this._dConfig.cancel !== 'undefined') {
buttons.push({
text: FIRSTCLASS.locale.uploader.cancel,
handler: function() { that[that._dConfig.cancel](); },
isDefault: true
});
}
if (typeof this._dConfig.done !== 'undefined') {
buttons.push({
text: this._dConfig.doneLabel,
handler: function() { that[that._dConfig.done](); },
isDefault: false,
isDisabled: true
});
}
this._dlg = new YAHOO.widget.Dialog("fcDocsDialog" + this._instance, {
width: this._dConfig.width || "450px",
draggable: true,
visible: false,
constraintoviewport: true,
postmethod: "none",
close: false,
hideaftersubmit: false,
xy: [this._config.paneEl.offsetHeight / 2 - 100, this._config.paneEl.offsetWidth / 2 - 200],
shim: (navigator.userAgent.toLowerCase().indexOf("msie") > -1),
buttons: buttons
});
// insert body and title if any
if (this._dConfig.title) {
this._dlg.setHeader(this._dConfig.title);
}
if (this._dConfig.body) {
this._dlg.setBody(this._dConfig.body);
}
this._dlg.render();
this._tagContainer = FIRSTCLASS.ui.Dom.getChildByIdName('fcTagger', this._el);
this._tags = FIRSTCLASS.ui.Dom.getChildByIdName('fcTags', this._el);
//this._itemTags = FIRSTCLASS.ui.Dom.getChildByIdName('fcItemTags', this._el);
if (this._isUpdate && this._config.dsr.tags && (this._config.dsr.tags.length > 0)) {
this._tags.value = this._config.dsr.tags;
//this._itemTags.value = this._tags.value;
}
this._tagcfg = {
domElement: this._tagContainer,
item: FIRSTCLASS.ui.parseServerTags(this._tags.value),
hidesuggestions: true,
destField: this._tags,
showonconfig: true
};
FIRSTCLASS.apps.Workflows.Tags.reconfigure(this._tagcfg);
this._dlg.show();
};
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.uploadCancel = function() {
if (this._useFlashUploader) {
this.cancelUploadFileWithFlash();
}
this.closeUploadDialog();
};
FIRSTCLASS.apps.Workflows.uploadDocument.prototype.closeUploadDialog = function() {
if (this._dlg !== null) {
this._dlg.destroy();
this._dlg = null;
if (this._config.onComplete && typeof this._config.onComplete == "function") {
this._config.onComplete();
}
this._el.innerHTML = "";
if (this._el.parentNode) {
this._el.parentNode.removeChild(this._el);
}
this._el = false;
}
FIRSTCLASS.apps.Workflows.uploadDocument._isOpen = false;
FIRSTCLASS.apps.Workflows.uploadDocument._isUploading = false;
};
FIRSTCLASS.apps.Workflows.SendTo = {};
FIRSTCLASS.apps.Workflows.SendTo.draw = function(config) {
if (!FIRSTCLASS.apps.Integration._isInitialized) {
// do init first
FIRSTCLASS.apps.Integration._onInit.push({func: FIRSTCLASS.apps.Workflows.SendTo.draw, 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 = [];
if (config.row.typedef.objtype == FIRSTCLASS.objTypes.fc || config.row.typedef.objtype== FIRSTCLASS.objTypes.file) {
var repositories = FIRSTCLASS.apps.Integration.getRepositories();
var ritems = [];
for (var i in repositories) {
ritems.push({
text:repositories[i].name,
onclick: {
fn:FIRSTCLASS.apps.Workflows.SendTo.sendTo,
obj: {type:"ECM", repository:i, row:config.row}
}
});
}
if (ritems.length) {
items.push(ritems);
}
}
items.push([{
text:FIRSTCLASS.locale.workflows.sendto.email.name,
onclick: {
fn:FIRSTCLASS.apps.Workflows.SendTo.sendTo,
obj: {type:"email", row:config.row}
}
}]);
if (FIRSTCLASS.session.ui.experimental) {
if (config.row.typedef.objtype != FIRSTCLASS.objTypes.file
&& config.row.typedef.objtype != FIRSTCLASS.objTypes.fcfile
&& config.row.typedef.objtype != FIRSTCLASS.objTypes.form) {
items.push(
[{
text:FIRSTCLASS.locale.workflows.sendto.blog.name,
onclick: {
fn:FIRSTCLASS.apps.Workflows.SendTo.sendTo,
obj: {type:"blog", row:config.row}
}
}]
);
}
}
var communities = FIRSTCLASS.apps.Desktop.getCommunities();
var citems = [];
for (var i in communities) {
if (communities[i].lconfcid && communities[i].lconfcid == config.community.cid) {
continue;
}
citems.push(
{
text:communities[i].name,
onclick: {
fn:FIRSTCLASS.apps.Workflows.SendTo.sendTo,
obj: {type:"community", community:communities[i], row:config.row}
}
});
}
if (citems.length) {
items.push(citems);
}
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];
FIRSTCLASS.apps.Integration.ECM.Browse.doBrowse({
'xuid':2000, '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});
} else if (object.type.indexOf("email") == 0) {
// open form, attach document
FIRSTCLASS.apps.Workflows.SendTo.doEmail(object);
} else if (object.type.indexOf("community") == 0) {
// copy
FIRSTCLASS.apps.Workflows.SendTo.doCopy(object);
} else if (object.type.indexOf("blog") == 0) {
// make blog post
FIRSTCLASS.apps.Workflows.SendTo.doBlog(object);
} else {
// do something else
}
}
};
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 + "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.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();
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();
FIRSTCLASS.apps.Workflows.SendTo._email.message.destroy();
};
FIRSTCLASS.apps.Workflows.SendTo.doSendValidateCB = function() {
return FIRSTCLASS.apps.Workflows.SendTo._email.message._validatedNames.length > 0;
};
FIRSTCLASS.apps.Workflows.SendTo.doSendNameValidateCB = function() {
if (FIRSTCLASS.apps.Workflows.SendTo.doSendValidateCB()) {
FIRSTCLASS.apps.Workflows.SendTo._email.dialog.getButtons()[0].set('disabled', false);
} else {
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: "HTML",
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 = ["",
" ",
" ",
" ",
" ",
"",
row.itemdata.body,
" "];
var tmpdom = document.createElement("div");
tmpdom.innerHTML = html.join("");
YAHOO.util.Connect.setForm(tmpdom.firstChild);
YAHOO.util.Connect.asyncRequest("POST", tmpdom.firstChild.action);
}
};
FIRSTCLASS.apps.Workflows.SendTo.doCopy = function(object) {
var itemuri = 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) {
to = FIRSTCLASS.session.baseURL + object.community.uri;
} else {
debugger;
}
var html = [" ",
" ",
" ",
" ",
" "];
var tmpdom = document.createElement("div");
tmpdom.innerHTML = html.join("");
YAHOO.util.Connect.setForm(tmpdom.firstChild);
YAHOO.util.Connect.asyncRequest("POST", tmpdom.firstChild.action, 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 = communityuri;
//FIRSTCLASS.apps.Workflows.MemberList._aclprivs = acl;
if (FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource) {
FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource.dispose();
FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource = false;
}
},
cleanup: function() {
if (!this._disabled) {
FIRSTCLASS.apps.Workflows.MemberList._dialog.hide();
FIRSTCLASS.apps.Workflows.MemberList._dialog.destroy();
FIRSTCLASS.apps.Workflows.MemberList._dialog = false;
FIRSTCLASS.apps.Workflows.MemberList._ACL = null;
FIRSTCLASS.apps.Workflows.MemberList._listView.dispose();
FIRSTCLASS.apps.Workflows.MemberList._listView = false;
FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource.dispose();
FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource = false;
FIRSTCLASS.apps.Workflows.MemberList._canedit = false;
}
},
doShow: function(communityuri, canedit) {
FIRSTCLASS.apps.Workflows.MemberList._canedit = canedit;
// show a dialog with a members list, merged with the ACL
FIRSTCLASS.apps.Workflows.MemberList.init(communityuri, canedit);
// get members list
var membersurl = communityuri + "__ListSubscribers";
var cfg = {
containerBaseUrl:membersurl,
itemrequest: false,
loadFull: true
};
FIRSTCLASS.apps.Workflows.MemberList.communityuri = 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) {
var aclurl = FIRSTCLASS.apps.Workflows.MemberList.communityuri + "__ACL/?Templates=JS&JSON=2";
YAHOO.util.Connect.asyncRequest('GET', aclurl, {
enableonreceived: enableonreceived,
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 && FIRSTCLASS.apps.Workflows.MemberList._MembersDataSource) {
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,
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();
}
},
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();
},
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 = this.communityuri + "__ACL";
var subscribersurl = this.communityuri + "__ListSubscribers";
var data = FIRSTCLASS.apps.Workflows.MemberList._ACL;
var found = false;
for (var i in data.records) {
if (data.records[i].cid == cid) {
found = i;
break;
}
}
if (subscription) {
var r = false;
for (var 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 = this.communityuri + "__ACL";
var data = FIRSTCLASS.apps.Workflows.MemberList._ACL;
var found = false;
for (var i in data.records) {
if (data.records[i].cid == cid) {
found = i;
if (data.records[i].rights == 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);
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 cid = FIRSTCLASS.apps.Workflows.MemberList.changeACLCB.cid;
var newacl = FIRSTCLASS.apps.Workflows.MemberList.changeACLCB.newacl;
var url = FIRSTCLASS.apps.Workflows.MemberList.communityuri + "__ACL/" + FIRSTCLASS.opCodes.FormSave + "?Clear=0&Close=0";
var data = FIRSTCLASS.apps.Workflows.MemberList._ACL;
var found = false;
if (data && data.records) {
for (var i in data.records) {
if (data.records[i].cid == cid) {
found = i;
}
}
}
var html = [" "];
html.push(" ");
html.push(" ");
html.push(" ");
var el = document.createElement("div");
el.innerHTML = html.join("");
FIRSTCLASS.util.submitForm(el.firstChild);
FIRSTCLASS.apps.Workflows.MemberList.requestACL(true);
},
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();
buttons[0].set('disabled', true);
for (var i in FIRSTCLASS.apps.Workflows.MemberList._elements.frm.elements) {
var 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();
buttons[0].set('disabled', false);
for (var i in FIRSTCLASS.apps.Workflows.MemberList._elements.frm.elements) {
var 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 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 + " ";
text.innerHTML = nameHtml;
FIRSTCLASS.util.User.setSmallProfPicUrlByCid(prof, row.cid, false,false,false,{width:20, height:27});
//element.setAttribute('fcid', 'user');
//element.setAttribute('fcattrs', row.name);
//element.setAttribute('uid', row.uid);
var data = FIRSTCLASS.apps.Workflows.MemberList._ACL;
var found = false;
if (data && data.records) {
for (var i in data.records) {
if (row.uid == data.records[i].cid) {
// found a record for this user
found = data.records[i];
break;
}
}
}
if (FIRSTCLASS.apps.Workflows.MemberList._ACL.edit && FIRSTCLASS.apps.Workflows.MemberList._canedit) {
// show delete, edit buttons
var html = [""];
for (var i in FIRSTCLASS.apps.Workflows.MemberList.rightsTrans) {
if (found && found.rights == i) {
html.push("");
} else {
html.push(" ");
}
html.push(FIRSTCLASS.apps.Workflows.MemberList.rightsTrans[i]);
html.push(" ");
}
if (found) {
html.push("");
} else {
html.push(" ");
}
html.push(FIRSTCLASS.locale.workflows.memberlist.rights.def);
html.push(" ");
html.push(" ");
html.push(" " + FIRSTCLASS.locale.workflows.memberlist.del + " ");
message.innerHTML = html.join("");
} else {
var rights = -1;
if (found) {
rights = found.rights;
}
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: {
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;
}
}
};
YAHOO.register("fcWorkflows", FIRSTCLASS.apps.Workflows, {version: "0.0.1", build: "1"});