From 6d76c5f3bdd7d78d5a73fb6e446da10e2aed96db Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Thu, 2 May 2013 15:39:52 +0200 Subject: [PATCH 1/3] [ADD] Module for field visibility by view mode --- web_mode_visibility/__init__.py | 0 web_mode_visibility/__openerp__.py | 40 +++++++++++++++++++ .../static/src/js/web_mode_visibility.js | 25 ++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 web_mode_visibility/__init__.py create mode 100644 web_mode_visibility/__openerp__.py create mode 100644 web_mode_visibility/static/src/js/web_mode_visibility.js diff --git a/web_mode_visibility/__init__.py b/web_mode_visibility/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/web_mode_visibility/__openerp__.py b/web_mode_visibility/__openerp__.py new file mode 100644 index 00000000..79068adb --- /dev/null +++ b/web_mode_visibility/__openerp__.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (). +# +# 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 . +# +############################################################################## + +{ + "name": "Visibility depending on view mode", + "version": "6.1.1.0r1", + "author": "Therp BV", + "category": "Tools", + "depends": ['web'], + "description": """ +Use the following context keys on fields to hide them in either page or form +mode: + +- page_invisible +- form_invisible + +This module is compatible with OpenERP 6.1. + """, + 'js': [ + 'static/src/js/web_mode_visibility.js', + ], +} diff --git a/web_mode_visibility/static/src/js/web_mode_visibility.js b/web_mode_visibility/static/src/js/web_mode_visibility.js new file mode 100644 index 00000000..4364cdf6 --- /dev/null +++ b/web_mode_visibility/static/src/js/web_mode_visibility.js @@ -0,0 +1,25 @@ +/* + + Copyright (C) 2013 Therp BV + License: GNU AFFERO GENERAL PUBLIC LICENSE + Version 3 or any later version + +*/ + +openerp.web_mode_visibility = function (openerp) { + openerp.web.form.Widget.include({ + init: function(view, node) { + this._super(view, node); + if (! this.invisible) { + if (this.view.form_template == "PageView") { + this.invisible = (this.node.attrs.context && + this.node.attrs.context.page_invisible); + } + else if (this.view.form_template == "FormView") { + this.invisible = (this.node.attrs.context && + this.node.attrs.context.form_invisible); + } + } + }, + }); +} From 70ed5cdf59a0074895a23d0456e81511bcaf657c Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Tue, 7 May 2013 14:18:51 +0200 Subject: [PATCH 2/3] [IMP] Use the options JSON dictionary to encode visibility options --- web_mode_visibility/__openerp__.py | 4 ++-- .../static/src/js/web_mode_visibility.js | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/web_mode_visibility/__openerp__.py b/web_mode_visibility/__openerp__.py index 79068adb..b1eb3ab2 100644 --- a/web_mode_visibility/__openerp__.py +++ b/web_mode_visibility/__openerp__.py @@ -26,8 +26,8 @@ "category": "Tools", "depends": ['web'], "description": """ -Use the following context keys on fields to hide them in either page or form -mode: +Use the following boolean switches in the options dictionary on fields to hide +them in either page or form mode: - page_invisible - form_invisible diff --git a/web_mode_visibility/static/src/js/web_mode_visibility.js b/web_mode_visibility/static/src/js/web_mode_visibility.js index 4364cdf6..3d023837 100644 --- a/web_mode_visibility/static/src/js/web_mode_visibility.js +++ b/web_mode_visibility/static/src/js/web_mode_visibility.js @@ -7,19 +7,20 @@ */ openerp.web_mode_visibility = function (openerp) { - openerp.web.form.Widget.include({ + openerp.web.form.Field.include({ + init: function(view, node) { this._super(view, node); if (! this.invisible) { + var options = this.get_definition_options(); if (this.view.form_template == "PageView") { - this.invisible = (this.node.attrs.context && - this.node.attrs.context.page_invisible); + this.invisible = options.page_invisible; } else if (this.view.form_template == "FormView") { - this.invisible = (this.node.attrs.context && - this.node.attrs.context.form_invisible); + this.invisible = options.form_invisible; } } }, + }); } From 195bcc8f6ef15b044cafc393df1204b1147e2cae Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Sun, 16 Jun 2013 18:48:32 +0200 Subject: [PATCH 3/3] [ADD] Concrete example in module description --- web_mode_visibility/__openerp__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/web_mode_visibility/__openerp__.py b/web_mode_visibility/__openerp__.py index b1eb3ab2..805be1a2 100644 --- a/web_mode_visibility/__openerp__.py +++ b/web_mode_visibility/__openerp__.py @@ -32,6 +32,10 @@ them in either page or form mode: - page_invisible - form_invisible +For example: + + + This module is compatible with OpenERP 6.1. """, 'js': [