/// class ProspectDirector.Web.UI.Queries.Commands.AddFilter
/// using ProspectDirector.Web.UI.Command

/**
@class AddFilter
@constructor
@namespace Web.UI.Queries.Commands
**/
ProspectDirector.Web.UI.Queries.Commands.AddFilter = ProspectDirector.Web.UI.Command.extend({

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

    get_editor: function () {
        return this.get_options().editor;
    },

    get_selectedConstraint: function () {
        return this.get_options().selectedConstraint;
    },

    get_featureSet: function () {
        return this.get_options().featureSet;
    },

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

    execute: function () {

        if (this.get_editor().filterCount() >= 30) {

            ProspectDirector.Web.UI.MessageDialog.warn({
                message: "No more than 30 filters may be added to constraints."
            });

            return;

        }

        ProspectDirector.Web.UI.Queries.SelectColumnsDialog.open({
            data: ProspectDirector.Web.UI.Canvas.Charts.ChartUtilities.GetQuerySettings(this.get_featureSet()),
            callbacks: {
                ok: $.proxy(this.addSelectedFilters, this)
            }
        });

    },

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

    addSelectedFilters: function (sender, e) {

        var that = this,
            selectedConstraintId = this.get_selectedConstraint() ? this.get_selectedConstraint().get_id() : undefined;

        e.selections.each(function (index, item) {
            
            that.get_editor().addFilter(new ProspectDirector.Web.UI.Queries.Filter({
                data: {
                    columnId: item.id,
                    columnName: item.name
                }
            }), selectedConstraintId);

        });

    }

});
