/// class PD.Web.UI.Controls.ViewGridColumnSortDescendingCommand
/// using PD.Web.UI.Controls.ViewGridColumnCommand

PD.Web.UI.Controls.ViewGridColumnSortDescendingCommand =
PD.Web.UI.Controls.ViewGridColumnCommand.extend({

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

    setDefaults: function () {
        this._super();
        this.props("id", "column/sort-descending");
        this.props("enabled", true);
        this.props("visible", true);
        this.props("icon", "arrow-down.18px.font");
        this.props("label", "Sort Descending");
        this.props("tooltip", "Sort Descending");
    },

    execute: function (e) {
        this._super(e);

        var columnId = this.get_columnId(),
            dataSource = this.get_viewGrid().get_kendo().dataSource,
            sort = dataSource._sort.slice(0),
            item = this._currentSort(sort, columnId);

        if (item != null) {
            item.dir = "desc";
        }
        else {
            sort[sort.length] = {
                field: columnId,
                dir: "desc"
            };
        }

        dataSource.sort(sort)
        dataSource.read();

    },

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

    _currentSort: function (sort, columnId) {

        var result = null;

        result = _.find(sort, function (column) {
            return column.field === columnId;
        });

        return result;

    }

});