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

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

    //===================================
    // FIELDS
    //===================================

    _items: null,

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

    init: function (options) {

        var content = null;

        this._super(options);

        content =
        "<div class=\"btn-group\">" +
            "<ul class=\"dropdown-menu\" role=\"menu\">" +
            "</ul>" +
        "</div>";

        this.setDomNode(content);

        this._addButton();

        this._items = new ProspectDirector.Web.List(options.items);

    },

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

    get_items: function () {
        return this._items;
    },

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

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

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

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

    render: function (content) {

        var that = this;

        this.get_items().each(function (index, data) {

            var item = new ProspectDirector.Web.UI.Controls.ToolBarItem(data);
            that.get_domNode().children("UL").append(item.render());

        });

        return this._super(content);

    },

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

    _addButton: function () {

        var $button = $("<button type=\"button\" class=\"btn btn-default dropdown-toggle\" data-toggle=\"dropdown\"></button>");

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

        $button.append(this.get_text());
        $button.append("<span class=\"caret\"></span>");

        $button.insertBefore(this.get_domNode().children("UL").first());

    }

});