[REF] website: reimplement redirect field in owl

The redirect field in website does not work properly in the new views.
With this commit, we just reimplement it to make it work with the new
code.

closes odoo/odoo#96865

Related: odoo/enterprise#30178
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Géry Debongnie
2022-08-08 12:33:12 +02:00
committed by Aaron Bohy
parent f88a1e9e7e
commit 9434969d5d
4 changed files with 133 additions and 4 deletions
+3 -4
View File
@@ -161,10 +161,7 @@
'website/static/src/scss/website.backend.scss',
'website/static/src/scss/website_visitor_views.scss',
'website/static/src/scss/website.theme_install.scss',
'website/static/src/js/backend/button.js',
'website/static/src/js/backend/dashboard.js',
'website/static/src/js/backend/res_config_settings.js',
'website/static/src/js/backend/view_hierarchy.js',
'website/static/src/js/backend/**/*',
'website/static/src/js/widget_iframe.js',
'website/static/src/js/theme_preview_kanban.js',
'website/static/src/js/theme_preview_form.js',
@@ -186,6 +183,7 @@
'web.qunit_suite_tests': [
'website/static/tests/dashboard_tests.js',
'website/static/tests/website_tests.js',
'website/static/tests/redirect_field_tests.js',
],
'web.tests_assets': [
'website/static/tests/website_service_mock.js',
@@ -268,6 +266,7 @@
'website/static/src/xml/website.backend.xml',
'website/static/src/xml/website_widget.xml',
'website/static/src/xml/theme_preview.xml',
'website/static/src/js/backend/**/*',
],
'website.test_bundle': [
'/web/static/lib/qweb/qweb2.js',
@@ -0,0 +1,24 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
const { Component } = owl;
class RedirectField extends Component {
get info() {
return this.props.value ? this.env._t("Published") : this.env._t("Unpublished");
}
onClick() {
this.env.onClickViewButton({
clickParams: {
type: "object",
name: "open_website_url"
},
record: this.props.record,
});
}
}
RedirectField.template = "website.RedirectField";
registry.category("fields").add("website_redirect_button", RedirectField);
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="website.RedirectField" owl="1">
<button type="button" class="btn oe_stat_button"
t-on-click="onClick"
t-att-aria-label="info"
t-att-title="info">
<i class="fa fa-fw o_button_icon fa-globe" t-att-class="this.props.value ? 'text-success' : 'text-danger'"/>
<div class="o_stat_info">
<span class="o_stat_text">Go to<br/>Website</span>
</div>
</button>
</t>
</templates>
@@ -0,0 +1,90 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { click, getFixture } from "@web/../tests/helpers/utils";
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
let serverData;
let target;
QUnit.module("redirect_field", (hooks) => {
hooks.beforeEach(() => {
target = getFixture();
serverData = {
models: {
appointment: {
fields: {
is_published: {
string: "Is published",
type: "boolean",
searchable: true,
trim: true,
},
},
records: [
{
id: 1,
is_published: true,
},
],
},
},
};
setupViewRegistries();
});
QUnit.test("redirect field in form view is green if value=true", async function (assert) {
await makeView({
type: "form",
resModel: "appointment",
resId: 1,
serverData,
arch: `
<form>
<sheet>
<div class="oe_button_box" name="button_box">
<field name="is_published" widget="website_redirect_button" />
</div>
</sheet>
</form>`,
});
assert.containsOnce(target, ".oe_stat_button .o_button_icon.text-success")
});
QUnit.test("clicking on redirect field works", async function (assert) {
registry.category("services").add(
"action",
{
start() {
return {
doActionButton(data) {
assert.step(data.type);
assert.step(data.name);
},
};
},
},
{ force: true }
);
await makeView({
type: "form",
resModel: "appointment",
resId: 1,
serverData,
arch: `
<form>
<sheet>
<div class="oe_button_box" name="button_box">
<field name="is_published" widget="website_redirect_button" />
</div>
</sheet>
</form>`,
});
await click(target, ".oe_stat_button");
assert.verifySteps(['object', 'open_website_url']);
});
});