/// class PD.Manage.Modules.Resources.FolderPropertiesDialogCommand
/// using PD.Manage.Modules.Resources.ResourceCommand

PD.Manage.Modules.Resources.FolderPropertiesDialogCommand =
PD.Manage.Modules.Resources.ResourceCommand.extend({

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

    setDefaults: function () {
        this._super();
        this.props("id", "folder/properties-dialog");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("pencil.png"));
        this.props("label", "Properties");
        this.props("tooltip", "Edit the properties of the selected folder.");
    },

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

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

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

    _isEnabled: function () {

        var result = false,
            resource = _.first(this.getResources());

        if (resource != null) {
            result = resource.type === "folder" && !PD.Type.isEmptyGuid(resource.id);
        }

        return result && this.hasSelections() && !this.isMultiSelect();

    },

    _showDialog: function () {

        var that = this,
            resource = _.first(this.getResources());

        ProspectDirector.Web.UI.FeatureSets.NHibTargetEditorDialog.open({
            config: {
                title: "Folder Properties",
                height: "400px",
                width: "450px"
            },
            data: {
                targetArbiter: "ProspectDirector.Web.Manage.Modules.Resources.FolderArbiter",
                targetType: "ProspectDirector.Web.Manage.Modules.Resources.FolderUIO",
                targetId: resource.id,
                layoutType: ProspectDirector.Web.UI.FeatureSets.Layouts.TabStripLayout
            },
            callbacks: {
                ok: function (sender, e) {

                    PD.context.get_default().get_events().publish("folder/edit", {
                        folderId: resource.id,
                        folderName: e.target.name,
                        parentId: e.target.parentId
                    });

                }
            }
        });

    }

});