/// class PD.Web.UI.Controls.ViewGridService

PD.Web.UI.Controls.ViewGridService =
Class.extend({

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

    addInlineFilter: function (viewStateId, filter, success, error) {

        var url = PD.Path.resolve("~/viewfilter/addquick?");

        PD.ajax({
            url: url + $.param({
                viewStateId: viewStateId,
                filter: JSON.stringify(filter)
            }),
            success: success,
            error: error
        });

    },

    removeFilter: function (viewStateId, columnId, success, error) {

        var that = this,
            url = PD.Path.resolve("~/viewfilter/removequick?");

        PD.ajax({
            url: url + $.param({
                viewStateId: viewStateId,
                filterId: columnId
            }),
            success: success,
            error: error
        });

    },

    clearAllFilters: function (viewStateId, success, error) {

        var that = this,
            url = PD.Path.resolve("~/viewfilter/clearquick?");

        PD.ajax({
            url: url + $.param({
                viewStateId: viewStateId
            }),
            success: success,
            error: error
        });

    },

    addColumnsLeft: function (viewStateId, sourceColumnId, columnIds, success, error) {
        this._addColumn(viewStateId, sourceColumnId, columnIds, false, success, error);
    },

    addColumnsRight: function (viewStateId, sourceColumnId, columnIds, success, error) {
        this._addColumn(viewStateId, sourceColumnId, columnIds, true, success, error);
    },

    removeColumn: function (viewStateId, columnId, success, error) {

        var url = PD.Path.resolve("~/viewcolumn/removefromdesign?")
                    + $.param({
                        viewStateId: viewStateId,
                        columnId: columnId
                    });

        PD.ajax({
            type: "POST",
            url: url,
            success: success,
            error: error
        });

    },

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

    _addColumn: function (viewStateId, sourceColumnId, columnIds, addRight, success, error) {

        PD.ajax({
            url: PD.Path.resolve("~/viewcolumn/addtodesign?"),
            type: "POST",
            data: {
                viewStateId: viewStateId,
                additions: columnIds,
                columnId: sourceColumnId,
                insertAfter: addRight
            },
            traditional: true,
            success: success,
            error: error
        });

    }

});