/** * Class Description * @namespace FIRSTCLASS.apps * @module FormDialog * @requires * @optional * @title */ /** * Constructor definition * @class FormDialog * @constructor * @param {Object} config (required) the configuration object * @param {HTMLElement} config.domElement (required) the DOM Element to load into * @param {FIRSTCLASS.util.DataSource} config.dataSource (required) the DataSource to bind to */ FIRSTCLASS.apps.FormDialog = function(config) { var that = this; this._domElement = config.domElement; this._showPass = true; var eatKeys = function(evt) { YAHOO.util.Event.stopPropagation(evt); }; YAHOO.util.Event.addListener(this._domElement, "keyup", eatKeys); YAHOO.util.Event.addListener(this._domElement, "keydown", eatKeys); var showhidepass = function() { if (that._showPass) { YAHOO.util.Dom.setStyle(document.getElementById('passwordarea'), "display", ""); YAHOO.util.Dom.setStyle(document.getElementById('emailArea'), "display", "none"); YAHOO.util.Dom.setStyle(document.getElementById('theLock'), "display", "none"); document.getElementById('clickhere').innerHTML = FIRSTCLASS.locale.workflows.account.changeemail; } else { YAHOO.util.Dom.setStyle(document.getElementById('passwordarea'), "display", "none"); YAHOO.util.Dom.setStyle(document.getElementById('emailArea'), "display", ""); YAHOO.util.Dom.setStyle(document.getElementById('theLock'), "display", ""); document.getElementById('clickhere').innerHTML = FIRSTCLASS.locale.workflows.account.changepassword; } that._showPass = !that._showPass; } this._dataSource = config.dataSource; var myonLoaded = config.onLoaded; var createDialog = function() { var handleSubmit = function() { var thata = this; if (config.submit) config.submit(); else { var passHidden = (YAHOO.util.Dom.getStyle(document.getElementById('passwordarea'), "display") == "none"); if (passHidden) { FIRSTCLASS.apps.FormDialog.setEmailAddress(thata); return; } var submitForm = document.getElementById('mainform'); if (submitForm != null) { if (document.getElementById('newpass').value != document.getElementById('retypedpass').value) alert( FIRSTCLASS.locale.workflows.account.nomatchpassword ); else { YAHOO.util.Connect.setForm(submitForm); var method = submitForm.method; if (!method) { method = "POST"; } var cb = { success: function(e) { if (e.status && ((e.status == 202) || ((e.status==200) && (e.responseText.indexOf('mainform') < 0)))) { if (typeof config.hideaftersubmit == "undefined" || config.hideaftersubmit) { thata.hide(); alert(FIRSTCLASS.locale.workflows.account.passwordchanged); } } else { alert(FIRSTCLASS.locale.workflows.account.passwordunchanged1); } }, failure: function(e) { alert(FIRSTCLASS.locale.workflows.account.passwordunchanged2); } }; YAHOO.util.Connect.asyncRequest(method, submitForm.action, cb); } } } }; var handleCancel = function() { if (config.cancel) { config.cancel(); } if (typeof config.hideaftercancel == "undefined" || config.hideaftercancel) { this.cancel(); } }; var buttons = [ { text:"Submit", handler:handleSubmit, isDefault:true }, { text:"Cancel", handler:handleCancel } ]; if (config.buttons) { buttons = config.buttons; for(var b in buttons) { if (buttons[b].type=="cancel") { var h = buttons[b].handler; buttons[b].handler = handleCancel; } if (buttons[b].type=="submit") { var h = buttons[b].handler; buttons[b].handler = handleSubmit; } } } var handleSuccess = function(o) { var response = o.responseText; response = response.split(" -1){ useShim = true; } else { useShim = false; } var width = "500px"; if (config.width) { width = config.width; } mySimpleDialog = new YAHOO.widget.Dialog("dialog1", { width : width, fixedcenter : true, visible : true, constraintoviewport : true, modal:true, buttons : buttons, shim: useShim } ); if (typeof config.title != "undefined") { mySimpleDialog.setHeader(config.title); } else { mySimpleDialog.setHeader(FIRSTCLASS.locale.workflows.account.windowtitle); } if (config.onHide) { mySimpleDialog.subscribe('hide', config.onHide); } mySimpleDialog.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_WARN); that.destroy = function() { mySimpleDialog.destroy(); }; that.hide = function() { mySimpleDialog.hide(); }; that.getButtons = function() { return mySimpleDialog.getButtons(); }; that.getDialog = function() { return mySimpleDialog; }; that.mySimpleDialog = mySimpleDialog; }; var handleHide = function() { if (config.hide) { config.hide(); } }; var handleSuccess = function(o){ if(myonLoaded){ myonLoaded(); } createDialog(); if(o.responseText !== undefined){ if (that._domElement) { that._domElement.innerHTML = o.responseText; that.mySimpleDialog.setBody(that._domElement); } else { that.mySimpleDialog.setBody(o.responseText); } } that.mySimpleDialog.render(document.body); YAHOO.util.Event.addListener(document.getElementById('clickhere'), "click", showhidepass); that.mySimpleDialog.hideEvent.subscribe(handleHide); if (config.onDomInserted) { config.onDomInserted(); } }; var handleFailure = function(o){ createDialog(); if (config.handleFailure) { config.handleFailure(o); } else { if(o.responseText !== undefined){ that.mySimpleDialog.setBody(o.responseText); that.mySimpleDialog.render(document.body); } } if (config.onDomInserted) { config.onDomInserted(); } }; var callback = { success:handleSuccess, failure: handleFailure, argument: { foo:"foo", bar:"bar" } }; var request = YAHOO.util.Connect.asyncRequest('GET', config.baseUrl, callback); }; FIRSTCLASS.apps.FormDialog.onSave= function() { this._theDialog.hide(); } FIRSTCLASS.apps.FormDialog.onLoaded= function(success) { if (!success) this.onFail(); } FIRSTCLASS.apps.FormDialog.onDisplay = function() { document.getElementById('toField').value = document.getElementById('emailaddress').value; this._editor.onSubmit(); } FIRSTCLASS.apps.FormDialog.onFail = function(a) { alert("Your notification email address could not be changed."); } FIRSTCLASS.apps.FormDialog.setEmailAddress = function(theDialog) { this._theDialog = theDialog; var theEmailField = document.getElementById('emailaddress'); if (theEmailField != null) { if (theEmailField.value != this.originalEmail) { this._emailPrefsUpdate = true; var msgCfg = { callback: this, element: document.getElementById('emailPrefsDiv'), objType: FIRSTCLASS.objTypes.formdoc, formID: 127, formElId: "emailPref", bodyType: "plain", quoteText: null, sendTo: null, op: FIRSTCLASS.opCodes.FormEdit, baseURL: FIRSTCLASS.session.baseURL + "__Preferences", dontClear: true }; this._editor = new FIRSTCLASS.util.Message(msgCfg); } } } /** * Public static variables definitions */ /** * Property Comment, describe it here * * @property * @type * @default */ //FIRSTCLASS.apps.FormDialog. = ; /** * Private member variables * * Private variables are identified by the convention of naming them with a leading underscore. * i.e. this._privateVariable */ /** * Variable Comment, describe it here * * @property _ * @type * @default */ FIRSTCLASS.apps.FormDialog.prototype._dataSource = null; FIRSTCLASS.apps.FormDialog.prototype._domElement = null; /** * Public member variables */ /** * Variable Comment, describe it here * * @property * @type * @default */ //FIRSTCLASS.apps.FormDialog.prototype. = ; /** * Public Static Method Definitions */ /** * Method Comment, describe it here * * @Method FormDialog. * @param {} paramname * @param ... * @return {} * @static */ //FIRSTCLASS.apps.FormDialog. = function() { //}; /** * Public method definitions */ /** * Method Comment, describe it here * * @Method FormDialog. * @param {} paramname * @param ... * @return {} */ //FIRSTCLASS.apps.FormDialog.prototype. = function() { //}; YAHOO.register("fcFormDialog", FIRSTCLASS.apps.FormDialog, {version: "0.0.1", build: "1"});