/// class PD.Manage.Modules.SelectionListDeleteCommand

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

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

    setDefaults: function () {

        this.props("id", "selection-list/delete");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected Selection List.");

        this.state("selectionList", null);

    },

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

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

        var that = this;
        var selectionList = this.state("selectionList");

        PD.Web.UI.MessageDialog.warn({
            title: "Delete Selection List",
            message: "Delete the \"" + selectionList.name + "\" selection list?",
            ok: function (e) {
                e.close();
                that._deleteList(selectionList.id, selectionList.name);
            }
        });

    },

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

    _deleteList: function (id, name) {

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

        service.deleteSelectionList(id, function (e) {
            if (e.requiresConfirmation) {
                that._showDeleteDeniedDialog(id, name);
            }
            else {
                PD.context.get_default().get_events().publish("selection-list/delete", id);
            }
        });

    },

    _showDeleteDeniedDialog: function (id, name) {

        var that = this;

        PD.Web.UI.MessageDialog.warn({
            title: "Delete List",
            message: "The \"" + name + "\" list is currently in use and cannot be deleted?",
            ok: function (e) {
                e.close();
            }
        });

    }

});