Alias.js 1.54 KB
/**
 * Conroller: Alias
 * 
 */
Ext.define('MyMA.controller.Alias', {
    extend: 'Ext.app.Controller',
    views: ['Alias'],
    refs: [{
        selector: 'alias',
        ref: 'aliasWindow'
    }],
    
    init: function() {
        this.control({
            'alias > toolbar > #savedata': {
                click: this.saveData
            }
        });
    },
    
    saveData: function(Button) {
        var form = this.getAliasWindow().down('form').getForm(),
            id = form.getValues().id || null;

        if(!form.isValid()) {
            return false;
        }
        
        form.submit({
        	url: Ext.Ajax.getRestUrl('api','alias', id),
            clientValidation: true,
            method: id > 0 ? 'PUT' : 'POST',
            scope: {
            	controller: this,
                win: this.getAliasWindow()
            },
            success: this.onSuccessSubmit,
            failure: this.onFailSubmit
        });
    },


    /**
     *
     */
    onSuccessSubmit: function(form, action) {
        this.win.close();
        this.controller.getController('Aliases').getStore('Aliases').reload({
            params: {
            	start: 0
            }
        });
        Ext.Msg.showInfo({
            msg: 'Data saved'
        })
    },


    /**
     *
     */
    onFailSubmit: function(form, action) {
        try {
            var data = Ext.decode(action.response.responseText);
            throw(data);
        }
        catch(e) {
            Ext.Msg.showError({
                msg: e
            });
        }
    }
});