/// class ProspectDirector.Web.UI.Queries.FilterAutoValueFeature
/// using ProspectDirector.Web.UI.Queries.FilterValueFeature

/**
@class FilterAutoValueFeature
@constructor
@namespace Web.UI.Queries
@extends Web.UI.Queries.FilterValueFeature
**/
ProspectDirector.Web.UI.Queries.FilterAutoValueFeature = ProspectDirector.Web.UI.Queries.FilterValueFeature.extend({

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

    get_valueField: function () {
        return this.get_valueWrapper().find("SELECT");
    },

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

    _valueField_onChange: function () {
        this.setValue("value", this.get_valueField().val());
        this.get_eventBus().publish("reload-target");
    },

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

    activate: function () {
        this._super();

        var that = this,
            items = new ProspectDirector.Web.List(this.get_options().init.autoValues);

        items.each(function (index, item) {
            that.get_valueField().append("<option value=\"" + item.value + "\">" + item.name + "</option>");
        });

        if (this.getValue("value") !== null) {
            this.get_valueField().val(this.getValue("value"));
        }
        else {
            this.get_valueField().val("");
        }

        this.get_valueField().on("change", $.proxy(this._valueField_onChange, this));

    },

    render: function () {

        var content = "" +
            "<label for=\"Value\" class=\"-pd-macro-editor-label\">Value</label><br/>" +
            "<select style=\"width:100%;box-sizing:border-box;\"></select>";

        return this._super(content);

    }

});