/**
 * 留言面板
 */
LeaveMessageWin = function(config) {
	Ext.apply(this, config);

	// 留言表单
	this.msgForm = new Ext.FormPanel({
		url : 'leaveMsg.do',
		labelAlign : 'left',
		defaultType : 'textfield',
		bodyStyle : 'padding:5px',
		labelWidth : 60,
		border : false,
		frame : true,
		scope : this,
		items : [{
					id : 'writerId',
					xtype : 'hidden',
					name : 'writerId'
				}, {
					id : 'writerName',
					fieldLabel : '姓名',
					name : 'writerName',
					allowBlank : false,
					blankText : '请留下您的姓名，以方便我们与您联系',
					anchor : '95%'
				}, {
					id : 'writerPhone',
					fieldLabel : '联系电话',
					name : 'writerPhone',
					allowBlank : false,
					blankText : '请留下您的联系电话，以方便我们与您联系',
					anchor : '95%'
				}, {
					id : 'writerEmail',
					fieldLabel : 'Email',
					name : 'writerEmail',
					vtype : 'email',
					anchor : '95%'
				}, {
					id : 'msgType',
					fieldLabel : '留言类别',
					name : 'msgType',
					anchor : '95%',
					xtype : 'combo',
					editable : false,
					forceSelection : true,
					triggerAction : 'all',
					mode : 'local',
					store : new Ext.data.SimpleStore({
						fields : ['returnValue', 'displayValue'],
						data : [['咨询', '咨询'], ['建议', '建议'], ['提问', '提问']]
					}),
					valueField : 'returnValue',
					displayField : 'displayValue'
				}, {
					id : 'msgTitle',
					fieldLabel : '留言标题',
					name : 'msgTitle',
					allowBlank : false,
					blankText : '请填写留言标题',
					maxLength : 100,
					maxLengthText : '标题不能超过100个字符，请稍作精简...',
					minLength : 2,
					minLengthText : '请认真填写留言标题...',
					anchor : '95%'
				}, {
					id : 'msgContent',
					fieldLabel : '留言内容',
					xtype : 'textarea',
					name : 'msgContent',
					height : 300,
					anchor : '95%'
				}],
		bbar : [{
					xtype : 'tbfill'
				}, {
					xtype : 'tbseparator'
				}, {
					id : 'btn-sumbit',
					text : '提交留言',
					type : 'submit',
					iconCls : 'cx-submit-3',
					scope : this,
					handler : this.submitForm
				}, {
					xtype : 'tbseparator'
				}, {
					text : '关闭',
					iconCls : 'cx-close-2',
					scope : this,
					handler : function() {
						this.close();
					}
				}]
	});

	LeaveMessageWin.superclass.constructor.call(this, {
				id : 'customer-leave-Msg-win',
				title : '留言板',
				width : 550,
				height : 520,
				layout : 'fit',
				items : this.msgForm
			});

	this.initForm();
}

Ext.extend(LeaveMessageWin, Ext.Window, {
			initForm : function() {
				this.store = new Ext.data.Store({
					proxy : new Ext.data.HttpProxy({
						url : 'cstFullInfo.do'
					}),
					reader : new Ext.data.JsonReader({
								root : 'record',
								totalProperty : 'totalProperty'
							},
							['id', 'contacter', 'areaCode', 'phone', 'email']),
					remoteSort : false
				});

				this.store.load({
					scope : this,
					callback : function(r, option, success) {
						if (success) {
							this.msgForm.findById('writerId')
									.setValue(r[0].data.id);
							this.msgForm.findById('writerName')
									.setValue(r[0].data.contacter);
							this.msgForm.findById('writerPhone')
									.setValue(r[0].data.areaCode + '-'
											+ r[0].data.phone);
							this.msgForm.findById('writerEmail')
									.setValue(r[0].data.email);
						}
					}
				});

				// 留言类别中默认选中"咨询"
				this.msgForm.findById('msgType').setValue('咨询');

			},

			submitForm : function() {
				if (this.msgForm.getForm().isValid()) {
					this.msgForm.getForm().submit({
						waitTitle : '提示',
						waitMsg : '正在提交数据, 请稍候...',
						scope : this,
						success : function(form, action) {
							if (action.result.success) {
								Ext.MessageBox.show({
									title : '消息',
									msg : '留言信息提交成功, 感谢您对我们的支持!',
									buttons : Ext.Msg.OK,
									icon : Ext.MessageBox.INFO
								});
								this.close();
							} else {
								Ext.MessageBox.show({
									title : '错误',
									msg : '提交数据错误, 请稍候再试...',
									buttons : Ext.Msg.OK,
									icon : Ext.MessageBox.ERROR
								});
							}
						},
						failure : function(form, action) {
							Ext.MessageBox.show({
								title : '错误',
								msg : '提交数据错误, 请稍候再试...',
								buttons : Ext.Msg.OK,
								icon : Ext.MessageBox.ERROR
							});
						}
					});
				} else {
					Ext.MessageBox.alert('提示', '您所提交的数据有误或不完整, 请核实...',
							Ext.Msg.INFO);
				}
			}
		});

