[REF] survey: convert survey_description_page
This commit converts the field "survey_description_page" field to the new WOWL field API. Part-of: odoo/odoo#97984
This commit is contained in:
@@ -105,7 +105,10 @@ sent mails with personal token for the invitation of the survey.
|
||||
],
|
||||
'web.assets_common': [
|
||||
'survey/static/src/js/tours/survey_tour.js',
|
||||
]
|
||||
],
|
||||
'web.assets_qweb': [
|
||||
'survey/static/src/question_page/*.xml',
|
||||
],
|
||||
},
|
||||
'license': 'LGPL-3',
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { CharField } from "@web/views/fields/char/char_field";
|
||||
import { registry } from "@web/core/registry";
|
||||
|
||||
const { useEffect, useRef } = owl;
|
||||
|
||||
class DescriptionPageField extends CharField {
|
||||
setup() {
|
||||
super.setup();
|
||||
const inputRef = useRef("input");
|
||||
useEffect(
|
||||
(input) => {
|
||||
if (input) {
|
||||
input.classList.add("col");
|
||||
}
|
||||
},
|
||||
() => [inputRef.el]
|
||||
);
|
||||
}
|
||||
onExternalBtnClick() {
|
||||
this.env.openRecord(this.props.record);
|
||||
}
|
||||
}
|
||||
DescriptionPageField.template = "survey.DescriptionPageField";
|
||||
|
||||
registry.category("fields").add("survey_description_page", DescriptionPageField);
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="survey.DescriptionPageField" t-inherit="web.CharField" owl="1">
|
||||
<xpath expr="//t[@t-else='']" position="replace">
|
||||
<t t-else="">
|
||||
<div class="input-group">
|
||||
<t t-call="web.CharField"/>
|
||||
<button type="button" title="Open section" class="btn oe_edit_only o_icon_button" t-on-click.stop="onExternalBtnClick">
|
||||
<i class="fa fa-fw o_button_icon fa-external-link"/>
|
||||
</button>
|
||||
</div>
|
||||
</t>
|
||||
</xpath>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
@@ -4,7 +4,16 @@ import { QuestionPageListRenderer } from "./question_page_list_renderer";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { X2ManyField } from "@web/views/fields/x2many/x2many_field";
|
||||
|
||||
class QuestionPageOneToManyField extends X2ManyField {}
|
||||
const { useSubEnv } = owl;
|
||||
|
||||
class QuestionPageOneToManyField extends X2ManyField {
|
||||
setup() {
|
||||
super.setup();
|
||||
useSubEnv({
|
||||
openRecord: (record) => this.openRecord(record),
|
||||
});
|
||||
}
|
||||
}
|
||||
QuestionPageOneToManyField.components = {
|
||||
...X2ManyField.components,
|
||||
ListRenderer: QuestionPageListRenderer,
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { click, clickEdit, getFixture } from "@web/../tests/helpers/utils";
|
||||
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
|
||||
|
||||
QUnit.module("DescriptionPageField", (hooks) => {
|
||||
let serverData;
|
||||
let target;
|
||||
|
||||
hooks.beforeEach(() => {
|
||||
target = getFixture();
|
||||
|
||||
serverData = {
|
||||
models: {
|
||||
partner: {
|
||||
fields: { lines: { type: "one2many", relation: "lines_sections" } },
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
lines: [1, 2],
|
||||
},
|
||||
],
|
||||
},
|
||||
lines_sections: {
|
||||
fields: {
|
||||
is_page: { type: "boolean" },
|
||||
title: { type: "char", string: "Title" },
|
||||
random_questions_count: { type: "number", string: "Question Count" },
|
||||
},
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
is_page: true,
|
||||
title: "firstSectionTitle",
|
||||
random_questions_count: 4,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
is_page: false,
|
||||
title: "recordTitle",
|
||||
random_questions_count: 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
views: {
|
||||
"lines_sections,false,form": `
|
||||
<form>
|
||||
<field name="title" />
|
||||
</form>
|
||||
`,
|
||||
},
|
||||
};
|
||||
|
||||
setupViewRegistries();
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"button is visible in the edited record and allows to open that record",
|
||||
async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="is_page" invisible="1" />
|
||||
<field name="title" widget="survey_description_page"/>
|
||||
<field name="random_questions_count" />
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
});
|
||||
assert.containsN(target, "td.o_survey_description_page_cell", 2);
|
||||
assert.containsNone(target, "button.o_icon_button");
|
||||
|
||||
await clickEdit(target);
|
||||
await click(target.querySelector(".o_data_cell"));
|
||||
assert.containsOnce(target.querySelector(".o_data_row"), "button.o_icon_button");
|
||||
assert.containsNone(target, ".modal .o_form_view_dialog");
|
||||
|
||||
await click(target, "button.o_icon_button");
|
||||
assert.containsOnce(target, ".modal .o_form_view_dialog");
|
||||
}
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user