/// class PD.Manage.Modules.Rules.RuleScriptDeleteCommand
// PD.Commands.Command

PD.Manage.Modules.Rules.RuleScriptDeleteCommand =
PD.Commands.Command.extend({

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

    setDefaults: function () {
        this._super();
        this.props("id", "rule-script/delete");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Delete");
        this.props("tooltip", "Delete the selected Rule Script.");
        this.state("rulescript", null);
    },

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

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

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

        PD.Web.UI.MessageDialog.warn({
            title: "Delete Rule Script?",
            message: "Delete the '" + rulescript.name + "' rule script?",
            ok: $.proxy(this._executeDeletion, this)
        });

    },

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

    _isEnabled: function () {

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

        return rulescript != null
            && rulescript.isBuiltIn !== true;

    },

    _executeDeletion: function (e) {

        var rulescript = this.state("rulescript"),
            service = new PD.Manage.Services.RulesService();

        e.close();

        service.deleteRuleScript(rulescript.id, function () {
            PD.context.get_default().get_events().publish("rule-script/delete");
        });

    }
});