/// class PD.Manage.Modules.DataLoadDeleteJobCommand

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

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

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

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

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

        var service = new PD.Manage.Services.DataLoadService(),
            jobIds = _.map(this._selectedJobs(), "id");

        this._showConfirmationDialog(function (e) {

            service.deleteJobs(jobIds, function (e) {
                PD.context.get_default().get_events().publish("jobs/delete");
            });

        });

    },

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

    _isEnabled: function () {
        return this._selectedJobs().length > 0;
    },

    _selectedJobs: function () {

        var result = [];

        if (_.isArray(this.state("jobs"))) {
            result = this.state("jobs");
        }

        return result;

    },

    _showConfirmationDialog: function (callback) {

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

        PD.Web.UI.MessageDialog.warn({
            title: "Delete Selected Jobs?",
            message: "Delete the " + jobs.length + " selected job(s)?",
            ok: function (e) {
                e.close();
                callback(e);
            }
        });

    }

});