mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[MIG] report_qweb_encrypt: Migration to 15.0
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import {Dialog} from "@web/core/dialog/dialog";
|
||||
import {download} from "@web/core/network/download";
|
||||
import {registry} from "@web/core/registry";
|
||||
|
||||
async function download_function(action, options, env) {
|
||||
const type = action.report_type;
|
||||
let url = `/report/${type}/${action.report_name}`;
|
||||
const actionContext = action.context || {};
|
||||
if (action.data && JSON.stringify(action.data) !== "{}") {
|
||||
// Build a query string with `action.data` (it's the place where reports
|
||||
// using a wizard to customize the output traditionally put their options)
|
||||
const action_options = encodeURIComponent(JSON.stringify(action.data));
|
||||
const context = encodeURIComponent(JSON.stringify(actionContext));
|
||||
url += `?options=${action_options}&context=${context}`;
|
||||
} else {
|
||||
if (actionContext.active_ids) {
|
||||
url += `/${actionContext.active_ids.join(",")}`;
|
||||
}
|
||||
if (type === "html") {
|
||||
const context = encodeURIComponent(
|
||||
JSON.stringify(env.services.user.context)
|
||||
);
|
||||
url += `?context=${context}`;
|
||||
}
|
||||
}
|
||||
env.services.ui.block();
|
||||
try {
|
||||
await download({
|
||||
url: "/report/download",
|
||||
data: {
|
||||
data: JSON.stringify([url, action.report_type]),
|
||||
context: JSON.stringify(env.services.user.context),
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
env.services.ui.unblock();
|
||||
}
|
||||
const onClose = options.onClose;
|
||||
if (action.close_on_report_download) {
|
||||
return env.services.action.doAction(
|
||||
{type: "ir.actions.act_window_close"},
|
||||
{onClose}
|
||||
);
|
||||
} else if (onClose) {
|
||||
onClose();
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
class EncryptDialog extends Dialog {
|
||||
onClick() {
|
||||
const action = this.props.action;
|
||||
action.context = _.extend({}, action.context, {
|
||||
encrypt_password: this.el.find(".o_password").val() || false,
|
||||
});
|
||||
return download_function(action, this.props.options, this.props.env);
|
||||
}
|
||||
}
|
||||
EncryptDialog.size = "small";
|
||||
EncryptDialog.title = "Encrypt";
|
||||
EncryptDialog.bodyTemplate = "report_qweb_encrypt.EncryptDialogBody";
|
||||
EncryptDialog.footerTemplate = "report_qweb_encrypt.EncryptDialogFooter";
|
||||
|
||||
registry
|
||||
.category("ir.actions.report handlers")
|
||||
.add("qweb-pdf-password", async function (action, options, env) {
|
||||
if (action.encrypt === "manual" && action.report_type === "qweb-pdf") {
|
||||
return env.services.dialog.add(EncryptDialog, {
|
||||
action: action,
|
||||
options: options,
|
||||
env: env,
|
||||
});
|
||||
}
|
||||
return Promise.resolve(false);
|
||||
});
|
||||
@@ -1,97 +0,0 @@
|
||||
// © 2017 Creu Blanca
|
||||
// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||
odoo.define("report_qweb_encrypt.Dialog", function (require) {
|
||||
"use strict";
|
||||
|
||||
var ActionManager = require("web.ActionManager");
|
||||
var Dialog = require("web.Dialog");
|
||||
var core = require("web.core");
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
var EncryptDialog = Dialog.extend({
|
||||
events: _.extend({}, Dialog.prototype.events, {
|
||||
change: "_onChange",
|
||||
}),
|
||||
_setValue: function () {
|
||||
this.value = this.$el.find(".o_password").val();
|
||||
},
|
||||
_onChange: function () {
|
||||
this._setValue();
|
||||
},
|
||||
});
|
||||
EncryptDialog.askPassword = function (owner, action, action_options, options) {
|
||||
var buttons = [
|
||||
{
|
||||
text: _t("Ok"),
|
||||
classes: "btn-primary",
|
||||
close: true,
|
||||
click: function () {
|
||||
var password = this.value || false;
|
||||
owner._executeReportAction(action, action_options, password);
|
||||
},
|
||||
},
|
||||
{
|
||||
text: _t("Cancel"),
|
||||
close: true,
|
||||
click: false,
|
||||
},
|
||||
];
|
||||
return new EncryptDialog(
|
||||
owner,
|
||||
_.extend(
|
||||
{
|
||||
size: "small",
|
||||
buttons: buttons,
|
||||
$content: $(
|
||||
'<div><input class="o_password" type="password"/></div>'
|
||||
),
|
||||
title: _t("Encrypt"),
|
||||
},
|
||||
options
|
||||
)
|
||||
).open();
|
||||
};
|
||||
|
||||
ActionManager.include({
|
||||
_executeReportAction: function (action, options, password) {
|
||||
if (
|
||||
action.encrypt === "manual" &&
|
||||
action.report_type === "qweb-pdf" &&
|
||||
password === undefined
|
||||
) {
|
||||
EncryptDialog.askPassword(this, action, options);
|
||||
return $.Deferred();
|
||||
} else if (action.encrypt === "manual") {
|
||||
action.context = _.extend({}, action.context, {
|
||||
encrypt_password: password,
|
||||
});
|
||||
}
|
||||
return this._super(action, options, password);
|
||||
},
|
||||
_makeReportUrls: function (action) {
|
||||
var reportUrls = this._super.apply(this, arguments);
|
||||
if (action.encrypt === "manual" && action.context.encrypt_password) {
|
||||
if (
|
||||
_.isUndefined(action.data) ||
|
||||
_.isNull(action.data) ||
|
||||
(_.isObject(action.data) && _.isEmpty(action.data))
|
||||
) {
|
||||
var serializedOptionsPath =
|
||||
"?context=" +
|
||||
encodeURIComponent(
|
||||
JSON.stringify({
|
||||
encrypt_password: action.context.encrypt_password,
|
||||
})
|
||||
);
|
||||
reportUrls = _.mapObject(reportUrls, function (value) {
|
||||
var val = value;
|
||||
val += serializedOptionsPath;
|
||||
return val;
|
||||
});
|
||||
}
|
||||
}
|
||||
return reportUrls;
|
||||
},
|
||||
});
|
||||
});
|
||||
13
report_qweb_encrypt/static/src/js/report/encrypt_dialog.xml
Normal file
13
report_qweb_encrypt/static/src/js/report/encrypt_dialog.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="report_qweb_encrypt.EncryptDialogFooter" owl="1">
|
||||
<button class="btn btn-primary" t-on-click="onClick">Ok</button>
|
||||
<button class="btn" t-on-click="close">Cancel</button>
|
||||
</t>
|
||||
|
||||
<t t-name="report_qweb_encrypt.EncryptDialogBody" owl="1">
|
||||
<div><input class="o_password" type="password" /></div>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
Reference in New Issue
Block a user