/// class PD.Manage.Modules.ObjectModel.EntityTypeDeleteCommand

PD.Manage.Modules.ObjectModel.EntityTypeDeleteCommand =
PD.Commands.Command.extend({

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

    setDefaults: function () {

        this.props("id", "entity-type/delete");
        this.props("enabled", true);
        this.props("icon", PD.Path.to16x16("DELETE.PNG"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected Entity Type.");

        this.state("entityTypeId", null);
        this.state("entityTypeName", null);

    },

    setState: function (state) {
        this._super(state);
        this.props("enabled", this.state("entityTypeId") != null)
    },

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

        var that = this,
            entityTypeId = this.state("entityTypeId"),
            entityTypeName = this.state("entityTypeName");

        PD.Web.UI.MessageDialog.warn({
            title: "Delete Entity Type",
            message: "Delete the \"" + entityTypeName + "\" entity type?",
            ok: function (e) {
                that._executeDeletion(e, entityTypeId)
            }
        });

    },

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

    _executeDeletion: function (e, entityTypeId) {

        var service = new PD.Manage.Services.EntityTypeService();

        e.close();

        service.deleteEntityType(entityTypeId, function (data) {
            PD.context.get_default().get_events().publish("entity-type/delete", {
                id: entityTypeId
            });
        });

    }

});