Account.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. MWF.xApplication.Setting.mobile = MWF.xApplication.Setting.mobile || {};
  2. MWF.xApplication.Setting.mobile.Account = new Class({
  3. Implements: [Options, Events],
  4. initialize: function(explorer){
  5. this.explorer = explorer;
  6. this.app = this.explorer.app;
  7. this.actions = this.app.actions;
  8. this.css = this.app.css;
  9. this.content = this.explorer.accountContent;
  10. this.page = this.app.mobilePage;
  11. this.load();
  12. },
  13. load: function(){
  14. this.inforNode = new Element("div", {"styles": this.css.mobileAccountInforNode}).inject(this.content);
  15. this.actionNode = new Element("div", {"styles": this.css.mobileAccountActionNode}).inject(this.content);
  16. this.titleNode = new Element("div", {"styles": this.css.mobileAccountTitleNode, "text": this.app.lp.loginCollect}).inject(this.inforNode);
  17. this.usernameNode = new Element("div", {"styles": this.css.mobileAccountUsernameNode}).inject(this.inforNode);
  18. this.usernameIconNode = new Element("div", {"styles": this.css.mobileAccountUsernameIconNode}).inject(this.usernameNode);
  19. this.usernameInputNode = new Element("div", {"styles": this.css.mobileAccountUsernameInputNode}).inject(this.usernameNode);
  20. this.usernameInput = new Element("input", {
  21. "styles": this.css.mobileAccountUsernameInput,
  22. "type": "text",
  23. "value": "Username"
  24. }).inject(this.usernameInputNode);
  25. this.passwordNode = new Element("div", {"styles": this.css.mobileAccountPasswordNode}).inject(this.inforNode);
  26. this.passwordIconNode = new Element("div", {"styles": this.css.mobileAccountPasswordIconNode}).inject(this.passwordNode);
  27. this.passwordInputNode = new Element("div", {"styles": this.css.mobileAccountPasswordInputNode}).inject(this.passwordNode);
  28. this.passwordInput = new Element("input", {
  29. "styles": this.css.mobileAccountPasswordInput,
  30. "type": "password",
  31. "value": "password"
  32. }).inject(this.passwordInputNode);
  33. this.codeNode = new Element("div", {"styles": this.css.mobileAccountCodeNode}).inject(this.inforNode);
  34. this.codeIconNode = new Element("div", {"styles": this.css.mobileAccountCodeIconNode}).inject(this.codeNode);
  35. this.codePicNode = new Element("div", {"styles": this.css.mobileAccountCodePicNode}).inject(this.codeNode);
  36. this.codeInputNode = new Element("div", {"styles": this.css.mobileAccountCodeInputNode}).inject(this.codeNode);
  37. this.codeInput = new Element("input", {
  38. "styles": this.css.mobileAccountCodeInput,
  39. "type": "text"
  40. }).inject(this.codeInputNode);
  41. this.inforTextNode = new Element("div", {"styles": this.css.mobileAccountInforTextNode}).inject(this.inforNode);
  42. this.loginAction = new Element("div", {
  43. "styles": this.css.mobileAccountLoginActionNode,
  44. "text": this.app.lp.loginText
  45. }).inject(this.inforNode);
  46. this.registerAction = new Element("div", {
  47. "styles": this.css.mobileAccountRegisterActionNode,
  48. "html": this.app.lp.registerText
  49. }).inject(this.inforNode);
  50. this.app.actions.getResCollect(function(json){
  51. this.usernameInput.set("value", json.data.name);
  52. this.passwordInput.set("value", json.data.password);
  53. }.bind(this));
  54. this.getCaptcha();
  55. this.setEvent();
  56. //if (this.explorer.checkOnline){
  57. // //if (!this.explorer.checkOnline.checkConnectStatus){
  58. // this.maskNode = new Element("div", {"styles": this.css.mobileAccountMaskNode}).inject(this.content, "after");
  59. // //}
  60. //}
  61. },
  62. getCaptcha: function(){
  63. this.app.actions.getCaptcha(function(json){
  64. this.codePicNode.empty();
  65. var picNode = new Element("img", {
  66. "styles": {
  67. "margin-top": "10px",
  68. "width": "120px",
  69. "height": "40px"
  70. },
  71. "src": "data:image/png;base64,"+json.data.image
  72. }).inject(this.codePicNode);
  73. this.captchaKey = json.data.key;
  74. this.codePicNode.store("key", json.data.key);
  75. }.bind(this));
  76. },
  77. setEvent: function(){
  78. this.codePicNode.addEvent("click", function(){
  79. this.getCaptcha();
  80. }.bind(this));
  81. this.usernameInput.addEvents({
  82. "focus": function(){if (this.usernameInput.get("value")=="Username") this.usernameInput.set("value", "");}.bind(this),
  83. "blur": function(){if (this.usernameInput.get("value")=="") this.usernameInput.set("value", "Username");}.bind(this),
  84. "keydown": function(){this.usernameInput.setStyle("background", "transparent");}.bind(this),
  85. });
  86. this.passwordInput.addEvents({
  87. "focus": function(){if (this.passwordInput.get("value")=="password") this.passwordInput.set("value", "");}.bind(this),
  88. "blur": function(){if (this.passwordInput.get("value")=="") this.passwordInput.set("value", "password");}.bind(this)
  89. });
  90. this.codeInput.addEvents({
  91. "keydown": function(){this.codeInput.setStyle("background", "transparent");}.bind(this)
  92. });
  93. this.loginAction.addEvent("click", function(){
  94. if (this.token){
  95. this.logout();
  96. }else{
  97. this.login();
  98. }
  99. }.bind(this));
  100. this.registerAction.addEvent("click", function(){
  101. this.register();
  102. }.bind(this));
  103. },
  104. register: function(){
  105. new MWF.xApplication.Setting.mobile.Account.Register(this);
  106. },
  107. logout: function(){
  108. this.inforTextNode.set("text", "");
  109. this.app.actions.logoutCollect(function(json){
  110. var data = {
  111. "name": "",
  112. "password": "",
  113. "enable": false
  114. }
  115. this.app.actions.updateResCollect(data, function(){
  116. this.token = "";
  117. this.name = "";
  118. this.tokenType = "";
  119. this.loginAction.set({
  120. "styles": this.css.mobileAccountLoginActionNode,
  121. "text": this.app.lp.loginText
  122. });
  123. this.titleNode.set({
  124. "styles": this.css.mobileAccountTitleNode,
  125. "text": this.app.lp.loginCollect
  126. });
  127. this.registerAction.setStyle("display", "block");
  128. this.getCaptcha();
  129. }.bind(this));
  130. }.bind(this), function(xhr, text, error){
  131. var json = JSON.decode(xhr.responseText);
  132. this.inforTextNode.set("text", json.message);
  133. this.getCaptcha();
  134. }.bind(this));
  135. },
  136. login: function(){
  137. this.inforTextNode.set("text", "");
  138. var name = this.usernameInput.get("value");
  139. var pass = this.passwordInput.get("value");
  140. var code = this.codeInput.get("value");
  141. if (!name){
  142. this.inforTextNode.set("text", this.app.lp.loginInputUsername);
  143. this.usernameInput.setStyle("background", "#ffebeb");
  144. return false;
  145. }
  146. if (!code){
  147. this.inforTextNode.set("text", this.app.lp.loginInputCode);
  148. this.codeInput.setStyle("background", "#ffebeb");
  149. return false;
  150. }
  151. var data = {
  152. "credential": name,
  153. "password": pass
  154. }
  155. this.app.actions.loginCollect(this.captchaKey, code, data, function(json){
  156. var data = {
  157. "name": name,
  158. "password": pass,
  159. "enable": true
  160. }
  161. this.app.actions.updateResCollect(data, function(){
  162. this.token = json.data.token;
  163. this.name = json.data.name;
  164. this.tokenType = json.data.tokenType;
  165. this.loginAction.set({
  166. "styles": this.css.mobileAccountLogoutActionNode,
  167. "text": this.app.lp.logoutText
  168. });
  169. this.titleNode.set({
  170. "styles": this.css.mobileAccountTitleLoginNode,
  171. "text": this.app.lp.loggedCollect
  172. });
  173. this.registerAction.setStyle("display", "none");
  174. }.bind(this));
  175. }.bind(this), function(xhr, text, error){
  176. var json = JSON.decode(xhr.responseText);
  177. this.inforTextNode.set("text", json.message);
  178. this.getCaptcha();
  179. }.bind(this));
  180. },
  181. destroy: function(){
  182. this.content.destroy();
  183. MWF.release(this);
  184. }
  185. });
  186. MWF.xApplication.Setting.mobile.Account.Register = new Class({
  187. initialize: function(account){
  188. this.account = account;
  189. this.explorer = this.account.explorer;
  190. this.app = this.explorer.app;
  191. this.actions = this.app.actions;
  192. this.css = this.app.css;
  193. this.content = this.explorer.accountContent;
  194. this.page = this.app.mobilePage;
  195. this.load();
  196. },
  197. load: function(){
  198. this.maskNode = new Element("div", {"styles": this.css.registerMaskNode}).inject(this.app.content);
  199. this.areaNode = new Element("div", {"styles": this.css.registerAreaNode}).inject(this.app.content);
  200. this.node = new Element("div", {"styles": this.css.registerNode}).inject(this.areaNode);
  201. this.setNodePositionFun = this.setNodePosition.bind(this);
  202. this.app.addEvent("resize", this.setNodePositionFun);
  203. this.setNodePosition();
  204. this.titleNode = new Element("div", {"styles": this.css.registerTitleNode, "text": this.app.lp.registerTitle}).inject(this.node);
  205. this.usernameNode = new Element("div", {"styles": this.css.registerUsernameNode}).inject(this.node);
  206. this.usernameIconNode = new Element("div", {"styles": this.css.registerUsernameIconNode}).inject(this.usernameNode);
  207. this.usernameInputNode = new Element("div", {"styles": this.css.registerUsernameInputNode}).inject(this.usernameNode);
  208. this.usernameInput = new Element("input", {
  209. "styles": this.css.registerUsernameInput,
  210. "type": "text",
  211. "value": this.app.lp.companyName
  212. }).inject(this.usernameInputNode);
  213. this.phoneNode = new Element("div", {"styles": this.css.registerUsernameNode}).inject(this.node);
  214. this.phoneIconNode = new Element("div", {"styles": this.css.registerPhoneIconNode}).inject(this.phoneNode);
  215. this.phoneInputNode = new Element("div", {"styles": this.css.registerUsernameInputNode}).inject(this.phoneNode);
  216. this.phoneInput = new Element("input", {
  217. "styles": this.css.registerUsernameInput,
  218. "type": "text",
  219. "value": this.app.lp.phone
  220. }).inject(this.phoneInputNode);
  221. this.codeNode = new Element("div", {"styles": this.css.registerCodeNode}).inject(this.node);
  222. this.codeIconNode = new Element("div", {"styles": this.css.registerCodeIconNode}).inject(this.codeNode);
  223. this.codeActionNode = new Element("div", {"styles": this.css.registerCodeActionNode, "text": this.app.lp.getPhoneCode}).inject(this.codeNode);
  224. this.codeInputNode = new Element("div", {"styles": this.css.registerCodeInputNode}).inject(this.codeNode);
  225. this.codeInput = new Element("input", {
  226. "styles": this.css.registerCodeInput,
  227. "type": "text",
  228. "value": this.app.lp.code
  229. }).inject(this.codeInputNode);
  230. this.passwordNode = new Element("div", {"styles": this.css.registerUsernameNode}).inject(this.node);
  231. this.passwordIconNode = new Element("div", {"styles": this.css.registerPasswordIconNode}).inject(this.passwordNode);
  232. this.passwordInputNode = new Element("div", {"styles": this.css.registerUsernameInputNode}).inject(this.passwordNode);
  233. this.passwordInput = new Element("input", {
  234. "styles": this.css.registerUsernameInput,
  235. "type": "password"
  236. }).inject(this.passwordInputNode);
  237. this.passwordHihtNode = new Element("div", {"styles": this.css.registerPasswordHintNode, "text": this.app.lp.password}).inject(this.passwordNode);
  238. this.confirmNode = new Element("div", {"styles": this.css.registerUsernameNode}).inject(this.node);
  239. this.confirmIconNode = new Element("div", {"styles": this.css.registerPasswordIconNode}).inject(this.confirmNode);
  240. this.confirmInputNode = new Element("div", {"styles": this.css.registerUsernameInputNode}).inject(this.confirmNode);
  241. this.confirmInput = new Element("input", {
  242. "styles": this.css.registerUsernameInput,
  243. "type": "password"
  244. }).inject(this.confirmInputNode);
  245. this.confirmHihtNode = new Element("div", {"styles": this.css.registerConfirmHintNode, "text": this.app.lp.confirmPassword}).inject(this.confirmNode);
  246. this.registerAction = new Element("div", {
  247. "styles": this.css.registerActionNode,
  248. "text": this.app.lp.registerActionText
  249. }).inject(this.node);
  250. this.cancelAction = new Element("div", {
  251. "styles": this.css.registerCancelActionNode,
  252. "text": this.app.lp.registerCancelActionText
  253. }).inject(this.node);
  254. this.inforTextNode = new Element("div", {"styles": this.css.registerInforTextNode}).inject(this.node);
  255. this.setEvent();
  256. },
  257. setEvent: function(){
  258. this.passwordHihtNode.addEvent("mousedown", function(){
  259. this.passwordHihtNode.setStyle("display", "none");
  260. var errorNode = this.passwordInput.retrieve("errorNode");
  261. if (errorNode){
  262. errorNode.setStyle("display", "none");
  263. this.passwordInputNode.setStyle("background", "transparent");
  264. }
  265. this.passwordInput.focus();
  266. }.bind(this));
  267. this.confirmHihtNode.addEvent("mousedown", function(){
  268. this.confirmHihtNode.setStyle("display", "none");
  269. var errorNode = this.confirmInput.retrieve("errorNode");
  270. if (errorNode){
  271. errorNode.setStyle("display", "none");
  272. this.confirmInputNode.setStyle("background", "transparent");
  273. }
  274. this.confirmInput.focus();
  275. }.bind(this));
  276. this.passwordInput.addEvents({
  277. "blur": function(){
  278. if (!this.passwordInput.get("value")){this.passwordHihtNode.setStyle("display", "block");}
  279. }.bind(this)
  280. });
  281. this.confirmInput.addEvents({
  282. "blur": function(){
  283. if (!this.confirmInput.get("value")){this.confirmHihtNode.setStyle("display", "block");}
  284. }.bind(this)
  285. });
  286. this.usernameInput.addEvents({
  287. "focus": function(){
  288. if (this.usernameInput.get("value")==this.app.lp.companyName){this.usernameInput.set("value", "");}
  289. }.bind(this),
  290. "blur": function(){
  291. if (!this.usernameInput.get("value")){this.usernameInput.set("value", this.app.lp.companyName);}
  292. }.bind(this)
  293. });
  294. this.phoneInput.addEvents({
  295. "focus": function(){
  296. if (this.phoneInput.get("value")==this.app.lp.phone){this.phoneInput.set("value", "");}
  297. }.bind(this),
  298. "blur": function(){
  299. if (!this.phoneInput.get("value")){this.phoneInput.set("value", this.app.lp.phone);}
  300. }.bind(this)
  301. });
  302. this.codeInput.addEvents({
  303. "focus": function(){
  304. if (this.codeInput.get("value")==this.app.lp.code){this.codeInput.set("value", "");}
  305. }.bind(this),
  306. "blur": function(){
  307. if (!this.codeInput.get("value")){this.codeInput.set("value", this.app.lp.code);}
  308. }.bind(this)
  309. });
  310. this.codeActionNode.addEvent("click", function(){
  311. if (!this.codeSend) this.getCode();
  312. }.bind(this));
  313. this.registerAction.addEvent("click", function(){
  314. this.register();
  315. }.bind(this));
  316. this.cancelAction.addEvent("click", function(e){
  317. this.cancelRegister(e);
  318. }.bind(this));
  319. },
  320. getCode: function(){
  321. var phone = this.phoneInput.get("value");
  322. if (!phone || phone==this.app.lp.phone){
  323. this.fieldError(this.phoneInput, this.app.lp.phoneError);
  324. return false;
  325. }
  326. if (isNaN(phone)){
  327. this.fieldError(this.phoneInput, this.app.lp.phoneTypeError);
  328. return false;
  329. }
  330. this.app.actions.getCode({"mobile": phone}, function(json){
  331. this.codeWaitTime = 60;
  332. this.codeActionNode.set("text", this.app.lp.getPhoneCodeWait+"("+this.codeWaitTime+")");
  333. this.codeActionNode.setStyle("color", "#EEE");
  334. this.codeSend = true;
  335. this.waitCode = window.setInterval(function(){
  336. this.codeWaitTime--;
  337. this.codeActionNode.set("text", this.app.lp.getPhoneCodeWait+"("+this.codeWaitTime+")");
  338. if (this.codeWaitTime==0){
  339. this.codeActionNode.setStyle("color", "#FFF");
  340. this.codeWaitTime = 60;
  341. this.codeSend = false;
  342. this.codeActionNode.set("text", this.app.lp.getPhoneCode);
  343. window.clearInterval(this.waitCode);
  344. }
  345. }.bind(this), 1000);
  346. }.bind(this));
  347. },
  348. register: function(){
  349. var name = this.usernameInput.get("value");
  350. var phone = this.phoneInput.get("value");
  351. var code = this.codeInput.get("value");
  352. var pass = this.passwordInput.get("value");
  353. var conf = this.confirmInput.get("value");
  354. var flag = true;
  355. if (!name || name == this.app.lp.companyName){
  356. this.fieldError(this.usernameInput, this.app.lp.nameError);
  357. flag = false;
  358. }
  359. if (!code || code == this.app.lp.code){
  360. this.fieldError(this.codeInput, this.app.lp.codeError);
  361. flag = false;
  362. }
  363. if (!phone || phone==this.app.lp.phone || isNaN(phone)){
  364. this.fieldError(this.phoneInput, this.app.lp.phoneTypeError);
  365. flag = false;
  366. }
  367. if (!pass){
  368. this.fieldError(this.passwordInput, this.app.lp.passwordError);
  369. flag = false;
  370. }
  371. if (!conf){
  372. this.fieldError(this.confirmInput, this.app.lp.confirmError);
  373. flag = false;
  374. }
  375. if (pass && conf){
  376. if (pass != conf){
  377. this.fieldError(this.confirmInput, this.app.lp.confirmPasswordError);
  378. flag = false;
  379. }
  380. }
  381. if (!flag) return false;
  382. this.data = {
  383. "mobile": phone,
  384. "code": code,
  385. "name": name,
  386. "password": pass
  387. }
  388. this.app.actions.register(this.data, function(json){
  389. //this.app.lp.registerSuccess
  390. //this.successNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(this.node);
  391. this.node.empty();
  392. this.titleNode = new Element("div", {"styles": this.css.registerTitleNode, "text": this.app.lp.registerSuccessTitle}).inject(this.node);
  393. var text = this.app.lp.registerSuccess.replace(/{name}/g, name);
  394. var inforNode = new Element("div", {"styles": this.css.registerSuccessInforNode, "html": text}).inject(this.node);
  395. inforNode.addEvent("click", function(){
  396. this.successClose();
  397. }.bind(this));
  398. window.setTimeout(function(){
  399. this.successClose();
  400. }.bind(this), 3000);
  401. }.bind(this), function(xhr, text, error){
  402. var json = JSON.decode(xhr.responseText);
  403. this.inforTextNode.set("text", json.message)
  404. }.bind(this));
  405. },
  406. successClose: function(){
  407. this.account.usernameInput.set("value", this.data.name);
  408. this.account.passwordInput.set("value", this.data.password);
  409. this.account.getCaptcha();
  410. this.destroy();
  411. },
  412. cancelRegister: function(e){
  413. var _self = this;
  414. this.app.confirm("warm", e, this.app.lp.cancelRegisterTitle, this.app.lp.cancelRegister, 300, 120, function(){
  415. _self.destroy();
  416. this.close();
  417. }, function(){
  418. this.close();
  419. });
  420. },
  421. destroy: function(){
  422. this.maskNode.destroy();
  423. this.areaNode.destroy();
  424. MWF.release(this);
  425. },
  426. fieldError: function(field, text){
  427. var errorNode = field.retrieve("errorNode");
  428. if (!errorNode){
  429. errorNode = new Element("div", {"styles": this.css.registerErrorNode}).inject(field, "after");
  430. field.store("errorNode", errorNode);
  431. errorNode.store("node", field);
  432. errorNode.addEvent("mousedown", function(){
  433. var field = this.retrieve("node");
  434. field.getParent().setStyle("background", "transparent");
  435. errorNode.setStyle("display", "none");
  436. field.focus();
  437. });
  438. }
  439. field.getParent().setStyle("background", "#ffebeb");
  440. errorNode.set("text", text);
  441. errorNode.setStyle("display", "block");
  442. },
  443. setNodePosition: function(){
  444. var contentSize = this.areaNode.getSize();
  445. var size = this.node.getSize();
  446. var x = (contentSize.x - size.x)/2;
  447. var y = (contentSize.y - size.y)/2;
  448. this.node.setStyles({
  449. "top": ""+y+"px",
  450. "left": ""+x+"px"
  451. });
  452. }
  453. });