/// class PD.Manage.Modules.DocumentTypeDeleteCommand

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

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

    setDefaults: function () {

        this.props("id", "document-type/delete");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected Document Type.");

        this.state("documentType", null);

    },

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

    isEnabled: function () {
        return this.state("documentType") != null
            && this.state("documentType").id != null;
    },

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

        var service = new PD.Manage.Services.DocumentTypeService(),
            documentType = this.state("documentType");

        PD.Web.UI.MessageDialog.warn({
            title: "Delete Document Type",
            message: this._getDeletePromptText(documentType.FileCount),
            ok: function (e) {

                e.close();

                service.deleteDocumentType(documentType.id, function () {
                    PD.context.get_default().get_events().publish("document-type/delete", {
                        id: documentType.id
                    });
                });

            }
        });

    },

    _getDeletePromptText: function (fileCount) {

        var result = ["Delete the selected document type?"];
        var prompt = [
            "<br/><br/>",
            "<b>WARNING:</b> This document type is currently in use. ",
            "Proceeding with deletion will remove this document type assignment",
            "from all documents to which it is currently assigned."
        ];

        if (fileCount > 0) {
            result = result.concat(result, prompt);
        }

        return result.join("");

    }

});