/// class PD.Manage.Modules.ObjectModel.ExplorerFolderDeleteCommand

PD.Manage.Modules.ObjectModel.ExplorerFolderDeleteCommand =
PD.Commands.Command.extend({

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

    setDefaults: function () {

        this.props("id", "explorer-folder/delete");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected folder<br/>and all of its descendants.");

        this.state("folderId", null);
        this.state("folderRole", null);
        this.state("folderName", null);

    },

    setState: function (state) {
        this._super(state);
        this.props("enabled", this.state("folderId") != null && this.state("folderRole") == "folder");
    },

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

        var folderName = this.state("folderName");

        PD.Web.UI.MessageDialog.warn({
            title: "Delete Explorer Folder",
            message: "Delete the \"" + folderName + "\" folder and all of its subfolders?",
            ok: $.proxy(this._executeDeletion, this)
        });

    },

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

    _executeDeletion: function (e) {

        var folderId = this.state("folderId"),
            service = new PD.Manage.Services.ExplorerModelService();

        e.close();

        service.deleteFolder(folderId, function () {
            PD.context.get_default().get_events().publish("explorer-folder/delete", {
                folderId: folderId
            });
        });

    }

});