summaryrefslogtreecommitdiff
path: root/jasper_reports/static/src/js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-09-13 12:05:33 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-09-13 12:05:33 +0700
commit8f3d096dbae18bacd95796d03b17d4d94a806c85 (patch)
treeae90032724dabe417b907db43145639e6df9565f /jasper_reports/static/src/js
parent0d87fec0c4c6fb573b1a09076f6d50844d8d0a80 (diff)
jasper report integration
Diffstat (limited to 'jasper_reports/static/src/js')
-rwxr-xr-xjasper_reports/static/src/js/report/jasperactionmanager.js100
1 files changed, 100 insertions, 0 deletions
diff --git a/jasper_reports/static/src/js/report/jasperactionmanager.js b/jasper_reports/static/src/js/report/jasperactionmanager.js
new file mode 100755
index 0000000..57616bf
--- /dev/null
+++ b/jasper_reports/static/src/js/report/jasperactionmanager.js
@@ -0,0 +1,100 @@
+odoo.define('report_xml.report', function (require) {
+ 'use strict';
+
+ var ActionManager = require('web.ActionManager');
+ var core = require('web.core');
+ var framework = require('web.framework');
+ var session = require('web.session');
+ var _t = core._t;
+
+ ActionManager.include({
+
+ _executeReportAction: function (action, options) {
+ var self = this;
+ if (action.report_type === 'jasper') {
+ return self._triggerDownload(action, options, 'jasper');
+ }
+ return this._super.apply(this, arguments);
+ },
+
+ _downloadReportJasper: function (url) {
+ var self = this;
+ framework.blockUI();
+ return new Promise(function (resolve, reject) {
+ var reporttype = url.split('/')[2];
+ var type = 'jasper';
+ var blocked = !session.get_file({
+ url: '/report/download',
+ data: {
+ data: JSON.stringify([url, type]),
+ context: JSON.stringify(session.user_context),
+ },
+ success: resolve,
+ error: (error) => {
+ self.call('crash_manager', 'rpc_error', error);
+ reject();
+ },
+ complete: framework.unblockUI,
+ });
+ if (blocked) {
+ // AAB: this check should be done in get_file service directly,
+ // should not be the concern of the caller (and that way, get_file
+ // could return a promise)
+ var message = _t('A popup window with your report was blocked. You ' +
+ 'may need to change your browser settings to allow ' +
+ 'popup windows for this page.');
+ self.do_warn(_t('Warning'), message, true);
+ }
+ });
+ },
+
+ _makeReportUrlsJasper: function (action) {
+ var reportUrls = this._makeReportUrls(action);
+ reportUrls.jasper = '/report/jasper/' + action.report_name;
+
+ // We may have to build a query string with `action.data`. It's the place
+ // were report's using a wizard to customize the output traditionally put
+ // their options.
+ if (_.isUndefined(action.data) || _.isNull(action.data) ||
+ (_.isObject(action.data) && _.isEmpty(action.data))) {
+ if (action.context.active_ids) {
+ var activeIDsPath = '/' + action.context.active_ids.join(',');
+ reportUrls = _.mapObject(reportUrls, function (value) {
+ return value += activeIDsPath;
+ });
+ }
+ reportUrls.html += '?context=' + encodeURIComponent(JSON.stringify(session.user_context));
+ } else {
+ var serializedOptionsPath = '?options=' + encodeURIComponent(JSON.stringify(action.data));
+ serializedOptionsPath += '&context=' + encodeURIComponent(JSON.stringify(action.context));
+ reportUrls = _.mapObject(reportUrls, function (value) {
+ return value += serializedOptionsPath;
+ });
+ }
+ return reportUrls;
+ },
+
+ _triggerDownload: function (action, options, type) {
+ if (type === "jasper") {
+ var self = this;
+ var reportUrls = this._makeReportUrlsJasper(action);
+ return this._downloadReportJasper(
+ reportUrls[type]).then(function () {
+ if (action.close_on_report_download) {
+ var closeAction = {
+ type: 'ir.actions.act_window_close'
+ };
+ return self.doAction(
+ closeAction, _.pick(options, 'on_close'));
+ } else {
+ return options.on_close();
+ }
+ }
+ );
+ }
+ return this._super.apply(this, arguments);
+
+ },
+
+ });
+});