/// class ProspectDirector.Web.UI.FeatureSets.Editors.RestrictAssignmentToEditor
/// using ProspectDirector.Web.UI.FeatureSets.Editors.CompositeEditor

ProspectDirector.Web.UI.FeatureSets.Editors.RestrictAssignmentToEditor =
ProspectDirector.Web.UI.FeatureSets.Editors.CompositeEditor.extend({

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

    get_listNode: function () {
        return this.get_input().find("DIV[data-role=list]");
    },

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

    _button_onClick: function (e) {

        var that = this;

        PDJS.Manage.Views.RestrictAssignmentToDialog.open({
            selections: this.getPrimaryValue(),
            callbacks: {
                ok: function (sender, e) {
                    that.setPrimaryValue(e);
                    that._populate();
                }
            }
        });

    },

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

    activate: function () {
        this._super();
        this._populate();
    },

    render: function () {

        return "<div id='" + this.getId() + "' class='-pd-micro-editor-composite' style='height:70px;'>" +
            "<div data-role='list' style='position:absolute;top:0;bottom:0;left:0;right:20px;overflow-y:scroll;'></div>" +
            "<input type='button' value='...'>" +
        "</div>";

    },

    _populate: function () {

        var that = this;

        this.get_listNode().empty();

        _.each(this.getPrimaryValue(), function (item) {
            if (item.icon) {
                var icon = Jade.IconSet.get("pd").resolve(item.icon, Jade.IconSetSizeSpecificDirectory.x16);
                that.get_listNode().append("<div style=\"height:24px;line-height:24px;padding-left:24px;overflow:hidden;text-overflow:ellipsis;background-repeat:no-repeat;background-position:4px center;background-image:url('" + icon + "');\">" + item.name + "</div>")
            }
            else {
                that.get_listNode().append("<div style='height:24px;line-height:24px;padding-left:5px;'>" + item.name + "</div>")
            }
        });

    }

});