Plugins.ThreeGiG.ProspectDirector.BuiltIn.DownloadReportAction =
PD.Actions.ActionDefinition.extend({

    init: function (options) {

        this._super({
            id: "download-report",
            pluginId: "builtin",
            name: "Download Report",
            description: "Downloads the specified report.",
            parameters: [
                new PD.Actions.ActionParameterDefinition({
                    name: "Entity ID",
                    type: PD.Actions.ActionParameterType.INTEGER,
                    required: true,
                    description: "The ID of the entity from which the report should be downloaded."
                }),
                new PD.Actions.ActionParameterDefinition({
                    name: "Report ID",
                    type: PD.Actions.ActionParameterType.INTEGER,
                    required: true,
                    description: "The ID of the report to be downloaded."
                })
            ]
        });

    },

    method: function (entityId, reportId) {

        if (reportId == null) {
            this._showErrorDialog("Report ID");
            return;
        }

        if (entityId == null) {
            ProspectDirector.RUNTIME.iframeRequest("~/Shared/Report/Export?id=" + reportId);
        }
        else {
            ProspectDirector.RUNTIME.iframeRequest("~/Shared/Report/Export?id=" + reportId + "&entityId="  + entityId);
        }

    },

    _showErrorDialog: function (label) {

        ProspectDirector.Web.UI.MessageDialog.warn({
            message: "Cannot complete the 'Download Report Action' because no " + label + " has been specified."
        });

    }

});