/// class PD.Manage.Modules.RecycleBinEmptyCommand

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

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

    setDefaults: function () {
        this.props("id", "recycle-bin/empty");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("arrow_circle2.png"));
        this.props("label", "Empty Recycle Bin");
        this.props("tooltip", "Permanently delete all Entities in the Recycle Bin.");
    },

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

        var that = this;

        PD.Manage.Modules.RecycleBinDeleteConfirmationDialog.show({
            callback: function (e) {
                e.close();
                that._emptyRecycleBin(e.value === "delete");
            }
        });

    },

    _emptyRecycleBin: function (deleteReferences) {

        PD.Shared.Dialogs.TaskStatus.open({
            config: {
                title: "Empty Recycle Bin"
            },
            showDetail: true,
            taskStart: function (args) {

                PD.ajax({
                    type: "DELETE",
                    url: PD.Path.resolve("~/Manage/RecycleBin/Empty"),
                    data: {
                        removeReferences: deleteReferences
                    },
                    success: function (e) {
                        args.startPolling(e);
                    },
                    error: function (e) {
                        args.abort(e.responseJSON);
                        e.errorHandled = true;
                    }
                });

            },
            close: function (e) {

                PD.context
                    .get_default()
                    .get_events()
                    .publish("recycle-bin/empty");

            }
        });

    }

});