Browse Source

widget boolean_switch POC

pull/236/head
Pierre Verkest 9 years ago
parent
commit
e5a81ef886
  1. 77
      web_widget_boolean_switch/README.rst
  2. 3
      web_widget_boolean_switch/__init__.py
  3. 38
      web_widget_boolean_switch/__openerp__.py
  4. 70
      web_widget_boolean_switch/demo/res_users_view.xml
  5. BIN
      web_widget_boolean_switch/static/description/icon.png
  6. 79
      web_widget_boolean_switch/static/description/icon.svg
  7. 110
      web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js
  8. 13
      web_widget_boolean_switch/static/src/xml/web_widget_boolean_switch.xml

77
web_widget_boolean_switch/README.rst

@ -0,0 +1,77 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=========================
Web widget boolean switch
=========================
This module add a widget to render boolean fields
Installation
============
To install this module, you need to:
* do this ...
Configuration
=============
To configure this module, you need to:
* go to ...
Usage
=====
To use this module, you need to:
* go to ...
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch}
.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "8.0" for example
Known issues / Roadmap
======================
* ...
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/
{project_repo}/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here <https://github.com/OCA/
{project_repo}/issues/new?body=module:%20
{module_name}%0Aversion:%20
{version}%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Pierre Verkest <pverkest@anybox.fr>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.

3
web_widget_boolean_switch/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# © 2015 <pverkest@anybox.fr>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

38
web_widget_boolean_switch/__openerp__.py

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
# © <YEAR(S)> <AUTHOR(S)>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Web widget boolean switch",
"summary": "This module add widget to render boolean fields",
"version": "7.0.1.0.0",
"category": "web",
"website": "https://odoo-community.org/",
"author": "<pverkest@anybox>, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"external_dependencies": {
"python": [],
"bin": [],
},
"depends": [
"base",
"web",
],
"data": [
],
"js": [
'static/lib/bootstrap-switch/bootstrap-switch.js',
'static/src/js/web_widget_boolean_switch.js',
],
"css": [
'static/lib/bootstrap-switch/bootstrap-switch.css',
],
'qweb': [
'static/src/xml/web_widget_boolean_switch.xml',
],
"demo": [
'demo/res_users_view.xml',
],
'description': """""", # TODO: copy README.rst
}

70
web_widget_boolean_switch/demo/res_users_view.xml

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_users_search" model="ir.ui.view">
<field name="inherit_id" ref="base.view_users_search"/>
<field name="name">res.users.search</field>
<field name="model">res.users</field>
<field name="arch" type="xml">
<xpath expr="//search[@string='Users']" position="inside">
<filter string="Active" context="{'group_by': 'active'}"/>
</xpath>
</field>
</record>
<record id="view_users_tree" model="ir.ui.view">
<field name="inherit_id" ref="base.view_users_tree"/>
<field name="name">res.users.tree</field>
<field name="model">res.users</field>
<field name="sequence">20</field>
<field name="arch" type="xml">
<field name="login" position="after">
<field name="active" widget="boolean_switch" options="{'quick_edit': True}"/>
</field>
</field>
</record>
<record id="view_users_form" model="ir.ui.view">
<field name="inherit_id" ref="base.view_users_form"/>
<field name="name">res.users.form</field>
<field name="model">res.users</field>
<field name="arch" type="xml">
<field name="active" position="replace">
<field name="active" widget="boolean_switch" options="{'quick_edit': True}"/>
</field>
</field>
</record>
<record id="view_users_tree_editable" model="ir.ui.view">
<field name="name">res.users.tree</field>
<field name="model">res.users</field>
<field name="arch" type="xml">
<tree string="Users" editable="top">
<field name="name"/>
<field name="login"/>
<field name="lang"/>
<field name="active" widget="boolean_switch" options="{'quick_edit': True}"/>
</tree>
</field>
</record>
<record id="action_res_users_tree_editable" model="ir.actions.act_window">
<field name="name">Tree Editable Users</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.users</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_users_tree_editable"/>
<field name="search_view_id" ref="base.view_users_search"/>
</record>
<record id="action_res_users_tree_view_editable" model="ir.actions.act_window.view">
<field eval="10" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="view_users_tree_editable"/>
<field name="act_window_id" ref="action_res_users_tree_editable"/>
</record>
<menuitem action="action_res_users_tree_editable"
id="menu_action_res_users_tree_editable"
parent="base.menu_users"/>
</data>
</openerp>

