Users.js 4.66 KB
Ext.define('MyMA.view.Users', {
    extend: 'Ext.window.Window',
    alias: 'widget.users',
    layout: 'fit',
	minimizable: true,
	constrainHeader: true,
	closeAction: 'destroy',
	width: 900,
	listeners: {
        render: function(win) {
            if(Ext.getBody().getHeight() > 500) {
                win.setHeight(Ext.getBody().getHeight() - 150);
            }
        }
    },
	items: [{
		xtype: 'grid',
		border: false,
		listeners: {
		    /**
		     * Initiate data save through proxy
		     * @param   editor : Ext.grid.plugin.Editing
		     * @param   object
             *           grid - The grid
             *           record - The record that was edited
             *           field - The field name that was edited
             *           value - The value being set
             *           row - The grid table row
             *           column - The grid Column defining the column that was edited.
             *           rowIdx - The row index that was edited
             *           colIdx - The column index that was edited
             *           originalValue - The original value for the field, before the edit (only when using CellEditing)
             *           originalValues - The original values for the field, before the edit (only when using RowEditing)
             *           newValues - The new values being set (only when using RowEditing)
             *           view - The grid view (only when using RowEditing)
             *           store - The grid store (only when using RowEditing)
		     */
		    edit: function(editor, data) {
		        if(data.originalValue == data.value) {
		            return;
		        }
		        data.record.save({
                    action: 'update',
                    scope: data,
                    success: function() {
                        this.record.commit();
                        //this.view.refresh();
                    }
                });
		    }
		},
		tbar: [{
			xtype: 'button',
			iconCls: 'x-ibtn-add',
			itemId: 'addrecord',
			text: 'New Item'
		}, {
            xtype: 'tbseparator',
            width: 5
		}, {
            xtype: 'searchfield',
            handler: 'search',
            name: 'query'
		}, {
            xtype: 'tbspacer',
            width: 5
		}, {
            xtype: 'button',
            itemId: 'search',
            text: 'Search'
		}],
		bbar: {
			xtype: 'pagingtoolbar',
			displayInfo: true,
			store: 'Users'
		},
		plugins: [
            Ext.create('Ext.grid.plugin.CellEditing', {
                clicksToEdit: 1
            })
        ],
        selModel: {
            selType: 'cellmodel'
        },
		columns: [{
		    xtype: 'actioncolumn',
            width: 30,
            items: [{
                getClass: function() {
                    return 'x-ibtn-edit x-ibtn-def';
                }
            }]
		}, {
			header: 'ID',
			dataIndex: 'id',
			width: 40
		}, {
			header: 'Name',
			dataIndex: 'name',
			editor: {
				xtype: 'textfield'
			},
			flex: 1
		}, {
		    header: 'Login',
		    dataIndex: 'login',
		    width: 120
		}, {
		    header: 'Password',
		    hidden: true,
            dataIndex: 'passwd'
		}, {
		    header: 'uid',
            dataIndex: 'uid',
            width: 40
		}, {
		    header: 'gid',
            dataIndex: 'gid',
            width: 40
		}, {
		    header: 'Mail directory',
            dataIndex: 'maildir'
		}, {
		    header: 'SMTP',
            dataIndex: 'smtp',
            editor: {
                xtype: 'combo',
                valueField: 'id',
                displayField: 'name',
                triggerAction: 'all',
                editable: false,
                store: 'Choice'
            },
            renderer: function(value) {
                if(value==1) {
                    return 'Yes';
                }
                return 'No';
            }
		}, {
			header: 'IMAP',
            dataIndex: 'imap',
            editor: {
                xtype: 'combo',
                valueField: 'id',
                displayField: 'name',
                triggerAction: 'all',
                editable: false,
                store: 'Choice'
            },
            renderer: function(value) {
                if(value==1) {
                    return 'Yes';
                }
                return 'No';
            }
		}, {
		    header: 'Quota',
            dataIndex: 'quota',
            editor: {
                xtype: 'numberfield',
                allowDecimal: false
            }
		}, {
            xtype: 'actioncolumn',
            width: 30,
            items: [{
                getClass: function() {
                    return 'x-ibtn-delete x-ibtn-def';
                }
            }]
		}],
		store: 'Users'
	}]
});