/// class PD.Manage.Modules.SyncEditDialogCommand

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

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

    get_selections: function () {
        return this.state("selections");
    },

    get_selection: function () {
        return _.first(this.get_selections());
    },

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

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

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

    execute: function (e) {
        this._super(e);
        this._showDialog(this.get_selection().id);
    },

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

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

    _showDialog: function (id) {

        ProspectDirector.Web.UI.FeatureSets.NHibTargetEditorDialog.open({
            config: {
                title: "Active Directory Sync Properties",
                height: 500,
                width: 500
            },
            data: {
                targetArbiter: "ProspectDirector.Web.Manage.Modules.Security.SyncSettingsArbiter",
                targetType: "ProspectDirector.Web.Manage.Modules.Security.SyncSettingsUIO",
                layoutType: ProspectDirector.Web.UI.FeatureSets.Layouts.TabStripLayout,
                targetId: id
            },
            callbacks: {
                ok: function (sender, e) {
                    PD.context.get_default().get_events().publish("sync/edit", {
                        id: e.target.id
                    });
                }
            }
        });

    }

});