/// class PD.Web.UI.Controls.ViewGridMessageModule
/// using PD.Web.UI.Controls.GridModule

PD.Web.UI.Controls.ViewGridMessageModule =
PD.Web.UI.Controls.GridModule.extend({

    //===================================
    // EVENT HANDLERS
    //===================================

    _onDataBound: function () {
        this.get_grid().clearMessage();
        this._noRecordsCheck();
        this._noColumnsCheck();
    },

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

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

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

    start: function () {
    
        this.get_kendo().bind(
            "dataBound",
            $.proxy(this._onDataBound, this));

    },

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

    _noColumnsCheck: function () {

        var columnsArray = this.get_configuration().get_instance().columns; 
        var columnCount = columnsArray == null ? 1 : columnsArray.length;

        if (columnCount === 1) {
            this.get_grid().addMessage("Click to add columns", this._showColumnDesignDialog);
        };

    },

    _noRecordsCheck: function () {

        var recordCount = this.get_dataSource().get_instance().total();

        if (recordCount === 0) {
            this.get_grid().addMessage("No records found");
        };

    },

    _showColumnDesignDialog: function () {

        var that = this;

        ProspectDirector.Modules.Views.ViewDesignColumnsDialog.Dialog.show({
            params: {
                viewStateId: this.get_grid().get_viewStateId()
            },
            callbacks: {
                ok: function () {
                    that.get_grid().build();
                }
            }
        });

    }

});