[IMP] hr_fleet: migrate hr_fleet_kanban to wowl2
closes odoo/odoo#101681 X-original-commit: 443123b64e2984026541c44c524f20c7f08eda0b Signed-off-by: Kevin Baptiste <kba@odoo.com> Signed-off-by: William Braeckman (wbr) <wbr@odoo.com>
This commit is contained in:
@@ -19,8 +19,7 @@
|
||||
],
|
||||
'assets': {
|
||||
'web.assets_backend': [
|
||||
'hr_fleet/static/src/js/attachment_kanban.js',
|
||||
'hr_fleet/static/src/xml/attachment_kanban.xml',
|
||||
'hr_fleet/static/src/views/**/*',
|
||||
],
|
||||
},
|
||||
'auto_install': True,
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import KanbanController from 'web.KanbanController';
|
||||
import KanbanView from 'web.KanbanView';
|
||||
import viewRegistry from 'web.view_registry';
|
||||
import { qweb } from 'web.core';
|
||||
import config from 'web.config'
|
||||
|
||||
const HRFleetKanbanController = KanbanController.extend({
|
||||
buttons_template: 'HRFleetKanbanView.buttons',
|
||||
events: _.extend({}, KanbanController.prototype.events, {
|
||||
'click .o_button_upload_fleet_attachment': '_onUpload',
|
||||
'change .o_fleet_documents_upload .o_form_binary_form': '_onAddAttachment',
|
||||
}),
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
init: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this.isMobile = config.device.isMobileDevice;
|
||||
},
|
||||
|
||||
start: function () {
|
||||
// define a unique uploadId and a callback method
|
||||
this.fileUploadID = _.uniqueId('hr_fleet_document_upload');
|
||||
$(window).on(this.fileUploadID, () => this.trigger_up('reload'));
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
_onUpload: function (event) {
|
||||
// If hidden upload form doesn't exist, create it
|
||||
var $formContainer = this.$('.o_content').find('.o_fleet_documents_upload');
|
||||
if (!$formContainer.length) {
|
||||
$formContainer = $(qweb.render('HRFleet.DocumentsHiddenUploadForm', {widget: this}));
|
||||
$formContainer.appendTo(this.$('.o_content'));
|
||||
}
|
||||
// Trigger the input to select a file
|
||||
this.$('.o_fleet_documents_upload .o_input_file').click();
|
||||
},
|
||||
|
||||
_onAddAttachment: function(ev) {
|
||||
// Auto submit form once we've selected an attachment
|
||||
const $input = $(ev.currentTarget).find('input.o_input_file');
|
||||
if ($input.val() !== '') {
|
||||
const $binaryForm = this.$('.o_fleet_documents_upload form.o_form_binary_form');
|
||||
$binaryForm.submit();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const HRFleetKanbanView = KanbanView.extend({
|
||||
config: _.extend({}, KanbanView.prototype.config, {
|
||||
Controller: HRFleetKanbanController,
|
||||
}),
|
||||
})
|
||||
|
||||
viewRegistry.add('hr_fleet_kanban_view', HRFleetKanbanView);
|
||||
@@ -0,0 +1,38 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { KanbanController } from "@web/views/kanban/kanban_controller";
|
||||
import { useBus, useService } from "@web/core/utils/hooks";
|
||||
|
||||
const { useRef } = owl;
|
||||
|
||||
export class HrFleetKanbanController extends KanbanController {
|
||||
setup() {
|
||||
super.setup(...arguments);
|
||||
this.uploadFileInput = useRef("uploadFileInput");
|
||||
this.uploadService = useService("file_upload");
|
||||
useBus(
|
||||
this.uploadService.bus,
|
||||
"FILE_UPLOAD_LOADED",
|
||||
() => {
|
||||
this.model.load();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
async onInputChange(ev) {
|
||||
if (!ev.target.files) {
|
||||
return;
|
||||
}
|
||||
this.uploadService.upload(
|
||||
"/web/binary/upload_attachment",
|
||||
ev.target.files,
|
||||
{
|
||||
buildFormData: (formData) => {
|
||||
formData.append("model", "fleet.vehicle.assignation.log");
|
||||
formData.append("id", this.props.context.active_id);
|
||||
},
|
||||
},
|
||||
);
|
||||
ev.target.value = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
<t t-name="hr_fleet.HrFleetKanbanController.Buttons" t-inherit="web.KanbanView.Buttons" t-inherit-mode="primary" owl="1">
|
||||
<xpath expr="//button[hasclass('o-kanban-button-new')]" position="replace">
|
||||
<input type="file" multiple="true" t-ref="uploadFileInput" class="o_input_file o_hidden" t-on-change.stop="onInputChange"/>
|
||||
<button type="button" t-att-class="'d-none d-md-block btn' + (!env.isSmall ? ' btn-primary' : 'btn-secondary')" t-on-click="() => this.uploadFileInput.el.click()">
|
||||
Upload
|
||||
</button>
|
||||
</xpath>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -0,0 +1,12 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
import { kanbanView } from "@web/views/kanban/kanban_view";
|
||||
import { HrFleetKanbanController } from "@hr_fleet/views/hr_fleet_kanban/hr_fleet_kanban_controller";
|
||||
|
||||
export const hrFleetKanbanView = {
|
||||
...kanbanView,
|
||||
Controller: HrFleetKanbanController,
|
||||
buttonTemplate: "hr_fleet.HrFleetKanbanController.Buttons",
|
||||
};
|
||||
registry.category("views").add("hr_fleet_kanban_view", hrFleetKanbanView);
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<templates>
|
||||
<t t-name="HRFleet.DocumentsHiddenUploadForm">
|
||||
<div class="d-none o_fleet_documents_upload">
|
||||
<t t-call="HiddenInputFile">
|
||||
<t t-set="multi_upload" t-value="true"/>
|
||||
<t t-set="fileupload_id" t-value="widget.fileUploadID"/>
|
||||
<t t-set="fileupload_action" t-translation="off">/web/binary/upload_attachment</t>
|
||||
<input type="hidden" name="model" t-att-value="'fleet.vehicle.assignation.log'"/>
|
||||
<input type="hidden" name="id" t-att-value="widget.initialState.context.active_id"/>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
<t t-extend="KanbanView.buttons" t-name="HRFleetKanbanView.buttons">
|
||||
<t t-jquery="button[t-attf-class*=o-kanban-button-new]" t-operation="replace">
|
||||
<button type="button" t-att-class="'d-none d-md-block btn' + (!widget.isMobile ? ' btn-primary' : 'btn-secondary') + ' o_button_upload_fleet_attachment'">
|
||||
Upload
|
||||
</button>
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
||||
Reference in New Issue
Block a user