/// class PD.Manage.Modules.ExpressionEditDialogCommand

PD.Manage.Modules.ExpressionEditDialogCommand =
PD.Commands.Command.extend({

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

    get_expressions: function () {
        return this.state("expressions") || [];
    },

    get_expression: function () {
        return _.first(this.get_expressions());
    },

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

    setDefaults: function () {
        this.props("id", "expression/edit-dialog");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("pencil.png"));
        this.props("label", "Edit");
        this.props("tooltip", "Edit the selected Expression.");
        this.state("expressions", null);
    },

    setState: function (state) {
        this._super(state);
        this.props("enabled", this._isEnabled());
    },

    execute: function (e) {
        this._super(e);

        var expression = this.get_expression();

        if (expression != null) {
            this._showDialog(expression.id);
        }

    },

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

    _isEnabled: function () {
        return this.get_expression() != null && this.get_expressions().length == 1;
    },

    _showDialog: function (id) {

        ProspectDirector.Web.UI.FeatureSets.NHibTargetEditorDialog.open({
            config: {
                title: "Tag Expression Properties",
                height: 400,
                width: 500
            },
            data: {
                targetArbiter: "ProspectDirector.Web.Manage.Modules.Tags.ExpressionArbiter",
                targetType: "ProspectDirector.Web.Manage.Modules.Tags.ExpressionUIO",
                layoutType: ProspectDirector.Web.UI.FeatureSets.Layouts.TabStripLayout,
                targetId: id
            },
            callbacks: {
                ok: function (sender, e) {
                    PD.context.get_default().get_events().publish("expression/edit", {
                        id: e.target.id
                    });
                }
            }
        });

    }

});