/// class PD.Manage.Modules.DataModel
// using PD.Manage.Module

PD.Manage.Modules.DataModel =
PD.Manage.Module.extend({

    //===================================
    // FIELDS
    //===================================

    _splitter: null,
    _grid: null,
    _extensions: null,

    //===================================
    // EVENT HANDLERS
    //===================================

    onInit: function () {
        this.data("hasToolbar", false);
        this.initExtensions();
        this.initColumns();
    },

    onActivate: function (e) {

        var that = this;

        this._splitter = this.get_node().find("[data-id=splitter]").kendoSplitter({
            orientation: "horizontal",
            panes: [
                { size: "275px" },
                {}
            ],
            resize: PD.BCL.Util.debounce(function () {
                that._splitter._resize();
            }, 20)
        }).data("kendoSplitter");

    },

    onFocus: function () {
        this._splitter.resize();
    },

    onRemove: function () {
        if (this._splitter != null) {
            this._splitter.destroy();
        }
    },

    prepare: function () {

        var that = this;

        PD.ajax({
            url: PD.Path.resolve("~/Manage/DataModel"),
            data: {
                id: this.data("targetId")
            },
            success: function (data) {
                that.data("extensionsViewStateId", data.extensionsViewStateId);
                that.data("viewStateId", data.viewStateId);
                that.data("isList", data.isList);
                that.ready();
            },
            error: function (e) {
                that.error();
                e.errorHandled = true;
            }
        });

    },

    //===================================
    // PROTECTED METHODS
    //===================================

    initExtensions: function () {

        this._extensions = new PD.Manage.Modules.DataModelExtensions({
            insertAt: "[data-id=splitter]",
            viewStateId: this.data("extensionsViewStateId"),
            isList: this.data("isList")
        });

        this.get_children().add(this._extensions);

    },

    initColumns: function () {

        var that = this;

        this._grid = new PD.Manage.Modules.DataModelColumns({
            insertAt: "[data-id=splitter]",
            viewStateId: this.data("viewStateId"),
            isList: that.data("isList")
        });

        this.get_children().add(this._grid);

    },

    template: function (e) {
        return [
            "<div style='position:absolute;top:10px;left:10px;right:10px;bottom:10px;box-sizing:border-box;'>",
                "<div data-id='splitter' class='-pd-minimal-splitter' style='height:100%;'></div>",
            "</div>"
        ];
    }

});
