/// class PD.Web.UI.Controls.ViewGrid
/// using PD.Web.UI.Controls.Control

PD.Web.UI.Controls.ViewGrid =
PD.Web.UI.Controls.Grid.extend({

    //===================================
    // CONSTRUCTORS
    //==================================

    init: function (options) {
        this._super(options);
    },

    //===================================
    // PROPERTIES
    //==================================

    get_viewStateId: function () {
        return this.get_options()["viewStateId"];
    },

    //===================================
    // PUBLIC METHODS
    //===================================

    getDefaultOptions: function () {

        return {
            autoBind: false,
            reorderable: true,
            scrollable: {
                virtual: true
            },
            showToolbar: true,
            footer: false,
            height: "100%"
        };

    },

    loadConfiguration: function () {

        var result = null;

        PD.context.createContext({
            id: this.get_id(),
            name: "View Grid",
            makeDefault: false
        });

        if (this.get_viewStateId() != null) {
            result = new PD.Web.UI.Controls.ViewGridConfiguration({
                viewStateId: this.get_viewStateId()
            });
        }

        return result;
    },

    loadDataSource: function (options, configuration) {
        return new PD.Web.UI.Controls.ViewGridDataSource({
            viewStateId: this.get_viewStateId(),
        });
    },

    addModules: function (modules) {

        var NS = PD.Web.UI.Controls;

        modules.add(new NS.ViewGridColumnMenuModule());
        modules.add(new NS.ViewGridColumnResizeModule());
        modules.add(new NS.ViewGridColumnOrderModule());
        modules.add(new NS.ViewGridColumnInlineFilterModule());
        modules.add(new NS.ViewGridHeaderModule());
        modules.add(new NS.ViewGridFooterModule());
        modules.add(new NS.ViewGridContextualFilterModule());
        modules.add(new NS.ViewGridMessageModule());

    },

    setViewState: function (viewStateId) {
        this.get_options()["viewStateId"] = viewStateId;
        this.build();
    },

    remove: function () {

        PD.context.destroyContext({
            id: this.get_id()
        });

    }

});
