Main.js 56 KB

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