Ext.define('FastUI.view.VTab', {
    extend:'Ext.Panel',
    alias:'widget.vtab',
    title:'All VTabs',
    vfactory:null,
    layout:"card",
    initComponent:function () {
        this.title = this.vfactory.getVData().title;
        this.restHelper = Ext.create('FastUI.view.RestHelper', this.vfactory.getVData().model_class);
        this.tbar = Ext.create('Ext.toolbar.Toolbar', {
            items:[
                {   text:'新建',
                    handler:function () {
                        this.cmdCreate();
                    },
                    scope:this
                },
                { text:'编辑',
                    handler:function () {
                        this.cmdEdit();
                    }, scope:this},
                { text:'列表',
                    handler:function () {
                        this.cmdList();
                    }, scope:this},
                { text:'保存',
                    handler:function () {
                        this.cmdSave();
                    }, scope:this},
                { text:'删除',
                    handler:function () {
                        this.cmdDelete();
                    }, scope:this},
                { text:'帮助',
                    handler:function () {
                        alert('帮助');
                    }, scope:this}
            ]
        });
        this.callParent();
    },
    listeners:{
        activate:function (tab, opts) {
            this.cmdList();
        }
    },
    cmdList:function () {
        if (!this.grid) {
            this.grid = Ext.create('FastUI.view.VGrid', {vfactory:this.vfactory});
            this.add(this.grid);
        }

        this.grid.getStore().reload(); // 不一定每次都要刷新 需修改
        this.getLayout().setActiveItem(this.grid.id);
    },
    cmdCreate:function () {
        if (!this.form) {
            this.form = Ext.create('FastUI.view.VForm', {vfactory:this.vfactory});
            this.add(this.form);
        }
        this.getLayout().setActiveItem(this.form.id);
        var form = this.form.getForm();
        form.url = this.restHelper.getPath('create');
        form.method = 'POST';
        form.reset();
    },
    cmdEdit:function () {
        var record = this.grid.getSelectionModel().getSelection();
        if (record) this.currentRecord = record[0];
        if (!this.form) {
            this.form = Ext.create('FastUI.view.VForm', {vfactory:this.vfactory});
            this.add(this.form);
        }

        var form = this.form.getForm();
        form.url = this.restHelper.getPath('update', this.currentRecord.get('id'));
        form.method = 'PUT';

        Ext.Ajax.request({
            url:this.restHelper.getPath('edit', this.currentRecord.get('id')),
            success:function (response) {
                var data = Ext.decode(response.responseText);
                var k, o = {};
                for (k in data) {
                    o[this.restHelper.getName() + '[' + k + ']'] = data[k];
                }
                form.setValues(o);
            }, scope:this
        });
        this.getLayout().setActiveItem(this.form.id);
    },
    cmdDelete:function () {
        var record = this.grid.getSelectionModel().getSelection();
        if (record) this.currentRecord = record[0];
        Ext.MessageBox.confirm('提示', '确定要删除此记录吗?', function (btn) {
            if (btn == 'yes') {
                Ext.Ajax.request({
                    url:this.restHelper.getPath('delete', this.currentRecord.get('id')),
                    method:'DELETE',
                    success:function () {
                        this.cmdList();
                        Ext.MessageBox.alert("提示", "操作成功！")
                    },
                    failure:function () {
                        Ext.MessageBox.alert("提示", "操作失败！")
                    },
                    scope:this
                });
            }
        }, this)

    },
    cmdSave:function () {
        if (this.form) {
            var form = this.form.getForm();
            if (form.isValid()) {
//                form.submit({
//                    scope:this,
//                    success:function (form, action) {
//                        Ext.Msg.alert('Success', action.result.msg);
//                        this.cmdList();
//                    },
//                    failure:function (form, action) {
//                        Ext.Msg.alert('Failed', action.result.msg);
//                    }
//                });
                Ext.Ajax.request({
                    url:form.url,
                    method:form.method,
                    params:form.getValues(false, false,false),
                    success:function () {
                        this.cmdList();
                        Ext.MessageBox.alert("提示", "操作成功！")
                    },
                    failure:function () {
                        Ext.MessageBox.alert("提示", "操作失败！")
                    },
                    scope:this
                });
            }
        }
    },
    constructAjaxRequest:function(){

    }
});

@@ -4460,32 +4460,34 @@
             %7D);%0A
+//
                 
@@ -4497,32 +4497,578 @@
 .Ajax.request(%7B%0A
+//                    url:form.url,%0A//                    method:form.method,%0A//                    params:form.getValues(false, false,false),%0A//                    success:function () %7B%0A//                        this.cmdList();%0A//                        Ext.MessageBox.alert(%22%E6%8F%90%E7%A4%BA%22, %22%E6%93%8D%E4%BD%9C%E6%88%90%E5%8A%9F%EF%BC%81%22)%0A//                    %7D,%0A//                    failure:function () %7B%0A//                        Ext.MessageBox.alert(%22%E6%8F%90%E7%A4%BA%22, %22%E6%93%8D%E4%BD%9C%E5%A4%B1%E8%B4%A5%EF%BC%81%22)%0A//                    %7D,%0A//                    scope:this%0A//                %7D);%0A                this.constructAjaxRequest(%7B%0A
                 
@@ -5519,33 +5519,32 @@
               %7D)
-;
 %0A            %7D%0A 
@@ -5597,11 +5597,274 @@
 ion(
-)%7B%0A
+options)%7B%0A        return Ext.Ajax.request(%7B%0A            url: options.url,%0A            method: options.method,%0A            params: options.params,%0A            success: options.success,%0A            failure: options.failure,%0A            scope: options.scope%0A        %7D);
 %0A   

use mtabs each