Skip to content
Snippets Groups Projects
Commit 9c0f10bd authored by Yannick Tivisse's avatar Yannick Tivisse
Browse files

[IMP] data_recycle: Migrate to Owl


closes odoo/odoo#98693

Related: odoo/enterprise#30666
Signed-off-by: default avatarYannick Tivisse (yti) <yti@odoo.com>
parent b38a5f78
Branches
Tags
No related merge requests found
......@@ -21,10 +21,10 @@
'application': True,
'assets': {
'web.assets_backend': [
'data_recycle/static/src/js/**/*',
'data_recycle/static/src/views/*.js',
],
'web.assets_qweb': [
'data_recycle/static/src/xml/**/*',
'data_recycle/static/src/views/*.xml',
],
},
'license': 'LGPL-3',
......
odoo.define('data_recycle.CommonListController', function (require) {
"use strict";
var ListController = require('web.ListController');
var DataCommonListController = ListController.extend({
/**
* Open the form view of the original record, and not the data_merge.record view
* @override
*/
_onOpenRecord: function(event) {
var record = this.model.get(event.data.id, {raw: true});
this.do_action({
type: 'ir.actions.act_window',
views: [[false, 'form']],
res_model: record.data.res_model_name,
res_id: record.data.res_id,
context: {
create: false,
edit: false
}
});
},
/**
* Render the "Merge" & "Unselect" buttons when records are selected
* @override
*/
_updateControlPanel: function() {
this._super.apply(this, arguments);
if(this.selectedRecords.length > 0) {
$('.o_list_buttons').removeClass('d-none');
} else {
$('.o_list_buttons').addClass('d-none');
}
},
/**
* Unselect all the records
* @param {*} ev
*/
_onUnselectClick: function(ev) {
this.renderer._onToggleSelection(ev);
},
});
return DataCommonListController;
});
odoo.define('data_recycle.ListView', function (require) {
"use strict";
var ListView = require('web.ListView');
var session = require('web.session');
var viewRegistry = require('web.view_registry');
var DataCommonListController = require('data_recycle.CommonListController');
var DataCleaningListController = DataCommonListController.extend({
buttons_template: 'DataRecycle.buttons',
/**
* @override
*/
renderButtons: function ($node) {
this._super.apply(this, arguments);
this.$buttons.on('click', '.o_data_recycle_validate_button', this._onValidateClick.bind(this));
this.$buttons.on('click', '.o_data_recycle_unselect_button', this._onUnselectClick.bind(this));
},
/**
* Validate all the records selected
* @param {*} ev
*/
_onValidateClick: async function(ev) {
const self = this;
const state = this.model.get(this.handle);
let record_ids;
if (this.isDomainSelected) {
record_ids = await this._domainToResIds(state.getDomain(), session.active_ids_limit);
} else {
record_ids = this.getSelectedIds();
}
this._rpc({
model: 'data_recycle.record',
method: 'action_validate',
args: [record_ids],
}).then(function(data) {
self.trigger_up('reload');
});
},
});
var DataCleaningListView = ListView.extend({
config: _.extend({}, ListView.prototype.config, {
Controller: DataCleaningListController,
}),
});
viewRegistry.add('data_recycle_list', DataCleaningListView);
});
/** @odoo-module **/
import { ListController } from "@web/views/list/list_controller";
import { useService } from "@web/core/utils/hooks";
export class DataCleaningCommonListController extends ListController {
setup() {
super.setup();
this.orm = useService("orm");
this.actionService = useService("action");
}
/**
* Open the form view of the original record, and not the data_merge.record view
* @override
*/
openRecord(record) {
this.actionService.doAction({
type: 'ir.actions.act_window',
views: [[false, 'form']],
res_model: record.data.res_model_name,
res_id: record.data.res_id,
context: {
create: false,
edit: false
}
});
}
/**
* Unselect all the records
*/
onUnselectClick() {
this.discardSelection();
}
};
/** @odoo-module **/
import { DataCleaningCommonListController } from "@data_recycle/views/data_cleaning_common_list";
import { registry } from '@web/core/registry';
import { listView } from '@web/views/list/list_view';
import { session } from "@web/session";
export class DataRecycleListController extends DataCleaningCommonListController {
/**
* Validate all the records selected
*/
async onValidateClick() {
let record_ids;
if (this.isDomainSelected) {
const domain = this.props.domain;
record_ids = await this._domainToResIds(domain, session.active_ids_limit);
} else {
record_ids = await this.getSelectedResIds();
}
await this.orm.call('data_recycle.record', 'action_validate', [record_ids]);
await this.model.load();
this.model.notify();
}
};
registry.category('views').add('data_recycle_list', {
...listView,
Controller: DataRecycleListController,
buttonTemplate: 'DataRecycle.buttons',
});
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="DataRecycle.buttons" t-inherit="web.ListView.Buttons" t-inherit-mode="primary" owl="1">
<xpath expr="//t[@t-if='props.showButtons']">
<t t-if="nbSelected">
<button type="button" class="btn btn-primary o_data_recycle_validate_button" t-on-click="onValidateClick">
Validate
</button>
<button type="button" class="btn btn-secondary o_data_recycle_unselect_button" t-on-click="onUnselectClick">
Unselect
</button>
</t>
</xpath>
</t>
</templates>
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="DataRecycle.buttons">
<div class="o_list_buttons d-none" role="toolbar" aria-label="Main actions">
<button type="button" class="btn btn-primary o_data_recycle_validate_button">
Validate
</button>
<button type="button" class="btn btn-secondary o_data_recycle_unselect_button">
Unselect
</button>
</div>
</t>
</templates>
......@@ -5,7 +5,7 @@
<field name="name">Field Recycle Record List</field>
<field name="model">data_recycle.record</field>
<field name="arch" type="xml">
<tree js_class="data_recycle_list" sample="1">
<tree js_class="data_recycle_list" sample="1" create="0" export_xlsx="0">
<field name="active" invisible="1" />
<field name="res_model_name" invisible="1" />
<field name="res_id" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment