// form.js - utilities for message creation and editing forms FIRSTCLASS.util.Form = { validateName: function(baseURL, string, fieldId, index, callback, options, allowgroups, params) { var requestUrl = FIRSTCLASS.lang.ensureSlashUrl(baseURL) + FIRSTCLASS.opCodes.Lookup+"?Templates=JS&Operation=InsertMulti&FieldID="+fieldId+"&charset=UTF-8&Srch="+FIRSTCLASS.lang.uesc(string); if (params) { requestUrl = requestUrl + "&"+ params; } if (typeof options == "undefined" || !options) { options = 4; } requestUrl += "&Options=" + options; var connManagerRequest = YAHOO.util.Connect.asyncRequest("GET", requestUrl, { success:function(response) { var newdata = []; try { newdata = YAHOO.lang.JSON.parse(response.responseText); } catch(x){ //YAHOO.log("JSON Parse Failed", "error", "Form.js"); callback.onFailure({"response":response}); return; } if (!allowgroups) { var data = []; for (var i in newdata.records) { if (newdata.records[i].nmattrs1.mailable == 1) { data.push(newdata.records[i]); } } newdata.records = data; } if (newdata.records && newdata.records.length == 1) { callback.onComplete({ "match":"single", "item":newdata.records[0], "pattern":string }); } else if (newdata.records && newdata.records.length > 1) { callback.onComplete({ "match":"multi", "dataSource":new FIRSTCLASS.util.DataSource({baseUrl:requestUrl, prePopulateData:newdata}), "pattern":string }); } else { callback.onComplete({ "match":"none", "pattern":string }); } }, failure:function(response) { callback.onFailure({"response":response}); } }); }, deleteName: function(baseURL, fieldId, index, cid, callback) { var param = "&Index="+index; if (typeof cid == "number") { param = "&ClientID="+cid; } var requestUrl = FIRSTCLASS.lang.ensureSlashUrl(baseURL) + FIRSTCLASS.opCodes.Lookup+"?Templates=JS&Operation=Delete&FieldID="+fieldId+param; var connManagerRequest = YAHOO.util.Connect.asyncRequest("GET", requestUrl, { success:function(response) { if (callback && callback.onComplete) { callback.onComplete(response); } }, failure:function(response) { if (callback && callback.onFailure) { callback.onFailure({"response":response}); } } }); }, add: function(baseURL, string, fieldId, index, callback, params, suppresslookup) { if (!params) { params = ""; } var lookup = FIRSTCLASS.opCodes.Lookup; if (suppresslookup) { lookup = ""; } var requestUrl = FIRSTCLASS.lang.ensureSlashUrl(baseURL) + lookup + "?Templates=JS&Operation=Add&FieldID="+fieldId + params; if (FIRSTCLASS.lang.isEmailAddress(string)) { requestUrl+="&Name=" + FIRSTCLASS.lang.uesc(string); } else { requestUrl+="&Name="+string; } var connManagerRequest = YAHOO.util.Connect.asyncRequest("GET", requestUrl, { success:function(response) { callback.onComplete(response); }, failure:function(response) { callback.onFailure({"response":response}); } }); }, nameValCompare: function(key, string) { var keys = key.split(" "); var strings = string.split("%20"); var lastindexfound = -1; var keyindex = 0; for (var i = 0; i < strings.length; i++) { if (strings[i] === "") { lastindexfound = i; continue; } while (keyindex < keys.length) { if (keys[keyindex++].indexOf(strings[i]) >= 0) { lastindexfound = i; break; } else { break; } } } return (lastindexfound == strings.length-1); } }; // Configuration variables for the message editor: // baseURL - the container for a new item or the item itself // op - operation to be performed - "Create" or "Edit" or FIRSTCLASS.opCodes.Reply or whatever // params - url param string to add to the edit request (no question mark) // element - element to contain the editor // objType - from FIRSTCLASS.objTypes // formID - the FirstClass form ID to be edited // formElId - the id of the
element in the template // bodytype - "plain" or "HTML" // quoteText - text to quote for replies // quoteAuth - him what said it // sendTo - default addressee // callback - callback object with the functions: // onLoaded - prepare calling object when editor is about to open // onFail - object failed to open // onDisplay - the editor content is in the DOM // validate - validate the forms data before submitting (return false to abort submitting) // onCancel - cancel button pressed // onSave - submit transaction completed // onCommand - user issued a command to the editor // onTyping - user typed in the editor // initHeight - initial height of editor // initWidth - initial width of editor // showAddr - show the address block // tbType - canned toolbar type - "message", "reply", "wiki", "blog" // toolbar - YUI toolbar config object if you want a custom toolbar // dataSource - data source for object's container // row - item's data source row if existing // upload - pass in YUI XHR upload param // autoHeight - true if you want editor to grow with the content // maxImage - (number) maximum pixel dimension of uploaded images; larger images will be thumbnailed FIRSTCLASS.util.Message = function(config) { if (!FIRSTCLASS.session.editor) { FIRSTCLASS.session.editor = new FIRSTCLASS.util.SharedEditor(); } this._maxImageSize = 0; // capture config this.configure(config); this._editor = null; // form the URL var url = []; var that = this; url.push(FIRSTCLASS.lang.ensureSlashUrl(this._baseUrl)); url.push(this._op); url.push("?FormID=" + this._formID); if (this._urlParams) { url.push("&" + this._urlParams); } url[0] = url.join(""); this._dialog = null; this._embedIdx = -1; this._embedContents = []; this._touches = []; // set up callbacks var callback = { success: function(o) { that.onOpen(o.responseText); }, failure: function(o) { window.clearInterval(this._touchTimer); this._touchTimer = null; if (that._callback.onFail) { var obj = {}; if (o && o.responseText) { try { obj = FIRSTCLASS.lang.JSON.parse(o.responseText); } catch (e) { } } that._callback.onFail(obj); } else { alert("FIRSTCLASS.util.Message - Failure to open"); } } }; // open the item YAHOO.util.Connect.asyncRequest("GET", url[0], callback); this._touchTimer = window.setInterval(function() { that.keepOpen(); }, 300000); }; FIRSTCLASS.util.Message.prototype.keepOpen = function() { var that = this; var callback = { success: function(o) { that._touches.push(true); }, failure: function(o) { that._touches.push(false); } }; url = FIRSTCLASS.lang.ensureSlashUrl(this._baseUrl) + "__Touch"; YAHOO.util.Connect.asyncRequest("GET",url,callback); }; FIRSTCLASS.util.Message.eatKeys = function(evt) { YAHOO.util.Event.stopPropagation(evt); }; FIRSTCLASS.util.Message.prototype.configure = function(config) { this._callback = config.callback || {}; this._baseUrl = config.baseURL; this._ds = config.dataSource; this._dsr = config.row; this._upload = config.upload; this.dontClear = config.dontClear; if (config.quoteText) { this._quote = config.quoteText; if (config.quoteAuth) { this._quoter = config.quoteAuth; } } var param = this._baseUrl.indexOf("?"); if (param != -1) { this._urlParams = this._baseUrl.slice(param+1); this._baseUrl = this._baseUrl.slice(0,param); } if (config.params) { if (this._urlParams) { this._urlParams += "&" + config.params; } else { this._urlParams = config.params; } } if (!config.overrideForms) { this._urlParams += "&Templates=Forms"; } else { this._urlParams += config.overrideForms; } this._op = config.op; this._domEl = config.element; YAHOO.util.Event.addListener(this._domEl, "keyup", FIRSTCLASS.util.Message.eatKeys); YAHOO.util.Event.addListener(this._domEl, "keydown", FIRSTCLASS.util.Message.eatKeys); this._formElId = config.formElId; this._objType = config.objType || FIRSTCLASS.objTypes.message; this._otTxt = "Message"; this._nvoptions = null; if (config.nvoptions) { this._nvoptions = config.nvoptions; } if (this._objType == FIRSTCLASS.objTypes.odocument) { this._otTxt = "Document"; this._formID = config.formID || 20501; } else { this._otTxt = "Message"; this._formID = config.formID || 141; } this._bodyType = config.bodyType || 'plain'; this._height = config.initHeight || this._domEl.offsetHeight; this._autoHeight = config.autoHeight || false; this._width = config.initWidth || '99%'; this._hPad = 60; if (config.showAddr !== undefined) { this._addressable = config.showAddr; } else { this._addressable = true; } this._editForm = null; this._nameTable = null; this._nameContainer = null; this._validatedNames = null; this._currentlySubmitting = false; if (config.maxImage) { this._maxImageSize = config.maxImage; } if (config.tbType) { this._tbType = config.tbType; } }; FIRSTCLASS.util.Message.prototype.destroy = function() { if (this._editor) { FIRSTCLASS.session.editor.release(); } }; FIRSTCLASS.util.Message.prototype.enableToolbarButtons = function(toolbarType) { var enableGroups; var group, label; switch (toolbarType) { case 'wiki': enableGroups = [ 'undoredo', 'insert', 'wikilink', 'doclink', 'weblink', 'embed', 'indent', 'align', 'list', 'parastyle', 'textattrs', 'textstyle']; break; case 'reply': enableGroups = [ 'undoredo', 'insert', 'weblink', 'quote', 'embed', 'list', 'textstyle' ]; break; case 'blog': enableGroups = [ 'undoredo', 'insert', 'weblink', 'embed', 'list', 'textattrs', 'textstyle' ]; break; case 'sendto': enableGroups = [ 'undoredo', 'insert', 'weblink', 'list', 'textattrs', 'textstyle' ]; break; default: enableGroups = [ 'undoredo', 'insert', 'weblink', 'quote', 'embed', 'list', 'textattrs', 'textstyle' ]; break; } var list = this._editor.toolbar._buttonGroupList; // disable all groups for (var i in list) { if (typeof list[i] === 'object') { group = list[i]; YAHOO.util.Dom.setStyle(list[i], 'display', 'none'); } if (FIRSTCLASS.session.editor._tbGroups[i]) { FIRSTCLASS.session.editor._tbGroups[i].enabled = false; } } // enable selected groups for (i in enableGroups) { if (typeof list[enableGroups[i]] === 'object') { label = enableGroups[i]; group = list[label]; YAHOO.util.Dom.setStyle(group, 'display', 'block'); } if (FIRSTCLASS.session.editor._tbGroups[enableGroups[i]]) { FIRSTCLASS.session.editor._tbGroups[enableGroups[i]].enabled = true; } } }; FIRSTCLASS.util.Message.prototype.onOpen = function(messageText) { var that = this; // check if content is editable var success = (messageText.indexOf("= 0) ? true : false; if (this._callback.onLoaded) { this._callback.onLoaded(success); } if (success) { // hide edit element FIRSTCLASS.ui.Dom.setInnerHTML(this._domEl, this.prepareContent(messageText)); if (this._bodyType == "HTML") { this.createEditor(); } var cancelBtn = FIRSTCLASS.ui.Dom.getChildByIdName("fcDocFormCancel", this._domEl); var saveBtn = FIRSTCLASS.ui.Dom.getChildByIdName("fcDocFormSave", this._domEl); var tags = FIRSTCLASS.ui.Dom.getChildByIdName("fcTagContainer", this._domEl); var oldtags = FIRSTCLASS.ui.Dom.getChildByIdName("fcTags", this._domEl); if (tags && FIRSTCLASS.apps.Workflows && FIRSTCLASS.apps.Workflows.Tags) { window.setTimeout(function() { tags.innerHTML = "
"; that.tagconfig = { domElement:tags.firstChild, item: FIRSTCLASS.ui.parseServerTags(oldtags.value), hidesuggestions:true, destField: tags.lastChild, showonconfig:true }; FIRSTCLASS.apps.Workflows.Tags.reconfigure(that.tagconfig); }, 10); } // set up form event hooks this._editForm = FIRSTCLASS.ui.Dom.getChildByIdName(this._formElId, this._domEl); if (this._editForm) { var newUrl = this._editForm.getAttribute("fcurl"); if (newUrl) { this._baseUrl = newUrl; } if (saveBtn) { YAHOO.util.Event.addListener(saveBtn, "click", function(evt) { if (!that._currentlySubmitting) { that._currentlySubmitting = true; that.onSubmit(); } }); } this._editForm.onsubmit = function() { return false; }; if (cancelBtn) { YAHOO.util.Event.addListener(cancelBtn,"click",function() { that.onCancel(that); }); } // addressing if (this._objType == FIRSTCLASS.objTypes.message) { var validatedNames = YAHOO.util.Dom.getElementsByClassName('fcValidatedName', "", this._editForm); this._nameContainer = FIRSTCLASS.ui.Dom.getChildByClassName('fcValidatedNamesTo', this._editForm); if (this._nameContainer) { this._nameTable = this._nameContainer.firstChild; if (!this._addressable) { YAHOO.util.Dom.setStyle(this._nameContainer, 'display', 'none'); YAHOO.util.Dom.setStyle(this._nameContainer.previousSibling, 'display', 'none'); } } if (this._addressable) { this._validatedNames = validatedNames; for (var i in validatedNames) { var nm = validatedNames[i]; var cont = document.createElement("div"); var button = new YAHOO.widget.Button({label:FIRSTCLASS.locale.workflows.sendto.email.remove, container:cont}); button.addListener("click", function() { that.deleteName(that._nameContainer, that.getIndexForRow(that._validatedNames, nm)); }); nm.lastChild.appendChild(cont); } var inputRow = FIRSTCLASS.ui.Dom.getChildByClassName("fcNameValInput", this._editForm); var addButton = new YAHOO.widget.Button(inputRow.lastChild.firstChild); this._inputRow = inputRow.cloneNode(true); var nameButtons = YAHOO.util.Dom.getElementsByClassName('fcNameAddButton', "", this._editForm); var nameInputs = YAHOO.util.Dom.getElementsByClassName('fcNameValTo', "", this._editForm); this.inputs = { "to": nameInputs[0] }; addButton.addListener("click", function(evt) { that.addName(that._nameContainer, nameInputs[0].value); }); YAHOO.util.Event.addListener(nameInputs[0], "keyup", function(evt) { if (evt.keyCode == 13) { that.addName(that._nameContainer, nameInputs[0].value); } }); YAHOO.util.Event.addListener(nameInputs[0], "blur", function(evt) { if (nameInputs[0].value.length > 0) { that.addName(that._nameContainer, nameInputs[0].value); } }); } } // show it if (this._bodyType == "HTML") { if (YAHOO.env.ua.ie && !FIRSTCLASS.session.editor._firstEdit) { that.onEditorReload(); this.onEditorLoaded(); } else { this._editor.render(); } } else { // post-display callback - non-styled case YAHOO.util.Dom.removeClass(this._domEl,"fcHidden"); if (this._callback.onDisplay) { this._callback.onDisplay(); } } } } }; FIRSTCLASS.util.Message.prototype.prepareContent = function (text) { if (text.indexOf('id="BODY"') > 0) return FIRSTCLASS.util.url.expandImageUrls(this._baseUrl, text); else return text; }; FIRSTCLASS.util.Message.prototype.refreshNameInput = function() { if (this._nameTable && this._inputRow) { var input = this._nameTable.lastChild.firstChild.firstChild.firstChild; input.value = ""; /* var newRow = this._inputRow.cloneNode(true); this._nameTable.replaceChild(newRow,this._nameTable.lastChild);*/ } }; FIRSTCLASS.util.Message.prototype.saveCheckpoint = function() { this.onSubmit(true); }; FIRSTCLASS.util.Message.prototype.onSubmit = function(incremental) { if (!incremental) { window.clearInterval(this._touchTimer); } if (this._editForm && this._editForm.action) { var that = this; var action = this._editForm.action; var parts = action.split("?"); action = parts[0]; if (incremental) { action += "?Close=-1"; } else { action += "?Close=0"; } if (this.dontClear) action += "&Clear=0"; if (this._callback.validate) { if (this._callback.validate() === false) { this._currentlySubmitting = false; return; } } var saveCB = { success: function(a) { if (that._callback.onSave && !incremental) { that._callback.onSave(); } YAHOO.util.Connect.resetDefaultHeaders(); }, failure: function(a) { if (that._callback.onFail && !incremental) { that._callback.onFail(a); } }, upload: function(eventType, args) { if (that._callback.onSave && !incremental) { that._callback.onSave(); } YAHOO.util.Connect.resetDefaultHeaders(); } }; if (incremental) { this._editForm["FieldID:8101=LITERALSTRING"].value = "Auto-saved"; } // grab attachment list, then grab content, audit attachments, and save that.getAttachmentList(function(attachments, success) { if (success) { that._attachmentList = attachments; } else { that._attachmentList = []; } that.getContentFromForm(); if (!incremental) { that.deleteUnusedAttachments(); } FIRSTCLASS.util.submitForm(that._editForm, that._upload, saveCB, action); }); } return; }; // increment ref-count for attachment with passed-in name FIRSTCLASS.util.Message.prototype.addAttachRef = function(attachName) { if (this._attachmentList) { for (var idx = 0; idx < this._attachmentList.length; idx++) { var attachment = this._attachmentList[idx]; if (attachment.name.toLowerCase().localeCompare(attachName.toLowerCase()) === 0) { if (attachment.refCount) { attachment.refCount++; } else { attachment.refCount = 1; } return; } } } }; // delete all embedded attachments with zero ref-count FIRSTCLASS.util.Message.prototype.deleteUnusedAttachments = function() { var url = this._baseUrl, deleteUrl = ""; if (url.charAt(url.length-1) != '/') { url = url.slice(0,url.lastIndexOf('/')); url = url.slice(0,url.lastIndexOf('/')+1); } if (url.indexOf(FIRSTCLASS.opCodes.FormEdit) > 0) { url = url.slice(0,url.lastIndexOf(FIRSTCLASS.opCodes.FormEdit)); } if (this._attachmentList) { for (var idx = 0; idx < this._attachmentList.length; idx++) { var attachment = this._attachmentList[idx]; if (attachment.embed && !attachment.refCount) { deleteUrl = url + attachment.name + "?Delete=1&Close=-1"; YAHOO.util.Connect.asyncRequest('GET',deleteUrl); } } } }; FIRSTCLASS.util.Message.prototype.filterContent = function(html) { // allow inline styles for wikis if (this._tbType !== "wiki") { // style tags html = html.replace(/]*>[\s\S]*?<\/style[^>]*>/gi, ''); // mso classes html = html.replace(/ class="Mso[a-zA-Z]*"/gi, ''); //ms m: tags html = html.replace(/]*>[\s\S]*?<\/m:[^>]*>/gi, ''); // xml defs html = html.replace(/]*>[\s\S]*?<\/xml[^>]*>/gi, ''); // comments html = html.replace(//gi, ''); } else { // just the if's html = html.replace(//gi, ''); } // terminate wacky embed divs if (YAHOO.env.ua.webkit) { html = html.replace(/]*fcEmbed[^>]*>/gi, "$&"); } // external stylesheets html = html.replace(/]*>/gi, ''); // meta tags html = html.replace(/]*>/gi, ''); return html; }; FIRSTCLASS.util.Message.prototype.getContentFromForm = function() { if (this._bodyType != 'HTML') { if (this._editForm.BODY) { var text = this._editForm.BODY.value; var lines = text.split("\n"); YAHOO.util.Dom.setStyle(this._editForm.BODY, "display", "none"); var saving = document.createElement("div"); saving.innerHTML = "Posting..."; this._editForm.BODY.parentNode.appendChild(saving); this._editForm.BODY.value = this.filterContent(lines.join("
")); } } else { // get root content node and process it and its kids var baseNode = this._editor._getDoc().body; this._formUrlObj = FIRSTCLASS.util.url.decomposeUrl(this._editForm.action); this.procBodyNodes(baseNode); FIRSTCLASS.session.editor.saveHTML(); var line = this._editForm.BODY.value.split("\n"); this._editForm.BODY.value = this.filterContent(line.join(" ")); var field = {}; var fields = null; fields = this._editForm.elements; for (var i in fields) { field = fields[i]; if (field && field.id && (typeof field.id === "string")) { if (field.id.indexOf("BODY_") >= 0 || field.id.indexOf("BODYCONTAINER") >= 0) { field.value = ""; } } } } this.prepareTags(); }; FIRSTCLASS.util.Message.prototype.procBodyNodes = function(inNode) { switch(inNode.tagName) { case 'IMG': this.procImageNode(inNode); break; case 'A': this.procAnchorNode(inNode); break; case 'DIV': this.procDivNode(inNode); break; } // process child nodes for (var n = 0; n < inNode.childNodes.length; n++) { this.procBodyNodes(inNode.childNodes[n]); } }; FIRSTCLASS.util.Message.prototype.procImageNode = function(node) { var imgObj = FIRSTCLASS.util.url.decomposeUrl(node.src); var fcattrs = node.getAttribute('fcattrs'); var fcid = node.getAttribute('fcid'); var isEmbed = ((fcid == 'fcestart') && (typeof fcattrs != 'undefined')) ? true : false; var isAttach = ((imgObj.path.length > 0) && (imgObj.path[0] == "Login")) ? true : false; if (isEmbed) { var attrs = fcattrs.split(';'); this.addAttachRef('embed' + attrs[0] + '.html'); var divNode = this._editor._getDoc().createElement('div'); divNode.className = 'fcEmbed'; divNode.setAttribute('fcid', 'fcestart'); divNode.setAttribute('fcattrs', fcattrs); node.parentNode.replaceChild(divNode, node); node = divNode; } else if (isAttach) { node.src = imgObj.path[imgObj.path.length - 1]; this.addAttachRef(imgObj.path[imgObj.path.length - 1]); } }; FIRSTCLASS.util.Message.prototype.procAnchorNode = function(node) { var dstObj = FIRSTCLASS.util.url.decomposeUrl(node.href); var fcth = node.getAttribute('fcth'); var isThumbnail = false; if ((fcth !== null) && (typeof fcth !== 'undefined')) { isThumbnail = true; } if (isThumbnail) { node.href = dstObj.path[dstObj.path.length - 1]; this.addAttachRef(dstObj.path[dstObj.path.length - 1]); } }; FIRSTCLASS.util.Message.prototype.procDivNode = function(node) { // get rid of temporary image tag if (node.className == "fcEmbed") { if (node.firstChild.tagName == 'IMG') { this.procImageNode(node.firstChild); } node.innerHTML = ""; } }; FIRSTCLASS.util.Message.prototype.prepareTags = function() { var tags = $("fcTags"); var otags = $("fcTagOriginal"); //var dtags = $("fcTagDiff"); var thetag; if (tags && otags) { var atags = tags.value.split(","); for (var i in atags) { thetag = FIRSTCLASS.lang.string.trim(atags[i]); if (thetag.charAt(0) == "\"" || thetag.charAt(0) == "\'") { thetag = thetag.substr(1); } if (thetag.charAt(thetag.length-1) == "\"" || thetag.charAt(thetag.length-1) == "\'") { thetag = thetag.substr(0, theTag.length-1); } atags[i] = thetag; } tags.value = atags.join(","); /*var adtags = []; for (var j in atags) { thetag = FIRSTCLASS.lang.string.trim(atags[j]); if (otags.value.indexOf(thetag) < 0 ) { adtags.push(thetag); } } dtags.value = adtags.join(",");*/ } }; FIRSTCLASS.util.Message.prototype.onCancel = function() { var that = this; var paramStr = "?Quit=1"; window.clearInterval(this._touchTimer); if (this._op == FIRSTCLASS.opCodes.MemForm) { if (that._callback.onCancel) { that._callback.onCancel(); } } else { if ((this._objType == FIRSTCLASS.objTypes.message) || (this._op == FIRSTCLASS.opCodes.FormNew) || (this._op == FIRSTCLASS.opCodes.MemForm)) { paramStr = "?Delete=1"; } var cancelCallback = { success: function(o) { if (that._callback.onCancel) { that._callback.onCancel(); } }, failure: function(o) { alert("Could not cancel message post"); if (that._callback.onCancel) { that._callback.onCancel(); } } }; if (this._editForm) { var url = this._editForm.getAttribute('fcUrl'); url = FIRSTCLASS.lang.removeSlashUrl(url) + paramStr; var request = YAHOO.util.Connect.asyncRequest("GET", url, cancelCallback); } } }; FIRSTCLASS.util.Message.prototype.createEditor = function () { var that = this; var myEditCfg = { toolbar: this._toolbar, height: this._height, width: (this._width > this._hPad ? this._width - this._hPad : "100%"), dompath: false, animate: true, filterWord: true }; if ((this._op == FIRSTCLASS.opCodes.Reply) || (this._op == FIRSTCLASS.opCodes.FormEdit) || (this._op == FIRSTCLASS.opCodes.FormNew)) { myEditCfg.focusAtStart = true; } if (this._autoHeight && !YAHOO.env.ua.ie) { myEditCfg.autoHeight = true; } if (YAHOO.env.ua.ie) { myEditCfg.css = 'html { height: 95%; } body { padding: 0px; background-color: #fff; font: 13px/1.22 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small; } a, a:visited, a:hover { color: blue !important; text-decoration: underline !important; cursor: text !important; } .warning-localfile { border-bottom: 1px dashed red !important; } .yui-busy { cursor: wait !important; } img.selected { border: 2px dotted #808080; } img { cursor: pointer !important; border: none; }'; } var domEl = FIRSTCLASS.ui.Dom.getChildByIdName('BODY', this._domEl); if (!domEl) { domEl = 'BODY'; } this._editor = FIRSTCLASS.session.editor.getEditor(this, domEl, myEditCfg); for (var i in this._editor._disabled) { if (this._editor._disabled[i] == 'createlink') { this._editor._disabled[i] = 'pglevel'; this._editor._disabled.splice(i,0,'textstyle'); break; } } }; FIRSTCLASS.util.Message.prototype.preProcessNodes = function() { // function to walk nodes and insert embed placeholders var processNode = function(node, cfg) { if (node.tagName == "DIV" && node.className == "fcEmbed") { var image = cfg.image.cloneNode(true); image.className = node.className; image.setAttribute('fcid', node.getAttribute('fcid')); image.setAttribute('fcattrs', node.getAttribute('fcattrs')); node.parentNode.replaceChild(image, node); } for (var c = 0; c < node.childNodes.length; c++) { processNode(node.childNodes[c], cfg); } }; // find base node if (this._editor && this._editor._getDoc()) { var baseEl = this._editor._getDoc().body; var theImage = this._editor._getDoc().createElement('img'); theImage.setAttribute('src', FIRSTCLASS.session.templatebase + "/firstclass/images/EmbedActiveContent.gif"); processNode(baseEl, { image: theImage, message: this }); } }; FIRSTCLASS.util.Message.prototype.onEditorLoaded = function() { if (this._callback.onDisplay) { this._callback.onDisplay(); } if (this._quote) { this.insertQuote(this._quote, this._quoter); } this.preProcessNodes(); this.updateEmbedIndex(); if (this._editForm && this._op != FIRSTCLASS.opCodes.Reply) { var subj = this._editForm.Subject; if (subj) { subj.focus(); } } else { if (!FIRSTCLASS.session.editor._firstEdit) { this._editor.focus(); } } }; FIRSTCLASS.util.Message.prototype.onEditorReload = function() { this._editor.setEditorHTML(FIRSTCLASS.session.editor._newContent); this.updateEditorDimensions(); this.enableToolbarButtons(this._tbType); }; FIRSTCLASS.util.Message.prototype.updateEditorDimensions = function() { if (this._editor && this._height) { var h = 240, th = (this._editor.toolbar.get('element').clientHeight + 2); if (typeof this._height === 'string') { h = this._height.slice(0, this._height.indexOf('px')); } else if (typeof this._height === 'number') { h = this._height; } var newH = (h - th); this._editor.set('height', newH + 'px'); } }; // OpenDialog - open a new editor dialog // Editor dialog config: // .title - "window title" // .tbid - toolbar container id (used to set up css) // .tb - toolbar config // .body - html body for non-toolbar dialogs (must include a tb container with id = tbid if including body and toolbar) // .width - sets the width of the dialog, surprisingly // .callback: // .done() // .cancel() // FIRSTCLASS.util.Message.prototype.openDialog = function(config) { var that = this; if (this._dialog !== null) { // close current this.closeDialog(); } this._dialog = {}; this._dialog.config = {}; YAHOO.lang.augmentObject(this._dialog.config, config); this._dialog.editEl = this._editor.currentElement[0]; this._dialog.el = document.createElement('div'); this._dialog.el.setAttribute('style','visibility:hidden'); this._dialog.el.setAttribute('id','fcEditorDialog'); var header = document.createElement('div'); var body = document.createElement('div'); // insert body if any if (this._dialog.config.body) { body.innerHTML = this._dialog.config.body; } // insert toolbar into body or selected subelement if (this._dialog.config.tb) { var tbarCont = document.createElement('div'); tbarCont.id = this._dialog.config.tbid + '_toolbar'; var ins = body; if (this._dialog.config.body) { var tbc = FIRSTCLASS.ui.Dom.getChildByIdName(this._dialog.config.tbid); if (tbc) { ins = tbc; } } ins.appendChild(tbarCont); this._dialog.tbar = new YAHOO.widget.Toolbar(tbarCont, this._dialog.config.tb); this._dialog.tbar.editor_el = this._dialog.editEl; var fm = this._dialog.tbar.getButtonByValue('fontname'); if (fm) { fm._menu.beforeShowEvent.subscribe(function() { this._menu.cfg.setProperty('zindex',3); },fm,true); } } this._domEl.appendChild(this._dialog.el); // create the dialog var buttons = []; if (typeof this._dialog.config.cancel !== 'undefined') { buttons.push( { text: FIRSTCLASS.locale.editor.textstyle.cancel, handler: function() { that[that._dialog.config.cancel](); }, isDefault:false }); } if (typeof this._dialog.config.done !== 'undefined') { buttons.push( { text:FIRSTCLASS.locale.editor.textstyle.done, handler: function() { that[that._dialog.config.done](); }, isDefault: true }); } var dlgConfig = { draggable: false, visible: false, constraintoviewport : true, postmethod : "manual", xy: [ this._domEl.offsetHeight/2 - 100, this._domEl.offsetWidth/2-200 ], iframe: (navigator.userAgent.toLowerCase().indexOf("msie") > -1), buttons : buttons }; if (this._dialog.config.width) { dlgConfig.width = this._dialog.config.width; } this._dialog.dlg = new YAHOO.widget.Dialog("fcEditorDialog", dlgConfig); if (this._dialog.config.title) { this._dialog.dlg.setHeader(this._dialog.config.title); } if (body) { this._dialog.dlg.setBody(body); } this._dialog.dlg.render(); this._dialog.dlg.show(); if (typeof this._dialog.config.cancel !== 'undefined') { this._dialog.dlg.cancelEvent.subscribe(function() { that[that._dialog.config.cancel](); }); } return; }; FIRSTCLASS.util.Message.prototype.openTSDialog = function() { var dlgCfg = {}; var that = this; if (YAHOO.env.ua.ie) { var e = this._editor; var el; if (e.get('insert')) { el = e._createInsertElement({}); } else { e._createCurrentElement('span', {}); e._selectNode(e.currentElement[0]); el = e.currentElement[0]; } } dlgCfg.tbid = 'fcTextStyle'; dlgCfg.title = FIRSTCLASS.locale.editor.textstyle.title; dlgCfg.width = '350px'; dlgCfg.tb = { collapse: true, titlebar: false, draggable: false, buttonType: 'advanced', buttons: [ { group: 'style', label: FIRSTCLASS.locale.editor.textstyle.style, buttons: [ { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.bold, value: 'bold' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.italic, value: 'italic' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.underline, value: 'underline' } ] }, { type: 'separator' }, { group: 'fontstyle', label: FIRSTCLASS.locale.editor.textstyle.font, buttons: [ { type: 'select', label: 'Arial', value: 'fontname', menu: [ { text: 'Arial', checked: true }, { text: 'Arial Black' }, { text: 'Comic Sans MS' }, { text: 'Courier New' }, { text: 'Lucida Console' }, { text: 'Tahoma' }, { text: 'Times New Roman' }, { text: 'Trebuchet MS' }, { text: 'Verdana' } ] } ] }, { type: 'separator' }, { group: 'fontsize', label: FIRSTCLASS.locale.editor.textstyle.size, buttons: [ { type: 'select', label: '13 pt', value: 'textsize', menu: [ { text: '9 pt' }, { text: '10 pt' }, { text: '12 pt' }, { text: '13 pt', checked: true }, { text: '14 pt' }, { text: '16 pt' }, { text: '18 pt' }, { text: '20 pt' }, { text: '24 pt' }, { text: '28 pt' }, { text: '36 pt' }, { text: '72 pt' } ] } ] }, { type: 'separator' }, { group: 'color', label: FIRSTCLASS.locale.editor.textstyle.color, buttons: [ { type: 'color', label: FIRSTCLASS.locale.editor.textstyle.fcolor, value: 'forecolor' } ] }, { type: 'separator' }, { group: 'alignment', label: FIRSTCLASS.locale.editor.textstyle.align, buttons: [ { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.left, value: 'justifyleft' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.center, value: 'justifycenter' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.right, value: 'justifyright' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.just, value: 'justifyfull' } ] }, { type: 'separator' }, { group: 'position', label: FIRSTCLASS.locale.editor.textstyle.pos, buttons: [ { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.sub, value: 'subscript' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.sup, value: 'superscript' } ] } ] }; dlgCfg.cancel = 'TSDCancel'; dlgCfg.done = 'TSDDone'; this.openDialog(dlgCfg); if (YAHOO.env.ua.ie) { this._dialog._tsElement = el; } // get current state from editor this._TSStates = []; this.updateTSForm(); this._TSUpdates = []; // set up callback this._dialog.tbar.on('buttonClick', this.handleTSClick, this, true); return; }; FIRSTCLASS.util.Message.prototype.handleTSClick = function(ev) { var value = ''; var cmd = ev.button.value; if (ev.button.menucmd) { value = cmd; cmd = ev.button.menucmd; } if (ev.button.color !== undefined) { value = ev.button.color; } this.updateTSForm({cmd:cmd, value:value}); YAHOO.util.Event.stopEvent(ev); return true; }; // Update the text style form controls based on document state and changes made so far FIRSTCLASS.util.Message.prototype.updateTSForm = function(update) { var initial = this._TSStates.length === 0, tb = this._dialog.tbar, fn_button = tb.getButtonByValue('fontname'), fs_button = tb.getButtonByValue('textsize'), Dom = YAHOO.util.Dom, path = this._editor._getDomPath(), elem = null, tag = null, cmd = null, family = null, fontsize = null, validFont = false; if (initial) { // initialize state array this._TSStates = { bold: false, italic: false, underline: false, forecolor: 0, justifyleft: true, justifyright: false, justifycenter: false, justifyfull: false, subscript: false, superscript: false, fontname: 'Arial', textsize: '13 pt' }; // traverse dom path to calculate initial values from content for (var i = 0; i < path.length; i++) { elem = path[i]; tag = elem.tagName.toLowerCase(); if (elem.getAttribute('tag')) { tag = elem.getAttribute('tag'); } cmd = this._editor._tag2cmd[tag]; if (cmd !== undefined) { this._TSStates[cmd] = true; } else { //Bold and Italic styles if (elem.style.fontWeight.toLowerCase() == 'bold') { this._TSStates.bold = true; } if (elem.style.fontStyle.toLowerCase() == 'italic') { this._TSStates.italic = true; } if (elem.style.textDecoration.toLowerCase() == 'underline') { this._TSStates.underline = true; } //Handle Alignment switch (elem.style.textAlign.toLowerCase()) { case 'left': case 'right': case 'center': case 'justify': var alignType = elem.style.textAlign.toLowerCase(); if (elem.style.textAlign.toLowerCase() == 'justify') { alignType = 'full'; } this._TSStates['justify'+alignType] = true; break; } // Handle font name and size family = elem.getAttribute('face'); if (Dom.getStyle(elem, 'font-family')) { family = Dom.getStyle(elem, 'font-family'); //Adobe AIR Code family = family.replace(/'/g, ''); } if (family !== null) { this._TSStates.fontname = family; } fontsize = parseInt(Dom.getStyle(elem, 'fontSize'), 10); if (fontsize !== null) { this._TSStates.textsize = '' + fontsize + ' pt'; } } } } // update state on change var j; if (update) { switch (update.cmd) { // delete duplicate toggles, set value case 'bold': case 'italic': case 'underline': case 'subscript': case 'superscript': update.value = this._TSStates[update.cmd] ? false : true; for (j in this._TSUpdates) { if (this._TSUpdates[j].cmd == update.cmd) { delete this._TSUpdates[j]; } } break; // radios case 'justifyleft': case 'justifyright': case 'justifycenter': case 'justifyfull': update.value = true; if (update.cmd !== 'justifyleft') { this._TSStates.justifyleft = false; for (j in this._TSUpdates) { if (this._TSUpdates[j].cmd == 'justifyleft') { delete this._TSUpdates[j]; } } } if (update.cmd !== 'justifyright') { this._TSStates.justifyright = false; for (j in this._TSUpdates) { if (this._TSUpdates[j].cmd == 'justifyright') { delete this._TSUpdates[j]; } } } if (update.cmd !== 'justifycenter') { this._TSStates.justifycenter = false; for (j in this._TSUpdates) { if (this._TSUpdates[j].cmd == 'justifycenter') { delete this._TSUpdates[j]; } } } if (update.cmd !== 'justifyfull') { this._TSStates.justifyfull = false; for (j in this._TSUpdates) { if (this._TSUpdates[j].cmd == 'justifyfull') { delete this._TSUpdates[j]; } } } break; // specials case 'forecolor': update.value = '#' + update.value; break; // case 'fontname': // case 'textsize': } this._TSUpdates.push(update); this._TSStates[update.cmd] = update.value; } // update the form for (var b in this._TSStates) { var s = this._TSStates[b]; if (b) { switch (b) { case 'bold': case 'italic': case 'underline': case 'justifyleft': case 'justifyright': case 'justifycenter': case 'justifyfull': case 'subscript': case 'superscript': if (s) { tb.selectButton(b); } else { tb.deselectButton(b); } break; case 'fontname': for (j = 0; j < fn_button._configs.menu.value.length; j++) { var m = fn_button._configs.menu.value[j].text.toLowerCase(); if (s && s.toLowerCase().indexOf(m) >= 0) { validFont = true; s = fn_button._configs.menu.value[j].text; break; } } if (!validFont) { s = 'Arial'; } var label = '' + s + ''; if (fn_button.get('label') != label) { fn_button.set('label', label); fn_button.checkValue(s); } break; case 'textsize': fontsize = parseInt(s, 10); if ((fontsize === null) || isNaN(fontsize)) { fontsize = 13; } fs_button.set('label', '' + fontsize + ' pt'); break; } } } return; }; FIRSTCLASS.util.Message.prototype.TSDCancel = function() { this.closeDialog(); return; }; FIRSTCLASS.util.Message.prototype.TSDDone = function() { var that = this; var i = 0; if (this._dialog._tsElement) { this._editor._selectNode(this._dialog._tsElement); } var t = window.setInterval(function() { var update = that._TSUpdates[i++]; if (update.cmd == 'textsize') { update.value = update.value.slice(0, 2) + 'px'; update.cmd = 'fontsize'; } that._editor.execCommand(update.cmd, update.value); if (i >= that._TSUpdates.length) { window.clearInterval(t); that.closeDialog(); } }, 100); return; }; // create new embed div or select current one if in selection path FIRSTCLASS.util.Message.prototype.createEmbedEl = function() { var el = this._editor._getSelectedElement(), theImage = null, e = this._editor; if (!e._isElement(el, 'img') || !YAHOO.util.Dom.hasClass(el, 'fcEmbed')) { if (!el || !el.tagName || (el.tagName !== 'IMG')) { e.execCommand('inserthtml', ""); var imgs = e._getDoc().getElementsByTagName('img'); for (var im = 0; im < imgs.length; im++) { if (imgs[im].getAttribute('src')) { if (imgs[im].getAttribute('src').indexOf('EmbedActiveContent.gif') >= 0) { if (!imgs[im].getAttribute('fcattrs')) { el = imgs[im]; e.currentElement[0] = el; YAHOO.util.Dom.addClass(e.currentElement[0], 'fcEmbed'); var brEl = e._getDoc().createElement('br'); YAHOO.util.Dom.insertAfter(brEl, e.currentElement[0]); return true; } } } } } // e._createCurrentElement('img'); // theImage = e._swapEl(e.currentElement[0], 'img'); // e.currentElement[0] = theImage; // YAHOO.util.Dom.addClass(theImage, 'fcEmbed'); // theImage.src = FIRSTCLASS.session.templatebase + "/firstclass/images/EmbedActiveContent.gif"; // var brEl = e._getDoc().createElement('br'); // YAHOO.util.Dom.insertAfter(brEl, e.currentElement[0]); // return true; } else { e.currentElement[0] = el; } return false; }; // check embed content and return any valid content if found FIRSTCLASS.util.Message.prototype.validEmbedContent = function() { var content = this._dialog._contentEl.value, srchTags = ['embed', 'object', 'applet'], valid = false, sPos, ePos, i, tag, start = -1, end = -1; for (i = 0; i < srchTags.length; i++) { tag = srchTags[i]; // find first tag start sPos = content.indexOf('<' + tag); // find end tag if (sPos >= 0) { var endtag = '\/'+tag+'>'; ePos = content.lastIndexOf(endtag); if (sPos < start || start < 0) { start = sPos; end = ePos + tag.length + 2; } } } if (start >= 0 && end >= 0) { this._dialog._contentEl.value = content.slice(start, end); valid = true; } return valid; }; FIRSTCLASS.util.Message.prototype.openEmbedDialog = function() { var newEmbed = this.createEmbedEl(); var embedEl = this._editor.currentElement[0]; var dlgCfg = {}; var that = this; dlgCfg.title = FIRSTCLASS.locale.editor.embed.title; dlgCfg.cancel = 'embedCancel'; dlgCfg.done = 'embedDone'; var html = []; html.push("
"); html.push(""); html.push(""); html.push("
"); html.push("
"); html.push("
"); dlgCfg.body = html.join(""); if (YAHOO.env.ua.ie) { dlgCfg.width = '415px'; } this.openDialog(dlgCfg); this._dialog._form = FIRSTCLASS.ui.Dom.getChildByIdName('fcembedform', this._dialog.el); this._dialog._form.setAttribute("autocomplete", "off"); this._dialog._contentEl = FIRSTCLASS.ui.Dom.getChildByIdName('fcEmbedField', this._dialog.el); this._dialog._embedEl = embedEl; this._dialog._isNew = newEmbed; // fetch previous contents and set focus var theAttrs = embedEl.getAttribute('fcattrs'); if (theAttrs) { var params = theAttrs.split(";"); var index = params[0] - 0; if (!newEmbed) { if (this._embedContents[index]) { this._dialog._contentEl.value = this._embedContents[index]; window.setTimeout(function() { that._dialog._contentEl.focus(); }, 200); } else { var callback = { success: function(response) { that._dialog._contentEl.value = response.responseText; that._dialog._contentEl.focus(); }, failure: function(response) { that._dialog._contentEl.focus(); } }; var url = this._baseUrl; if (url.indexOf(this._op)) { url = url.slice(0, url.indexOf(this._op)); } url = FIRSTCLASS.lang.ensureSlashUrl(url) + "embed" + index + ".html?Close=-1"; YAHOO.util.Connect.asyncRequest('GET', url, callback); } } } return; }; // walk nodes to trap highest embed index FIRSTCLASS.util.Message.prototype.updateEmbedIndex = function() { // recursive index finder var getMaxEmbedIdx = function(node, index) { var nIdx = 0; var attrs; var attrVals = []; if (node.tagName == "IMG") { attrs = node.getAttribute('fcattrs'); if (attrs && node.getAttribute('fcid') === 'fcestart') { attrVals = attrs.split(';'); nIdx = attrVals[0] - 0; if (nIdx > index) { index = nIdx; } } } for (var c = 0; c < node.childNodes.length; c++) { index = getMaxEmbedIdx(node.childNodes[c], index); } return index; }; // find base node var baseEl = this._domEl; if (this._editor && this._editor._getDoc) { var doc = this._editor._getDoc(); if (doc.body) { baseEl = doc.body; } } this._embedIdx = getMaxEmbedIdx(baseEl, this._embedIdx); }; FIRSTCLASS.util.Message.prototype.embedDone = function() { var that = this; // cheesily figure out the content size var content = this._dialog._contentEl.value; var w = 320, h = 240; var pos = content.indexOf('width="'); if (pos > 0) { w = content.slice(pos + 7, content.indexOf('"', pos + 7)) - 0; } pos = content.indexOf('height="'); if (pos > 0) { h = content.slice(pos + 8, content.indexOf('"', pos + 8)) - 0; } // post the attachment data var url = FIRSTCLASS.lang.ensureSlashUrl(this._baseUrl) + FIRSTCLASS.opCodes.FormSave + "?KeepNames=1&Close=-1"; this._dialog._form.action = url; this._embedIdx++; this._dialog._form.AttName.value = "embed" + this._embedIdx + ".html"; this._dialog._form.setAttribute("enctype", "multipart/form-data"); if (!this.validEmbedContent()) { alert(FIRSTCLASS.locale.editor.embed.cant) that.embedCancel(); } else { if (this._dialog._contentEl.value !== "" || this._dialog._isNew) { this._embedContents[this._embedIdx] = this._dialog._contentEl.value; FIRSTCLASS.util.submitForm(this._dialog._form, false, { success: function() { // set attributes on content element var attrs = [that._embedIdx, w, h]; that._dialog._embedEl.setAttribute('fcid', 'fcestart'); that._dialog._embedEl.setAttribute('fcattrs', attrs.join(";")); that.closeDialog(); }, failure: function() { // complain and bail alert(FIRSTCLASS.locale.editor.embed.cant); that.embedCancel(); } }); } else { this.embedCancel(); } } return; }; FIRSTCLASS.util.Message.prototype.embedCancel = function() { if (this._dialog._isNew) { this._dialog._embedEl.parentNode.removeChild(this._dialog._embedEl.nextSibling); this._dialog._embedEl.parentNode.removeChild(this._dialog._embedEl); } this.closeDialog(); }; FIRSTCLASS.util.Message.prototype.openQuoteDialog = function() { var dlgCfg = {}; var that = this; dlgCfg.title = FIRSTCLASS.locale.editor.quote.title; dlgCfg.cancel = 'closeDialog'; dlgCfg.done = 'quoteDone'; var html = []; html.push("
"); html.push("
"); html.push("
"); html.push("
"); dlgCfg.body = html.join(""); if (YAHOO.env.ua.ie) { dlgCfg.width = '415px'; } this.openDialog(dlgCfg); window.setTimeout( function() { var contentEl = FIRSTCLASS.ui.Dom.getChildByIdName('fcQuoteField', that._dialog.el); contentEl.focus(); }, 500); return; }; FIRSTCLASS.util.Message.prototype.quoteDone = function() { var contentEl = FIRSTCLASS.ui.Dom.getChildByIdName('fcQuoteField', this._dialog.el); if (contentEl) { this.insertQuote(contentEl.value); } this.closeDialog(); return; }; FIRSTCLASS.util.Message.prototype.insertQuote = function(text, from) { var html = ""; if (from) { html += "" + from + " writes:
"; } if (text) { html += "
“" + text + "”

"; } this._editor.execCommand('inserthtml',html); }; FIRSTCLASS.util.Message.prototype.insertHTML = function(html) { this._editor.execCommand('inserthtml',html); }; // Front end of link creation: // If selection is a link and type is 'weblink', configure it. // If selection is text and type is 'weblink', create a new link with said text. // Otherwise ignore the selection. FIRSTCLASS.util.Message.prototype.handleLinkCommand = function(linkType) { var isNew = false; var wasBlank = false; var linkEl = this._editor._getSelectedElement(); this._editor.cmd_createlink(); if (this._editor.currentElement[0] != linkEl) { isNew = true; linkEl = this._editor.currentElement[0]; } switch (linkType) { case 'weblink': if (linkEl && (linkEl.innerHTML == "")) { wasBlank = true; linkEl.innerHTML = FIRSTCLASS.locale.editor.weblink.weblink; } this.openLinkDialog(linkEl); break; case 'wikilink': if (linkEl && (linkEl.innerHTML == "")) { wasBlank = true; linkEl.innerHTML = FIRSTCLASS.locale.editor.weblink.bflink + " " + FIRSTCLASS.locale.editor.weblink.wiki; } this.openWikiLinkDialog(linkEl); break; case 'doclink': if (linkEl && (linkEl.innerHTML == "")) { wasBlank = true; linkEl.innerHTML = FIRSTCLASS.locale.editor.weblink.bflink + " " + FIRSTCLASS.locale.editor.weblink.doc; } this.openDocLinkDialog(linkEl); } this._dialog._linkEl = linkEl; this._dialog._isNew = isNew; this._dialog._wasBlank = wasBlank; this._dialog._textUpdated = false; return; }; // -- web link FIRSTCLASS.util.Message.prototype.openLinkDialog = function(sel) { var newTab = false, url = "", alt = "", text = ""; if (typeof sel == 'object') { if (sel.target && sel.target == '_new') { newTab = true; } if (sel.href) { url = sel.href; } text = sel.innerHTML; alt = sel.title; } else if (typeof sel == 'string') { text = sel; } var dlgCfg = {}; var that = this; dlgCfg.title = FIRSTCLASS.locale.editor.weblink.header; dlgCfg.cancel = 'linkCancel'; dlgCfg.done = 'linkDone'; var html = []; html.push("
"); html.push(""); html.push(""); html.push(""); html.push(""); html.push(""); html.push("
" + FIRSTCLASS.locale.editor.weblink.urlguide + " 0) { html.push(" value='" + url + "' "); } html.push("/>
" + FIRSTCLASS.locale.editor.weblink.altguide + " 0) { html.push(" value='" + alt + "' "); } html.push("/>
" + FIRSTCLASS.locale.editor.weblink.clickguide + " 0) { html.push(" value='" + text + "' "); } html.push("/>
" + FIRSTCLASS.locale.editor.weblink.newcheck + "
"); dlgCfg.body = html.join(""); if (YAHOO.env.ua.ie) { dlgCfg.width = '480px'; } this.openDialog(dlgCfg); window.setTimeout( function() { var contentEl = FIRSTCLASS.ui.Dom.getChildByIdName('fcLinkUrl', that._dialog.el); contentEl.focus(); }, 500); this._dialog._form = FIRSTCLASS.ui.Dom.getChildByIdName('fcLinkForm', that._dialog.el); if (url.length > 0) { this.parsePastedLink(); } // event handler on link data change to initiate parsing YAHOO.util.Event.on(this._dialog._form.linkurl,'change', this.parsePastedLink, this, true); // event handler on link text change to save at close time YAHOO.util.Event.on(this._dialog._form.linktext,'change', function() { that._dialog._textUpdated = true; }); return; }; FIRSTCLASS.util.Message.prototype.parsePastedLink = function() { var linkType = "", linkObjType = "", linkContainer = "", linkName = ""; var urlStr = this._dialog._form.linkurl.value.toUpperCase(); var urlObj = FIRSTCLASS.util.url.decomposeUrl(urlStr); var myUrlObj = FIRSTCLASS.util.url.decomposeUrl(FIRSTCLASS.session.domain.toUpperCase()); if (urlObj.server == myUrlObj.server) { linkType = FIRSTCLASS.locale.editor.weblink.bflink; if (urlObj.fragment && urlObj.fragment.length > 0) { var parts = urlObj.fragment.split("/"); var context = {}; if (parts[0].indexOf("DESKTOP") >= 0) { // user desktop - no indication } else if (parts[0].indexOf("OPEN-USER") >= 0) { linkContainer = FIRSTCLASS.locale.editor.weblink.user; // profile or blog if (parts.length > 3) { linkObjType = FIRSTCLASS.locale.editor.weblink.blog; } } else if ((parts[0].indexOf("OPEN-CONF") >= 0) || (parts[0].indexOf("FAV") == 0) || (parts[0].indexOf("FOV") == 0)) { linkContainer = FIRSTCLASS.locale.editor.weblink.comm; if (parts[0].indexOf("OPEN-CONF") >= 0) { context = FIRSTCLASS.util.parseThreadContextParameter(parts[2]); } else { context = FIRSTCLASS.util.parseThreadContextParameter(parts[1]); } switch (context.objtype) { case FIRSTCLASS.objTypes.file: linkObjType = FIRSTCLASS.locale.editor.weblink.doc; break; case FIRSTCLASS.objTypes.odocument: linkObjType = FIRSTCLASS.locale.editor.weblink.wiki; break; case FIRSTCLASS.objTypes.confitem: linkObjType = FIRSTCLASS.locale.editor.weblink.thread; break; } } else if (parts[0].indexOf("SEARCH") >= 0) { linkContainer = FIRSTCLASS.locale.editor.weblink.search; } } } else { linkType = FIRSTCLASS.locale.editor.weblink.weblink; } // post the results to the form info area var el = FIRSTCLASS.ui.Dom.getChildByIdName('fclinktype',this._dialog.el); if (el) { el.innerHTML = linkType; } el = FIRSTCLASS.ui.Dom.getChildByIdName('fclinkobjtype',this._dialog.el); if (el && linkObjType.length > 0) { el.innerHTML = linkObjType; } el = FIRSTCLASS.ui.Dom.getChildByIdName('fclinkcommunity',this._dialog.el); if (el) { if (linkName.length > 0) { el.innerHTML = linkContainer + " " + linkName; } else { el.innerHTML = linkContainer; } } }; FIRSTCLASS.util.Message.prototype.linkDone = function() { var newTab = this._dialog._form.linknewtab.value == 'new' ? true : false, url = this._dialog._form.linkurl.value || "", alt = this._dialog._form.linkalt.value || "", text = this._dialog._form.linktext.value || ""; if (this._dialog._linkEl !== null && url.length > 0) { this._dialog._linkEl.setAttribute('href',url); this._dialog._linkEl.setAttribute('title',alt); if (this._dialog._textUpdated) { this._dialog._linkEl.innerHTML = text; } if (newTab) { this._dialog._linkEl.setAttribute('target','_new'); } } this.closeDialog(); return; }; FIRSTCLASS.util.Message.prototype.linkCancel = function() { if (this._dialog._isNew) { if (this._dialog._wasBlank) { this._dialog._linkEl.parentNode.removeChild(this._dialog._linkEl); } else { this._editor.cmd_unlink(); } } this.closeDialog(); }; // -- document link FIRSTCLASS.util.Message.prototype.openDocLinkDialog = function() { var dlgCfg = {}; var that = this; dlgCfg.title = FIRSTCLASS.locale.editor.insertdoc.title; dlgCfg.cancel = 'docLinkCancel'; dlgCfg.done = 'docLinkDone'; var html = []; html.push("
"); html.push(""); html.push(""); html.push("
" + FIRSTCLASS.locale.editor.insertdoc.choose + "
"); dlgCfg.body = html.join(""); if (YAHOO.env.ua.ie) { dlgCfg.width = '450px'; } this.openDialog(dlgCfg); // populate doc selection list this._docNames = []; this._selDocDS = this._ds.createSlave({}); this._selDocDS.addRowListener( { fillFinished: function(isNew) { that._docNames = []; var recs = that._selDocDS._data.records; var keep; for (var row in recs) { keep = true; if (typeof recs[row].name === undefined) { keep = false; } switch(recs[row].typedef.objtype) { case FIRSTCLASS.objTypes.file: case FIRSTCLASS.objTypes.fcfile: case FIRSTCLASS.objTypes.formdoc: break; default: keep = false; } if (recs[row].status.backversion !== 0) { keep = false; } if (keep) { that._docNames.push(recs[row].name); } } that._docNames.sort(); // suppress duplicates for (var i in that._docNames) { if (i > 0) { while (that._docNames[i] == that._docNames[i-1]) { that._docNames.splice(i,1); if (i >= that._docNames.length) { break; } } } } var select=[]; select.push(""); var listTd = FIRSTCLASS.ui.Dom.getChildByClassName('fcDocPick',that._dialog.el); if (listTd) { listTd.innerHTML = select.join(""); } } }); this._selDocDS.activate(); this._selDocDS.fetchRowsByObjType(FIRSTCLASS.objTypes.file, false); // NOTE - add request here for livelink documents when we are ready return; }; FIRSTCLASS.util.Message.prototype.docLinkDone = function() { var selEl = FIRSTCLASS.ui.Dom.getChildByIdName('fcDocSelect', this._dialog.el); if (this._dialog._linkEl && selEl) { var targetName = ""; if (YAHOO.env.ua.ie) { targetName += selEl.childNodes[selEl.selectedIndex].text; } else { targetName += selEl.value; } var rows = this._selDocDS.query('name', targetName, true); if (rows.length > 0) { targetName = rows[0][0]; var url = "CID" + this._selDocDS._data.cid + "/" + targetName + "?FCItemID=TF-" + rows[0][1].threadid; this._dialog._linkEl.setAttribute('href', url); this._dialog._linkEl.setAttribute('target', '_new'); if (this._dialog._wasBlank) { this._dialog._linkEl.innerHTML = targetName; } if (this._dialog._isNew) { var brEl = this._editor._getDoc().createElement('br'); YAHOO.util.Dom.insertAfter(brEl, this._dialog._linkEl); } } } if (this._selDocDS) { this._selDocDS.dispose(); this._selDocDS = null; } this.closeDialog(); return; }; FIRSTCLASS.util.Message.prototype.docLinkCancel = function() { if (this._selDocDS) { this._selDocDS.dispose(); this._selDocDS = null; } if (this._dialog._isNew) { if (this._dialog._wasBlank) { this._dialog._linkEl.parentNode.removeChild(this._dialog._linkEl); } else { this._editor.cmd_unlink(); } } this.closeDialog(); return; }; // -- wiki link FIRSTCLASS.util.Message.prototype.openWikiLinkDialog = function(sel) { var initText = ""; if (typeof sel === "object" && typeof sel.innerHTML !== "undefined" && sel.innerHTML.length > 0) { initText += sel.innerHTML; } var dlgCfg = {}; var that = this; this._quickFind = null; dlgCfg.title = FIRSTCLASS.locale.editor.wikilink.title; dlgCfg.cancel = 'wikiLinkCancel'; var html = []; html.push("
"); html.push(""); html.push(""); html.push(""); html.push(""); html.push(""); html.push("
" + FIRSTCLASS.locale.editor.wikilink.choose + "
" + FIRSTCLASS.locale.editor.wikilink.or + "
" + FIRSTCLASS.locale.editor.wikilink.link + "
" + FIRSTCLASS.locale.editor.wikilink.typename + "
"); dlgCfg.body = html.join(""); if (YAHOO.env.ua.ie) { dlgCfg.width = '450px'; } this.openDialog(dlgCfg); // make action buttons into YUI buttons var btn = new YAHOO.widget.Button("fcMakeLinkBtn"); btn.on("click", function() { that.wikiLinkMake(); }); btn = new YAHOO.widget.Button("fcNewLinkBtn"); btn.on("click", function() { that.wikiLinkCreate(); }); // populate page selection list var names = []; var recs = this._ds._data.records; var keep; for (var row in recs) { keep = true; if (typeof recs[row].name === undefined) { keep = false; } if (recs[row].typedef.objtype != FIRSTCLASS.objTypes.odocument) { keep = false; } if (recs[row].status.backversion !== 0) { keep = false; } if (keep) { names.push(recs[row].name); } } names.sort(); for (var i in names) { if (i > 0) { while (names[i] == names[i-1]) { names.splice(i,1); if (i >= names.length) { break; } } } } var select=[]; select.push(""); var listTd = FIRSTCLASS.ui.Dom.getChildByClassName('fcLinkPick',this._dialog.el); if (listTd) { listTd.innerHTML = select.join(""); } // prefill and focus based on selection if (found >= 0) { list.value = names[found]; list.select(); } else if (initText.length >= 0) { var newEl = FIRSTCLASS.ui.Dom.getChildByIdName('fcLinkName', this._dialog.el); newEl.value = initText; newEl.select(); } else { listTd.firstChild.select(); } return; }; FIRSTCLASS.util.Message.prototype.wikiLinkCancel = function() { if (this._dialog._isNew) { if (this._dialog._wasBlank) { this._dialog._linkEl.parentNode.removeChild(this._dialog._linkEl); } else { this._editor.cmd_unlink(); } } this.closeDialog(); return; }; FIRSTCLASS.util.Message.prototype.wikiLinkMake = function() { var selEl = FIRSTCLASS.ui.Dom.getChildByIdName('fcLinkSelect', this._dialog.el); if (this._dialog._linkEl && selEl) { var targetName = ""; if (YAHOO.env.ua.ie) { targetName += selEl.childNodes[selEl.selectedIndex].text; } else { targetName += selEl.value; } var exRows = this._ds.query('name', targetName, true); if (exRows.length > 0) { targetName = exRows[0][0]; } this._dialog._linkEl.href = targetName; this._dialog._linkEl.setAttribute('class','fcwl'); this._dialog._linkEl.innerHTML = targetName; if (this._dialog._isNew) { var brEl = this._editor._getDoc().createElement('br'); YAHOO.util.Dom.insertAfter(brEl, this._dialog._linkEl); } } this.closeDialog(); return; }; FIRSTCLASS.util.Message.prototype.wikiLinkCreate = function() { var newEl = FIRSTCLASS.ui.Dom.getChildByIdName('fcLinkName', this._dialog.el); if (this._dialog._linkEl && newEl) { var name = newEl.value; var compare = function(k, s) { return (k == s); }; var exists = this._ds.query('name', name, true, compare); if (exists.length > 0) { var msg = FIRSTCLASS.locale.editor.wikilink.dup; msg = msg.replace("^1",name); alert(msg); } else { // create the page var url = FIRSTCLASS.lang.ensureSlashUrl(this._ds.getContainerUrl()) + FIRSTCLASS.opCodes.FormNew + "?FormID=20501&Quit=1&Name=" + name; YAHOO.util.Connect.asyncRequest("POST",url); // create the link this._dialog._linkEl.href = "../" + name; this._dialog._linkEl.setAttribute('class','fcwl'); this._dialog._linkEl.innerHTML = name; if (this._dialog._isNew) { var brEl = this._editor._getDoc().createElement('br'); YAHOO.util.Dom.insertAfter(brEl, this._dialog._linkEl); } // done this.closeDialog(); } } return; }; FIRSTCLASS.util.Message.prototype.closeDialog = function() { if (this._dialog !== null) { this._dialog.dlg.destroy(); this._dialog = null; } }; FIRSTCLASS.util.Message.prototype.openInsertImageDialog = function(selImage) { var dlgCfg = {}; var that = this; dlgCfg.title = FIRSTCLASS.locale.editor.insertimage.title; dlgCfg.cancel = 'insertImageCancel'; dlgCfg.done = 'insertImageDone'; var html = []; // browse form html.push("
"); html.push("
" + FIRSTCLASS.locale.editor.insertimage.choose + ""); html.push(""); html.push("
"); // url form html.push("
"); html.push("
" + FIRSTCLASS.locale.editor.insertimage.url + ""); html.push(""); html.push("
"); // attr form and preview html.push("
"); html.push("
"); html.push(""); html.push(""); html.push(""); html.push("
" + FIRSTCLASS.locale.editor.insertimage.scale + ""); html.push(""); html.push("
" + FIRSTCLASS.locale.editor.insertimage.width + "
" + FIRSTCLASS.locale.editor.insertimage.height + "
" + FIRSTCLASS.locale.editor.insertimage.align + ""); html.push(""); html.push("
" + FIRSTCLASS.locale.editor.insertimage.pad + "
"); html.push("
"); html.push("
"); html.push("
"); dlgCfg.body = html.join(""); if (YAHOO.env.ua.ie) { dlgCfg.width = '425px'; } this.openDialog(dlgCfg); this._dialog._uploadForm = FIRSTCLASS.ui.Dom.getChildByIdName('insertimage_browse',this._dialog.el); this._dialog._uploadForm.setAttribute("action",this._baseUrl); this._dialog._uploadForm.setAttribute("enctype","multipart/form-data"); this._dialog._uploadForm.setAttribute("autocomplete","off"); this._dialog._previewBox = FIRSTCLASS.ui.Dom.getChildByIdName('insertimage_preview', this._dialog.el); this._dialog._pts = FIRSTCLASS.ui.Dom.getChildByIdName('insertimage_top', this._dialog.el); this._dialog._pls = FIRSTCLASS.ui.Dom.getChildByIdName('insertimage_left', this._dialog.el); this._dialog._prs = FIRSTCLASS.ui.Dom.getChildByIdName('insertimage_right', this._dialog.el); this._dialog._attrForm = FIRSTCLASS.ui.Dom.getChildByIdName('insertimage_attrs', this._dialog.el); this._dialog._imageStamp = FIRSTCLASS.ui.Dom.getChildByIdName('insertimage_stamp', this._dialog.el); this._dialog._imageUrl = FIRSTCLASS.ui.Dom.getChildByIdName('insertimage_url', this._dialog.el); this._dialog._imageUrlBtn = FIRSTCLASS.ui.Dom.getChildByIdName('insertimage_urlupdate', this._dialog.el); this._dialog._isUpload = false; this._dialog._mainImageUrl = false; this._dialog._imageOversize = false; this._dialog._imageEl = selImage; this._dialog._isNew = false; if (selImage && selImage.src && selImage.src.indexOf('blankimage') >= 0) { this._dialog._isNew = true; } this.enableImageInsert(false); this.setPreviewState("init"); // form event hooks YAHOO.util.Event.on('insertimage_upload', 'change', function(ev) { YAHOO.util.Event.stopEvent(ev); // no default click action that.setPreviewState("upload"); that.uploadFile(that._dialog._uploadForm, function(url,success) { if (success) { that._dialog._isUpload = true; that.setInsertImageUrl(url); that.setPreviewState("measure"); } else { alert(FIRSTCLASS.locale.editor.insertimage.err); } }, that, true); return false; }); // attribute form updates var f = this._dialog._attrForm; YAHOO.util.Event.on(f.align,'change',function() { that.updateImagePreview('align'); }, this, true); YAHOO.util.Event.on(f.scale,'change',function() { that.updateImagePreview('scale'); }, this, true); YAHOO.util.Event.on(f.imgwidth,'change',function() { that.updateImagePreview('imgwidth'); }, this, true); YAHOO.util.Event.on(f.imgheight,'change',function() { that.updateImagePreview('imgheight'); }, this, true); YAHOO.util.Event.on(f.pad,'change',function() { that.updateImagePreview('padding'); }, this, true); // url update YAHOO.util.Event.on(this._dialog._imageUrlBtn, 'click',function() { that.fillImageForm(this._dialog._imageUrl.value); }, this, true); // if we are editing an existing image, update the form state if (selImage && !this._dialog._isNew) { this.fillImageForm(selImage); } return; }; // initialize form from existing image or URL FIRSTCLASS.util.Message.prototype.fillImageForm = function(source) { if (typeof source == "object") { if (source.tagName && source.tagName == 'IMG') { this.setInsertImageUrl(source.src); } else { var images = source.getElementsByTagName('IMG'); if (images[0]) { this.setInsertImageURL(images[0].src); } } } else if (typeof source == 'string') { this.setInsertImageUrl(source); } this.setPreviewState("measure"); this.enableImageInsert(true); }; FIRSTCLASS.util.Message.prototype.setInsertImageUrl = function(url) { this._dialog._url = url; this._dialog._imageUrl.value = url; }; FIRSTCLASS.util.Message.prototype.enableImageInsert = function(enable) { var buttons = this._dialog.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.editor.textstyle.done) { if (enable) { button._button.removeAttribute("disabled"); button.removeStateCSSClasses("disabled"); } else { button._button.setAttribute("disabled", "disabled"); button.addStateCSSClasses("disabled"); } } } } }; // check if passed-in image needs to be thumbnailed. If the oversize bit is already set, // this image IS a thumbnail so return false and proceed with preview FIRSTCLASS.util.Message.prototype.thumbnailImage = function(imgEl) { var needThumbnail = false; // skip if no max set or not uploading if ((this._maxImageSize > 0) && (this._dialog._isUpload)) { // check if dimensions over max if ((imgEl.width > this._maxImageSize) || (imgEl.height > this._maxImageSize)) { // calculate thumbnail scale factor var scale = imgEl.width > imgEl.height ? this._maxImageSize/imgEl.width : this._maxImageSize/imgEl.height; // initiate thumbnail upload - update form action and re-post this._dialog._thumbWidth = Math.round(imgEl.width * scale); this._dialog._thumbHeight = Math.round(imgEl.height * scale); this._dialog._imageOversize = true; needThumbnail = true; } } return needThumbnail; }; FIRSTCLASS.util.Message.prototype.setPreviewState = function(state) { var that = this; if (this._dialog && this._dialog.dlg) { this._dialog.upState = state; switch(state) { case "init": break; case "upload": // display progress icon this.insertImagePreview(32, 32, FIRSTCLASS.session.templatebase + '/firstclass/images/uploading_ar32x32.gif'); this._dialog._pts.innerHTML = FIRSTCLASS.locale.editor.insertimage.prog; break; case "measure": // trap the natural image size YAHOO.util.Event.on(this._dialog._imageStamp,'load',function() { that.measureUploadedImage(this); that.enableImageInsert(true); }, this._dialog._imageStamp, true); this._dialog._imageStamp.src = encodeURI(this._dialog._url); break; case "preview": // display image preview this._dialog._pts.innerHTML = ""; this._dialog._previewBox.innerHTML = ""; this.updateImagePreview('init'); } } }; // measure passed-in image, and if it needs thumbnailing, set up the new URL and retrigger the load event FIRSTCLASS.util.Message.prototype.measureUploadedImage = function() { var that = this; var dlg = this._dialog; var doThumbnail = this.thumbnailImage(dlg._imageStamp); if (doThumbnail) { dlg._mainImageUrl = dlg._url; // massage the url to make the thumbnail var thumbUrl = dlg._url; var filePath = YAHOO.util.Dom.get('insertimage_upload').value; var fileName = filePath.match(/[^\/\\]+$/); var thumbName = FIRSTCLASS.lang.createThumbName(fileName[0]); dlg._url = dlg._url.replace(fileName[0], thumbName); thumbUrl += "?WidthAA=" + dlg._thumbWidth + "&HeightAA=" + dlg._thumbHeight + "&SaveDest=" + dlg._url; YAHOO.util.Event.removeListener(dlg._imageStamp,'load'); var parent = dlg._imageStamp.parentNode; parent.removeChild(dlg._imageStamp); parent.innerHTML = ""; dlg._imageStamp = parent.firstChild; YAHOO.util.Event.on(dlg._imageStamp,'load',function() { that.measureUploadedImage(); }, dlg._imageStamp, true); dlg._imageStamp.src = thumbUrl; } else { dlg._trueSize = { h: dlg._imageStamp.width, v: dlg._imageStamp.height }; that.setPreviewState('preview'); YAHOO.util.Event.removeListener(dlg._imageStamp,'load'); dlg._imageStamp.src=""; YAHOO.util.Dom.removeClass(dlg._attrForm.firstChild,'fcHidden'); } }; FIRSTCLASS.util.Message.prototype.updateImagePreview = function(trig) { var f = this._dialog._attrForm; var imgEl = []; var img = null; // set initial preview size if (!this._dialog._preSize) { this._dialog._preSize = { h: 100.0, v: 100.0 }; } if (this._dialog._trueSize) { switch (trig) { case 'init': // set length and width f.imgheight.value = this._dialog._trueSize.v; f.imgwidth.value = this._dialog._trueSize.h; f.pad.value = 2; break; case 'scale': case 'align': case 'padding': var form = document.fcimageattrs; var scaleStr = form.scale.options[form.scale.selectedIndex].text; var scale = scaleStr.slice(0,scaleStr.indexOf("%")) - 0.0; if (scaleStr == FIRSTCLASS.locale.editor.insertimage.original) { scale = 100.0; } if (scaleStr != FIRSTCLASS.locale.editor.insertimage.other) { f.imgheight.value = Math.floor(this._dialog._trueSize.v * scale / 100.0); f.imgwidth.value = Math.floor(this._dialog._trueSize.h * scale / 100.0); } if (!f.pad.value) { f.pad.value = 2; } break; case 'imgwidth': f.scale.value = FIRSTCLASS.locale.editor.insertimage.other; break; case 'imgheight': f.scale.value = FIRSTCLASS.locale.editor.insertimage.other; break; } // update preview size var ar = this._dialog._trueSize.h/this._dialog._trueSize.v; if (isNaN(ar)) { ar = 1; } if (ar > 1) { this._dialog._preSize.h = 100.0; this._dialog._preSize.v = Math.round(100.0/ar); } else { this._dialog._preSize.v = 100.0; this._dialog._preSize.h = Math.round(ar * 100.0); } } var html=[]; this.insertImagePreview(this._dialog._preSize.h, this._dialog._preSize.v,this._dialog._url); return; }; FIRSTCLASS.util.Message.prototype.insertImagePreview = function(h,v,src) { var side = Math.round((150.0 - h) / 2.0); var top = Math.round((115.0 - v) / 2.0); this._dialog._pls.setAttribute("style","width:" + side + "px;"); this._dialog._prs.setAttribute("style","width:" + side + "px;"); this._dialog._pts.setAttribute("style","height:" + top + "px;"); this._dialog._previewBox.innerHTML = ""; return; }; FIRSTCLASS.util.Message.prototype.insertImageDone = function() { var imageEl = null; var linkEl = null; var hadThumbnail = false; var f = this._dialog._attrForm; if (this._dialog._isNew) { imageEl = this._editor._getDoc().createElement('img'); linkEl = this._editor._getDoc().createElement('a'); } else { imageEl = this._dialog._imageEl; if (imageEl.parentNode && imageEl.parentNode.tagName === 'A' && imageEl.parentNode.getAttribute('fcth')) { hadThumbnail = true; linkEl = imageEl.parentNode; } else { linkEl = this._editor._getDoc().createElement('a'); } } // if thumbnailing, configure link if (this._dialog._imageOversize) { linkEl.href = this._dialog._mainImageUrl; linkEl.title = FIRSTCLASS.locale.editor.insertimage.big; linkEl.target = '_blank'; linkEl.setAttribute('fcth','1'); } // configure image imageEl.src = this._dialog._url; imageEl.setAttribute('align',f.align.value); YAHOO.util.Dom.setStyle(imageEl,'height',f.imgheight.value + 'px'); YAHOO.util.Dom.setStyle(imageEl,'width', f.imgwidth.value + 'px'); YAHOO.util.Dom.setStyle(imageEl,'padding', f.pad.value + 'px'); // object swap if required if (this._dialog._isNew || (this._dialog._imageOversize != hadThumbnail)) { var par = this._dialog._imageEl.parentNode; var child = imageEl; var old = this._dialog._imageEl; if (hadThumbnail) { old = par; par = par.parentNode; } if (this._dialog._imageOversize) { child = linkEl; if (!hadThumbnail) { linkEl.appendChild(imageEl); } } par.replaceChild(child,old); if (this._dialog._isNew || (this._dialog._imageOversize && !hadThumbnail)) { var brEl = this._editor._getDoc().createElement('br'); YAHOO.util.Dom.insertAfter(brEl, child); } } this._editor.currentElement = []; // close the dialog this.closeDialog(); }; FIRSTCLASS.util.Message.prototype.insertImageCancel = function() { if (this._dialog._isNew && this._dialog._imageEl.parentNode) { this._dialog._imageEl.parentNode.removeChild(this._dialog._imageEl); } this._editor.currentElement = []; this.closeDialog(); }; FIRSTCLASS.util.Message.prototype.openInsertFileDialog = function() { var dlgCfg = {}; var that = this; dlgCfg.title = 'Insert File:'; dlgCfg.cancel = 'insertFileCancel'; dlgCfg.done = 'insertFileDone'; var html = []; html.push(""); html.push(""); html.push("
"); html.push("
"); html.push("
"); html.push("
Alignment:
"); html.push("
"); dlgCfg.body = html.join(""); this.openDialog(dlgCfg); this._dialog._uploadForm = FIRSTCLASS.ui.Dom.getChildByIdName('insertfile_browse',this._dialog.el); this._dialog._uploadForm.setAttribute("action",this._baseUrl); this._dialog._uploadForm.setAttribute("enctype","multipart/form-data"); this._dialog._uploadForm.setAttribute("autocomplete","off"); this._dialog._attrForm = FIRSTCLASS.ui.Dom.getChildByIdName('insertfile_attrs', this._dialog.el); this._dialog._progIcon = FIRSTCLASS.ui.Dom.getChildByIdName('insertfileprogicon', this._dialog.el); this.setInsertFileProgress("init"); // form event hooks YAHOO.util.Event.on('insertimage_upload', 'change', function(ev) { YAHOO.util.Event.stopEvent(ev); that.setInsertFileProgress("upload"); that.uploadFile(that._dialog._uploadForm, function(url,success) { if (success) { that._dialog._url = url; that.setInsertFileProgress("done"); } else { alert("Unable to upload the file."); } }, that, true); return false; }); return; }; FIRSTCLASS.util.Message.prototype.setInsertFileProgress = function(state) { var that = this; if (this._dialog && this._dialog.dlg) { switch(state) { case "init": this._dialog._progIcon.innerHTML = ""; break; case "upload": // display progress icon this._dialog._progIcon.innerHTML = ""; break; case "done": // display image preview this._dialog._progIcon.innerHTML = ""; break; } } }; FIRSTCLASS.util.Message.prototype.insertFileDone = function() { var f = this._dialog._attrForm; var iconID = FIRSTCLASS.util.Display.getIconID(this._dialog._url); var name = FIRSTCLASS.lang.removeSlashUrl(this._dialog._url); name = name.slice(name.lastIndexOf("/") + 1); html = []; var alignStr = ""; switch(f.align.value) { case 'left': alignStr = "style='float:left;'"; break; case 'right': alignStr = "style='float:right;'"; break; case 'middle': alignStr = "style='display:inline-block;'"; break; } html.push("
"); html.push("
"); html.push("
" + name + "

"); this._editor.execCommand('inserthtml',html.join("")); this.closeDialog(); }; FIRSTCLASS.util.Message.prototype.insertFileCancel = function() { this.closeDialog(); }; // upload image from browse sub-form FIRSTCLASS.util.Message.prototype.uploadFile = function(form, callback) { var that = this; var uploadUrl = that._baseUrl; var Dom = YAHOO.util.Dom; // post the upload // YAHOO.util.Connect.setForm(form, true); var imageUrl = uploadUrl; if (uploadUrl.charAt(uploadUrl.length-1) != '/') { imageUrl = uploadUrl.slice(0,uploadUrl.lastIndexOf('/')); imageUrl = imageUrl.slice(0,imageUrl.lastIndexOf('/')+1); } if (imageUrl.indexOf(FIRSTCLASS.opCodes.FormEdit) > 0) { imageUrl = imageUrl.slice(0,imageUrl.lastIndexOf(FIRSTCLASS.opCodes.FormEdit)); } var picker = Dom.get('insertimage_upload'); var filePath = picker.value; var fileName = filePath.match(/[^\/\\]+$/); imageUrl += fileName[0]; var formAction = uploadUrl + FIRSTCLASS.opCodes.FormSave + '?KeepNames=1&Close=-1'; form.action = formAction; FIRSTCLASS.util.submitForm(form, true, { upload: function() { that.testForAttachment(fileName, imageUrl, callback); } }); }; // Get the current object's attachment list and return it if possible. Callback params are (attachments, success), // where attachments is the JSON array returned by IS, and success is a boolean indicating the status of the request. // On failure, attachments will be an empty array. FIRSTCLASS.util.Message.prototype.getAttachmentList = function(callback) { var attachments = []; var url = FIRSTCLASS.lang.removeSlashUrl(this._editForm.getAttribute('fcurl')); url += "?Show=2&Templates=JS&Close=-1&" + FIRSTCLASS.ui.Dom.getCurrTimestamp(); var req = YAHOO.util.Connect.asyncRequest('GET', url, { success:function (response) { // parse JSON data var msgData = []; try { msgData = YAHOO.lang.JSON.parse(response.responseText); } catch(x) { if (callback) { callback(attachments, false); } return; } if (msgData.attachments) { for (var idx = 0; idx < msgData.attachments.length; idx++) { attachments.push(msgData.attachments[idx]); } } if (callback) { callback(attachments, true); return; } }, failure:function (response) { if (callback) { callback(attachments, false); } } }); }; // test for attachment available in item FIRSTCLASS.util.Message.prototype.testForAttachment = function(name, url, callback) { var that = this; var notYets = 0; // set up timer to poll for selected attachment var pollT = window.setInterval(function() { that.getAttachmentList(function(attachments, success) { if (success) { for (var idx = 0; idx < attachments.length; idx++) { var attachment = attachments[idx]; if (attachment.name.localeCompare(name) === 0) { window.clearInterval(pollT); if (callback) { callback(url, true); } return; } } if (notYets++ > 5) { window.clearInterval(pollT); if (callback) { callback(null, false); } } } else { window.clearInterval(pollT); if (callback) { callback(null, false); } } }); },5000); }; FIRSTCLASS.util.Message.prototype.getMessageId = function() { var msgid = null; if (this._editForm) { var url = this._editForm.getAttribute('fcurl'); var start = url.indexOf("/S") + 1; if (start >= 0) { var end = url.indexOf("/",start); if (end >= 0) { msgid = url.slice(start, end); } else { msgid = url.slice(start); } } } return msgid; }; FIRSTCLASS.util.Message.prototype.autoCompleteSelectHandler = function(sType, aArgs, where) { var that = this; var rowData = aArgs[2]; var addString = rowData[1].cid; var icon = rowData[1].icon; var clientid = rowData[1].cid; var online = rowData[1].online; var addname = rowData[1].name; FIRSTCLASS.util.Form.add(that._baseUrl, addString, 4, 1000, { onComplete:function() { var myIndex = that._validatedNames.length; var tmp = that._nameTable.insertRow(myIndex); YAHOO.util.Dom.addClass(tmp, "fcValidatedName"); if (online) { YAHOO.util.Dom.addClass(tmp, "fcNameOnline"); } tmp.clientid = clientid; var tmp2 = document.createElement("td"); var tmp3 = document.createElement("td"); tmp.appendChild(tmp2); tmp.appendChild(tmp3); tmp2.innerHTML=""+addname; var cont = document.createElement("div"); var button = new YAHOO.widget.Button({label:FIRSTCLASS.locale.workflows.sendto.email.remove, container:cont}); that._validatedNames.push(tmp); button.addListener("click", function(evt) { that.deleteName(where,that.getIndexForRow(that._validatedNames, tmp)); }); tmp3.appendChild(cont); that.refreshNameInput(); if (that._callback.onNameValidate) { that._callback.onNameValidate(); } that._isNameValidating = false; }, onFailure:function(err) { that._isNameValidating = false; alert("addressing failure"); // that._autoComplete.destroy(); } }); }; FIRSTCLASS.util.Message.prototype.addName = function(where, inputValue) { if (this._isNameValidating) { return; } this._isNameValidating = true; var that = this; FIRSTCLASS.util.Form.validateName(that._baseUrl, inputValue, 4, 1000, { onComplete: function(obj) { var addString; var icon; var clientid; var online; var addname; switch(obj.match) { case "multi": var dsDef = obj.dataSource.getYAHOOWidgetDataSource('name', true, FIRSTCLASS.util.Form.nameValCompare); var ac = FIRSTCLASS.ui.Dom.getChildByClassName("fcNameValAutoComplete", that._editForm); if (!that._autoComplete) { that._autoComplete = new YAHOO.widget.AutoComplete(that.inputs.to,ac,dsDef.dataSource); //that._autoComplete.maxResultsDisplayed = 5; //that._autoComplete.typeAhead = true; //that._autoComplete.useShadow = true; that._autoComplete.formatResult = dsDef.formatResult; that._autoComplete.itemSelectEvent.subscribe(function(s,a) { that.autoCompleteSelectHandler(s,a, where); }); } that._autoComplete.sendQuery(obj.pattern); return; case "single": if (obj.item.nmattrs1.isperson) { addString = obj.item.cid; } else if (FIRSTCLASS.lang.isEmailAddress(obj.item.name)) { addString = obj.item.name; } else { return; } icon = obj.item.icon; clientid = obj.item.cid; online = obj.item.online; addname = obj.item.name; break; default: if (!FIRSTCLASS.lang.isEmailAddress(inputValue)) { alert("No Match"); return; } else { addString = inputValue; icon = "/Icons/9204"; clientid = "CID0"; online = false; addname = inputValue; } } FIRSTCLASS.util.Form.add(that._baseUrl, addString, 4, 1000, { onComplete:function() { var myIndex = that._validatedNames.length; var tmp = that._nameTable.insertRow(myIndex); YAHOO.util.Dom.addClass(tmp, "fcValidatedName"); if (online) { YAHOO.util.Dom.addClass(tmp, "fcNameOnline"); } tmp.clientid = clientid; var tmp2 = document.createElement("td"); var tmp3 = document.createElement("td"); tmp.appendChild(tmp2); tmp.appendChild(tmp3); tmp2.innerHTML=""+addname; var cont = document.createElement("div"); var button = new YAHOO.widget.Button({label:FIRSTCLASS.locale.workflows.sendto.email.remove, container:cont}); that._validatedNames.push(tmp); button.addListener("click", function(evt) { that.deleteName(where,that.getIndexForRow(that._validatedNames, tmp)); }); tmp3.appendChild(cont); that.refreshNameInput(); if (that._callback.onNameValidate) { that._callback.onNameValidate(); } that._isNameValidating = false; }, onFailure:function(err) { that._isNameValidating = false; alert("addressing failure"); } }); }, onFailure: function(obj) { } }, this._nvoptions); }; FIRSTCLASS.util.Message.prototype.deleteName = function(where, index) { // delete the name at index var that = this; if (index == -1) { return; } FIRSTCLASS.util.Form.deleteName(that._baseUrl, 4, index, false, { onComplete:function(obj) { var rows = YAHOO.util.Dom.getElementsByClassName("fcValidatedName", "", where); var theRow = rows[index]; var tbody = theRow.parentNode; tbody.deleteRow(index); for (var i in that._validatedNames) { if (theRow == that._validatedNames[i]) { that._validatedNames.splice(i,1); break; } } }, onFailure:function(obj) { } }); }; FIRSTCLASS.util.Message.prototype.getIndexForRow = function(where, row) { for (var i in this._validatedNames) { if (this._validatedNames[i] == row) { return i; } } return -1; }; // ---- implementation of the SharedEditor class // This class implements a persistent static YUI editor that can be repeatedly used throughout a BlueField // session. There will typically be a single instance of this class stored in the firstclass session // namespace. Applications that need to implement a styled text editor will create a new Message // object, which will engage the services of the editor for the lifecycle of the edit session, releasing // it back to the sharedEditor when finished. The sharedEditor provides the following functions: // constructor - constructs the editor // release() - releases the editor for reuse, transferring it back to the SharedEditor's holding DIV // getEditor(msg, el, config) - installs and configures the editor into the owning message; creates editor // instance on first call. The msg is the owning Message object. The element is the // TEXTAREA to be replaced. // The config is the vanilla YUI editor config, and is either // passed to the editor if it's new, or used to reconfigure the editor piece by piece. // Returns the editor. // saveHTML() - save the editor's HTML to the passed-in textarea FIRSTCLASS.util.SharedEditor = function() { this.initialize(false); }; FIRSTCLASS.util.SharedEditor.prototype.initialize = function(reInit) { this._editor = null; if (!reInit) { this._container = document.createElement('div'); } this._formBox = document.createElement('div'); var html = []; html.push("
"); this._formBox.innerHTML = html.join(""); YAHOO.util.Dom.addClass(this._formBox, 'fcEditorContainer'); this._subForm = FIRSTCLASS.ui.Dom.getChildByClassName('fcBodySubForm', this._formBox); this._editTextarea = FIRSTCLASS.ui.Dom.getChildByIdName('BODYCONTAINER', this._formBox); this._currMsg = null; this._hidden = false; this._firstEdit = true; }; // create button structure and pass it back in config.toolbar FIRSTCLASS.util.SharedEditor.prototype.createToolbar = function(config) { this._tbGroups = []; config.toolbar = { collapse: true, titlebar: false, draggable: false, buttonType: 'advanced', buttons: [ { group: 'undoredo', buttons: [ { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.undo, value: 'undo', disabled: true }, { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.redo, value: 'redo', disabled: true } ] }, { group: 'insert', buttons: [ { type: 'separator' }, { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.insertimage, value: 'insertimage' } ] }, { group: 'wikilink', buttons: [ { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.wikilink, value: 'wikilink' } ] }, { group: 'doclink', buttons: [ { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.insertdoc, value: 'insertfile' } ] }, { group: 'weblink', buttons: [ { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.weblink, value: 'createlink' } ] }, { group: 'quote', buttons: [ { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.quote, value: 'insertquote' } ] }, { group: 'embed', buttons: [ { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.embed, value: 'insertembed' } ] }, { group: 'indent', buttons: [ { type: 'separator' }, { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.indent, value: 'indent', disabled: true }, { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.outdent, value: 'outdent', disabled: true } ] }, { group: 'align', buttons: [ { type: 'separator' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.left, value: 'justifyleft' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.center, value: 'justifycenter' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.right, value: 'justifyright' } ] }, { group: 'list', buttons: [ { type: 'separator' }, { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.bullet, value: 'insertunorderedlist' }, { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.number, value: 'insertorderedlist' } ] }, { group: 'parastyle', buttons: [ { type: 'separator' }, { type: 'select', label: FIRSTCLASS.locale.toolbars.editor.body, value: 'pglevel', disabled: true, menu: [ { text: FIRSTCLASS.locale.toolbars.editor.body, value: 'none', checked: true }, { text: FIRSTCLASS.locale.toolbars.editor.head, value: 'h2' }, { text: FIRSTCLASS.locale.toolbars.editor.subhead, value: 'h3' } ] } ] }, { group: 'textattrs', buttons: [ { type: 'separator' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.bold, value: 'bold' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.italic, value: 'italic' }, { type: 'push', label: FIRSTCLASS.locale.editor.textstyle.underline, value: 'underline' } ] }, { group: 'textstyle', buttons: [ { type: 'separator' }, { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.style, value: 'textstyle', disabled: true }, { type: 'push', label: FIRSTCLASS.locale.toolbars.editor.plain, value: 'removeformat' } ] } ] }; // create list of toolbar groups for (var i in config.toolbar.buttons) { if (config.toolbar.buttons[i].group) { this._tbGroups[config.toolbar.buttons[i].group] = {}; } } }; FIRSTCLASS.util.SharedEditor.prototype.release = function() { if (YAHOO.env.ua.ie) { if (this._editor) { // purge the undo chain this._editor._undoCache = []; this._editor._undoLevel = 0; // hide the editor this._editor.hide(); } this._hidden = true; FIRSTCLASS.ui.Dom.reparentNode(this._formBox, this._container); } this._currMsg = null; this._firstEdit = false; }; FIRSTCLASS.util.SharedEditor.prototype.getEditor = function(msg, textEl, config) { var rv = null; this._currMsg = msg; if (YAHOO.env.ua.ie) { // save and hide target field for data this._target = textEl; YAHOO.util.Dom.addClass(textEl, 'fcDocEditorTextarea'); // grudgingly create new editor if HTML has been trashed if (this._editor !== null) { if (!this._editor._getDoc()) { this.initialize(true); } } // install edit form in place of textarea textEl.parentNode.insertBefore(this._formBox, textEl); this._editTextarea.value = textEl.value; if (this._editor == null) { this.createToolbar(config); // install editor bound to container text area this._editor = new YAHOO.widget.Editor(this._editTextarea, config); this.registerEditorEvents(); } if (this._hidden) { this._editor.show(); this._newContent = textEl.value; this._hidden = false; } rv = this._editor; } else { this.createToolbar(config); this._editor = new YAHOO.widget.Editor(textEl, config); this.registerEditorEvents(); rv = this._editor; } return rv; }; FIRSTCLASS.util.SharedEditor.prototype.registerEditorEvents = function() { var that = this; this._editor.on('editorKeyDown', function(o) { // trap alt-arrows if (o.ev.altKey) { if ((o.ev.keyCode == 18) || (o.ev.keyCode == 39)) { YAHOO.util.Event.stopEvent(o.ev); } } if (o.ev.metaKey) { if ((o.ev.keyCode == 37) || (o.ev.keyCode == 39)) { YAHOO.util.Event.stopEvent(o.ev); } } // report typing to owner if (that._currMsg._callback.onTyping) { that._currMsg._callback.onTyping(o.ev); } }); this._editor.on('toolbarLoaded', function(o) { this.addToolbarHooks(); this._currMsg.enableToolbarButtons(this._currMsg._tbType); }, this, true); this._editor.on('editorContentLoaded', function(o) { this._currMsg.onEditorLoaded(); }, this,true); // home-brewed replacement for heading selector this._editor.on('afterNodeChange', function(o) { var path = this._getDomPath(), elm = null, hd_button = this.toolbar.getButtonByValue('pglevel'), theTag = 'none'; theLabel = FIRSTCLASS.locale.toolbars.editor.body; if (that._tbGroups['parastyle'].enabled) { // if the current element or any parent is an , set the label for (var i = 0; i < path.length; i++) { elm = path[i]; var tag = elm.tagName.toLowerCase(); if (elm.getAttribute('tag')) { tag = elm.getAttribute('tag'); } if (tag.substring(0, 1) == 'h') { if (hd_button) { for (var h = 0; h < hd_button._configs.menu.value.length; h++) { if (hd_button._configs.menu.value[h].value.toLowerCase() == tag) { theLabel = hd_button._configs.menu.value[h].text; } } theTag = tag; break; } } } hd_button.set('label', theLabel); this._updateMenuChecked('pglevel', theTag); } }, this._editor, true); }; FIRSTCLASS.util.SharedEditor.prototype.addToolbarHooks = function() { var el = null; // font size picker - process list item this._editor.toolbar.on('textsizeClick', function(ob) { var value = ob.button.value; value = value.slice(0, 2) + 'px'; this.execCommand('fontsize', value); this.STOP_EXEC_COMMAND = true; }, this._editor, true); // paragraph style picker click this._editor.toolbar.on('pglevelClick', function(ob) { if (el !== null) { this._selectNode(el); el = null; } this.execCommand('heading', ob.button.value); this.STOP_EXEC_COMMAND = true; }, this._editor, true); // paragraph style picker focus var pg = this._editor.toolbar.getButtonByValue('pglevel'); if (pg) { var icon = FIRSTCLASS.ui.Dom.getChildByClassName('yui-toolbar-icon', pg._button.parentNode.parentNode); if (icon) { YAHOO.util.Event.addListener(icon, 'mousedown', function(evt) { if (YAHOO.env.ua.ie) { if (this._hasSelection()) { this._createCurrentElement('span', {}); el = this.currentElement[0]; } } }, this._editor, true); } } // text style click handler (call obj is Message) this._editor.toolbar.on('textstyleClick', function(evt) { // put up text style dialog if (this._editor._hasSelection()) { this._currMsg.openTSDialog(); } }, this, true); // embed content click handler this._editor.toolbar.on('insertembedClick', function(evt) { this._currMsg.openEmbedDialog(); }, this, true); // insert quote click handler this._editor.toolbar.on('insertquoteClick', function(evt) { this._currMsg.openQuoteDialog(); }, this, true); // wiki link handler this._editor.toolbar.on('wikilinkClick', function(evt) { this._currMsg.handleLinkCommand('wikilink'); }, this, true); // insert file handler this._editor.toolbar.on('insertfileClick', function(evt) { this._currMsg.handleLinkCommand('doclink'); }, this, true); // overridden insertimage handler this._editor.toolbar.on('insertimageClick', function(evt) { var el = this._editor._getSelectedElement(); if (!el || !el.tagName || (el.tagName !== 'IMG')) { this._editor.execCommand('inserthtml', ""); var imgs = this._editor._getDoc().getElementsByTagName('img'); for (var im = 0; im < imgs.length; im++) { if (imgs[im].getAttribute('src')) { if (imgs[im].getAttribute('src').indexOf('blankimage.png') >= 0) { el = imgs[im]; } } } } YAHOO.util.Event.stopEvent(evt); if (YAHOO.util.Dom.hasClass(el, "fcEmbed")) { this._currMsg.openEmbedDialog(); } else { this._currMsg.openInsertImageDialog(el); } return false; }, this, true); // overridden link handler this._editor.toolbar.on('createlinkClick', function(evt) { this._currMsg.handleLinkCommand('weblink'); YAHOO.util.Event.stopEvent(evt); return false; }, this, true); return; }; FIRSTCLASS.util.SharedEditor.prototype.saveHTML = function() { this._editor.saveHTML(); if (YAHOO.env.ua.ie) { this._target.value = this._subForm.BODYCONTAINER.value; } }; YAHOO.register("fcFormUtils", FIRSTCLASS.util.Form, {version: "0.0.1", build: "1"});