diff --git a/web_widget_boolean_switch/README.rst b/web_widget_boolean_switch/README.rst new file mode 100644 index 00000000..5cc824ad --- /dev/null +++ b/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 `_. +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 `_. + + +Credits +======= + +Contributors +------------ + +* Pierre Verkest + +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. diff --git a/web_widget_boolean_switch/__init__.py b/web_widget_boolean_switch/__init__.py new file mode 100644 index 00000000..87ba95e2 --- /dev/null +++ b/web_widget_boolean_switch/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# © 2015 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/web_widget_boolean_switch/__openerp__.py b/web_widget_boolean_switch/__openerp__.py new file mode 100644 index 00000000..a4c085df --- /dev/null +++ b/web_widget_boolean_switch/__openerp__.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# © +# 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": ", 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 +} diff --git a/web_widget_boolean_switch/demo/res_users_view.xml b/web_widget_boolean_switch/demo/res_users_view.xml new file mode 100644 index 00000000..1543c83a --- /dev/null +++ b/web_widget_boolean_switch/demo/res_users_view.xml @@ -0,0 +1,70 @@ + + + + + + res.users.search + res.users + + + + + + + + + + res.users.tree + res.users + 20 + + + + + + + + + res.users.form + res.users + + + + + + + + + + res.users.tree + res.users + + + + + + + + + + + + Tree Editable Users + ir.actions.act_window + res.users + form + + + + + + tree + + + + + + + diff --git a/web_widget_boolean_switch/static/description/icon.png b/web_widget_boolean_switch/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/web_widget_boolean_switch/static/description/icon.png differ diff --git a/web_widget_boolean_switch/static/description/icon.svg b/web_widget_boolean_switch/static/description/icon.svg new file mode 100644 index 00000000..a7a26d09 --- /dev/null +++ b/web_widget_boolean_switch/static/description/icon.svg @@ -0,0 +1,79 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js b/web_widget_boolean_switch/static/src/js/web_widget_boolean_switch.js new file mode 100644 index 00000000..5b214e11 --- /dev/null +++ b/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('', + 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 + } + }, + + }); +}; diff --git a/web_widget_boolean_switch/static/src/xml/web_widget_boolean_switch.xml b/web_widget_boolean_switch/static/src/xml/web_widget_boolean_switch.xml new file mode 100644 index 00000000..809fef2c --- /dev/null +++ b/web_widget_boolean_switch/static/src/xml/web_widget_boolean_switch.xml @@ -0,0 +1,13 @@ + + + + + + + +