1 /**
  2  *
  3  * 绑定邮箱
  4  *
  5  * @fileOverView
  6  * @author  <a href="mailto:zhang.gd@foxmail.com">Zhang Guangda</a>
  7  * @date    2012-10-25
  8  */
  9 define(
 10 	[
 11 		"component/form",
 12 		"component/process_components"
 13 	], 
 14 	function() {
 15 		var _html = '<div class="we_cell_form_box" attr="root"></div>',
 16 			_btmTips = ['温馨提示:进行邮箱认证后,您可以使用以下服务:<br>', '<strong>修改密码:</strong>认证成功后,可通过邮箱修改账号密码<br>', '<strong>接收资料:</strong>认证成功后,邮箱可接收补办、查询密宝服务卡的各类资料'].join(""),
 17 			_emailName = "邮箱地址";
 18 
 19 		/**
 20 		 * 绑定手机组件
 21 		 * @lends  $we.widget.bind_email.start
 22 		 */
 23 		$we.widget.reg("bind_email.start", {
 24 			/**
 25 			 * @constructs
 26 			 */
 27 			init: function(el, params) {
 28 				this.el = el;
 29 				this.params = params || {};
 30 				this.params.btmTips = $we.utils.setValue(this.params.btmTips, _btmTips);
 31 				this.params.emailName = $we.utils.setValue(this.params.emailName, _emailName);
 32 			},
 33 			/**
 34 			 * interfaces
 35 			 * @memberOf $we.widget.bind_email.start#
 36 			 */
 37 			interfaces: {
 38 				render: function() {
 39 					this.append(this.el, _html);
 40 					var me = this;
 41 					this.form = $we.widget.add("Form", this.node.root, {
 42 						form_elements: [{
 43 							label: this.params.emailName,
 44 							name: 'email',
 45 							expression: 'email',
 46 							type: 'autocomplete',
 47 							acConfig: {
 48 								title: '请选择邮箱类型',
 49 								ds: ['@sina.com', '@163.com', '@qq.com', '@126.com', '@hotmail.com', '@gmail.com', '@sohu.com', '@yahoo.cn', '@yahoo.com'],
 50 								search_parse: function(data) {
 51 									var v = this.val();
 52 									var i = v.indexOf('@');
 53 									if(i >= 0) {
 54 										var tail = v.substr(i);
 55 										if(data.indexOf(tail) >= 0) {
 56 											return v.substr(0, i) + data;
 57 										} else {
 58 											return null;
 59 										}
 60 									} else {
 61 										return v + data;
 62 									}
 63 								}
 64 							},
 65 							success: "填写正确",
 66 							placeholder: "在这里输入邮箱",
 67 							require: "true"
 68 						}],
 69 						commit: function() {
 70 							me.notify("next");
 71 						}
 72 					});
 73 					this.notify("renderBottom", _btmTips);
 74 				}
 75 			},
 76 			/**
 77 			 * process
 78 			 * @memberOf $we.widget.bind_email.start#
 79 			 */
 80 			process: {
 81 				start: function() {
 82 					this.render();
 83 				},
 84 				end: function() {
 85 					$(this.node.root).remove();
 86 					this.notify("renderBottom", "");
 87 				},
 88 				checkSucc: function() {
 89 					if(!this.form.valid()) {
 90 						this.notify("pause");
 91 						return;
 92 					}
 93 					$we.process.setData("bind_email", this.form.getValue("email"));
 94 					this.notify("goNext");
 95 				}
 96 			}
 97 		});
 98 
 99 		$we.widget.reg("bind_email.end", {
100 			init: function(el, config) {
101 				this.extend("process.end", [el, config]);
102 			},
103 			interfaces: {
104 				render: function(params) {
105 					if (!params.email || !params.v_date) return;
106 
107 					this.config.title = "恭喜您完成操作!";
108 					this.config.content = "您认证的邮箱是:" + params.email + ",将在" + params.v_date + "通过验证期。";
109 					this._super.render();
110 
111 					this.notify("setButton", {next: "完成"});
112 				}
113 			},
114 			process: {
115 				start: function(params) { this.render(params); },
116 				end: function() { this.config.success(); $(this.node.root).remove(); },
117 				checkSucc: function() { this.notify("close"); }
118 			}
119 		});
120 
121 		return $we.widget.amd("bind_email");
122 	}
123 );