// form.js - utilities for message creation and editing forms FIRSTCLASS.util.Form = { validateName: function(baseURL, string, fieldId, index, callback, options, allowgroups, params, ignorelast) { if (this._lastNameValidated == string && !ignorelast) return; this._lastNameValidated = string; var requestUrl = FIRSTCLASS.lang.ensureSlashUrl(baseURL) + FIRSTCLASS.opCodes.Lookup+"?Templates=JS&JSON=2&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 = FIRSTCLASS.util.net.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, name:'ValidateName (' + string + ")"}), "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&JSON=2&Operation=Delete&FieldID="+fieldId+param; var connManagerRequest = FIRSTCLASS.util.net.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, close) { if (!params) { params = ""; } var lookup = FIRSTCLASS.opCodes.Lookup; if (suppresslookup) { lookup = ""; } var requestUrl = FIRSTCLASS.lang.ensureSlashUrl(baseURL) + lookup + "?Templates=JS&JSON=2&Operation=Add&FieldID="+fieldId + params; if (FIRSTCLASS.lang.isEmailAddress(string)) { requestUrl+="&Name=" + FIRSTCLASS.lang.uesc(string); } else { requestUrl+="&Name="+string; } if (close) { requestUrl += "&Close=0"; } var connManagerRequest = FIRSTCLASS.util.net.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; } } } 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