BIN
web_widget_boolean_switch/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

79
web_widget_boolean_switch/static/description/icon.svg
File diff suppressed because it is too large
View File

110
web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js

@ -0,0 +1,110 @@
'use strict';
openerp.web_widget_boolean_switch = function(instance){
var inst = instance;
instance.web.form.widgets.add('boolean_switch',
'instance.web.form.FieldBooleanSwitch');
$.fn.bootstrapSwitch.defaults.size = 'mini';
$.fn.bootstrapSwitch.defaults.onColor = 'success';
instance.web.form.FieldBooleanSwitch = instance.web.form.AbstractField.extend(
instance.web.form.ReinitializeFieldMixin, {
template: 'FieldBooleanSwitch',
init: function(field_manager, node) {
this._super(field_manager, node);
},
start: function() {
var self = this;
this.$checkbox = $("input", this.$el);
this.$checkbox.bootstrapSwitch({
onSwitchChange: _.bind(function(event, state) {
this.internal_set_value(this.$checkbox.is(':checked'));
event.preventDefault();
}, this)
});
this.setupFocus(this.$checkbox);
// var check_readonly = function() {
// self.$checkbox.prop('disabled', self.get("effective_readonly"));
// };
// this.on("change:effective_readonly", this, check_readonly);
// check_readonly.call(this);
this._super.apply(this, arguments);
},
render_value: function() {
this.$checkbox.bootstrapSwitch('state', this.get('value'), true);
//this.$checkbox[0].checked =
},
focus: function() {
var input = this.$checkbox && this.$checkbox[0];
return input ? input.focus() : false;
}
});
/*instance.web.ListView.Groups.include({
render: function(post_render){
var self = this;
var prender = function(){
self.init_widget_boolean_switch();
if (post_render) { post_render(); }
};
return this._super(prender);
},
init_widget_boolean_switch: function(){
var switch_fields = this.columns.filter(function(c){
return c.widget === 'boolean_switch';
});
if(switch_fields.length > 0){
// details lines
var checkboxes = this.view.$el.find(
'.oe_list_field_boolean_switch > input[type="checkbox"]');
checkboxes.bootstrapSwitch({'readonly': false,
});
// TODO: the Group-by line
}
},
});*/
instance.web.list.columns.add('field.boolean_switch', 'instance.web.list.FieldBooleanSwitch');
instance.web.list.FieldBooleanSwitch = instance.web.list.Column.extend({
_format: function (row_data, options) {
var quick_edit = false;
quick_edit = py.eval(this.options).quick_edit ? py.eval(this.options).quick_edit : false;
return _.str.sprintf('<input type="checkbox" %s %s/>',
row_data[this.id].value ? 'checked="checked"' : '',
quick_edit ? '' : 'readonly="readonly"');
}
});
instance.web.ListView.include({
reload_record: function(record){
var self = this;
return this._super(record).then(function(){
self.init_widget_boolean_switch();
});
},
reload_content: function(){
var self = this;
return this._super.apply(this, arguments).always( function (){
self.init_widget_boolean_switch();
});
},
init_widget_boolean_switch:function(){
var switch_fields = this.columns.filter(function(c){
return c.widget === 'boolean_switch';
});
if(switch_fields.length > 0){
// details lines
var checkboxes = this.$el.find(
'.oe_list_field_boolean_switch > input[type="checkbox"]');
checkboxes.bootstrapSwitch({'readonly': false,
});
// TODO: the Group-by line
}
},
});
};

13
web_widget_boolean_switch/static/src/xml/web_widget_boolean_switch.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="FieldBooleanSwitch">
<span class="oe_form_field oe_form_field_boolean_switch" t-att-style="widget.node.attrs.style">
<input type="checkbox"
t-att-id="widget.id_for_label"
t-att-name="widget.name"
t-att-tabindex="widget.node.attrs.tabindex"
t-att-autofocus="widget.node.attrs.autofocus"
class="field_boolean_switch"/>
</span>
</t>
</templates>
Loading…
Cancel
Save