Main.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. MWF.xApplication.Collect.options.multitask = false;
  2. MWF.require("MWF.xDesktop.Access", null, false);
  3. MWF.xDesktop.requireApp("Collect", "Actions.RestActions", null, false);
  4. MWF.xApplication.Collect.Main = new Class({
  5. Extends: MWF.xApplication.Common.Main,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "name": "Collect",
  10. "icon": "icon.png",
  11. "width": "400",
  12. "height": "500",
  13. "isResize": false,
  14. "isMax": false,
  15. "title": MWF.xApplication.Collect.LP.title
  16. },
  17. onQueryLoad: function(){
  18. this.lp = MWF.xApplication.Collect.LP;
  19. this.action = MWF.Actions.get("x_program_center");
  20. //this.action = new MWF.xApplication.Collect.Actions.RestActions();
  21. this.connected = false;
  22. this.login = false;
  23. this.connectChecked = false;
  24. this.loginChecked = false;
  25. },
  26. loadWindow: function(isCurrent){
  27. this.fireAppEvent("queryLoadWindow");
  28. this.window = new MWF.xDesktop.WindowTransparent(this, {"container": this.desktop.node});
  29. this.fireAppEvent("loadWindow");
  30. this.window.show();
  31. this.content = this.window.content;
  32. if (isCurrent) this.setCurrent();
  33. this.fireAppEvent("postLoadWindow");
  34. this.fireAppEvent("queryLoadApplication");
  35. this.loadApplication(function(){
  36. this.fireAppEvent("postLoadApplication");
  37. }.bind(this));
  38. },
  39. loadApplication: function(callback){
  40. if (!MWF.AC.isAdministrator()){
  41. try{
  42. this.close();
  43. }catch(e){};
  44. }else{
  45. this.node = new Element("div", {"styles": this.css.node}).inject(this.content);
  46. this.setNodeResize();
  47. this.node.addEvent("selectstart", function(e){e.target.setStyle("-webkit-user-select", "none")}.bind(this));
  48. this.loadContent();
  49. this.addEvent("queryclose", function(){
  50. if (this.registerForm){
  51. if (this.registerForm.codeNextTimer){
  52. window.clearTimeout(this.registerForm.codeNextTimer);
  53. }
  54. }
  55. }.bind(this));
  56. }
  57. },
  58. loadContent: function(){
  59. this.titleAreaNode = new Element("div", {"styles": this.css.titleAreaNode}).inject(this.node);
  60. this.backNode = new Element("div", {"styles": this.css.backNode}).inject(this.titleAreaNode);
  61. this.closeNode = new Element("div", {"styles": this.css.closeNode}).inject(this.titleAreaNode);
  62. this.closeNode.addEvent("click", function(){this.close();}.bind(this));
  63. this.titleNode = new Element("div", {"styles": this.css.titleNode, "text": this.lp.title}).inject(this.titleAreaNode);
  64. this.checkContentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  65. this.loginContentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  66. this.modifyContentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  67. this.modifyPwdContentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  68. this.deleteContentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  69. this.registerContentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  70. this.check = new MWF.xApplication.Collect.Check(this);
  71. this.showContent("checkContentNode");
  72. },
  73. showContent: function(node){
  74. this.checkContentNode.setStyle("display", "none");
  75. this.loginContentNode.setStyle("display", "none");
  76. this.modifyContentNode.setStyle("display", "none");
  77. this.modifyPwdContentNode.setStyle("display", "none");
  78. this.deleteContentNode.setStyle("display", "none");
  79. this.registerContentNode.setStyle("display", "none");
  80. this[node].setStyle("display", "block");
  81. },
  82. setNodeResize: function(){
  83. this.setNodePositionAndSizeFun = this.setNodePositionAndSize.bind(this);
  84. this.setNodePositionAndSizeFun();
  85. $(window).addEvent("resize", this.setNodePositionAndSizeFun);
  86. this.addEvent("queryClose", function(){
  87. $(window).removeEvent("resize", this.setNodePositionAndSizeFun);
  88. }.bind(this));
  89. },
  90. setNodePositionAndSize: function(){
  91. this.node.position({
  92. relativeTo: this.desktop.node,
  93. position: 'center',
  94. edge: 'center'
  95. });
  96. }
  97. });
  98. MWF.xApplication.Collect.Check = new Class({
  99. initialize: function(collect){
  100. this.collect = collect;
  101. this.lp = this.collect.lp;
  102. this.css = this.collect.css;
  103. this.contentNode = this.collect.checkContentNode;
  104. this.action = this.collect.action;
  105. this.load();
  106. },
  107. load: function(){
  108. this.connectChecked = true;
  109. this.loginChecked = false;
  110. this.statusConnectNode = new Element("div", {"styles": this.css.statusConnectNode}).inject(this.contentNode);
  111. this.setStatusConnectNode();
  112. this.statusLoginNode = new Element("div", {"styles": this.css.statusLoginNode}).inject(this.contentNode);
  113. this.setStatusLoginNode();
  114. this.actionsNode = new Element("div", {"styles": this.css.actionsNode}).inject(this.contentNode);
  115. },
  116. setActionsNode: function(){
  117. if (this.connectChecked && this.loginChecked) {
  118. this.actionsNode.empty();
  119. if (this.connected && this.login){
  120. this.setLoginInfor();
  121. }else if (this.connected && !this.login){
  122. this.setNotLoginInfor();
  123. }else if (!this.connected && !this.login){
  124. this.setDisconnectedInfor();
  125. }else{
  126. //impossible
  127. }
  128. }
  129. },
  130. setLoginInfor: function(){
  131. new Element("div", {"styles": this.css.loginInfor, "html": this.lp.connectedAndLogin}).inject(this.actionsNode);
  132. new Element("div", {"styles": this.css.loginInfor, "html": this.lp.modifyAccount}).inject(this.actionsNode);
  133. this.modifyAccountAction = new Element("div", {"styles": this.css.inforAction, "html": this.lp.modifyAccountAction}).inject(this.actionsNode);
  134. this.disconnectAction = new Element("div", {"styles": this.css.inforAction, "html": this.lp.doDisconnect}).inject(this.actionsNode);
  135. this.disconnectAction.addEvent("click", this.disconnect.bind(this));
  136. this.modifyPwdAccountAction = new Element("div", {"styles": this.css.inforAction, "html": this.lp.modifyPwdAccountAction}).inject(this.actionsNode);
  137. this.deleteAccountAction = new Element("div", {"styles": this.css.inforAction, "html": this.lp.deleteAccountAction}).inject(this.actionsNode);
  138. this.modifyAccountAction.addEvent("click", this.showModifyForm.bind(this));
  139. this.modifyPwdAccountAction.addEvent("click", this.showModifyPwdForm.bind(this));
  140. this.deleteAccountAction.addEvent("click", this.showDeleteForm.bind(this));
  141. new Element("div", {"styles": this.css.loginInfor, "html": this.lp.loginAccount}).inject(this.actionsNode);
  142. this.loginAccountAction = new Element("div", {"styles": this.css.inforAction, "html": this.lp.login}).inject(this.actionsNode);
  143. this.loginAccountAction.addEvent("click", this.showLoginForm.bind(this));
  144. },
  145. setNotLoginInfor: function(){
  146. new Element("div", {"styles": this.css.notLoginInfor, "html": this.lp.notLogin}).inject(this.actionsNode);
  147. new Element("div", {"styles": this.css.notLoginInfor, "html": this.lp.notLoginInfoLogin}).inject(this.actionsNode);
  148. this.loginAction = new Element("div", {"styles": this.css.inforAction, "html": this.lp.login}).inject(this.actionsNode);
  149. new Element("div", {"styles": this.css.notLoginInfor, "html": this.lp.notLoginInfoRegister}).inject(this.actionsNode);
  150. this.registerAction = new Element("div", {"styles": this.css.inforAction, "html": this.lp.register}).inject(this.actionsNode);
  151. this.loginAction.addEvent("click", this.showLoginForm.bind(this));
  152. this.registerAction.addEvent("click", this.showRegisterForm.bind(this));
  153. //this.modifyAccountAction = new Element("div", {"styles": this.css.modifyAccountAction, "html": this.lp.modifyAccountAction}).inject(this.actionsNode);
  154. },
  155. setDisconnectedInfor: function(){
  156. new Element("div", {"styles": this.css.loginInfor, "html": this.lp.disconnect}).inject(this.actionsNode);
  157. new Element("div", {"styles": this.css.disconnectInfor, "html": this.lp.disconnectInfo}).inject(this.actionsNode);
  158. },
  159. setStatusConnectNode: function(){
  160. this.statusConnectNode.empty();
  161. this.setStatusConnectNodeContent();
  162. this.action.collectConnected(function(json){
  163. if (json.data.value){
  164. this.setStatusConnectSuccess();
  165. this.connected = true;
  166. }else{
  167. this.setStatusConnectFailure();
  168. this.connected = false;
  169. }
  170. this.connectChecked = true;
  171. this.setActionsNode();
  172. }.bind(this), function(){
  173. this.setStatusConnectFailure();
  174. this.connected = false;
  175. this.connectChecked = true;
  176. this.setActionsNode();
  177. }.bind(this));
  178. },
  179. setStatusConnectNodeContent: function(){
  180. this.statusConnectNode.empty();
  181. this.statusConnectIconsNode = new Element("div", {"styles": this.css.statusConnectIconsNode}).inject(this.statusConnectNode);
  182. this.statusConnectIconCenterNode = new Element("div", {"styles": this.css.statusConnectIconCenterNode}).inject(this.statusConnectIconsNode);
  183. this.statusConnectIconConnectNode = new Element("div", {"styles": this.css.statusConnectIconConnectNode}).inject(this.statusConnectIconsNode);
  184. this.statusConnectIconCollectNode = new Element("div", {"styles": this.css.statusConnectIconCollectNode}).inject(this.statusConnectIconsNode);
  185. this.statusConnectTextNode = new Element("div", {"styles": this.css.statusConnectTextNode, "text": this.lp.checking}).inject(this.statusConnectNode);
  186. },
  187. setStatusConnectSuccess: function(){
  188. this.statusConnectIconConnectNode.setStyles(this.css.statusConnectIconConnectedNode);
  189. this.statusConnectTextNode.set("text", this.lp.collectConnected);
  190. },
  191. setStatusConnectFailure: function(){
  192. this.statusConnectIconConnectNode.setStyles(this.css.statusConnectIconDisconnectNode);
  193. this.statusConnectTextNode.set("text", this.lp.collectDisconnect);
  194. },
  195. setStatusLoginNode: function(){
  196. this.statusLoginNode.empty();
  197. this.setStatusLoginNodeContent();
  198. this.action.collectValidate(function(json){
  199. if (json.data.value){
  200. this.setStatusLoginSuccess();
  201. this.login = true;
  202. }else{
  203. this.setStatusLoginFailure();
  204. this.login = false;
  205. }
  206. this.recheckActionNode = new Element("div", {"styles": this.css.recheckActionNode, "text": this.lp.recheck}).inject(this.statusLoginTextNode, "before");
  207. this.recheckActionNode.addEvent("click", function(){this.recheck();}.bind(this));
  208. this.loginChecked = true;
  209. this.setActionsNode();
  210. }.bind(this), function(){
  211. this.setStatusLoginFailure();
  212. this.login = false;
  213. this.recheckActionNode = new Element("div", {"styles": this.css.recheckActionNode, "text": this.lp.recheck}).inject(this.statusLoginTextNode, "before");
  214. this.recheckActionNode.addEvent("click", function(){this.recheck();}.bind(this));
  215. this.loginChecked = true;
  216. this.setActionsNode();
  217. }.bind(this));
  218. },
  219. setStatusLoginNodeContent: function(){
  220. this.statusLoginIconsNode = new Element("div", {"styles": this.css.statusLoginIconsNode}).inject(this.statusLoginNode);
  221. this.statusLoginIconCenterNode = new Element("div", {"styles": this.css.statusLoginIconCenterNode}).inject(this.statusLoginIconsNode);
  222. this.statusLoginIconConnectNode = new Element("div", {"styles": this.css.statusLoginIconConnectNode}).inject(this.statusLoginIconsNode);
  223. this.statusLoginIconCollectNode = new Element("div", {"styles": this.css.statusLoginIconCollectNode}).inject(this.statusLoginIconsNode);
  224. this.statusLoginTextNode = new Element("div", {"styles": this.css.statusLoginTextNode, "text": this.lp.checking}).inject(this.statusLoginNode);
  225. },
  226. setStatusLoginSuccess: function(){
  227. this.statusLoginIconConnectNode.setStyles(this.css.statusLoginIconConnectedNode);
  228. this.statusLoginTextNode.set("text", this.lp.collectLogin);
  229. },
  230. setStatusLoginFailure: function(){
  231. this.statusLoginIconConnectNode.setStyles(this.css.statusLoginIconDisconnectNode);
  232. this.statusLoginTextNode.set("text", this.lp.collectNotLogin);
  233. },
  234. disconnect : function(){
  235. this.action.disconnect( function(json){
  236. this.recheck();
  237. }.bind(this), null , false);
  238. },
  239. recheck: function(){
  240. this.contentNode.empty();
  241. this.load();
  242. },
  243. showModifyForm: function(){
  244. if (!this.collect.modifyForm){
  245. this.collect.modifyForm = new MWF.xApplication.Collect.ModifyForm(this.collect);
  246. }
  247. this.collect.modifyForm.show();
  248. },
  249. showModifyPwdForm: function(){
  250. if (!this.collect.modifyPwdForm){
  251. this.collect.modifyPwdForm = new MWF.xApplication.Collect.ModifyPwdForm(this.collect);
  252. }
  253. this.collect.modifyPwdForm.show();
  254. },
  255. showDeleteForm: function(){
  256. if (!this.collect.deleteForm){
  257. this.collect.deleteForm = new MWF.xApplication.Collect.DeleteForm(this.collect);
  258. }
  259. this.collect.deleteForm.show();
  260. },
  261. showLoginForm: function(){
  262. if (!this.collect.loginForm){
  263. this.collect.loginForm = new MWF.xApplication.Collect.LoginForm(this.collect);
  264. }
  265. this.collect.loginForm.show();
  266. },
  267. showRegisterForm: function(){
  268. if (!this.collect.registerForm){
  269. this.collect.registerForm = new MWF.xApplication.Collect.RegisterForm(this.collect);
  270. }
  271. this.collect.registerForm.show();
  272. }
  273. });
  274. MWF.xApplication.Collect.LoginForm = new Class({
  275. initialize: function(collect){
  276. this.collect = collect;
  277. this.lp = this.collect.lp;
  278. this.css = this.collect.css;
  279. this.contentNode = this.collect.loginContentNode;
  280. this.action = this.collect.action;
  281. this.load();
  282. },
  283. load: function(){
  284. this.usernameNode = new Element("div", {"styles": this.css.loginUsernameNode}).inject(this.contentNode);
  285. var icon = new Element("div", {"styles": this.css.loginUsernameIconNode}).inject(this.usernameNode);
  286. var inputArea = new Element("div", {"styles": this.css.loginInputAreaNode}).inject(this.usernameNode);
  287. this.usernameInput = new Element("input", {"styles": this.css.loginInputNode, "type": "text", "value": this.lp.username}).inject(inputArea);
  288. var errorNode = new Element("div", {"styles": this.css.loginErrorNode}).inject(this.contentNode);
  289. this.passwordNode = new Element("div", {"styles": this.css.loginPasswordNode}).inject(this.contentNode);
  290. icon = new Element("div", {"styles": this.css.loginPasswordIconNode}).inject(this.passwordNode);
  291. inputArea = new Element("div", {"styles": this.css.loginInputAreaNode}).inject(this.passwordNode);
  292. this.passwordInput = new Element("input", {"styles": this.css.loginInputNode, "type": "password", "value": this.lp.password}).inject(inputArea);
  293. errorNode = new Element("div", {"styles": this.css.loginErrorNode}).inject(this.contentNode);
  294. this.setInputEvent();
  295. this.setDefaultValue();
  296. this.loginActionNode = new Element("div", {"styles": this.css.loginActionNode, "text": this.lp.login}).inject(this.contentNode);
  297. this.loginActionNode.addEvent("click", this.login.bind(this));
  298. this.otherActionNode = new Element("div", {"styles": this.css.loginOtherActionNode}).inject(this.contentNode);
  299. this.registerActionNode = new Element("div", {"styles": this.css.loginRegisterActionNode, "text": this.lp.register}).inject(this.otherActionNode);
  300. this.forgetActionNode = new Element("div", {"styles": this.css.loginForgetActionNode, "text": this.lp.forget}).inject(this.otherActionNode);
  301. this.setOtherActionEvent();
  302. this.errorNode = new Element("div", {"styles": this.css.loginErrorNode}).inject(this.contentNode);
  303. },
  304. login: function(){
  305. if (!this.isLogining){
  306. this.loginActionNode.set("text", this.lp.logining);
  307. this.isLogining = true;
  308. this.errorNode.set("text", "");
  309. var user = this.usernameInput.get("value");
  310. var pass = this.passwordInput.get("value");
  311. var errorText = "";
  312. this.checkLogin = true;
  313. if (!user || user==this.lp.username) this.errorUsername(this.lp.errorUsername);
  314. if (!pass || pass==this.lp.password) this.errorPassword(this.lp.errorPassword);
  315. if (this.checkLogin){
  316. this.action.collectValidateInput({"name": user, "password": pass}, function(json){
  317. if (json.data.value){
  318. this.action.updateCollect({"name": user, "password": pass, "enable": true}, function(json){
  319. this.loginCanceled();
  320. this.collect.showContent("checkContentNode");
  321. this.collect.backNode.setStyle("display", "none");
  322. this.check.recheck();
  323. }.bind(this), function(xhr, text, error){
  324. var errorText = error+":"+text;
  325. if (xhr) errorText = xhr.responseText;
  326. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  327. this.loginCanceled();
  328. }.bind(this));
  329. }else{
  330. this.errorNode.set("text", this.lp.loginError);
  331. this.loginCanceled();
  332. }
  333. }.bind(this), function(xhr, text, error){
  334. if (xhr){
  335. var json = JSON.decode(xhr.responseText);
  336. this.errorNode.set("text", json.message);
  337. }else{
  338. var errorText = error+":"+text;
  339. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  340. }
  341. this.loginCanceled();
  342. }.bind(this));
  343. }
  344. }
  345. },
  346. loginCanceled: function(){
  347. this.loginActionNode.set("text", this.lp.login);
  348. this.isLogining = false;
  349. },
  350. errorUsername: function(text){
  351. if (text){
  352. this.usernameNode.setStyles(this.css.loginUsernameNode_error);
  353. this.checkLogin = false;
  354. }else{
  355. this.usernameNode.setStyles(this.css.loginUsernameNode);
  356. }
  357. this.usernameNode.getNext().set("text", text);
  358. },
  359. errorPassword: function(text){
  360. if (text){
  361. this.passwordNode.setStyles(this.css.loginPasswordNode_error);
  362. this.checkLogin = false;
  363. }else{
  364. this.passwordNode.setStyles(this.css.loginPasswordNode);
  365. }
  366. this.passwordNode.getNext().set("text", text);
  367. },
  368. show: function(){
  369. this.collect.showContent("loginContentNode");
  370. this.collect.backNode.setStyle("display", "block");
  371. this.collect.backNode.removeEvents("click");
  372. this.collect.backNode.addEvent("click", function(){
  373. this.collect.showContent("checkContentNode");
  374. this.collect.backNode.setStyle("display", "none");
  375. }.bind(this));
  376. this.setDefaultValue();
  377. },
  378. setInputEvent: function(){
  379. this.usernameInput.addEvents({
  380. "focus": function(){
  381. this.errorUsername("");
  382. this.usernameNode.setStyles(this.css.loginUsernameNode_over);
  383. if (this.usernameInput.get("value")==this.lp.username){
  384. this.usernameInput.set("value", "");
  385. }
  386. }.bind(this),
  387. "blur": function(){
  388. this.usernameNode.setStyles(this.css.loginUsernameNode);
  389. if (!this.usernameInput.get("value")){
  390. this.usernameInput.set("value", this.lp.username);
  391. this.errorUsername(this.lp.errorUsername);
  392. }
  393. }.bind(this),
  394. "selectstart": function(e){e.stopPropagation();}
  395. });
  396. this.passwordInput.addEvents({
  397. "focus": function(){
  398. this.errorPassword("");
  399. this.passwordNode.setStyles(this.css.loginPasswordNode_over);
  400. if (this.passwordInput.get("value")==this.lp.password){
  401. this.passwordNode.getNext().set("text", "");
  402. this.passwordInput.set("value", "");
  403. }
  404. }.bind(this),
  405. "blur": function(){
  406. this.passwordNode.setStyles(this.css.loginPasswordNode);
  407. if (!this.passwordInput.get("value")){
  408. this.errorPassword(this.lp.errorPassword);
  409. this.passwordInput.set("value", this.lp.password);
  410. }
  411. }.bind(this),
  412. "selectstart": function(e){e.stopPropagation();}
  413. });
  414. },
  415. setDefaultValue: function(){
  416. this.action.getCollectConfig(function(json){
  417. if (json.data.name) this.usernameInput.set("value", json.data.name);
  418. if (json.data.password) this.passwordInput.set("value", json.data.password);
  419. }.bind(this));
  420. },
  421. setOtherActionEvent: function(){
  422. this.registerActionNode.addEvents({
  423. "mouseover": function(){this.registerActionNode.setStyles(this.css.loginRegisterActionNode_over);}.bind(this),
  424. "mouseout": function(){this.registerActionNode.setStyles(this.css.loginRegisterActionNode);}.bind(this),
  425. "click": this.showRegisterForm.bind(this)
  426. });
  427. this.forgetActionNode.addEvents({
  428. "mouseover": function(){this.forgetActionNode.setStyles(this.css.loginForgetActionNode_over);}.bind(this),
  429. "mouseout": function(){this.forgetActionNode.setStyles(this.css.loginForgetActionNode);}.bind(this),
  430. "click": this.showModifyForm.bind(this)
  431. });
  432. },
  433. showModifyForm: function(){
  434. /*if (!this.collect.modifyForm){
  435. this.collect.modifyForm = new MWF.xApplication.Collect.ModifyForm(this.collect);
  436. }
  437. this.collect.modifyForm.show();*/
  438. if (!this.collect.modifyPwdForm){
  439. this.collect.modifyPwdForm = new MWF.xApplication.Collect.ModifyPwdForm(this.collect);
  440. }
  441. this.collect.modifyPwdForm.show();
  442. },
  443. showRegisterForm: function(){
  444. if (!this.collect.registerForm){
  445. this.collect.registerForm = new MWF.xApplication.Collect.RegisterForm(this.collect);
  446. }
  447. this.collect.registerForm.show();
  448. }
  449. });
  450. MWF.xApplication.Collect.RegisterForm = new Class({
  451. initialize: function(collect){
  452. this.collect = collect;
  453. this.lp = this.collect.lp;
  454. this.css = this.collect.css;
  455. this.contentNode = this.collect.registerContentNode;
  456. this.action = this.collect.action;
  457. this.load();
  458. },
  459. createNode: function(iconCss, text, type){
  460. var node = new Element("div", {"styles": this.css.registerAreaNode}).inject(this.contentNode);
  461. var icon = new Element("div", {"styles": this.css[iconCss]}).inject(node);
  462. var inputCheckArea = new Element("div", {"styles": this.css.registerCheckIconNode}).inject(node);
  463. var inputArea = new Element("div", {"styles": this.css.registerInputAreaNode}).inject(node);
  464. var inputNode = new Element("input", {"styles": this.css.registerInputNode, "type": type || "text", "value": this.lp[text]}).inject(inputArea);
  465. var errorNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(this.contentNode);
  466. return node;
  467. },
  468. load: function(){
  469. this.contentNode.setStyle("padding-top", "30px");
  470. this.usernameNode = this.createNode("registerUsernameIconNode", "username");
  471. this.usernameInput = this.usernameNode.getElement("input");
  472. this.mobileNode = this.createNode("registerMobileIconNode", "mobile");
  473. this.mobileInput = this.mobileNode.getElement("input");
  474. this.codeNode = this.createNode("registerCodeIconNode", "code");
  475. this.codeInput = this.codeNode.getElement("input");
  476. this.passwordNode = this.createNode("registerPasswordIconNode", "password", "password");
  477. this.passwordInput = this.passwordNode.getElement("input");
  478. this.setInputEvent();
  479. this.registerActionNode = new Element("div", {"styles": this.css.registerActionNode, "text": this.lp.register}).inject(this.contentNode);
  480. this.registerActionNode.addEvent("click", this.register.bind(this));
  481. //this.otherActionNode = new Element("div", {"styles": this.css.loginOtherActionNode}).inject(this.contentNode);
  482. //this.registerActionNode = new Element("div", {"styles": this.css.loginRegisterActionNode, "text": this.lp.register}).inject(this.otherActionNode);
  483. //this.forgetActionNode = new Element("div", {"styles": this.css.loginForgetActionNode, "text": this.lp.forget}).inject(this.otherActionNode);
  484. //this.setOtherActionEvent();
  485. this.errorNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(this.contentNode);
  486. },
  487. errorInput: function(node, text){
  488. if (text){
  489. node.setStyles(this.css.registerAreaNode_error);
  490. this.checkRegister = false;
  491. }else{
  492. node.setStyles(this.css.registerAreaNode_normal);
  493. }
  494. node.getNext().set("text", text);
  495. },
  496. setInputNodeEvent: function(node, input, text, errorText, name){
  497. input.addEvents({
  498. "focus": function(){
  499. this.errorInput(node, "");
  500. node.setStyles(this.css.registerAreaNode_over);
  501. if (input.get("value")==text) input.set("value", "");
  502. }.bind(this),
  503. "blur": function(){
  504. node.setStyles(this.css.registerAreaNode_normal);
  505. if (!input.get("value")) input.set("value", text);
  506. this[name+"Verification"]();
  507. //if (!input.get("value")){
  508. // input.set("value", text);
  509. // this.errorInput(node, errorText);
  510. //}
  511. }.bind(this),
  512. "selectstart": function(e){e.stopPropagation();}
  513. });
  514. },
  515. resetCodeNode: function(){
  516. this.codeAreaNode = new Element("div", {"styles": this.css.registerCodeAreaNode}).inject(this.codeNode, "before");
  517. this.codeNode.getNext().inject(this.codeAreaNode);
  518. this.codeNode.inject(this.codeAreaNode, "top");
  519. this.codeNode.setStyles({
  520. "width": "auto",
  521. "margin": "0px 160px 0px 0px"
  522. });
  523. this.getCodeAtionNode = new Element("div", {"styles": this.css.registerGetCodeAtionNode, "text": this.lp.getCodeAtion}).inject(this.codeAreaNode, "top");
  524. this.getCodeAtionNode.addEvent("click", this.getCode.bind(this));
  525. },
  526. getCodeNext: function(){
  527. this.getCodeAtionNode.setStyles(this.css.registerGetCodeAtionNode_next);
  528. this.getCodeAtionNode.set("text", this.lp.getCodeNext+"(60)");
  529. this.getCodeAtionNode.removeEvents("click");
  530. this.codeNextTimerCount = 60;
  531. },
  532. getCodeNextTimer: function(){
  533. this.codeNextTimerCount--;
  534. if (this.codeNextTimerCount>0){
  535. this.getCodeAtionNode.set("text", this.lp.getCodeNext+"("+this.codeNextTimerCount+")");
  536. this.codeNextTimer = window.setTimeout(function(){
  537. this.getCodeNextTimer();
  538. }.bind(this), 1000);
  539. }else{
  540. this.regetCode();
  541. }
  542. },
  543. regetCode: function(){
  544. this.getCodeAtionNode.setStyles(this.css.registerGetCodeAtionNode);
  545. this.getCodeAtionNode.set("text", this.lp.getCodeAtion);
  546. this.getCodeAtionNode.addEvent("click", this.getCode.bind(this));
  547. this.codeNextTimer = null;
  548. },
  549. getCode: function(){
  550. if (this.mobileVerification()){
  551. this.getCodeNext();
  552. this.action.getCode(this.mobileInput.get("value"), function(json){
  553. this.codeNextTimer = window.setTimeout(function(){
  554. this.getCodeNextTimer();
  555. }.bind(this), 1000);
  556. }.bind(this), function(xhr, text, error){
  557. if (xhr){
  558. var json = JSON.decode(xhr.responseText);
  559. this.errorNode.set("text", json.message);
  560. }else{
  561. var errorText = error+":"+text;
  562. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  563. }
  564. this.regetCode();
  565. }.bind(this));
  566. }
  567. },
  568. setInputEvent: function(){
  569. this.setInputNodeEvent(this.usernameNode, this.usernameInput, this.lp.username, this.lp.errorUsername, "username");
  570. this.setInputNodeEvent(this.passwordNode, this.passwordInput, this.lp.password, this.lp.errorPassword, "password");
  571. this.setInputNodeEvent(this.mobileNode, this.mobileInput, this.lp.mobile, this.lp.errorMobile, "mobile");
  572. this.setInputNodeEvent(this.codeNode, this.codeInput, this.lp.code, this.lp.errorCode, "code");
  573. this.resetCodeNode();
  574. },
  575. show: function(){
  576. this.collect.showContent("registerContentNode");
  577. this.collect.backNode.setStyle("display", "block");
  578. this.collect.backNode.removeEvents("click");
  579. this.collect.backNode.addEvent("click", function(){
  580. this.collect.showContent("checkContentNode");
  581. this.collect.backNode.setStyle("display", "none");
  582. }.bind(this));
  583. },
  584. registering: function(){
  585. this.registerActionNode.removeEvents("click");
  586. this.registerActionNode.set("text", this.lp.registering);
  587. },
  588. registered: function(){
  589. this.registerActionNode.addEvent("click", this.register.bind(this));
  590. this.registerActionNode.set("text", this.lp.register);
  591. },
  592. register: function(){
  593. var user = this.usernameInput.get("value");
  594. var mobile = this.mobileInput.get("value");
  595. var code = this.codeInput.get("value");
  596. var password = this.passwordInput.get("value");
  597. if (this.usernameVerification() & this.mobileVerification() & this.codeVerification() & this.passwordVerification()){
  598. this.registering();
  599. var data = {
  600. codeAnswer: code,
  601. mobile: mobile,
  602. name: user,
  603. password: password
  604. };
  605. this.action.createCollect(data, function(){
  606. this.action.updateCollect({"name": user, "password": password, "enable": true}, function(json){
  607. this.registered();
  608. this.collect.showContent("checkContentNode");
  609. this.collect.backNode.setStyle("display", "none");
  610. window.setTimeout(function(){
  611. this.check.recheck();
  612. }.bind(this), 1000);
  613. }.bind(this), function(xhr, text, error){
  614. var errorText = error+":"+text;
  615. if (xhr) errorText = xhr.responseText;
  616. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  617. this.registered();
  618. }.bind(this));
  619. }.bind(this), function(xhr, text, error){
  620. if (xhr){
  621. var json = JSON.decode(xhr.responseText);
  622. this.errorNode.set("text", json.message);
  623. }else{
  624. var errorText = error+":"+text;
  625. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  626. }
  627. this.registered();
  628. }.bind(this));
  629. }
  630. },
  631. passwordVerification: function(){
  632. var password = this.passwordInput.get("value");
  633. if (!password || password==this.lp.password){
  634. this.errorInput(this.passwordNode, this.lp.errorPassword);
  635. return false;
  636. }
  637. var flag = "";
  638. this.action.passwordValidate({"password": password}, function(json){
  639. //if (json.data.value<4){
  640. // flag = this.lp.errorPasswordRule;
  641. //}
  642. flag = json.data.value || "";
  643. }.bind(this), function(xhr, text, error){
  644. }.bind(this), false);
  645. if (flag){
  646. this.errorInput(this.passwordNode, flag);
  647. return false;
  648. }
  649. return true;
  650. },
  651. codeVerification: function(){
  652. var code = this.codeInput.get("value");
  653. if (!code || code==this.lp.mobile){
  654. this.errorInput(this.codeNode, this.lp.errorCode);
  655. return false;
  656. }
  657. return true;
  658. },
  659. usernameVerification: function(){
  660. var user = this.usernameInput.get("value");
  661. if (!user || user==this.lp.username){
  662. this.errorInput(this.usernameNode, this.lp.errorUsername);
  663. return false;
  664. }
  665. var flag = "";
  666. this.action.nameExist(user, function(json){
  667. if (json.data.value){
  668. flag = this.lp.usernameExisted;
  669. }
  670. }.bind(this), function(xhr, text, error){
  671. if (xhr){
  672. var json = JSON.decode(xhr.responseText);
  673. flag = json.message;
  674. //this.errorNode.set("text", json.message);
  675. }else{
  676. var errorText = error+":"+text;
  677. flag = this.lp.requestError+errorText;
  678. //MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  679. }
  680. }.bind(this), false);
  681. if (flag){
  682. this.errorInput(this.usernameNode, flag);
  683. return false;
  684. }
  685. return true;
  686. },
  687. mobileVerification: function(){
  688. var mobile = this.mobileInput.get("value");
  689. if (!mobile || mobile==this.lp.mobile){
  690. this.errorInput(this.mobileNode, this.lp.errorMobile);
  691. return false;
  692. }
  693. if (mobile.length!=11){
  694. this.errorInput(this.mobileNode, this.lp.errorMobile);
  695. return false;
  696. }
  697. return true;
  698. }
  699. });
  700. MWF.xApplication.Collect.ModifyForm = new Class({
  701. Extends: MWF.xApplication.Collect.RegisterForm,
  702. initialize: function(collect){
  703. this.collect = collect;
  704. this.lp = this.collect.lp;
  705. this.css = this.collect.css;
  706. this.contentNode = this.collect.modifyContentNode;
  707. this.action = this.collect.action;
  708. this.load();
  709. },
  710. load: function(){
  711. this.contentNode.setStyle("padding-top", "30px");
  712. this.usernameNode = this.createNode("registerUsernameIconNode", "username");
  713. this.usernameInput = this.usernameNode.getElement("input");
  714. this.mobileNode = this.createNode("registerMobileIconNode", "mobile");
  715. this.mobileInput = this.mobileNode.getElement("input");
  716. this.codeNode = this.createNode("registerCodeIconNode", "code");
  717. this.codeInput = this.codeNode.getElement("input");
  718. this.newNameNode = this.createNode("registerNewNameIconNode");
  719. this.newNameInput = this.newNameNode.getElement("input");
  720. this.secretNode = this.createNode("registerSecretIconNode", "secret");
  721. this.secretInput = this.secretNode.getElement("input");
  722. this.keyNode = this.createNode("registerKeyIconNode", "key");
  723. this.keyInput = this.keyNode.getElement("input");
  724. this.setInputEvent();
  725. this.nextActionNode = new Element("div", {"styles": this.css.registerActionNode, "text": this.lp.modifyNextStep}).inject(this.contentNode);
  726. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  727. this.errorNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(this.contentNode);
  728. this.newNameNode.setStyle("display", "none");
  729. this.newNameNode.getNext().setStyle("display", "none");
  730. this.secretNode.setStyle("display", "none");
  731. this.secretNode.getNext().setStyle("display", "none");
  732. this.keyNode.setStyle("display", "none");
  733. this.keyNode.getNext().setStyle("display", "none");
  734. this.setDefaultValue();
  735. },
  736. setDefaultValue: function(){
  737. this.action.getCollectConfig(function(json){
  738. if (json.data.name) this.usernameInput.set("value", json.data.name);
  739. if (json.data.name) this.newNameInput.set("value", json.data.name);
  740. if (json.data.key) this.keyInput.set("value", json.data.key);
  741. if (json.data.secret) this.secretInput.set("value", json.data.secret);
  742. }.bind(this));
  743. },
  744. nextStepWait: function(){
  745. this.nextActionNode.removeEvents("click");
  746. this.nextActionNode.set("text", this.lp.nextStepWait);
  747. this.errorNode.empty();
  748. },
  749. setInputEvent: function(){
  750. this.setInputNodeEvent(this.usernameNode, this.usernameInput, this.lp.username, this.lp.errorUsername, "username");
  751. this.setInputNodeEvent(this.newNameNode, this.newNameInput, this.lp.username, this.lp.errorUsername, "newName");
  752. this.setInputNodeEvent(this.secretNode, this.secretInput, this.lp.secret, this.lp.errorSecret, "secret");
  753. this.setInputNodeEvent(this.keyNode, this.keyInput, this.lp.key, this.lp.errorKey, "key");
  754. this.setInputNodeEvent(this.mobileNode, this.mobileInput, this.lp.mobile, this.lp.errorMobile, "mobile");
  755. this.setInputNodeEvent(this.codeNode, this.codeInput, this.lp.code, this.lp.errorCode, "code");
  756. this.resetCodeNode();
  757. },
  758. nextStepWaited: function(){
  759. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  760. this.nextActionNode.set("text", this.lp.modifyNextStep);
  761. },
  762. firstStep: function(){
  763. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  764. this.nextActionNode.set("text", this.lp.modifyNextStep);
  765. this.newNameNode.setStyle("display", "none");
  766. this.newNameNode.getNext().setStyle("display", "none");
  767. this.secretNode.setStyle("display", "none");
  768. this.secretNode.getNext().setStyle("display", "none");
  769. this.keyNode.setStyle("display", "none");
  770. this.keyNode.getNext().setStyle("display", "none");
  771. this.usernameNode.setStyle("display", "block");
  772. this.usernameNode.getNext().setStyle("display", "block");
  773. this.mobileNode.setStyle("display", "block");
  774. this.mobileNode.getNext().setStyle("display", "block");
  775. this.codeNode.getParent().setStyle("display", "block");
  776. this.codeNode.getNext().setStyle("display", "block");
  777. this.errorNode.empty();
  778. },
  779. nextStep: function(){
  780. var user = this.usernameInput.get("value");
  781. var mobile = this.mobileInput.get("value");
  782. var code = this.codeInput.get("value");
  783. if (this.usernameVerification() & this.mobileVerification() & this.codeVerification()){
  784. this.nextStepWait();
  785. this.action.codeValidate({"codeAnswer": code, "mobile": mobile}, function(json){
  786. if (json.data.value){
  787. this.nextActionNode.removeEvents("click");
  788. this.nextActionNode.set("text", this.lp.modifyUnit);
  789. this.nextActionNode.addEvent("click", this.modifyUnit.bind(this));
  790. this.newNameNode.setStyle("display", "block");
  791. this.newNameNode.getNext().setStyle("display", "block");
  792. this.secretNode.setStyle("display", "block");
  793. this.secretNode.getNext().setStyle("display", "block");
  794. this.keyNode.setStyle("display", "block");
  795. this.keyNode.getNext().setStyle("display", "block");
  796. this.usernameNode.setStyle("display", "none");
  797. this.usernameNode.getNext().setStyle("display", "none");
  798. this.mobileNode.setStyle("display", "none");
  799. this.mobileNode.getNext().setStyle("display", "none");
  800. this.codeNode.getParent().setStyle("display", "none");
  801. this.codeNode.getNext().setStyle("display", "none");
  802. this.errorNode.empty();
  803. }else{
  804. this.errorInput(this.codeNode, this.lp.errorCode);
  805. }
  806. }.bind(this), function(xhr, text, error){
  807. if (xhr){
  808. var json = JSON.decode(xhr.responseText);
  809. this.errorInput(this.codeNode, json.message);
  810. }else{
  811. var errorText = error+":"+text;
  812. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  813. }
  814. this.nextStepWaited();
  815. }.bind(this));
  816. }
  817. },
  818. modifyUnit: function(){
  819. var user = this.usernameInput.get("value");
  820. var newName = this.newNameInput.get("value");
  821. var code = this.codeInput.get("value");
  822. var secret = this.secretInput.get("value");
  823. var key = this.keyInput.get("value");
  824. var mobile = this.mobileInput.get("value");
  825. if (this.newNameVerification()){
  826. this.nextStepWait();
  827. var data = {
  828. mobile: mobile,
  829. codeAnswer: code,
  830. newName: newName,
  831. secret: secret,
  832. key: key,
  833. name: user
  834. };
  835. this.action.updateUnitCollect(data, function(json){
  836. this.firstStep();
  837. this.collect.showContent("checkContentNode");
  838. this.collect.backNode.setStyle("display", "none");
  839. this.check.recheck();
  840. }.bind(this), function(xhr, text, error){
  841. var errorText = error+":"+text;
  842. if (xhr) errorText = xhr.responseText;
  843. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  844. this.firstStep();
  845. }.bind(this));
  846. }
  847. },
  848. usernameVerification: function(){
  849. var user = this.usernameInput.get("value");
  850. if (!user || user==this.lp.username){
  851. this.errorInput(this.usernameNode, this.lp.errorUsername);
  852. return false;
  853. }
  854. return true;
  855. },
  856. newNameVerification: function(){
  857. var user = this.usernameInput.get("value");
  858. if (!user || user==this.lp.username){
  859. this.errorInput(this.usernameNode, this.lp.errorUsername);
  860. return false;
  861. }
  862. return true;
  863. },
  864. keyVerification: function(){
  865. var user = this.usernameInput.get("value");
  866. if (!user || user==this.lp.username){
  867. this.errorInput(this.usernameNode, this.lp.errorUsername);
  868. return false;
  869. }
  870. return true;
  871. },
  872. secretVerification: function(){
  873. var user = this.usernameInput.get("value");
  874. if (!user || user==this.lp.username){
  875. this.errorInput(this.usernameNode, this.lp.errorUsername);
  876. return false;
  877. }
  878. return true;
  879. },
  880. show: function(){
  881. this.collect.showContent("modifyContentNode");
  882. this.collect.backNode.setStyle("display", "block");
  883. this.collect.backNode.removeEvents("click");
  884. this.collect.backNode.addEvent("click", function(){
  885. this.firstStep();
  886. this.collect.showContent("checkContentNode");
  887. this.collect.backNode.setStyle("display", "none");
  888. }.bind(this));
  889. }
  890. });
  891. MWF.xApplication.Collect.ModifyPwdForm = new Class({
  892. Extends: MWF.xApplication.Collect.RegisterForm,
  893. initialize: function(collect){
  894. this.collect = collect;
  895. this.lp = this.collect.lp;
  896. this.css = this.collect.css;
  897. this.contentNode = this.collect.modifyPwdContentNode;
  898. this.action = this.collect.action;
  899. this.load();
  900. },
  901. load: function(){
  902. this.contentNode.setStyle("padding-top", "30px");
  903. this.usernameNode = this.createNode("registerUsernameIconNode", "username");
  904. this.usernameInput = this.usernameNode.getElement("input");
  905. this.mobileNode = this.createNode("registerMobileIconNode", "mobile");
  906. this.mobileInput = this.mobileNode.getElement("input");
  907. this.codeNode = this.createNode("registerCodeIconNode", "code");
  908. this.codeInput = this.codeNode.getElement("input");
  909. this.passwordNode = this.createNode("registerPasswordIconNode", "password", "password");
  910. this.passwordInput = this.passwordNode.getElement("input");
  911. this.setInputEvent();
  912. this.nextActionNode = new Element("div", {"styles": this.css.registerActionNode, "text": this.lp.modifyNextStep}).inject(this.contentNode);
  913. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  914. //this.otherActionNode = new Element("div", {"styles": this.css.loginOtherActionNode}).inject(this.contentNode);
  915. //this.registerActionNode = new Element("div", {"styles": this.css.loginRegisterActionNode, "text": this.lp.register}).inject(this.otherActionNode);
  916. //this.forgetActionNode = new Element("div", {"styles": this.css.loginForgetActionNode, "text": this.lp.forget}).inject(this.otherActionNode);
  917. //this.setOtherActionEvent();
  918. this.errorNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(this.contentNode);
  919. this.passwordNode.setStyle("display", "none");
  920. this.passwordNode.getNext().setStyle("display", "none");
  921. this.setDefaultValue();
  922. },
  923. setDefaultValue: function(){
  924. this.action.getCollectConfig(function(json){
  925. if (json.data.name) this.usernameInput.set("value", json.data.name);
  926. }.bind(this));
  927. },
  928. nextStepWait: function(){
  929. this.nextActionNode.removeEvents("click");
  930. this.nextActionNode.set("text", this.lp.nextStepWait);
  931. this.errorNode.empty();
  932. },
  933. nextStepWaited: function(){
  934. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  935. this.nextActionNode.set("text", this.lp.modifyNextStep);
  936. },
  937. firstStep: function(){
  938. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  939. this.nextActionNode.set("text", this.lp.modifyNextStep);
  940. this.passwordNode.setStyle("display", "none");
  941. this.passwordNode.getNext().setStyle("display", "none");
  942. this.usernameNode.setStyle("display", "block");
  943. this.usernameNode.getNext().setStyle("display", "block");
  944. this.mobileNode.setStyle("display", "block");
  945. this.mobileNode.getNext().setStyle("display", "block");
  946. this.codeNode.getParent().setStyle("display", "block");
  947. this.codeNode.getNext().setStyle("display", "block");
  948. this.errorNode.empty();
  949. },
  950. nextStep: function(){
  951. var user = this.usernameInput.get("value");
  952. var mobile = this.mobileInput.get("value");
  953. var code = this.codeInput.get("value");
  954. if (this.usernameVerification() & this.mobileVerification() & this.codeVerification()){
  955. this.nextStepWait();
  956. this.action.codeValidate({"codeAnswer": code, "mobile": mobile}, function(json){
  957. if (json.data.value){
  958. this.nextActionNode.removeEvents("click");
  959. this.nextActionNode.set("text", this.lp.modifyPassword);
  960. this.nextActionNode.addEvent("click", this.modifyPassword.bind(this));
  961. this.passwordNode.setStyle("display", "block");
  962. this.passwordNode.getNext().setStyle("display", "block");
  963. this.usernameNode.setStyle("display", "none");
  964. this.usernameNode.getNext().setStyle("display", "none");
  965. this.mobileNode.setStyle("display", "none");
  966. this.mobileNode.getNext().setStyle("display", "none");
  967. this.codeNode.getParent().setStyle("display", "none");
  968. this.codeNode.getNext().setStyle("display", "none");
  969. this.errorNode.empty();
  970. }else{
  971. this.errorInput(this.codeNode, this.lp.errorCode);
  972. }
  973. }.bind(this), function(xhr, text, error){
  974. if (xhr){
  975. var json = JSON.decode(xhr.responseText);
  976. this.errorInput(this.codeNode, json.message);
  977. }else{
  978. var errorText = error+":"+text;
  979. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  980. }
  981. this.nextStepWaited();
  982. }.bind(this));
  983. }
  984. },
  985. modifyPassword: function(){
  986. var user = this.usernameInput.get("value");
  987. var mobile = this.mobileInput.get("value");
  988. var code = this.codeInput.get("value");
  989. var password = this.passwordInput.get("value");
  990. if (this.usernameVerification() & this.mobileVerification() & this.codeVerification() & this.passwordVerification()){
  991. this.nextStepWait();
  992. var data = {
  993. codeAnswer: code,
  994. mobile: mobile,
  995. name: user,
  996. password: password
  997. };
  998. debugger;
  999. this.action.resetPassword(data, function(){
  1000. this.action.updateCollect({"name": user, "password": password, "enable": true}, function(json){
  1001. this.firstStep();
  1002. this.collect.showContent("checkContentNode");
  1003. this.collect.backNode.setStyle("display", "none");
  1004. this.check.recheck();
  1005. }.bind(this), function(xhr, text, error){
  1006. var errorText = error+":"+text;
  1007. if (xhr) errorText = xhr.responseText;
  1008. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1009. this.firstStep();
  1010. }.bind(this));
  1011. }.bind(this), function(xhr, text, error){
  1012. if (xhr){
  1013. var json = JSON.decode(xhr.responseText);
  1014. this.errorNode.set("text", json.message);
  1015. }else{
  1016. var errorText = error+":"+text;
  1017. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1018. }
  1019. this.firstStep();
  1020. }.bind(this));
  1021. }
  1022. },
  1023. usernameVerification: function(){
  1024. var user = this.usernameInput.get("value");
  1025. if (!user || user==this.lp.username){
  1026. this.errorInput(this.usernameNode, this.lp.errorUsername);
  1027. return false;
  1028. }
  1029. return true;
  1030. },
  1031. show: function(){
  1032. this.collect.showContent("modifyPwdContentNode");
  1033. this.collect.backNode.setStyle("display", "block");
  1034. this.collect.backNode.removeEvents("click");
  1035. this.collect.backNode.addEvent("click", function(){
  1036. this.firstStep();
  1037. this.collect.showContent("checkContentNode");
  1038. this.collect.backNode.setStyle("display", "none");
  1039. }.bind(this));
  1040. }
  1041. });
  1042. MWF.xApplication.Collect.DeleteForm = new Class({
  1043. Extends: MWF.xApplication.Collect.RegisterForm,
  1044. initialize: function(collect){
  1045. this.collect = collect;
  1046. this.lp = this.collect.lp;
  1047. this.css = this.collect.css;
  1048. this.contentNode = this.collect.deleteContentNode;
  1049. this.action = this.collect.action;
  1050. this.load();
  1051. },
  1052. load: function(){
  1053. this.contentNode.setStyle("padding-top", "30px");
  1054. this.usernameNode = this.createNode("registerUsernameIconNode", "username");
  1055. this.usernameInput = this.usernameNode.getElement("input");
  1056. this.mobileNode = this.createNode("registerMobileIconNode", "mobile");
  1057. this.mobileInput = this.mobileNode.getElement("input");
  1058. this.codeNode = this.createNode("registerCodeIconNode", "code");
  1059. this.codeInput = this.codeNode.getElement("input");
  1060. this.passwordNode = this.createNode("registerPasswordIconNode", "password", "password");
  1061. this.passwordInput = this.passwordNode.getElement("input");
  1062. this.setInputEvent();
  1063. this.nextActionNode = new Element("div", {"styles": this.css.registerActionNode, "text": this.lp.confirmDelete}).inject(this.contentNode);
  1064. this.nextActionNode.addEvent("click", this.deleteCollect.bind(this));
  1065. this.errorNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(this.contentNode);
  1066. this.passwordNode.setStyle("display", "none");
  1067. this.passwordNode.getNext().setStyle("display", "none");
  1068. this.setDefaultValue();
  1069. },
  1070. setDefaultValue: function(){
  1071. this.action.getCollectConfig(function(json){
  1072. if (json.data.name) this.usernameInput.set("value", json.data.name);
  1073. }.bind(this));
  1074. },
  1075. deleteCollect:function(){
  1076. var user = this.usernameInput.get("value");
  1077. var mobile = this.mobileInput.get("value");
  1078. var code = this.codeInput.get("value");
  1079. if (this.usernameVerification() & this.mobileVerification() & this.codeVerification() ){
  1080. this.action.deleteCollect(user,mobile,code, function(json){
  1081. this.collect.showContent("checkContentNode");
  1082. this.collect.backNode.setStyle("display", "none");
  1083. }.bind(this), function(xhr, text, error){
  1084. var errorText = error+":"+text;
  1085. if (xhr) errorText = xhr.responseText;
  1086. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1087. this.firstStep();
  1088. }.bind(this));
  1089. }
  1090. },
  1091. usernameVerification: function(){
  1092. var user = this.usernameInput.get("value");
  1093. if (!user || user==this.lp.username){
  1094. this.errorInput(this.usernameNode, this.lp.errorUsername);
  1095. return false;
  1096. }
  1097. return true;
  1098. },
  1099. firstStep: function(){
  1100. this.passwordNode.setStyle("display", "none");
  1101. this.passwordNode.getNext().setStyle("display", "none");
  1102. this.usernameNode.setStyle("display", "block");
  1103. this.usernameNode.getNext().setStyle("display", "block");
  1104. this.mobileNode.setStyle("display", "block");
  1105. this.mobileNode.getNext().setStyle("display", "block");
  1106. this.codeNode.getParent().setStyle("display", "block");
  1107. this.codeNode.getNext().setStyle("display", "block");
  1108. this.errorNode.empty();
  1109. },
  1110. show: function(){
  1111. this.collect.showContent("deleteContentNode");
  1112. this.collect.backNode.setStyle("display", "block");
  1113. this.collect.backNode.removeEvents("click");
  1114. this.collect.backNode.addEvent("click", function(){
  1115. this.firstStep();
  1116. this.collect.showContent("checkContentNode");
  1117. this.collect.backNode.setStyle("display", "none");
  1118. }.bind(this));
  1119. }
  1120. });