StatusModalWindow.js 3.25 KB
Ext.define('amdaUI.StatusModalWindow',{
    extend: 'Ext.window.Window',
    alias: 'widget.statusmodalwindow',

    requires:[
        'amdaUI.StatusGrid'
    ],
    statusGrid: null,
    object : null,
    constructor:function(config){
        this.object = config.object;
        this.statusGrid =  Ext.create('amdaUI.StatusGrid',{type:config.type, status : config.status})
        this.init(config);
		this.callParent();
    },

    init:function(config){
        var me=this;
        Ext.apply(this,  {
            title: 'Status Grid',
            width: 285,
            height: 250,
            closable:false,
            modal:true,
            resizable: false,
            items: [
                {
                    xtype: 'form',
                    renderTo: Ext.getBody(),
                    layout:'hbox',
                    frame: false,
                    items: [
                    {
                        flex:1,
                        items:[me.statusGrid],
                    }],

                    buttons: [{
                        text: 'Save',
                        handler: function() {

                            // Check to be sure that max > min
                            invalidRecord = null;
                            if(config.type != "cat"){
                                var records = me.statusGrid.store.getRange();
                                for (var i = 0; i < records.length; i++) {
                                    var record = records[i];
                                    if (record.get('maxVal') < record.get('minVal')) {
                                        invalidRecord = record;
                                        break;
                                    }
                                }
                                if (invalidRecord) {
                                    Ext.Msg.alert('Error', 'Max value must be greater than Min value', function() {
                                        me.statusGrid.cellEditing.startEditByPosition({row: invalidRecord, column: 0});
                                        invalidRecord = null;
                                    });
                                    return;
                                }
                            }

                            // Saving part
                            
                            config.object.set('status',me.statusGrid.getStatusString());
                            me.statusGrid.clearStore();
                            me.close();
                        },
                    },
                    {
                        // to reset the form
                        text: 'Reset',
                        handler: function() {
                            me.statusGrid.clearStore();
                            me.statusGrid.parseStatus(config.status);
                        }
                    },
                    {
                        // To quit the window
                        text: 'Cancel',
                        handler: function() {
                            me.statusGrid.clearStore();
                            me.statusGrid.destroy();
                            me.close();
                        }
                    }]
                }
            ]
        });
    }
});