[IMP] hr_recruitment: convert widget to Owl

Convert the ApplicantChar (opening the form view of the applicant) to
Owl.

closes odoo/odoo#101495

X-original-commit: d1ff94c6675acff76b19ff984fcbc89805bd4d38
Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
Kevin Baptiste
2022-09-29 09:08:58 +02:00
parent a32bca2bdc
commit 55f75818a1
6 changed files with 48 additions and 51 deletions
+3 -2
View File
@@ -41,8 +41,9 @@
'application': True,
'assets': {
'web.assets_backend': [
'hr_recruitment/static/src/scss/*.scss',
'hr_recruitment/static/src/js/recruitment.js',
'hr_recruitment/static/src/**/*.js',
'hr_recruitment/static/src/**/*.scss',
'hr_recruitment/static/src/**/*.xml',
'hr_recruitment/static/src/js/tours/hr_recruitment.js',
],
},
@@ -0,0 +1,30 @@
/** @odoo-module */
import { CharField } from "@web/views/fields/char/char_field";
import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks";
export class ApplicantCharField extends CharField {
setup() {
super.setup();
this.action = useService("action");
}
onClick() {
const record = this.props.record.data;
if (record.res_id !== undefined && record.res_model == 'hr.applicant') {
this.action.doAction({
type: 'ir.actions.act_window',
res_model: 'hr.applicant',
res_id: record.res_id,
views: [[false, "form"]],
view_mode: "form",
target: "current",
});
}
}
}
ApplicantCharField.template = "hr_recruitment.ApplicantCharField";
registry.category("fields").add("applicant_char", ApplicantCharField);
@@ -0,0 +1,7 @@
.o_field_applicant_char {
color: $link-color;
&:hover {
color: $link-hover-color;
}
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="hr_recruitment.ApplicantCharField" t-inherit="web.CharField" t-inherit-mode="primary" owl="1">
<xpath expr="//span[@t-esc='formattedValue']" position="attributes">
<attribute name="t-on-click.prevent.stop">onClick</attribute>
</xpath>
</t>
</templates>
@@ -1,41 +0,0 @@
/** @odoo-module **/
import fieldRegistry from 'web.field_registry';
import { FieldChar, StateSelectionWidget } from 'web.basic_fields';
const RecruitmentStateSelectionWidget = StateSelectionWidget.extend({
init() {
this._super(...arguments);
this.mode = 'edit';
},
});
const ApplicantChar = FieldChar.extend({
events: _.extend({}, FieldChar.prototype.events, {
'click': '_onClick',
}),
_onClick(ev) {
if (this.recordData['res_id'] !== undefined && this.recordData['res_model'] === 'hr.applicant') {
ev.stopPropagation();
this.do_action({
type: 'ir.actions.act_window',
res_model: 'hr.applicant',
res_id: this.recordData['res_id'],
views: [[false, "form"]],
view_mode: "form",
target: "current",
});
}
},
_renderReadonly() {
this._super(...arguments);
this.$el.addClass('o_hr_applicant_widget');
}
});
fieldRegistry
.add('recruitment_state_selection', RecruitmentStateSelectionWidget)
.add('applicant_char', ApplicantChar);
@@ -13,11 +13,3 @@
}
}
}
.o_hr_applicant_widget {
color: $link-color;
&:hover {
color: $link-hover-color;
}
}