/// class PD.Web.UI.Controls.ViewGridDataSource
/// using PD.Web.UI.Controls.GridDataSource

PD.Web.UI.Controls.ViewGridDataSource =
PD.Web.UI.Controls.GridDataSource.extend({

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

    get_gridConfiguration: function () {
        return this.get_grid().get_configuration().get_instance();
    },

    get_pageSize: function () {
        return this.get_gridConfiguration()["pageSize"];
    },

    get_defaultSort: function () {
        return this.get_gridConfiguration()["sort"];
    },

    get_viewStateId: function () {
        return this._options.viewStateId;
    },

    //===================================
    // OVERRIDABLE METHODS
    //===================================

    getDataSource: function (onComplete) {

        this._dataSourceOnReadCallback = this.get_grid().getOption("dataSource.transport.read.data");

        onComplete(new kendo.data.DataSource({
            transport: {
                read: {
                    type: "POST",
                    url: PD.Path.resolve("~/view/query"),
                    data: $.proxy(this._onDataSourceRead, this)
                }
            },
            schema: {
                data: "data",
                total: "totalCount",
                model: {
                    id: "ObjectId"
                }
            },
            serverPaging: true,
            serverSorting: true,
            pageSize: this.get_pageSize(),
            sort: this.get_defaultSort(),
            change: $.proxy(this._onDataSourceChange, this),
            error: $.proxy(this._onDataSourceError, this)
        }));

    },

    getReadParameters: function () {
        return {
            viewStateId: this.get_viewStateId()
        };
    }

});