Goran Kliska has proposed merging lp:~gkliska/server-env-tools/server-env-tools-61 into lp:server-env-tools/6.1.
Requested reviews: Server Environment And Tools Core Editors (server-env-tools-core-editors) For more details, see: https://code.launchpad.net/~gkliska/server-env-tools/server-env-tools-61/+merge/204699 New web module for 6.1 web client. 1.Fixing wishlist: Fields with attribute readonly=True do not preserve on_change values https://bugs.launchpad.net/openerp-web/+bug/378824 Reported by Ferdinand on 2009-05-20 If field is (readonly and required and dirty) then it is "readonly_writable". 3 LOC 2.Allowing parent.field for in attrs Example: <field name="amount" attrs="{'readonly':[('*parent.*entry_type','!=','amount')],'required':[('*parent.*entry_type','!=','amount')]}"/> -- https://code.launchpad.net/~gkliska/server-env-tools/server-env-tools-61/+merge/204699 Your team Server Environment And Tools Core Editors is requested to review the proposed merge of lp:~gkliska/server-env-tools/server-env-tools-61 into lp:server-env-tools/6.1.
=== added directory 'web_base' === added file 'web_base/__init__.py' --- web_base/__init__.py 1970-01-01 00:00:00 +0000 +++ web_base/__init__.py 2014-02-04 14:41:41 +0000 @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2014 Decodio ERP/Slobodni Programi d.o.o. (<http://slobodni-programi.com>). +# +# 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/>. +# +############################################################################## + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: === added file 'web_base/__openerp__.py' --- web_base/__openerp__.py 1970-01-01 00:00:00 +0000 +++ web_base/__openerp__.py 2014-02-04 14:41:41 +0000 @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2014 Decodio / Slobodni Programi d.o.o. (<http://slobodni-programi.com>). +# Author: Goran Kliska +# +# 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': 'Web Base', + 'version': '6.3.1.0', + 'category': 'Borg/Base', + 'complexity': "normal", + "depends": [ + # 'base_base', + 'web', + ], + "js": [ + 'static/src/js/view_form_base.js', + # 'static/src/js/view_list_base.js', + ], + 'qweb': [ + # 'static/xml/*.xml', + ], + 'css': [ + # 'static/css/*.css', + ], + 'author': 'Decodio - Slobodni programi d.o.o.', + 'website': 'http://slobodni-programi.com', + 'installable' : True, + 'active' : False, + # 'auto_install': True, + 'description': + """ + 1. Fixing Wishlist: Fields with attribute readonly=True do not preserve on_change values + https://bugs.launchpad.net/openerp-web/+bug/378824 Reported by Ferdinand on 2009-05-20 + If field is (readonly and required and dirty) then it is "readonly_writable". 3 LOC + Example: + <field name="uom_id" on_change="onchange_product_uom( ... + <field name="base_uom_qty" readonly="1" required="1"/> + Method onchange_product_uom(...) is calculating and changing value of + "base_uom_qty" field and making it "dirty". + Field is readonly and required and it will be saved in the client dataset + and sent to orm create and write methods. + It is good practice to recalculate all important fields again in create and write methods. + + 2. Allowing parent.field for in attrs + Example: <field name="amount" attrs="{'readonly':[('parent.entry_type','!=','amount')],'required':[('parent.entry_type','!=','amount')]}"/> + """, + 'data': [], + 'demo_xml': [], + 'images': [], +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: === added directory 'web_base/static' === added directory 'web_base/static/src' === added directory 'web_base/static/src/js' === added file 'web_base/static/src/js/view_form_base.js' --- web_base/static/src/js/view_form_base.js 1970-01-01 00:00:00 +0000 +++ web_base/static/src/js/view_form_base.js 2014-02-04 14:41:41 +0000 @@ -0,0 +1,193 @@ +openerp.web_base = function(openerp) { +var QWeb = openerp.web.qweb, + _t = openerp.web._t, + _lt = openerp.web._lt; + +openerp.web.form.Field = openerp.web.form.Field.extend({ + + is_dirty: function() { + // DECODIO KGB START Save readony required dirty + //return this.dirty && !this.readonly; + return this.dirty && ( !this.readonly || (this.required && this.readonly)); + } +}); + + +openerp.web.FormView = openerp.web.FormView.extend({ + do_save: function(success, prepend_on_create) { + var self = this; + return this.mutating_mutex.exec(function() { return self.is_initialized.pipe(function() { + try { + var form_invalid = false, + values = {}, + first_invalid_field = null; + for (var f in self.fields) { + f = self.fields[f]; + if (!f.is_valid()) { + form_invalid = true; + if (!first_invalid_field) { + first_invalid_field = f; + } + } else if (f.name !== 'id' && !f.readonly && (!self.datarecord.id || f.is_dirty())) { + // Special case 'id' field, do not save this field + // on 'create' : save all non readonly fields + // on 'edit' : save non readonly modified fields + values[f.name] = f.get_value(); + // DECODIO KGB START Save readony required dirty + } else if (f.name !== 'id' && f.readonly && f.required && f.is_dirty()) { + values[f.name] = f.get_value(); + // DECODIO KGB END Save readony required dirty + } + f.update_dom(true); + } + if (form_invalid) { + first_invalid_field.focus(); + self.on_invalid(); + return $.Deferred().reject(); + } else { + var save_deferral; + if (!self.datarecord.id) { + //console.log("FormView(", self, ") : About to create", values); + save_deferral = self.dataset.create(values).pipe(function(r) { + return self.on_created(r, undefined, prepend_on_create); + }, null); + } else if (_.isEmpty(values) && ! self.force_dirty) { + //console.log("FormView(", self, ") : Nothing to save"); + save_deferral = $.Deferred().resolve({}).promise(); + } else { + self.force_dirty = false; + //console.log("FormView(", self, ") : About to save", values); + save_deferral = self.dataset.write(self.datarecord.id, values, {}).pipe(function(r) { + return self.on_saved(r); + }, null); + } + return save_deferral.then(success); + } + } catch (e) { + console.error(e); + return $.Deferred().reject(); + } + });}); + }, + +}); + +openerp.web.form.Widget = openerp.web.form.Widget.extend({ + + process_modifiers: function() { + var compute_domain = openerp.web.form.compute_domain; + /** DECODIO START KGB allow parent.field in attribs */ + // trying to find (guesswork) parent fields values + var parent_fields; + var i=0; + tmp_parent = this.view.widget_parent; + while (i<10) { + if (tmp_parent && tmp_parent.model){ + if (tmp_parent.model !== this.view.model) { + parent_fields = tmp_parent.fields; + break; + } + } + if (tmp_parent.widget_parent){ + tmp_parent = tmp_parent.widget_parent; + } else { + parent_fields = false; + break; + } + i++; + } + for (var a in this.modifiers) { + //this[a] = compute_domain(this.modifiers[a], this.view.fields); + this[a] = compute_domain(this.modifiers[a], this.view.fields, parent_fields); + } + } +}); + + +/** DECODIO KGB allow parent.field in attribs */ +openerp.web.form.compute_domain = function(expr, fields, parent_fields) { + var stack = []; + for (var i = expr.length - 1; i >= 0; i--) { + var ex = expr[i]; + if (ex.length == 1) { + var top = stack.pop(); + switch (ex) { + case '|': + stack.push(stack.pop() || top); + continue; + case '&': + stack.push(stack.pop() && top); + continue; + case '!': + stack.push(!top); + continue; + default: + throw new Error(_.str.sprintf( + _t("Unknown operator %s in domain %s"), + ex, JSON.stringify(expr))); + } + } + + var field = fields[ex[0]]; + /** DECODIO START KGB allow parent.field in attribs */ + var parent_field; + var splitted; + if (parent_fields && !field ) { + splitted = ex[0].split('.'); + if (splitted.length > 1 && splitted[0] === "parent") { + parent_field = parent_fields[splitted[1]]; + } + } + if ((!field) && (!parent_field)) { + throw new Error(_.str.sprintf( + _t("Unknown field %s in domain %s"), + ex[0], JSON.stringify(expr))); + } + if (field) { + var field_value = field.get_value ? fields[ex[0]].get_value() : fields[ex[0]].value; + } + if (parent_field) { + var field_value = parent_field.get_value ? parent_fields[splitted[1]].get_value() : parent_fields[splitted[1]].value; + } + /** DECODIO END KGB allow parent.field in attribs */ + var op = ex[1]; + var val = ex[2]; + + switch (op.toLowerCase()) { + case '=': + case '==': + stack.push(field_value == val); + break; + case '!=': + case '<>': + stack.push(field_value != val); + break; + case '<': + stack.push(field_value < val); + break; + case '>': + stack.push(field_value > val); + break; + case '<=': + stack.push(field_value <= val); + break; + case '>=': + stack.push(field_value >= val); + break; + case 'in': + if (!_.isArray(val)) val = [val]; + stack.push(_(val).contains(field_value)); + break; + case 'not in': + if (!_.isArray(val)) val = [val]; + stack.push(!_(val).contains(field_value)); + break; + default: + console.warn( + _t("Unsupported operator %s in domain %s"), + op, JSON.stringify(expr)); + } + } + return _.all(stack, _.identity); +}; +}; \ No newline at end of file
-- Mailing list: https://launchpad.net/~openerp-community-reviewer Post to : [email protected] Unsubscribe : https://launchpad.net/~openerp-community-reviewer More help : https://help.launchpad.net/ListHelp

