/// class PD.Manage.Modules.MailQueueDeleteAllCommand

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

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

    setDefaults: function () {
        this.props("id", "mail-queue-item/delete-all");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete All");
        this.props("tooltip", "Delete all messages in the queue.");
    },

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

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Warning,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            allowClose: true,
            title: "Delete Queued Messages",
            message: "Delete all the queued messages in the queue?",
            select: (e) => {
                e.close();
                if (e.button === Jade.UI.MessageDialogButton.ok) {
                    this._executeDelete();
                }
            }
        });

    },

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

    _executeDelete: function () {

        let service = new PD.Manage.Services.MailQueueService();

        service.deleteAll(function () {
            PD.context
                .get_default()
                .get_events()
                .publish("mail-queue-item/delete-all");
        });

    }

});