Main.js 54 KB

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