app/assets/javascripts/fastui/app/view/VForm.js in fastui-0.1.3 vs app/assets/javascripts/fastui/app/view/VForm.js in fastui-0.1.4
- old
+ new
@@ -1,38 +1,43 @@
Ext.define('FastUI.view.VForm', {
- extend:'Ext.form.Panel',
+ extend: 'Ext.form.Panel',
requires: ['FastUI.view.vfield.VFieldFactory'],
- tab:{},
- bodyPadding:5,
- layout:'anchor',
+ tab: {},
+ successText:'Success',
+ failureText:'Failed',
+ invalidText:'Invalid',
+ bodyPadding: 5,
+ layout: 'anchor',
fieldDefaults: {
labelAlign: 'right',
labelWidth: 100,
//anchor: '60%'
width: 650
},
- defaultType:'textfield',
- border:false,
- initComponent:function () {
+ defaultType: 'textfield',
+ border: false,
+ initComponent: function () {
this.title = this.getValue('title');
this.items = this.getFFields();
this.callParent();
},
- getValue:function(key){
+ getValue: function (key) {
return this.tab.valueObject[key];
},
- getMEntity:function(){
+ getMEntity: function () {
return this.tab.valueObject.entity;
},
- getFFields:function () {
+ getFFields: function () {
var fields = [];
Ext.each(this.getValue('members'), function (member) {
member.readonly = member.readonly || false;
member.display = member.display || 'all';
- if (member.display == 'all' || member.display == 'form'){
- fields.push(FastUI.view.vfield.VFieldFactory.buildField(member,this.tab.winCtx, this.tab.winId,this.tab.rest));
+ member.vtype = member.vtype || '';
+
+ if (member.display == 'all' || member.display == 'form') {
+ fields.push(FastUI.view.vfield.VFieldFactory.buildField(member, this.tab.winCtx, this.tab.winId, this.tab.rest));
}
}, this);
return fields;
},
cmdCreate: function () {
@@ -43,14 +48,14 @@
this.setAutoFields(form); // 有数据时要进行测试
},
setAutoFields: function (form) {
var temp = {};
var logic = "";
- Ext.each(this.getValue('m_fields'), function (mfield) {
- if (mfield.default_logic && mfield.default_logic.length > 0) {
- logic = this.winCtx.parseCtx(this.winId, mfield.default_logic);
- temp[this.tab.rest.getTableName() + '[' + mfield.m_property.name + ']'] = Ext.decode(logic);
+ Ext.each(this.getValue('members'), function (member) {
+ if (member.default_logic) {
+ logic = this.tab.winCtx.parseCtx(this.tab.winId, member.default_logic);
+ temp[this.tab.rest.getTableName() + '[' + member.name + ']'] = Ext.decode(logic);
}
}, this);
form.setValues(temp);
},
cmdEdit: function () {
@@ -66,52 +71,41 @@
success: function (response) {
var data = Ext.decode(response.responseText);
var k, o = {};
for (k in data) {
if (k.match(/_id$/)) {
- var attr = data[k.replace('_id', '')];
- var title = data[k];
- if (attr && attr.title) {
- title = attr.title
- }
- o[this.tab.rest.getTableName() + '[' + k + ']'] = {id: data[k], title: title};
+ var attr = data[k.replace('_id', '')] || data[k];
+ o[this.tab.rest.getTableName() + '[' + k + ']'] = attr;
} else if (k.match(/_ids$/)) {
o[this.tab.rest.getTableName() + '[' + k + '][]'] = data[k];
}
else {
o[this.tab.rest.getTableName() + '[' + k + ']'] = data[k];
}
}
// alert(Ext.encode(o));
form.setValues(o);
- }, scope: this
+ },
+ failure: function (response,action) {
+ Ext.Msg.alert(this.failureText, action.result.msg);
+ },
+ scope: this
});
},
cmdSave: function () {
- var form = this.getForm();
- if (form.isValid()) {
- this.constructAjaxRequest({
- url: form.url,
- method: form.method,
- params: form.getValues(false, false, false),
- success: function () {
- Ext.MessageBox.alert("提示", "操作成功!")
- },
- failure: function () {
- Ext.MessageBox.alert("提示", "操作失败!")
- },
- scope: this
- });
- }
- },
- constructAjaxRequest: function (options) {
- return Ext.Ajax.request({
- url: options.url,
- method: options.method,
- params: options.params,
- success: options.success,
- failure: options.failure,
- scope: options.scope
- });
+ var form = this.getForm();
+ if (form.isValid()) { // make sure the form contains valid data before submitting
+ form.submit({
+ success: function (form, action) {
+ this.tab.vgrid.store.reload();
+ Ext.Msg.alert(this.successText, action.result.msg);
+ },
+ failure: function (form, action) {
+ Ext.Msg.alert(this.failureText, action.result.msg);
+ },
+ scope: this
+ });
+ } else { // display error alert if the data is invalid
+ Ext.Msg.alert(this.invalidText, 'Please correct form errors.')
+ }
}
-
});
\ No newline at end of file