/// class PD.Manage.Modules.GroupDeleteCommand

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

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

    setDefaults: function () {
        this.props("id", "group/delete");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected Group.");
        this.state("groups", null);
    },

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

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

        var service = new PD.Manage.Services.GroupService(),
            group = _.first(this.state("groups"));

        this._showConfirmationDialog(group, function (e) {

            service.deleteGroup(group.id, function (e) {
                PD.context.get_default().get_events().publish("group/delete", {
                    id: group.id
                });
            });

        });

    },

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

    _isEnabled: function () {
        return _.isArray(this.state("groups"))
            && this.state("groups") != null;
    },

    _showConfirmationDialog: function (group, callback) {

        ProspectDirector.Web.UI.MessageDialog.confirm({
            message: "Delete the \"" + group.name + "\" group?",
            buttons: {
                ok: {
                    label: "OK",
                    callback: callback
                },
                cancel: {
                    label: "Cancel"
                }
            }
        });

    }

});