Main.js 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  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. if (!this.collect.modifyPwdForm){
  432. this.collect.modifyPwdForm = new MWF.xApplication.Collect.ModifyPwdForm(this.collect);
  433. }
  434. this.collect.modifyPwdForm.show();
  435. },
  436. showRegisterForm: function(){
  437. if (!this.collect.registerForm){
  438. this.collect.registerForm = new MWF.xApplication.Collect.RegisterForm(this.collect);
  439. }
  440. this.collect.registerForm.show();
  441. }
  442. });
  443. MWF.xApplication.Collect.RegisterForm = new Class({
  444. initialize: function(collect){
  445. this.collect = collect;
  446. this.lp = this.collect.lp;
  447. this.css = this.collect.css;
  448. this.contentNode = this.collect.registerContentNode;
  449. this.action = this.collect.action;
  450. this.load();
  451. },
  452. createNode: function(iconCss, text, type){
  453. var node = new Element("div", {"styles": this.css.registerAreaNode}).inject(this.contentNode);
  454. var icon = new Element("div", {"styles": this.css[iconCss]}).inject(node);
  455. var inputCheckArea = new Element("div", {"styles": this.css.registerCheckIconNode}).inject(node);
  456. var inputArea = new Element("div", {"styles": this.css.registerInputAreaNode}).inject(node);
  457. var inputNode = new Element("input", {"styles": this.css.registerInputNode, "type": type || "text", "value": this.lp[text]}).inject(inputArea);
  458. var errorNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(this.contentNode);
  459. return node;
  460. },
  461. load: function(){
  462. this.contentNode.setStyle("padding-top", "30px");
  463. this.usernameNode = this.createNode("registerUsernameIconNode", "username");
  464. this.usernameInput = this.usernameNode.getElement("input");
  465. this.mobileNode = this.createNode("registerMobileIconNode", "mobile");
  466. this.mobileInput = this.mobileNode.getElement("input");
  467. this.codeNode = this.createNode("registerCodeIconNode", "code");
  468. this.codeInput = this.codeNode.getElement("input");
  469. this.passwordNode = this.createNode("registerPasswordIconNode", "password", "password");
  470. this.passwordInput = this.passwordNode.getElement("input");
  471. this.setInputEvent();
  472. this.registerActionNode = new Element("div", {"styles": this.css.registerActionNode, "text": this.lp.register}).inject(this.contentNode);
  473. this.registerActionNode.addEvent("click", this.register.bind(this));
  474. //this.otherActionNode = new Element("div", {"styles": this.css.loginOtherActionNode}).inject(this.contentNode);
  475. //this.registerActionNode = new Element("div", {"styles": this.css.loginRegisterActionNode, "text": this.lp.register}).inject(this.otherActionNode);
  476. //this.forgetActionNode = new Element("div", {"styles": this.css.loginForgetActionNode, "text": this.lp.forget}).inject(this.otherActionNode);
  477. //this.setOtherActionEvent();
  478. this.errorNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(this.contentNode);
  479. },
  480. errorInput: function(node, text){
  481. if (text){
  482. node.setStyles(this.css.registerAreaNode_error);
  483. this.checkRegister = false;
  484. }else{
  485. node.setStyles(this.css.registerAreaNode_normal);
  486. }
  487. node.getNext().set("text", text);
  488. },
  489. setInputNodeEvent: function(node, input, text, errorText, name){
  490. input.addEvents({
  491. "focus": function(){
  492. this.errorInput(node, "");
  493. node.setStyles(this.css.registerAreaNode_over);
  494. if (input.get("value")==text) input.set("value", "");
  495. }.bind(this),
  496. "blur": function(){
  497. node.setStyles(this.css.registerAreaNode_normal);
  498. if (!input.get("value")) input.set("value", text);
  499. this[name+"Verification"]();
  500. //if (!input.get("value")){
  501. // input.set("value", text);
  502. // this.errorInput(node, errorText);
  503. //}
  504. }.bind(this),
  505. "selectstart": function(e){e.stopPropagation();}
  506. });
  507. },
  508. resetCodeNode: function(){
  509. this.codeAreaNode = new Element("div", {"styles": this.css.registerCodeAreaNode}).inject(this.codeNode, "before");
  510. this.codeNode.getNext().inject(this.codeAreaNode);
  511. this.codeNode.inject(this.codeAreaNode, "top");
  512. this.codeNode.setStyles({
  513. "width": "auto",
  514. "margin": "0px 160px 0px 0px"
  515. });
  516. this.getCodeAtionNode = new Element("div", {"styles": this.css.registerGetCodeAtionNode, "text": this.lp.getCodeAtion}).inject(this.codeAreaNode, "top");
  517. this.getCodeAtionNode.addEvent("click", this.getCode.bind(this));
  518. },
  519. getCodeNext: function(){
  520. this.getCodeAtionNode.setStyles(this.css.registerGetCodeAtionNode_next);
  521. this.getCodeAtionNode.set("text", this.lp.getCodeNext+"(60)");
  522. this.getCodeAtionNode.removeEvents("click");
  523. this.codeNextTimerCount = 60;
  524. },
  525. getCodeNextTimer: function(){
  526. this.codeNextTimerCount--;
  527. if (this.codeNextTimerCount>0){
  528. this.getCodeAtionNode.set("text", this.lp.getCodeNext+"("+this.codeNextTimerCount+")");
  529. this.codeNextTimer = window.setTimeout(function(){
  530. this.getCodeNextTimer();
  531. }.bind(this), 1000);
  532. }else{
  533. this.regetCode();
  534. }
  535. },
  536. regetCode: function(){
  537. this.getCodeAtionNode.setStyles(this.css.registerGetCodeAtionNode);
  538. this.getCodeAtionNode.set("text", this.lp.getCodeAtion);
  539. this.getCodeAtionNode.addEvent("click", this.getCode.bind(this));
  540. this.codeNextTimer = null;
  541. },
  542. getCode: function(){
  543. if (this.mobileVerification()){
  544. this.getCodeNext();
  545. this.action.getCode(this.mobileInput.get("value"), function(json){
  546. this.codeNextTimer = window.setTimeout(function(){
  547. this.getCodeNextTimer();
  548. }.bind(this), 1000);
  549. }.bind(this), function(xhr, text, error){
  550. if (xhr){
  551. var json = JSON.decode(xhr.responseText);
  552. this.errorNode.set("text", json.message);
  553. }else{
  554. var errorText = error+":"+text;
  555. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  556. }
  557. this.regetCode();
  558. }.bind(this));
  559. }
  560. },
  561. setInputEvent: function(){
  562. this.setInputNodeEvent(this.usernameNode, this.usernameInput, this.lp.username, this.lp.errorUsername, "username");
  563. this.setInputNodeEvent(this.passwordNode, this.passwordInput, this.lp.password, this.lp.errorPassword, "password");
  564. this.setInputNodeEvent(this.mobileNode, this.mobileInput, this.lp.mobile, this.lp.errorMobile, "mobile");
  565. this.setInputNodeEvent(this.codeNode, this.codeInput, this.lp.code, this.lp.errorCode, "code");
  566. this.resetCodeNode();
  567. },
  568. show: function(){
  569. this.collect.showContent("registerContentNode");
  570. this.collect.backNode.setStyle("display", "block");
  571. this.collect.backNode.removeEvents("click");
  572. this.collect.backNode.addEvent("click", function(){
  573. this.collect.showContent("checkContentNode");
  574. this.collect.backNode.setStyle("display", "none");
  575. }.bind(this));
  576. },
  577. registering: function(){
  578. this.registerActionNode.removeEvents("click");
  579. this.registerActionNode.set("text", this.lp.registering);
  580. },
  581. registered: function(){
  582. this.registerActionNode.addEvent("click", this.register.bind(this));
  583. this.registerActionNode.set("text", this.lp.register);
  584. },
  585. register: function(){
  586. var user = this.usernameInput.get("value");
  587. var mobile = this.mobileInput.get("value");
  588. var code = this.codeInput.get("value");
  589. var password = this.passwordInput.get("value");
  590. if (this.usernameVerification() & this.mobileVerification() & this.codeVerification() & this.passwordVerification()){
  591. this.registering();
  592. var data = {
  593. codeAnswer: code,
  594. mobile: mobile,
  595. name: user,
  596. password: password
  597. };
  598. this.action.createCollect(data, function(){
  599. this.action.updateCollect({"name": user, "password": password, "enable": true}, function(json){
  600. this.registered();
  601. this.collect.showContent("checkContentNode");
  602. this.collect.backNode.setStyle("display", "none");
  603. window.setTimeout(function(){
  604. this.check.recheck();
  605. }.bind(this), 1000);
  606. }.bind(this), function(xhr, text, error){
  607. var errorText = error+":"+text;
  608. if (xhr) errorText = xhr.responseText;
  609. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  610. this.registered();
  611. }.bind(this));
  612. }.bind(this), function(xhr, text, error){
  613. if (xhr){
  614. var json = JSON.decode(xhr.responseText);
  615. this.errorNode.set("text", json.message);
  616. }else{
  617. var errorText = error+":"+text;
  618. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  619. }
  620. this.registered();
  621. }.bind(this));
  622. }
  623. },
  624. passwordVerification: function(){
  625. var password = this.passwordInput.get("value");
  626. if (!password || password==this.lp.password){
  627. this.errorInput(this.passwordNode, this.lp.errorPassword);
  628. return false;
  629. }
  630. var flag = "";
  631. this.action.passwordValidate({"password": password}, function(json){
  632. //if (json.data.value<4){
  633. // flag = this.lp.errorPasswordRule;
  634. //}
  635. flag = json.data.value || "";
  636. }.bind(this), function(xhr, text, error){
  637. }.bind(this), false);
  638. if (flag){
  639. this.errorInput(this.passwordNode, flag);
  640. return false;
  641. }
  642. return true;
  643. },
  644. codeVerification: function(){
  645. var code = this.codeInput.get("value");
  646. if (!code || code==this.lp.mobile){
  647. this.errorInput(this.codeNode, this.lp.errorCode);
  648. return false;
  649. }
  650. return true;
  651. },
  652. usernameVerification: function(){
  653. var user = this.usernameInput.get("value");
  654. if (!user || user==this.lp.username){
  655. this.errorInput(this.usernameNode, this.lp.errorUsername);
  656. return false;
  657. }
  658. var flag = "";
  659. this.action.nameExist(user, function(json){
  660. if (json.data.value){
  661. flag = this.lp.usernameExisted;
  662. }
  663. }.bind(this), function(xhr, text, error){
  664. if (xhr){
  665. var json = JSON.decode(xhr.responseText);
  666. flag = json.message;
  667. //this.errorNode.set("text", json.message);
  668. }else{
  669. var errorText = error+":"+text;
  670. flag = this.lp.requestError+errorText;
  671. //MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  672. }
  673. }.bind(this), false);
  674. if (flag){
  675. this.errorInput(this.usernameNode, flag);
  676. return false;
  677. }
  678. return true;
  679. },
  680. mobileVerification: function(){
  681. var mobile = this.mobileInput.get("value");
  682. if (!mobile || mobile==this.lp.mobile){
  683. this.errorInput(this.mobileNode, this.lp.errorMobile);
  684. return false;
  685. }
  686. if (mobile.length!=11){
  687. this.errorInput(this.mobileNode, this.lp.errorMobile);
  688. return false;
  689. }
  690. return true;
  691. }
  692. });
  693. MWF.xApplication.Collect.ModifyForm = new Class({
  694. Extends: MWF.xApplication.Collect.RegisterForm,
  695. initialize: function(collect){
  696. this.collect = collect;
  697. this.lp = this.collect.lp;
  698. this.css = this.collect.css;
  699. this.contentNode = this.collect.modifyContentNode;
  700. this.action = this.collect.action;
  701. this.load();
  702. },
  703. load: function(){
  704. this.contentNode.setStyle("padding-top", "30px");
  705. this.usernameNode = this.createNode("registerUsernameIconNode", "username");
  706. this.usernameInput = this.usernameNode.getElement("input");
  707. this.mobileNode = this.createNode("registerMobileIconNode", "mobile");
  708. this.mobileInput = this.mobileNode.getElement("input");
  709. this.codeNode = this.createNode("registerCodeIconNode", "code");
  710. this.codeInput = this.codeNode.getElement("input");
  711. this.newNameNode = this.createNode("registerNewNameIconNode");
  712. this.newNameInput = this.newNameNode.getElement("input");
  713. this.secretNode = this.createNode("registerSecretIconNode", "secret");
  714. this.secretInput = this.secretNode.getElement("input");
  715. this.keyNode = this.createNode("registerKeyIconNode", "key");
  716. this.keyInput = this.keyNode.getElement("input");
  717. this.setInputEvent();
  718. this.nextActionNode = new Element("div", {"styles": this.css.registerActionNode, "text": this.lp.modifyNextStep}).inject(this.contentNode);
  719. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  720. this.errorNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(this.contentNode);
  721. this.newNameNode.setStyle("display", "none");
  722. this.newNameNode.getNext().setStyle("display", "none");
  723. this.secretNode.setStyle("display", "none");
  724. this.secretNode.getNext().setStyle("display", "none");
  725. this.keyNode.setStyle("display", "none");
  726. this.keyNode.getNext().setStyle("display", "none");
  727. this.setDefaultValue();
  728. },
  729. setDefaultValue: function(){
  730. this.action.getCollectConfig(function(json){
  731. if (json.data.name) this.usernameInput.set("value", json.data.name);
  732. if (json.data.name) this.newNameInput.set("value", json.data.name);
  733. if (json.data.key) this.keyInput.set("value", json.data.key);
  734. if (json.data.secret) this.secretInput.set("value", json.data.secret);
  735. }.bind(this));
  736. },
  737. nextStepWait: function(){
  738. this.nextActionNode.removeEvents("click");
  739. this.nextActionNode.set("text", this.lp.nextStepWait);
  740. this.errorNode.empty();
  741. },
  742. setInputEvent: function(){
  743. this.setInputNodeEvent(this.usernameNode, this.usernameInput, this.lp.username, this.lp.errorUsername, "username");
  744. this.setInputNodeEvent(this.newNameNode, this.newNameInput, this.lp.username, this.lp.errorUsername, "newName");
  745. this.setInputNodeEvent(this.secretNode, this.secretInput, this.lp.secret, this.lp.errorSecret, "secret");
  746. this.setInputNodeEvent(this.keyNode, this.keyInput, this.lp.key, this.lp.errorKey, "key");
  747. this.setInputNodeEvent(this.mobileNode, this.mobileInput, this.lp.mobile, this.lp.errorMobile, "mobile");
  748. this.setInputNodeEvent(this.codeNode, this.codeInput, this.lp.code, this.lp.errorCode, "code");
  749. this.resetCodeNode();
  750. },
  751. nextStepWaited: function(){
  752. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  753. this.nextActionNode.set("text", this.lp.modifyNextStep);
  754. },
  755. firstStep: function(){
  756. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  757. this.nextActionNode.set("text", this.lp.modifyNextStep);
  758. this.newNameNode.setStyle("display", "none");
  759. this.newNameNode.getNext().setStyle("display", "none");
  760. this.secretNode.setStyle("display", "none");
  761. this.secretNode.getNext().setStyle("display", "none");
  762. this.keyNode.setStyle("display", "none");
  763. this.keyNode.getNext().setStyle("display", "none");
  764. this.usernameNode.setStyle("display", "block");
  765. this.usernameNode.getNext().setStyle("display", "block");
  766. this.mobileNode.setStyle("display", "block");
  767. this.mobileNode.getNext().setStyle("display", "block");
  768. this.codeNode.getParent().setStyle("display", "block");
  769. this.codeNode.getNext().setStyle("display", "block");
  770. this.errorNode.empty();
  771. },
  772. nextStep: function(){
  773. var user = this.usernameInput.get("value");
  774. var mobile = this.mobileInput.get("value");
  775. var code = this.codeInput.get("value");
  776. if (this.usernameVerification() & this.mobileVerification() & this.codeVerification()){
  777. this.nextStepWait();
  778. this.action.codeValidate({"codeAnswer": code, "mobile": mobile}, function(json){
  779. if (json.data.value){
  780. this.nextActionNode.removeEvents("click");
  781. this.nextActionNode.set("text", this.lp.modifyUnit);
  782. this.nextActionNode.addEvent("click", this.modifyUnit.bind(this));
  783. this.newNameNode.setStyle("display", "block");
  784. this.newNameNode.getNext().setStyle("display", "block");
  785. this.secretNode.setStyle("display", "block");
  786. this.secretNode.getNext().setStyle("display", "block");
  787. this.keyNode.setStyle("display", "block");
  788. this.keyNode.getNext().setStyle("display", "block");
  789. this.usernameNode.setStyle("display", "none");
  790. this.usernameNode.getNext().setStyle("display", "none");
  791. this.mobileNode.setStyle("display", "none");
  792. this.mobileNode.getNext().setStyle("display", "none");
  793. this.codeNode.getParent().setStyle("display", "none");
  794. this.codeNode.getNext().setStyle("display", "none");
  795. this.errorNode.empty();
  796. }else{
  797. this.errorInput(this.codeNode, this.lp.errorCode);
  798. }
  799. }.bind(this), function(xhr, text, error){
  800. if (xhr){
  801. var json = JSON.decode(xhr.responseText);
  802. this.errorInput(this.codeNode, json.message);
  803. }else{
  804. var errorText = error+":"+text;
  805. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  806. }
  807. this.nextStepWaited();
  808. }.bind(this));
  809. }
  810. },
  811. modifyUnit: function(){
  812. var user = this.usernameInput.get("value");
  813. var newName = this.newNameInput.get("value");
  814. var code = this.codeInput.get("value");
  815. var secret = this.secretInput.get("value");
  816. var key = this.keyInput.get("value");
  817. var mobile = this.mobileInput.get("value");
  818. if (this.newNameVerification()){
  819. this.nextStepWait();
  820. var data = {
  821. mobile: mobile,
  822. codeAnswer: code,
  823. newName: newName,
  824. secret: secret,
  825. key: key,
  826. name: user
  827. };
  828. this.action.updateUnitCollect(data, function(json){
  829. this.firstStep();
  830. this.collect.showContent("checkContentNode");
  831. this.collect.backNode.setStyle("display", "none");
  832. this.check.recheck();
  833. }.bind(this), function(xhr, text, error){
  834. var errorText = error+":"+text;
  835. if (xhr) errorText = xhr.responseText;
  836. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  837. this.firstStep();
  838. }.bind(this));
  839. }
  840. },
  841. usernameVerification: function(){
  842. var user = this.usernameInput.get("value");
  843. if (!user || user==this.lp.username){
  844. this.errorInput(this.usernameNode, this.lp.errorUsername);
  845. return false;
  846. }
  847. return true;
  848. },
  849. newNameVerification: function(){
  850. var user = this.usernameInput.get("value");
  851. if (!user || user==this.lp.username){
  852. this.errorInput(this.usernameNode, this.lp.errorUsername);
  853. return false;
  854. }
  855. return true;
  856. },
  857. keyVerification: function(){
  858. var user = this.usernameInput.get("value");
  859. if (!user || user==this.lp.username){
  860. this.errorInput(this.usernameNode, this.lp.errorUsername);
  861. return false;
  862. }
  863. return true;
  864. },
  865. secretVerification: function(){
  866. var user = this.usernameInput.get("value");
  867. if (!user || user==this.lp.username){
  868. this.errorInput(this.usernameNode, this.lp.errorUsername);
  869. return false;
  870. }
  871. return true;
  872. },
  873. show: function(){
  874. this.collect.showContent("modifyContentNode");
  875. this.collect.backNode.setStyle("display", "block");
  876. this.collect.backNode.removeEvents("click");
  877. this.collect.backNode.addEvent("click", function(){
  878. this.firstStep();
  879. this.collect.showContent("checkContentNode");
  880. this.collect.backNode.setStyle("display", "none");
  881. }.bind(this));
  882. }
  883. });
  884. MWF.xApplication.Collect.ModifyPwdForm = new Class({
  885. Extends: MWF.xApplication.Collect.RegisterForm,
  886. initialize: function(collect){
  887. this.collect = collect;
  888. this.lp = this.collect.lp;
  889. this.css = this.collect.css;
  890. this.contentNode = this.collect.modifyPwdContentNode;
  891. this.action = this.collect.action;
  892. this.load();
  893. },
  894. load: function(){
  895. this.contentNode.setStyle("padding-top", "30px");
  896. this.usernameNode = this.createNode("registerUsernameIconNode", "username");
  897. this.usernameInput = this.usernameNode.getElement("input");
  898. this.mobileNode = this.createNode("registerMobileIconNode", "mobile");
  899. this.mobileInput = this.mobileNode.getElement("input");
  900. this.codeNode = this.createNode("registerCodeIconNode", "code");
  901. this.codeInput = this.codeNode.getElement("input");
  902. this.passwordNode = this.createNode("registerPasswordIconNode", "password", "password");
  903. this.passwordInput = this.passwordNode.getElement("input");
  904. this.setInputEvent();
  905. this.nextActionNode = new Element("div", {"styles": this.css.registerActionNode, "text": this.lp.modifyNextStep}).inject(this.contentNode);
  906. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  907. //this.otherActionNode = new Element("div", {"styles": this.css.loginOtherActionNode}).inject(this.contentNode);
  908. //this.registerActionNode = new Element("div", {"styles": this.css.loginRegisterActionNode, "text": this.lp.register}).inject(this.otherActionNode);
  909. //this.forgetActionNode = new Element("div", {"styles": this.css.loginForgetActionNode, "text": this.lp.forget}).inject(this.otherActionNode);
  910. //this.setOtherActionEvent();
  911. this.errorNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(this.contentNode);
  912. this.passwordNode.setStyle("display", "none");
  913. this.passwordNode.getNext().setStyle("display", "none");
  914. this.setDefaultValue();
  915. },
  916. setDefaultValue: function(){
  917. this.action.getCollectConfig(function(json){
  918. if (json.data.name) this.usernameInput.set("value", json.data.name);
  919. }.bind(this));
  920. },
  921. nextStepWait: function(){
  922. this.nextActionNode.removeEvents("click");
  923. this.nextActionNode.set("text", this.lp.nextStepWait);
  924. this.errorNode.empty();
  925. },
  926. nextStepWaited: function(){
  927. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  928. this.nextActionNode.set("text", this.lp.modifyNextStep);
  929. },
  930. firstStep: function(){
  931. this.nextActionNode.addEvent("click", this.nextStep.bind(this));
  932. this.nextActionNode.set("text", this.lp.modifyNextStep);
  933. this.passwordNode.setStyle("display", "none");
  934. this.passwordNode.getNext().setStyle("display", "none");
  935. this.usernameNode.setStyle("display", "block");
  936. this.usernameNode.getNext().setStyle("display", "block");
  937. this.mobileNode.setStyle("display", "block");
  938. this.mobileNode.getNext().setStyle("display", "block");
  939. this.codeNode.getParent().setStyle("display", "block");
  940. this.codeNode.getNext().setStyle("display", "block");
  941. this.errorNode.empty();
  942. },
  943. nextStep: function(){
  944. var user = this.usernameInput.get("value");
  945. var mobile = this.mobileInput.get("value");
  946. var code = this.codeInput.get("value");
  947. if (this.usernameVerification() & this.mobileVerification() & this.codeVerification()){
  948. this.nextStepWait();
  949. this.action.codeValidate({"codeAnswer": code, "mobile": mobile}, function(json){
  950. if (json.data.value){
  951. this.nextActionNode.removeEvents("click");
  952. this.nextActionNode.set("text", this.lp.modifyPassword);
  953. this.nextActionNode.addEvent("click", this.modifyPassword.bind(this));
  954. this.passwordNode.setStyle("display", "block");
  955. this.passwordNode.getNext().setStyle("display", "block");
  956. this.usernameNode.setStyle("display", "none");
  957. this.usernameNode.getNext().setStyle("display", "none");
  958. this.mobileNode.setStyle("display", "none");
  959. this.mobileNode.getNext().setStyle("display", "none");
  960. this.codeNode.getParent().setStyle("display", "none");
  961. this.codeNode.getNext().setStyle("display", "none");
  962. this.errorNode.empty();
  963. }else{
  964. this.errorInput(this.codeNode, this.lp.errorCode);
  965. }
  966. }.bind(this), function(xhr, text, error){
  967. if (xhr){
  968. var json = JSON.decode(xhr.responseText);
  969. this.errorInput(this.codeNode, json.message);
  970. }else{
  971. var errorText = error+":"+text;
  972. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  973. }
  974. this.nextStepWaited();
  975. }.bind(this));
  976. }
  977. },
  978. modifyPassword: function(){
  979. var user = this.usernameInput.get("value");
  980. var mobile = this.mobileInput.get("value");
  981. var code = this.codeInput.get("value");
  982. var password = this.passwordInput.get("value");
  983. if (this.usernameVerification() & this.mobileVerification() & this.codeVerification() & this.passwordVerification()){
  984. this.nextStepWait();
  985. var data = {
  986. codeAnswer: code,
  987. mobile: mobile,
  988. name: user,
  989. password: password
  990. };
  991. debugger;
  992. this.action.resetPassword(data, function(){
  993. this.action.updateCollect({"name": user, "password": password, "enable": true}, function(json){
  994. this.firstStep();
  995. this.collect.showContent("checkContentNode");
  996. this.collect.backNode.setStyle("display", "none");
  997. this.check.recheck();
  998. }.bind(this), function(xhr, text, error){
  999. var errorText = error+":"+text;
  1000. if (xhr) errorText = xhr.responseText;
  1001. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1002. this.firstStep();
  1003. }.bind(this));
  1004. }.bind(this), function(xhr, text, error){
  1005. if (xhr){
  1006. var json = JSON.decode(xhr.responseText);
  1007. this.errorNode.set("text", json.message);
  1008. }else{
  1009. var errorText = error+":"+text;
  1010. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1011. }
  1012. this.firstStep();
  1013. }.bind(this));
  1014. }
  1015. },
  1016. usernameVerification: function(){
  1017. var user = this.usernameInput.get("value");
  1018. if (!user || user==this.lp.username){
  1019. this.errorInput(this.usernameNode, this.lp.errorUsername);
  1020. return false;
  1021. }
  1022. return true;
  1023. },
  1024. show: function(){
  1025. this.collect.showContent("modifyPwdContentNode");
  1026. this.collect.backNode.setStyle("display", "block");
  1027. this.collect.backNode.removeEvents("click");
  1028. this.collect.backNode.addEvent("click", function(){
  1029. this.firstStep();
  1030. this.collect.showContent("checkContentNode");
  1031. this.collect.backNode.setStyle("display", "none");
  1032. }.bind(this));
  1033. }
  1034. });
  1035. MWF.xApplication.Collect.DeleteForm = new Class({
  1036. Extends: MWF.xApplication.Collect.RegisterForm,
  1037. initialize: function(collect){
  1038. this.collect = collect;
  1039. this.lp = this.collect.lp;
  1040. this.css = this.collect.css;
  1041. this.contentNode = this.collect.deleteContentNode;
  1042. this.action = this.collect.action;
  1043. this.load();
  1044. },
  1045. load: function(){
  1046. this.contentNode.setStyle("padding-top", "30px");
  1047. this.usernameNode = this.createNode("registerUsernameIconNode", "username");
  1048. this.usernameInput = this.usernameNode.getElement("input");
  1049. this.mobileNode = this.createNode("registerMobileIconNode", "mobile");
  1050. this.mobileInput = this.mobileNode.getElement("input");
  1051. this.codeNode = this.createNode("registerCodeIconNode", "code");
  1052. this.codeInput = this.codeNode.getElement("input");
  1053. this.passwordNode = this.createNode("registerPasswordIconNode", "password", "password");
  1054. this.passwordInput = this.passwordNode.getElement("input");
  1055. this.setInputEvent();
  1056. this.nextActionNode = new Element("div", {"styles": this.css.registerActionNode, "text": this.lp.confirmDelete}).inject(this.contentNode);
  1057. this.nextActionNode.addEvent("click", this.deleteCollect.bind(this));
  1058. this.errorNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(this.contentNode);
  1059. this.passwordNode.setStyle("display", "none");
  1060. this.passwordNode.getNext().setStyle("display", "none");
  1061. this.setDefaultValue();
  1062. },
  1063. setDefaultValue: function(){
  1064. this.action.getCollectConfig(function(json){
  1065. if (json.data.name) this.usernameInput.set("value", json.data.name);
  1066. }.bind(this));
  1067. },
  1068. deleteCollect:function(){
  1069. var user = this.usernameInput.get("value");
  1070. var mobile = this.mobileInput.get("value");
  1071. var code = this.codeInput.get("value");
  1072. if (this.usernameVerification() & this.mobileVerification() & this.codeVerification() ){
  1073. this.action.deleteCollect(user,mobile,code, function(json){
  1074. this.collect.showContent("checkContentNode");
  1075. this.collect.backNode.setStyle("display", "none");
  1076. }.bind(this), function(xhr, text, error){
  1077. var errorText = error+":"+text;
  1078. if (xhr) errorText = xhr.responseText;
  1079. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  1080. this.firstStep();
  1081. }.bind(this));
  1082. }
  1083. },
  1084. usernameVerification: function(){
  1085. var user = this.usernameInput.get("value");
  1086. if (!user || user==this.lp.username){
  1087. this.errorInput(this.usernameNode, this.lp.errorUsername);
  1088. return false;
  1089. }
  1090. return true;
  1091. },
  1092. firstStep: function(){
  1093. this.passwordNode.setStyle("display", "none");
  1094. this.passwordNode.getNext().setStyle("display", "none");
  1095. this.usernameNode.setStyle("display", "block");
  1096. this.usernameNode.getNext().setStyle("display", "block");
  1097. this.mobileNode.setStyle("display", "block");
  1098. this.mobileNode.getNext().setStyle("display", "block");
  1099. this.codeNode.getParent().setStyle("display", "block");
  1100. this.codeNode.getNext().setStyle("display", "block");
  1101. this.errorNode.empty();
  1102. },
  1103. show: function(){
  1104. this.collect.showContent("deleteContentNode");
  1105. this.collect.backNode.setStyle("display", "block");
  1106. this.collect.backNode.removeEvents("click");
  1107. this.collect.backNode.addEvent("click", function(){
  1108. this.firstStep();
  1109. this.collect.showContent("checkContentNode");
  1110. this.collect.backNode.setStyle("display", "none");
  1111. }.bind(this));
  1112. }
  1113. });