/// class ProspectDirector.Web.UI.Controls.ToolBarButton
/// using ProspectDirector.Web.UI.Controls.Control

/**
@class ToolBarButton
@namespace Web.UI.Controls
@constructor
**/
ProspectDirector.Web.UI.Controls.ToolBarButton = ProspectDirector.Web.UI.Controls.Control.extend({

    //===================================
    // CONSTRUCTOR
    //===================================

    init: function (options) {

        this._super($.extend({
            type: "button",
            text: "",
            command: null,
            disabled: false
        }, options));

        this.setDomNode("<button type=\"button\" class=\"btn btn-default\" title=\"" + this.getToolTip() + "\">" + this.get_text() + "</button>");

        this._registerCommand();

    },

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

    get_command: function () {
        return this.get_options().command;
    },

    get_disabled: function () {
        return this.get_options().disabled;
    },

    get_text: function () {
        return this.get_options().text;
    },

    set_text: function (value) {
        return this._options.text = value;
    },

    get_icon: function () {
        return this._options.icon;
    },

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

    getToolTip: function () {

        var result = "";

        result = this.get_options().toolTip ? this.get_options().toolTip : "";

        return result;
    },

    render: function (content) {

        if (this.get_disabled()) {
            this.get_domNode().attr("disabled", "");
        }
        else {
            this.get_domNode().removeAttr("disabled");
        }

        if (this.get_icon()) {
            this.get_domNode().append("<img src=\"" + ProspectDirector.RUNTIME.resolveUrl("~/application/icons/16x16/" + this.get_icon()) + "\" style=\"vertical-align:middle;\"/>");
        }

        return this._super(content);

    },

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

    _registerCommand: function () {

        var command = this.get_command();

        if (command === undefined || command === null) {
            return;
        }

        switch (true) {
            case $.isFunction(command):
                this.get_domNode().on("click", $.proxy(command, this));
                break;
            case $.isFunction(command.execute):
                this.get_domNode().on("click", $.proxy(command.execute, command));
                break;
        }

    }

});