PasswordView.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. MWF.xApplication.ThreeMember = MWF.xApplication.ThreeMember || {};
  2. MWF.require("MWF.widget.O2Identity", null, false);
  3. //MWF.xDesktop.requireApp("ThreeMember", "Access", null, false);
  4. //MWF.xDesktop.requireApp("ThreeMember", "Actions.RestActions", null, false);
  5. MWF.xDesktop.requireApp("Template", "Explorer", null, false);
  6. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  7. MWF.xApplication.ThreeMember.PasswordView = new Class({
  8. Extends: MWF.widget.Common,
  9. Implements: [Options, Events],
  10. options: {
  11. "style": "default",
  12. "title": MWF.xApplication.ThreeMember.LP.title
  13. },
  14. initialize: function(node, app, options){
  15. this.setOptions(options);
  16. this.path = "../x_component_ThreeMember/$PasswordView/";
  17. this.cssPath = "../x_component_ThreeMember/$PasswordView/"+this.options.style+"/css.wcss";
  18. this._loadCss();
  19. this.app = app;
  20. this.content = $(node);
  21. this.lp = MWF.xApplication.ThreeMember.LP;
  22. this.load();
  23. },
  24. reload: function () {
  25. this.clear();
  26. this.load();
  27. },
  28. load: function () {
  29. this.content.setStyle("overflow", "hidden");
  30. this.node = new Element("div", {
  31. "styles": this.css.node
  32. }).inject(this.content);
  33. this.contentContainerNode = new Element("div.contentContainerNode", {
  34. "styles": this.css.contentContainerNode
  35. }).inject(this.node);
  36. this.middleNode = new Element("div.middleNode", {
  37. "styles": this.css.middleNode
  38. }).inject(this.contentContainerNode);
  39. this.contentScrollNode = new Element("div.contentScrollNode", {
  40. "styles": this.css.contentScrollNode
  41. }).inject(this.middleNode);
  42. this.contentNode = new Element("div.contentNode", {
  43. "styles": this.css.contentNode
  44. }).inject(this.contentScrollNode);
  45. this.bottomNode = new Element("div.bottomNode", {
  46. "styles": this.css.bottomNode
  47. }).inject(this.contentContainerNode);
  48. this.loadActions();
  49. this.loadForm();
  50. this.setContentSizeFun = this.setContentSize.bind(this);
  51. this.app.addEvent("resize", this.setContentSizeFun);
  52. this.setContentSize();
  53. },
  54. getOffsetY: function (node) {
  55. return (node.getStyle("margin-top").toInt() || 0) +
  56. (node.getStyle("margin-bottom").toInt() || 0) +
  57. (node.getStyle("padding-top").toInt() || 0) +
  58. (node.getStyle("padding-bottom").toInt() || 0) +
  59. (node.getStyle("border-top-width").toInt() || 0) +
  60. (node.getStyle("border-bottom-width").toInt() || 0);
  61. },
  62. setContentSize: function () {
  63. var nodeSize = this.content.getSize();
  64. var h = nodeSize.y - this.getOffsetY(this.content);
  65. var topY = this.topContainerNode ? (this.getOffsetY(this.topContainerNode) + this.topContainerNode.getSize().y) : 0;
  66. h = h - topY;
  67. var bottomY = this.bottomNode ? (this.getOffsetY(this.bottomNode) + this.bottomNode.getSize().y) : 0;
  68. h = h - bottomY;
  69. h = h - this.getOffsetY(this.contentScrollNode);
  70. this.contentScrollNode.setStyles({
  71. "height": "" + h + "px",
  72. "overflow": "auto"
  73. });
  74. },
  75. clear: function () {
  76. if (this.setContentSizeFun) this.removeEvent("resize", this.setContentSizeFun);
  77. if( this.form )this.form.destroy();
  78. if (this.contentContainerNode) {
  79. this.contentContainerNode.destroy();
  80. }
  81. this.node.destroy();
  82. },
  83. loadActions: function(){
  84. this.loadReadModeAction();
  85. },
  86. loadReadModeAction: function(){
  87. this.bottomNode.empty();
  88. this.saveAction = null;
  89. this.cancelAction = null;
  90. this.editAction = new Element("div", {
  91. "styles" : this.css.inputEditButton,
  92. "text": this.lp.edit,
  93. "events":{
  94. "click": function () {
  95. this.form.changeMode(true);
  96. this.loadEditModeAction();
  97. }.bind(this)
  98. }
  99. }).inject( this.bottomNode );
  100. },
  101. loadEditModeAction: function(){
  102. this.bottomNode.empty();
  103. this.editAction = null;
  104. this.saveAction = new Element("div", {
  105. "styles" : this.css.inputOkButton,
  106. "text": this.lp.save,
  107. "events":{
  108. "click": function () {
  109. var result = this.form.getResult(true, null, true, true);
  110. if(!result)return;
  111. if(Object.keys(result).length > 0){
  112. this.saveForm(result);
  113. }else{
  114. this.form.changeMode(true);
  115. this.loadReadModeAction();
  116. }
  117. }.bind(this)
  118. }
  119. }).inject( this.bottomNode );
  120. this.cancelAction = new Element("div", {
  121. "styles" : this.css.inputCancelButton,
  122. "text": this.lp.cancel,
  123. "events":{
  124. "click": function () {
  125. this.form.changeMode();
  126. this.loadReadModeAction();
  127. }.bind(this)
  128. }
  129. }).inject( this.bottomNode );
  130. },
  131. saveForm: function(data){
  132. var actions = [];
  133. // if( data.adminPassword ){
  134. // actions.push(
  135. // o2.Actions.load("x_program_center").ConfigAction.setToken({
  136. // password: data.adminPassword
  137. // })
  138. // );
  139. // delete data.adminPassword;
  140. // }
  141. if( data.systemManagerPassword || data.securityManagerPassword || data.auditManagerPassword ) {
  142. var d = {};
  143. if (data.systemManagerPassword) {
  144. d.systemManagerPassword = data.systemManagerPassword;
  145. delete data.systemManagerPassword;
  146. }
  147. if (data.securityManagerPassword){
  148. d.securityManagerPassword = data.securityManagerPassword;
  149. delete data.securityManagerPassword;
  150. }
  151. if( data.auditManagerPassword ){
  152. d.auditManagerPassword = data.auditManagerPassword;
  153. delete data.auditManagerPassword;
  154. }
  155. actions.push(
  156. o2.Actions.load("x_program_center").ConfigAction.setTernaryManagement(d)
  157. );
  158. }
  159. if( Object.keys(data).length > 0 ){
  160. actions.push(
  161. o2.Actions.load("x_program_center").ConfigAction.setPerson(data)
  162. );
  163. }
  164. if( actions.length > 0 ){
  165. Promise.all(actions).then(function () {
  166. this.app.notice( this.lp.saveSuccess );
  167. this.form.changeMode(true);
  168. this.loadReadModeAction();
  169. }.bind(this)).catch(function (json) {
  170. if (json.text) {
  171. this.app.notice(json.text, "error");
  172. }else if(json.xhr){
  173. var responseJSON = JSON.parse( json.xhr.responseText );
  174. if( responseJSON.message ){
  175. this.app.notice( responseJSON.message, "error" );
  176. }else{
  177. this.app.notice( this.lp.saveFailure, "error" );
  178. }
  179. }else{
  180. this.app.notice( this.lp.saveFailure, "error" );
  181. }
  182. }.bind(this))
  183. }
  184. },
  185. loadForm: function(){
  186. this.loadData( function (data) {
  187. this._loadForm(data)
  188. }.bind(this))
  189. },
  190. loadData: function( callback ){
  191. var personAction = o2.Actions.load("x_program_center").ConfigAction.getPerson();
  192. var TMAction = o2.Actions.load("x_program_center").ConfigAction.getTernaryManagement();
  193. // var tokenAction = o2.Actions.load("x_program_center").ConfigAction.getToken();
  194. Promise.all([personAction, TMAction]).then(function (args) {
  195. this.personData = args[0].data;
  196. this.TMData = args[1].data;
  197. // this.tokenData = args[2].data;
  198. var data = Object.clone(this.personData);
  199. // data.adminPassword = this.tokenData.password;
  200. data.systemManagerPassword = "";
  201. data.securityManagerPassword = "";
  202. data.auditManagerPassword = "";
  203. // data.systemManagerPassword = this.TMData.systemManagerPassword;
  204. // data.securityManagerPassword = this.TMData.securityManagerPassword;
  205. // data.auditManagerPassword = this.TMData.auditManagerPassword;
  206. callback( data );
  207. }.bind(this))
  208. },
  209. _loadForm: function( data ){
  210. var lp = this.lp.passwordConfig;
  211. this.contentNode.set("html", this.getHtml());
  212. MWF.xDesktop.requireApp("Template", "MForm", function () {
  213. this.form = new MForm(this.contentNode, data, {
  214. isEdited: false,
  215. style : "setting",
  216. hasColon : true,
  217. itemTemplate: {
  218. password: { "text": lp.password, tType : "text", notEmpty: true, attr: {"autocomplete": "off"} },
  219. passwordPeriod: { "text": lp.passwordPeriod, tType : "number", attr: {"autocomplete": "off"} },
  220. // adminPassword: { "text": lp.adminPassword, type : "password", notEmpty: true, attr: {"autocomplete": "off"} },
  221. passwordRegex: { "text": lp.passwordRegex, tType : "text", notEmpty: true, attr: {"autocomplete": "off"} },
  222. passwordRegexHint: { "text": lp.passwordRegexHint, tType : "text", notEmpty: true, attr: {"autocomplete": "off"} },
  223. failureCount: { "text": lp.failureCount, tType : "number", attr: {"autocomplete": "off"} },
  224. failureInterval: { "text": lp.failureInterval, tType : "number", attr: {"autocomplete": "off"} },
  225. systemManagerPassword: { "text": lp.systemManagerPassword, type : "password", attr: {"autocomplete": "off"} },
  226. securityManagerPassword: { "text": lp.securityManagerPassword, type : "password", attr: {"autocomplete": "off"} },
  227. auditManagerPassword: { "text": lp.auditManagerPassword, type : "password", attr: {"autocomplete": "off"} }
  228. }
  229. }, this.app);
  230. this.form.load();
  231. }.bind(this), true);
  232. },
  233. getHtml : function(){
  234. var lp = this.lp.passwordConfig;
  235. return "<div styles='formTitle'>"+lp.title+"</div>"+
  236. "<table width='90%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable'>" +
  237. "<tr><td styles='formTableTitle'>"+lp.password+"</td></tr>" +
  238. "<tr><td styles='formTableNote'>"+lp.passwordNote+"</td></tr>" +
  239. "<tr><td styles='formTableValue' item='password'></td></tr>" +
  240. "<tr><td styles='formTableTitle'>"+lp.passwordPeriod+"</td></tr>" +
  241. "<tr><td styles='formTableNote'>"+lp.passwordPeriodNote+"</td></tr>" +
  242. "<tr><td styles='formTableValue' item='passwordPeriod'></td></tr>" +
  243. "<tr><td styles='formTableTitle'>"+lp.passwordRegex+"</td></tr>" +
  244. "<tr><td styles='formTableNote'>"+lp.passwordRegexNote+"</td></tr>" +
  245. "<tr><td styles='formTableValue' item='passwordRegex'></td></tr>" +
  246. "<tr><td styles='formTableTitle'>"+lp.passwordRegexHint+"</td></tr>" +
  247. "<tr><td styles='formTableNote'>"+lp.passwordRegexHintNote+"</td></tr>" +
  248. "<tr><td styles='formTableValue' item='passwordRegexHint'></td></tr>" +
  249. "<tr><td styles='formTableTitle'>"+lp.failureCount+"</td></tr>" +
  250. "<tr><td styles='formTableNote'>"+lp.failureCountNote+"</td></tr>" +
  251. "<tr><td styles='formTableValue' item='failureCount'></td></tr>" +
  252. "<tr><td styles='formTableTitle'>"+lp.failureInterval+"</td></tr>" +
  253. "<tr><td styles='formTableNote'>"+lp.failureIntervalNote+"</td></tr>" +
  254. "<tr><td styles='formTableValue' item='failureInterval'></td></tr>" +
  255. // "<tr><td styles='formTableTitle'>"+lp.adminPassword+"</td></tr>" +
  256. // "<tr><td styles='formTableNote'>"+lp.adminPasswordNote+"</td></tr>" +
  257. // "<tr><td styles='formTableValue' item='adminPassword'></td></tr>" +
  258. "</table>"+
  259. "<table width='90%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable'>" +
  260. "<tr>" +
  261. " <td styles='formTableTitle'>"+lp.systemManagerPassword+"</td>" +
  262. " <td styles='formTableTitle'>"+lp.securityManagerPassword+"</td>" +
  263. " <td styles='formTableTitle'>"+lp.auditManagerPassword+"</td>" +
  264. "</tr>" +
  265. "<tr>" +
  266. " <td styles='formTableNote'>"+lp.systemManagerPasswordNote+"</td>" +
  267. " <td styles='formTableNote'>"+lp.securityManagerPasswordNote+"</td>" +
  268. " <td styles='formTableNote'>"+lp.auditManagerPasswordNote+"</td>" +
  269. "</tr>" +
  270. "<tr>" +
  271. " <td styles='formTableValue' item='systemManagerPassword'></td>" +
  272. " <td styles='formTableValue' item='securityManagerPassword'></td>" +
  273. " <td styles='formTableValue' item='auditManagerPassword'></td>" +
  274. "</tr>" +
  275. "</table>"
  276. },
  277. recordStatus: function () {
  278. var status = {};
  279. status.explorer = "passwordview";
  280. return status;
  281. }
  282. });