Reputation: 208
I would like to custom List view padding in my custom module, so i proceeded like follows :
my_custom_module.js :
odoo.define('my_custom_module', function(require){
'use strict';
var core = require('web.core');
var List = core.view_registry.get('list');
var QWeb = core.qweb;
List.List.include({
render: function () {
var self = this;
this.$current.html(
QWeb.render('ListView.rows', _.extend({}, this, {
render_cell: function () {
return self.render_cell.apply(self, arguments); }
})));
this.pad_table_to(1);
},
});
});
And in my XML :
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="assets_backend" name="my_custom_module assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script src="/my_custom_module/static/src/js/my_custom_module.js" type="text/javascript" />
</xpath>
</template>
</odoo>
But problem is that this applies to all my Odoo modules !
How can i specify that the customization applies only to my my_custom_module ?
Thanks for help :)
Upvotes: 1
Views: 926
Reputation: 3747
By using List.List.include({ ...
you extend the already existing functionality of the List widget. What you have to do is create your own widget that extends List and assign it to your view
If you do not want than and you want to continue with the approach you already have you can insert an element to your view that will be used as a hook that you can use is as a hook so that you can apply the changes only to your views. For example insert an element in your view:
<div style="visibility: hidden" id="my_view" />
And then in your javascript:
if ($( "#my_view" ).length) {
// your element exists, that means the javascript code runs on your view and your custom code should be executed.
} else {
// another list is being rendered and you should not run any custom code.
}
Upvotes: 0