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

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

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

    setDefaults: function () {
        this._super();
        this.props("id", "column/sort-ascending");
        this.props("enabled", true);
        this.props("visible", true);
        this.props("icon", PD.Path.to16x16("sort_az_ascending2.png"));
        this.props("label", "Sort Ascending");
        this.props("tooltip", "Sort Ascending");
    },

    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 = "asc";
        }
        else {
            sort[sort.length] = {
                field: columnId,
                dir: "asc"
            };
        }

        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;

    }

});