/// class PD.Manage.Modules.ExtensionColumnDeleteDialogCommand

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

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

    setDefaults: function () {

        this.props("id", "extension-column/delete-dialog");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("table_selection_column_delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected Column.");

        this.state("extensionColumns", null);

    },

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

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

        var that = this;
        var extensionColumns = this.state("extensionColumns");
        var extensionColumnsIds = _.map(extensionColumns, "id");

        PD.Web.UI.MessageDialog.warn({
            title: "Delete Columns",
            message: "Delete the selected column(s)?",
            ok: function (e) {
                e.close();
                that._deleteColumns(extensionColumnsIds, null);
            }
        });

    },

    isEnabled: function () {

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

        return extensionColumns != null
            && _.isArray(extensionColumns)
            && extensionColumns.length > 0;

    },

    _deleteColumns: function (ids, confirmation) {

        var that = this;
        var service = new PD.Manage.Services.ExtensionColumnService();

        service.deleteColumns(ids, confirmation, function (e) {
            if (e.requiresConfirmation) {
                that._showDeleteConfirmationDialog(ids, e);
            }
            else {

                PD.context
                    .get_default()
                    .get_events()
                    .publish("extension-column/delete", {
                        ids: ids
                    });

            }
        });

    },

    _showDeleteConfirmationDialog: function (ids, args) {

        var that = this;

        PD.Web.UI.BoxedDialog.warn({
            title: "Data Loss Warning",
            message: "The following extension columns contain data:{{items}}Continuing with the deletion will result in the loss of this data. Continue with the deletion?",
            items: args.names,
            ok: function (e) {
                e.close();
                that._deleteColumns(ids, args.confirmation);
            }
        });

    }

});