-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
619 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
{ | ||
"name": "Odoo cookbook - Chapter 14, recipe 01", | ||
"version": "11.0.1.0.0", | ||
"author": "Odoo cookbook", | ||
"license": "AGPL-3", | ||
"category": "Odoo cookbook", | ||
"summary": "Create custom widgets", | ||
"depends": [ | ||
'web', | ||
], | ||
"data": [ | ||
"views/res_partner.xml", | ||
"views/templates.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.oe_form_field_many2one_buttons button | ||
{ | ||
margin: 0em .2em .2em 0em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
odoo.define('r1_widgets', function(require) | ||
{ | ||
var registry = require('web.field_registry'), | ||
AbstractField = require('web.AbstractField'); | ||
|
||
var FieldMany2OneButtons = AbstractField.extend({ | ||
className: 'oe_form_field_many2one_buttons', | ||
supportedFieldTypes: ['many2one'], | ||
init: function() | ||
{ | ||
this._super.apply(this, arguments); | ||
this.user_list = { | ||
1: { | ||
name: 'Administrator', | ||
}, | ||
4: { | ||
name: 'Demo user', | ||
}, | ||
}; | ||
}, | ||
events: { | ||
'click .btn': '_button_clicked', | ||
}, | ||
_render: function() | ||
{ | ||
var self = this; | ||
this.$el.empty(); | ||
_.each(this.user_list, function(description, id) | ||
{ | ||
self.$el.append( | ||
jQuery('<button>').attr({ | ||
'data-id': id, | ||
'class': 'btn btn-default btn-sm', | ||
}) | ||
.text(description.name) | ||
.toggleClass( | ||
'btn-primary', | ||
self.value ? self.value.res_id == id : false | ||
) | ||
); | ||
}); | ||
this.$el.find('button'). | ||
prop('disabled', this.mode == 'readonly'); | ||
}, | ||
_button_clicked: function(e) | ||
{ | ||
this._setValue( | ||
parseInt(jQuery(e.target).attr('data-id')) | ||
); | ||
}, | ||
}); | ||
|
||
registry.add('many2one_buttons', FieldMany2OneButtons); | ||
|
||
return { | ||
FieldMany2OneButtons: FieldMany2OneButtons, | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="view_partner_form" model="ir.ui.view"> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base.view_partner_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="user_id" position="attributes"> | ||
<attribute name="widget">many2one_buttons</attribute> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<template id="assets_backend" inherit_id="web.assets_backend"> | ||
<xpath expr="." position="inside"> | ||
<link href="/r1_widgets/static/src/css/r1_widgets.css" rel="stylesheet" type="text/css"/> | ||
<script src="/r1_widgets/static/src/js/r1_widgets.js" type="text/javascript" /> | ||
</xpath> | ||
</template> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
{ | ||
"name": "Odoo cookbook - Chapter 14, recipe 02", | ||
"version": "11.0.1.0.0", | ||
"author": "Odoo cookbook", | ||
"license": "AGPL-3", | ||
"category": "Odoo cookbook", | ||
"summary": "Using client side templates: QWeb", | ||
"depends": [ | ||
'web', | ||
], | ||
"qweb": [ | ||
'static/src/xml/r2_clientside_qweb.xml', | ||
], | ||
"data": [ | ||
"views/res_partner.xml", | ||
"views/templates.xml", | ||
], | ||
} |
4 changes: 4 additions & 0 deletions
4
Chapter14/r2_clientside_qweb/static/src/css/r2_clientside_qweb.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.oe_form_field_many2one_buttons button | ||
{ | ||
margin: 0em .2em .2em 0em; | ||
} |
42 changes: 42 additions & 0 deletions
42
Chapter14/r2_clientside_qweb/static/src/js/r2_clientside_qweb.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
odoo.define('r2_clientside_qweb', function(require) | ||
{ | ||
var registry = require('web.field_registry'), | ||
AbstractField = require('web.AbstractField'); | ||
|
||
var FieldMany2OneButtons = AbstractField.extend({ | ||
template: 'FieldMany2OneButtons', | ||
className: 'oe_form_field_many2one_buttons', | ||
supportedFieldTypes: ['many2one'], | ||
init: function() | ||
{ | ||
this._super.apply(this, arguments); | ||
this.user_list = { | ||
1: { | ||
name: 'Administrator', | ||
}, | ||
4: { | ||
name: 'Demo user', | ||
}, | ||
}; | ||
}, | ||
events: { | ||
'click .btn': '_button_clicked', | ||
}, | ||
_render: function() | ||
{ | ||
this.renderElement(); | ||
}, | ||
_button_clicked: function(e) | ||
{ | ||
this._setValue( | ||
parseInt(jQuery(e.target).attr('data-id')) | ||
); | ||
}, | ||
}); | ||
|
||
registry.add('many2one_buttons', FieldMany2OneButtons); | ||
|
||
return { | ||
FieldMany2OneButtons: FieldMany2OneButtons, | ||
} | ||
}); |
11 changes: 11 additions & 0 deletions
11
Chapter14/r2_clientside_qweb/static/src/xml/r2_clientside_qweb.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<templates> | ||
<t t-name="FieldMany2OneButtons"> | ||
<div class="oe_form_field_many2one_buttons"> | ||
<t t-foreach="widget.user_list" t-as="user_id"> | ||
<button t-att-disabled="widget.mode == 'readonly' ? 'disabled' : False" t-att-data-id="user_id" t-attf-class="btn btn-default btn-sm {{(widget.value and widget.value.res_id == user_id) and 'btn-primary' or ''}}"> | ||
<t t-esc="widget.user_list[user_id].name" /> | ||
</button> | ||
</t> | ||
</div> | ||
</t> | ||
</templates> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="view_partner_form" model="ir.ui.view"> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base.view_partner_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="user_id" position="attributes"> | ||
<attribute name="widget">many2one_buttons</attribute> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<template id="assets_backend" inherit_id="web.assets_backend"> | ||
<xpath expr="." position="inside"> | ||
<link href="/r2_clientside_qweb/static/src/css/r2_clientside_qweb.css" rel="stylesheet" type="text/css"/> | ||
<script src="/r2_clientside_qweb/static/src/js/r2_clientside_qweb.js" type="text/javascript" /> | ||
</xpath> | ||
</template> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
{ | ||
"name": "Odoo cookbook - Chapter 14, recipe 03", | ||
"version": "11.0.1.0.0", | ||
"author": "Odoo cookbook", | ||
"license": "AGPL-3", | ||
"category": "Odoo cookbook", | ||
"summary": "Making RPC calls to the server", | ||
"depends": [ | ||
'web', | ||
], | ||
"qweb": [ | ||
'static/src/xml/r3_rpc_calls.xml', | ||
], | ||
"data": [ | ||
"views/res_partner.xml", | ||
"views/templates.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.oe_form_field_many2one_buttons button | ||
{ | ||
margin: 0em .2em .2em 0em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
odoo.define('r3_rpc_calls', function(require) | ||
{ | ||
var registry = require('web.field_registry'), | ||
AbstractField = require('web.AbstractField'); | ||
|
||
var FieldMany2OneButtons = AbstractField.extend({ | ||
template: 'FieldMany2OneButtons', | ||
className: 'oe_form_field_many2one_buttons', | ||
supportedFieldTypes: ['many2one'], | ||
events: { | ||
'click .btn': '_button_clicked', | ||
}, | ||
willStart: function() | ||
{ | ||
var deferred = new jQuery.Deferred(), | ||
self = this; | ||
self.user_list = {} | ||
this._rpc({ | ||
model: this.field.relation, | ||
method: 'search_read', | ||
fields: ['display_name'], | ||
domain: this.field.domain, | ||
}) | ||
.then(function(records) | ||
{ | ||
_.each(records, function(record) | ||
{ | ||
self.user_list[record.id] = record; | ||
self.user_list[record.id].name = record.display_name; | ||
}); | ||
deferred.resolve(); | ||
}); | ||
return jQuery.when( | ||
this._super.apply(this, arguments), | ||
deferred | ||
); | ||
}, | ||
_render: function() | ||
{ | ||
this.renderElement(); | ||
}, | ||
_button_clicked: function(e) | ||
{ | ||
this._setValue( | ||
parseInt(jQuery(e.target).attr('data-id')) | ||
); | ||
}, | ||
}); | ||
|
||
registry.add('many2one_buttons', FieldMany2OneButtons); | ||
|
||
return { | ||
FieldMany2OneButtons: FieldMany2OneButtons, | ||
} | ||
}); |
Oops, something went wrong.