Ext.define("App.view.SystemGroupWindow_ViewUser", {
    extend: "Ext.window.Window",
    alias: "widget.systemGroupWindow_ViewUser",
    title: App.localeRes("View User"),
    modal: true,
    resizable: true,
    height: 500,
    width: 500,
    layout: "fit",
    constrainHeader: true,

    loadWindow: function () {
        var me = this;
        me.down("grid")
        .getStore()
        .load({
            params: {
                sysGroupId: me.params.id
            },
            callback: function(records, operation, success) {}
        });
    },
    doSave: function(){
        var me = this;
        var f = me.down("form");

        if (f.isValid()) {
            f.submit({
                url: App.url("/user/sys-group/save"),
                method: 'POST',
                submitEmptyText: false,
                success: function (form, action) {
                    App.showMsg('Saved');
                    me.close();
                }
            });
        }
    },

    initComponent: function () {
        var me = this;
        Ext.apply(me, {
            items: [
                {
                    xtype: "grid",
                    padding: '4 16 0 16',
                    store: Ext.create("App.store.UserStore", {}),
                    params: {},
                    tbar: [
                        {
                            text: App.localeRes('New'),
                            margin: '0 0 16 0',
                            handler: function(){
                                App.loadModuleWin('',App.localeRes(''),{
                                    params: {},
                                });
                            }
                        }
                    ],
                    columns: [ 
                        {
                            xtype: 'rownumberer'
                        },
                        {
                            dataIndex: "username",
                            text: App.localeRes("User Name"),
                            flex: 1,
                        },
                        {
                            xtype: 'datecolumn',
                            text: App.localeRes('Create Date'),
                        },
                        {
                            text: App.localeRes('Locked'),
                        },
                        {
                            xtype: "actioncolumn",
                            width: 80,
                            align: "center",
                            items: [
                                {
                                    iconCls: "silk-cross",
                                    handler: function(view, rowIndex, colIndex, item, e, record) {
                                        var me = this;
                                        App.confirm("Confirm Delete", "User Confirm Del", function(buttonId, text, opt) {
                                            if (buttonId === "yes") {
                                                Ext.Ajax.request({
                                                    url: App.url("/user/delete"),
                                                    params: { id: record.data.id },
                                                    success: function(response, opts) {
                                                        App.showMsg("User Deleted");
                                                        me.reloadStore();
                                                    },
                                                    failure: function(response, opts) {
                                                        App.showError(
                                                            'Cannot Delete\n<@spring.message "COMMON.code"/>: ' +
                                                                response.status
                                                        );
                                                    },
                                                });
                                            }
                                        });
                                    },
                                }
                            ]
                        }
                    ],
                },
            ],
            listeners: {
                show: function () {
                    if(me.params.id){
                        me.loadWindow();
                    }
                },
                close: function (window, opts) {
                    if (me.callbackOnClose) {
                        me.callbackOnClose();
                    }
                }
            }
        });
        me.callParent(arguments);
    }
});
