/// class PD.Manage.Modules.SystemSettingClearCacheCommand

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

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

    setDefaults: function (options) {

        this.props("id", "system-setting/clear-cache");
        this.props("enabled", true);
        this.props("label", "Clear Cache");
        this.props("icon", PD.Path.to16x16("arrow_circle2.png"));
        this.props("tooltip", "Clear the Application Cache.");

    },

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

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

    _showConfirmationDialog: function () {

        Jade.UI.MessageDialog.open({
            dialogStyle: Jade.UI.MessageDialogStyle.Warning,
            dialogButtons: Jade.UI.MessageDialogButtonStyle.OKCancel,
            title: "Clear Cache?",
            message: "Clear the application cache?",
            select: (e) => {
                e.close();
                if (e.button == Jade.UI.MessageDialogButton.ok) {
                    this._execute();
                }
            }
        });

    },

    _execute: function () {

        PD.ajax({
            type: "POST",
            url: PD.Path.resolve("~/Manage/Settings/ClearCache"),
            success: function () {

                Jade.UI.MessageDialog.open({
                    dialogStyle: Jade.UI.MessageDialogStyle.Success,
                    dialogButtons: Jade.UI.MessageDialogButtonStyle.OK,
                    title: "Cache Cleared",
                    message: "The application cache has been cleared successfully."
                });

            }
        })

    }

});
