/// class ProspectDirector.Web.UI.Queries.FilterScalarFunctionFeature
/// using ProspectDirector.Web.UI.FeatureSets.MacroEditorBase

/**
@class FilterScalarFunctionFeature
@constructor
@namespace Web.UI.Queries
@extends Web.UI.FeatureSets.MacroEditorBase
**/
ProspectDirector.Web.UI.Queries.FilterScalarFunctionFeature = ProspectDirector.Web.UI.FeatureSets.MacroEditorBase.extend({

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

    get_functionField: function () {
        return this.get_container().find("SELECT");
    },

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

    _functionField_onChange: function () {
        this.get_eventBus().publish("reload-target");
    },

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

    activate: function () {

        var that = this,
            items = new ProspectDirector.Web.List(this.getValue("scalarFunctions"));

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

        this.get_functionField().val(this.getValue("scalarFunctionId"));

        this.get_functionField().on("change", $.proxy(this._functionField_onChange, this));

    },

    commit: function () {
        this.setValue("scalarFunctionId", this.get_functionField().val());
    },

    render: function () {

        var result = "" +

        "<div id=\"" + this.getId() + "\" style=\"padding:10px 10px 0px 10px;\">" +
        "<label style=\"font-size:12px;\">Filter Using</label><br/>" +
        "<select style=\"width:100%;box-sizing:border-box;\"></select>" +
        "</div>";

        return result;

    }

});