forked from Techsystech/web
[MIG] web_ir_actions_act_window_message: Migration to 15.0
parent
2ec24428e6
commit
f09a8e0d1f
|
@ -2,13 +2,20 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
{
|
{
|
||||||
"name": "Client side message boxes",
|
"name": "Client side message boxes",
|
||||||
"version": "14.0.1.0.0",
|
"version": "15.0.1.0.0",
|
||||||
"author": "Therp BV, " "ACSONE SA/NV, " "Odoo Community Association (OCA)",
|
"author": "Therp BV, " "ACSONE SA/NV, " "Odoo Community Association (OCA)",
|
||||||
"website": "https://github.com/OCA/web",
|
"website": "https://github.com/OCA/web",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"category": "Hidden/Dependency",
|
"category": "Hidden/Dependency",
|
||||||
"summary": "Show a message box to users",
|
"summary": "Show a message box to users",
|
||||||
"depends": ["web"],
|
"depends": ["web"],
|
||||||
"data": ["security/ir.model.access.csv", "views/templates.xml"],
|
"data": ["security/ir.model.access.csv"],
|
||||||
"qweb": ["static/src/xml/web_ir_actions_act_window_message.xml"],
|
"assets": {
|
||||||
|
"web.assets_backend": [
|
||||||
|
"web_ir_actions_act_window_message/static/src/**/**.esm.js",
|
||||||
|
],
|
||||||
|
"web.assets_qweb": [
|
||||||
|
"web_ir_actions_act_window_message/static/src/**/**.xml",
|
||||||
|
],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import {registry} from "@web/core/registry";
|
||||||
|
import Dialog from "web.Dialog";
|
||||||
|
|
||||||
|
function ir_actions_act_window_message_get_buttons(env, action, close_func) {
|
||||||
|
// Return an array of button definitions from action
|
||||||
|
return _.map(action.buttons || [], function (button_definition) {
|
||||||
|
return {
|
||||||
|
text: button_definition.name || "No name set",
|
||||||
|
classes: button_definition.classes || "btn-default",
|
||||||
|
click: function () {
|
||||||
|
if (button_definition.type === "method") {
|
||||||
|
env.services
|
||||||
|
.rpc("/web/dataset/call_button", {
|
||||||
|
model: button_definition.model,
|
||||||
|
method: button_definition.method,
|
||||||
|
args: button_definition.args,
|
||||||
|
kwargs: button_definition.kwargs,
|
||||||
|
})
|
||||||
|
.then(function (result) {
|
||||||
|
if (_.isObject(result)) {
|
||||||
|
return env.services.action.doAction(result);
|
||||||
|
}
|
||||||
|
// Always refresh the view after the action
|
||||||
|
// ex: action updates a status
|
||||||
|
const {__legacy_widget__} =
|
||||||
|
env.services.action.currentController.getLocalState();
|
||||||
|
__legacy_widget__.reload({});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return env.services.action.doAction(button_definition);
|
||||||
|
}
|
||||||
|
close_func();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function _executeWindowMessageAction({env, action}) {
|
||||||
|
var buttons = [];
|
||||||
|
if (action.close_button_title !== false) {
|
||||||
|
buttons.push({
|
||||||
|
text: action.close_button_title || env._t("Close"),
|
||||||
|
click: function () {
|
||||||
|
// Refresh the view before closing the dialog
|
||||||
|
const {__legacy_widget__} =
|
||||||
|
env.services.action.currentController.getLocalState();
|
||||||
|
__legacy_widget__.reload({});
|
||||||
|
this.close();
|
||||||
|
},
|
||||||
|
classes: "btn-default",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var is_html = action.is_html_message === true;
|
||||||
|
var content_properties = {};
|
||||||
|
|
||||||
|
if (is_html) {
|
||||||
|
content_properties = {
|
||||||
|
html: action.message,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
content_properties = {
|
||||||
|
text: action.message,
|
||||||
|
css: {
|
||||||
|
"white-space": "pre-line",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var dialog = new Dialog(
|
||||||
|
this,
|
||||||
|
_.extend({
|
||||||
|
size: "medium",
|
||||||
|
title: action.title,
|
||||||
|
$content: $("<div>", content_properties),
|
||||||
|
buttons: buttons.concat(
|
||||||
|
ir_actions_act_window_message_get_buttons(env, action, function () {
|
||||||
|
dialog.close();
|
||||||
|
})
|
||||||
|
),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return dialog.open()._opened;
|
||||||
|
}
|
||||||
|
|
||||||
|
registry
|
||||||
|
.category("action_handlers")
|
||||||
|
.add("ir.actions.act_window.message", _executeWindowMessageAction);
|
|
@ -1,109 +0,0 @@
|
||||||
/* Copyright 2017 Therp BV, ACSONE SA/NV
|
|
||||||
* * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
|
||||||
|
|
||||||
odoo.define("web.web_ir_actions_act_window_message", function (require) {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var ActionManager = require("web.ActionManager"),
|
|
||||||
core = require("web.core"),
|
|
||||||
Dialog = require("web.Dialog");
|
|
||||||
|
|
||||||
var _t = core._t;
|
|
||||||
|
|
||||||
ActionManager.include({
|
|
||||||
_handleAction: function (action, options) {
|
|
||||||
if (action.type === "ir.actions.act_window.message") {
|
|
||||||
return this._executeWindowMessageAction(action, options);
|
|
||||||
}
|
|
||||||
return this._super.apply(this, arguments);
|
|
||||||
},
|
|
||||||
_executeWindowMessageAction: function (action, options) {
|
|
||||||
var self = this,
|
|
||||||
buttons = [];
|
|
||||||
|
|
||||||
if (action.close_button_title !== false) {
|
|
||||||
buttons.push({
|
|
||||||
text: action.close_button_title || _t("Close"),
|
|
||||||
click: function () {
|
|
||||||
// Refresh the view before closing the dialog
|
|
||||||
var controller = self.getCurrentController();
|
|
||||||
if (controller && controller.widget) {
|
|
||||||
controller.widget.reload();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
classes: "btn-default",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var is_html = action.is_html_message === true;
|
|
||||||
var content_properties = {};
|
|
||||||
|
|
||||||
if (is_html) {
|
|
||||||
content_properties = {
|
|
||||||
html: action.message,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
content_properties = {
|
|
||||||
text: action.message,
|
|
||||||
css: {
|
|
||||||
"white-space": "pre-line",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
var dialog = new Dialog(
|
|
||||||
this,
|
|
||||||
_.extend(
|
|
||||||
{
|
|
||||||
size: "medium",
|
|
||||||
title: action.title,
|
|
||||||
$content: $("<div>", content_properties),
|
|
||||||
buttons: buttons.concat(
|
|
||||||
this.ir_actions_act_window_message_get_buttons(
|
|
||||||
action,
|
|
||||||
function () {
|
|
||||||
dialog.close();
|
|
||||||
}
|
|
||||||
)
|
|
||||||
),
|
|
||||||
},
|
|
||||||
options
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return dialog.open()._opened;
|
|
||||||
},
|
|
||||||
ir_actions_act_window_message_get_buttons: function (action, close_func) {
|
|
||||||
// Return an array of button definitions from action
|
|
||||||
var self = this;
|
|
||||||
return _.map(action.buttons || [], function (button_definition) {
|
|
||||||
return {
|
|
||||||
text: button_definition.name || "No name set",
|
|
||||||
classes: button_definition.classes || "btn-default",
|
|
||||||
click: function () {
|
|
||||||
if (button_definition.type === "method") {
|
|
||||||
self._rpc({
|
|
||||||
model: button_definition.model,
|
|
||||||
method: button_definition.method,
|
|
||||||
args: button_definition.args,
|
|
||||||
kwargs: button_definition.kwargs,
|
|
||||||
}).then(function (result) {
|
|
||||||
if (_.isObject(result)) {
|
|
||||||
self.do_action(result);
|
|
||||||
}
|
|
||||||
// Always refresh the view after the action
|
|
||||||
// ex: action updates a status
|
|
||||||
var controller = self.getCurrentController();
|
|
||||||
if (controller && controller.widget) {
|
|
||||||
controller.widget.reload();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
self.do_action(button_definition);
|
|
||||||
}
|
|
||||||
close_func();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,17 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<!-- Copyright 2017 Therp BV, ACSONE SA/NV
|
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
|
||||||
<odoo>
|
|
||||||
<template
|
|
||||||
id="assets_backend"
|
|
||||||
name="web_ir_actions_act_window_message assets"
|
|
||||||
inherit_id="web.assets_backend"
|
|
||||||
>
|
|
||||||
<xpath expr="." position="inside">
|
|
||||||
<script
|
|
||||||
type="text/javascript"
|
|
||||||
src="/web_ir_actions_act_window_message/static/src/js/web_ir_actions_act_window_message.js"
|
|
||||||
/>
|
|
||||||
</xpath>
|
|
||||||
</template>
|
|
||||||
</odoo>
|
|
Loading…
Reference in New Issue