// <#-- Group Form <Group Auth Grid Left> -->
Ext.define("App.view.GroupAuthGridLeft", {
    extend: "App.view.CustomSearchPanel",
    xtype: "groupAuthGridLeft",
    title: App.localeRes("Authority"),
    id: "groupAuthGridLeft",
    layout: "fit",
    width: "100%",
    height: "100%",
    fil:"authority",

    reloadStore: function() {
        this.getStore().reload();
    },

    initComponent: function() {
        var me = this;
        Ext.apply(me, {
            store: Ext.create("App.store.AuthStore", {}),
            columns: [
                {
                    xtype: "actioncolumn",
                    flex: 1,
                    width: 70,
                    align: "center",
                    items: [
                        {
                            iconCls: "x-fa fa-lg fa-plus-circle",
                            handler: function(view, rowIndex, colIndex, item, e, record) {
                                var leftStore = me.getStore();
                                var rightStore = me
                                    .up("container")
                                    .down("groupAuthGridRight")
                                    .getStore();
                                record.data.v = true;
                                record.dirty = true;
                                record.phantom = false;
                                rightStore.add(record);
                            },
                            scope: me
                        }
                    ]
                },
                {
                    xtype: "gridcolumn",
                    dataIndex: "name",
                    text: App.localeRes("Name"),
                    flex: 7
                },
            ],
            features: [
                {
                    ftype: "grouping",
                    enableGroupingMenu: true,
                    groupHeaderTpl: '{name}',
                    startCollapsed: true
                }
            ],
            listeners: {
                added: function(panel, parent, pos, opts) {
                    me.getStore().load({
                        callback: function(records, operation, success) {}
                    });
                }
            }
        });

        me.callParent(arguments);
    }
});

// <#-- Group Form <Group Auth Grid right> -->
Ext.define("App.view.GroupAuthGridRight", {
    extend: "Ext.grid.Panel",
    xtype: "groupAuthGridRight",
    alias: "widget.groupAuthGridRight",
    id: "GroupAuthGridRight",
    width: "100%",
    height: "100%",
    plugins: ["gridfilters"],

    initComponent: function() {
        var me = this;
        Ext.apply(me, {
            store: Ext.create("App.store.GroupAuthStore", {}),
            columns: [
                {
                    xtype: "actioncolumn",
                    flex: 1,
                    width: 70,
                    align: "center",
                    items: [
                        {
                            iconCls: "x-fa fa-lg fa-minus-circle",
                            handler: function(view, rowIndex, colIndex, item, e, record) {
                                var leftSto = me
                                    .up("container")
                                    .down("groupAuthGridLeft")
                                    .getStore();
                                var leftStoV = leftSto.findRecord("authority", record.data.authority);
                                leftStoV.data.v = false;
                                leftStoV.dirty = true;
                                leftStoV.phantom = false;
                                console.log(leftStoV);

                                var rightSto = me.getStore();
                                rightSto.remove(record);
                            },
                            scope: me
                        }
                    ]
                },
                {
                    xtype: "gridcolumn",
                    dataIndex: "name",
                    text: App.localeRes("name"),
                    flex: 7
                },
                {
                    xtype: "gridcolumn",
                    dataIndex: "v",
                    text: "selected",
                    flex: 7,
                    hidden: true,
                    filter: {
                        type: "boolean",
                        value: true
                    }
                }
            ],
            listeners: {
                added: function(panel, parent, pos, opts) {
                    if (me.params.record) {
                        console.log(me.params.record.data.id);
                        me.getStore().load({
                            params: { id: me.params.record.data.id },
                            callback: function(records, operation, success) {}
                        });
                    }
                }
            }
        });

        me.callParent(arguments);
    }
});
