MWF.xApplication.ThreeMember = MWF.xApplication.ThreeMember || {}; MWF.require("MWF.widget.O2Identity", null, false); //MWF.xDesktop.requireApp("ThreeMember", "Access", null, false); //MWF.xDesktop.requireApp("ThreeMember", "Actions.RestActions", null, false); MWF.xDesktop.requireApp("Template", "Explorer", null, false); MWF.xDesktop.requireApp("Template", "MForm", null, false); MWF.xApplication.ThreeMember.PasswordView = new Class({ Extends: MWF.widget.Common, Implements: [Options, Events], options: { "style": "default", "title": MWF.xApplication.ThreeMember.LP.title }, initialize: function(node, app, options){ this.setOptions(options); this.path = "../x_component_ThreeMember/$PasswordView/"; this.cssPath = "../x_component_ThreeMember/$PasswordView/"+this.options.style+"/css.wcss"; this._loadCss(); this.app = app; this.content = $(node); this.lp = MWF.xApplication.ThreeMember.LP; this.load(); }, reload: function () { this.clear(); this.load(); }, load: function () { this.content.setStyle("overflow", "hidden"); this.node = new Element("div", { "styles": this.css.node }).inject(this.content); this.contentContainerNode = new Element("div.contentContainerNode", { "styles": this.css.contentContainerNode }).inject(this.node); this.middleNode = new Element("div.middleNode", { "styles": this.css.middleNode }).inject(this.contentContainerNode); this.contentScrollNode = new Element("div.contentScrollNode", { "styles": this.css.contentScrollNode }).inject(this.middleNode); this.contentNode = new Element("div.contentNode", { "styles": this.css.contentNode }).inject(this.contentScrollNode); this.bottomNode = new Element("div.bottomNode", { "styles": this.css.bottomNode }).inject(this.contentContainerNode); this.loadActions(); this.loadForm(); this.setContentSizeFun = this.setContentSize.bind(this); this.app.addEvent("resize", this.setContentSizeFun); this.setContentSize(); }, getOffsetY: function (node) { return (node.getStyle("margin-top").toInt() || 0) + (node.getStyle("margin-bottom").toInt() || 0) + (node.getStyle("padding-top").toInt() || 0) + (node.getStyle("padding-bottom").toInt() || 0) + (node.getStyle("border-top-width").toInt() || 0) + (node.getStyle("border-bottom-width").toInt() || 0); }, setContentSize: function () { var nodeSize = this.content.getSize(); var h = nodeSize.y - this.getOffsetY(this.content); var topY = this.topContainerNode ? (this.getOffsetY(this.topContainerNode) + this.topContainerNode.getSize().y) : 0; h = h - topY; var bottomY = this.bottomNode ? (this.getOffsetY(this.bottomNode) + this.bottomNode.getSize().y) : 0; h = h - bottomY; h = h - this.getOffsetY(this.contentScrollNode); this.contentScrollNode.setStyles({ "height": "" + h + "px", "overflow": "auto" }); }, clear: function () { if (this.setContentSizeFun) this.removeEvent("resize", this.setContentSizeFun); if( this.form )this.form.destroy(); if (this.contentContainerNode) { this.contentContainerNode.destroy(); } this.node.destroy(); }, loadActions: function(){ this.loadReadModeAction(); }, loadReadModeAction: function(){ this.bottomNode.empty(); this.saveAction = null; this.cancelAction = null; this.editAction = new Element("div", { "styles" : this.css.inputEditButton, "text": this.lp.edit, "events":{ "click": function () { this.form.changeMode(true); this.loadEditModeAction(); }.bind(this) } }).inject( this.bottomNode ); }, loadEditModeAction: function(){ this.bottomNode.empty(); this.editAction = null; this.saveAction = new Element("div", { "styles" : this.css.inputOkButton, "text": this.lp.save, "events":{ "click": function () { var result = this.form.getResult(true, null, true, true); if(!result)return; if(Object.keys(result).length > 0){ this.saveForm(result); }else{ this.form.changeMode(true); this.loadReadModeAction(); } }.bind(this) } }).inject( this.bottomNode ); this.cancelAction = new Element("div", { "styles" : this.css.inputCancelButton, "text": this.lp.cancel, "events":{ "click": function () { this.form.changeMode(); this.loadReadModeAction(); }.bind(this) } }).inject( this.bottomNode ); }, saveForm: function(data){ var actions = []; // if( data.adminPassword ){ // actions.push( // o2.Actions.load("x_program_center").ConfigAction.setToken({ // password: data.adminPassword // }) // ); // delete data.adminPassword; // } if( data.systemManagerPassword || data.securityManagerPassword || data.auditManagerPassword ) { var d = {}; if (data.systemManagerPassword) { d.systemManagerPassword = data.systemManagerPassword; delete data.systemManagerPassword; } if (data.securityManagerPassword){ d.securityManagerPassword = data.securityManagerPassword; delete data.securityManagerPassword; } if( data.auditManagerPassword ){ d.auditManagerPassword = data.auditManagerPassword; delete data.auditManagerPassword; } actions.push( o2.Actions.load("x_program_center").ConfigAction.setTernaryManagement(d) ); } if( Object.keys(data).length > 0 ){ actions.push( o2.Actions.load("x_program_center").ConfigAction.setPerson(data) ); } if( actions.length > 0 ){ Promise.all(actions).then(function () { this.app.notice( this.lp.saveSuccess ); this.form.changeMode(true); this.loadReadModeAction(); }.bind(this)).catch(function (json) { if (json.text) { this.app.notice(json.text, "error"); }else if(json.xhr){ var responseJSON = JSON.parse( json.xhr.responseText ); if( responseJSON.message ){ this.app.notice( responseJSON.message, "error" ); }else{ this.app.notice( this.lp.saveFailure, "error" ); } }else{ this.app.notice( this.lp.saveFailure, "error" ); } }.bind(this)) } }, loadForm: function(){ this.loadData( function (data) { this._loadForm(data) }.bind(this)) }, loadData: function( callback ){ var personAction = o2.Actions.load("x_program_center").ConfigAction.getPerson(); var TMAction = o2.Actions.load("x_program_center").ConfigAction.getTernaryManagement(); // var tokenAction = o2.Actions.load("x_program_center").ConfigAction.getToken(); Promise.all([personAction, TMAction]).then(function (args) { this.personData = args[0].data; this.TMData = args[1].data; // this.tokenData = args[2].data; var data = Object.clone(this.personData); // data.adminPassword = this.tokenData.password; data.systemManagerPassword = ""; data.securityManagerPassword = ""; data.auditManagerPassword = ""; // data.systemManagerPassword = this.TMData.systemManagerPassword; // data.securityManagerPassword = this.TMData.securityManagerPassword; // data.auditManagerPassword = this.TMData.auditManagerPassword; callback( data ); }.bind(this)) }, _loadForm: function( data ){ var lp = this.lp.passwordConfig; this.contentNode.set("html", this.getHtml()); MWF.xDesktop.requireApp("Template", "MForm", function () { this.form = new MForm(this.contentNode, data, { isEdited: false, style : "setting", hasColon : true, itemTemplate: { password: { "text": lp.password, tType : "text", notEmpty: true, attr: {"autocomplete": "off"} }, passwordPeriod: { "text": lp.passwordPeriod, tType : "number", attr: {"autocomplete": "off"} }, // adminPassword: { "text": lp.adminPassword, type : "password", notEmpty: true, attr: {"autocomplete": "off"} }, passwordRegex: { "text": lp.passwordRegex, tType : "text", notEmpty: true, attr: {"autocomplete": "off"} }, passwordRegexHint: { "text": lp.passwordRegexHint, tType : "text", notEmpty: true, attr: {"autocomplete": "off"} }, failureCount: { "text": lp.failureCount, tType : "number", attr: {"autocomplete": "off"} }, failureInterval: { "text": lp.failureInterval, tType : "number", attr: {"autocomplete": "off"} }, systemManagerPassword: { "text": lp.systemManagerPassword, type : "password", attr: {"autocomplete": "off"} }, securityManagerPassword: { "text": lp.securityManagerPassword, type : "password", attr: {"autocomplete": "off"} }, auditManagerPassword: { "text": lp.auditManagerPassword, type : "password", attr: {"autocomplete": "off"} } } }, this.app); this.form.load(); }.bind(this), true); }, getHtml : function(){ var lp = this.lp.passwordConfig; return "
"+lp.title+"
"+ "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + // "" + // "" + // "" + "
"+lp.password+"
"+lp.passwordNote+"
"+lp.passwordPeriod+"
"+lp.passwordPeriodNote+"
"+lp.passwordRegex+"
"+lp.passwordRegexNote+"
"+lp.passwordRegexHint+"
"+lp.passwordRegexHintNote+"
"+lp.failureCount+"
"+lp.failureCountNote+"
"+lp.failureInterval+"
"+lp.failureIntervalNote+"
"+lp.adminPassword+"
"+lp.adminPasswordNote+"
"+ "" + "" + " " + " " + " " + "" + "" + " " + " " + " " + "" + "" + " " + " " + " " + "" + "
"+lp.systemManagerPassword+""+lp.securityManagerPassword+""+lp.auditManagerPassword+"
"+lp.systemManagerPasswordNote+""+lp.securityManagerPasswordNote+""+lp.auditManagerPasswordNote+"
" }, recordStatus: function () { var status = {}; status.explorer = "passwordview"; return status; } });