Aliases.js 2.66 KB
Ext.define('MyMA.controller.Aliases', {
    extend: 'Ext.app.Controller',
    stores: ['Aliases'],
    views: ['Aliases','Alias'],
    refs: [{
        selector: 'aliases > grid',
        ref: 'aliasesList'
    }],
    
    init: function() {
        this.control({
            'aliases > grid > toolbar > #addrecord': {
                click: this.showForm
            },
            'aliases > grid > toolbar > #search': {
                click: this.onSearch
            },
            'aliases actioncolumn': {
                click: this.onActionColumn
            },
            'aliases > grid': {
                afterrender: this.onGridRender
            }
        });
    },
    
    
    /**
     * Handles action columns click
     * @param {Object} grid view
     * @param {HTMLElement} Element
     * @param {Integer} row index
     * @param {Integer} column index
     * @param {Object} Event object
     * @param {Object} Scope object
     * @param {Object}
     */
    onActionColumn: function(gridview, el, rowIndex, colIndex, e, scope, rowEl) {
        if(e.getTarget('.x-ibtn-edit')) {
            var record = scope.store.getAt(rowIndex);

            var widget = this.getController('Taskpanel').addProgram({
                name: 'alias'
            });

            widget.setTitle('Alias: ' + record.get('alias'));
            widget.down('form').getForm().loadRecord(record);
        }
        if(e.getTarget('.x-ibtn-delete')) {
            var record = scope.store.getAt(rowIndex);
            
            Ext.Msg.confirm('Info', 'Press Yes to confirm remove action', function(button) {
                if (button === 'yes') {
                    this.record.destroy({
                        scope: this,
                        success: function() {
                            this.store.remove(this.record)
                        }
                    });
                }
            }, {
                store: scope.store,
                record: record
            });
        }
    },
    
    
    /**
     * Show form to add new record or edit existing data
     * @param {Object} Button
     */
    showForm: function(Button) {
        this.getController('Taskpanel').addProgram({
            name: 'alias',
            title: 'New Alias'
        });
    },
    
    
    /**
     * Search action
     */
    onSearch: function(Button) {
        var store = this.getAliasesList().getStore();
        store.getProxy().extraParams = Ext.apply({}, Button.up('toolbar').getValues());
        store.reload({
            params: { }
        });
    },
    

    /**
     * Fires when widget is shown
     */
    onGridRender: function(grid) {
        grid.getStore().reload();
    }
});