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

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

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

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

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

    get_type: function () {
        return this.get_options().type;
    },

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

    execute: function () {

        var parentId = this.get_selectedConstraint() ? this.get_selectedConstraint().get_id() : undefined;

        if (this.get_editor().conditionCount() >= 20) {

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

        }

        this.get_editor().addCondition(new ProspectDirector.Web.UI.Queries.Condition({
            data: {
                operatorName: this.get_type()
            }
        }), parentId);

    }

});