Ext.define("Portfolio.ux.navigation.view.Main", {

    extend: "Ext.panel.Panel",

    requires: [
        "Portfolio.ux.navigation.view.UserRolePanel",
        "Portfolio.ux.navigation.controller.UserRole"
    ],

    layout: "fit",

    config: {
        record: null,
        entity: "",
        rolePanel: null
    },

    listeners: {
        entityready: {
            fn: function(i_self, i_record) {

                i_self.setRecord(i_record);
                i_self.add(i_self.createItems());

            },
            single: true
        },
        entitySave: {
            fn: function(i_self) {

                var i_rolePanel = i_self.getRolePanel();

                var i_controller = i_rolePanel.getController();

                i_controller.doSave(function() {
                    i_self.fireEvent("saveComplete");
                });

                return false;
            }
        }
    },

    initComponent: function() {

        var i_self = this;
        i_self.callParent(arguments);
        
    },

    createItems: function() {

        var i_self = this;

        var i_rolePanel = Ext.widget("userrolepanel", {
            record: i_self.getRecord(),
            entity: i_self.getEntity()
        });

        i_self.setRolePanel(i_rolePanel);

        var a_items = [i_rolePanel];

        return a_items;
    },

    updateRecord: function(i_record) {
        
        var i_self = this;
        var i_rolePanel = i_self.getRolePanel();

        if (i_rolePanel) {

            i_rolePanel.record = i_record;
        }
    }
});