/// class PD.Web.UI.Controls.ViewGridConfiguration
/// using PD.Web.UI.Controls.GridConfiguration

PD.Web.UI.Controls.ViewGridConfiguration =
PD.Web.UI.Controls.GridConfiguration.extend({

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

    _settings: null,

    //===================================
    // CONSTRUCTOR
    //===================================

    init: function (options) {
        this._super($.extend({
            viewStateId: null
        }, options));
    },

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

    get_settings: function () {
        return this._settings;
    },

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

    getConfiguration: function (onComplete) {

        var that = this,
            controlContext = PD.context.getContextById(this.get_grid().get_id()),
            commandContext = controlContext.get_commands();
            
        PD.ajax({
            url: that._getUrl(),
            dataType: "json",
            success: function (configuration) {
                that._settings = configuration.settings;
                onComplete(configuration);
                commandContext.setState({
                    "pd/view-grid": {
                        viewGrid: that.get_grid()
                    }
                });
            }
        });

    },

    ready: function (configuration) {

        var that = this;

        /* must add an empty column with no width for other columns to be sized correctly */
        configuration.columns[configuration.columns.length] = {
            field: null,
            template: "&nbsp;",
            attributes: {
                style: "border-width:0 0 0 1px;background-color:white;cursor:default;"
            },
            headerAttributes: {
                style: "border-width:0 0 1px;",
                "class": "-pd-noresize"
            }
        };

    },

    //===================================
    // PRIVATE METHODS
    //===================================

    _getUrl: function () {
        return PD.Path.resolve("~/view/getconfiguration?") + $.param({
            viewStateId: this.get_options()["viewStateId"]
        })
    }

});