/// class PD.Manage.Modules.LicenseDeleteCommand

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

    //===================================
    // PROPERTIES
    //===================================

    get_selection: function () {
        return this.state("selection");
    },

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

    setDefaults: function () {

        this.props("id", "license/delete");
        this.props("enabled", false);
        this.props("icon", PD.Path.to16x16("delete.png"));
        this.props("label", "Remove License");
        this.props("tooltip", "Removes the license from the selected product.");
        this.state("selection", []);

    },

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

    isEnabled: function () {
        return this.get_selection() != null
            && this.get_selection() != "Missing";
    },

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

        var license = this.get_selection();
        var service = new PD.Manage.Services.LicenseService();

        PD.Web.UI.MessageDialog.warn({
            title: "Remove License",
            message: "Remove the selected license?",
            ok: function (e) {

                e.close();

                service.delete(license.id, function () {
                    PD.context
                        .get_default()
                        .get_events()
                        .publish("license/deleted", {
                        id: license.id
                    });
                });

            }
        });

    }

});