Browse Source

[ADD] web_readonly_bypass: allow to save an onchange modifications on readonly fields

pull/164/head
Jonathan Nemry 11 years ago
committed by Pierre Verkest
parent
commit
6966470f9d
  1. 28
      web_readonly_bypass/__init__.py
  2. 61
      web_readonly_bypass/__openerp__.py
  3. 109
      web_readonly_bypass/static/src/js/readonly_bypass.js
  4. 12
      web_readonly_bypass/views/readonly_bypass.xml

28
web_readonly_bypass/__init__.py

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Nemry Jonathan & Laetitia Gangloff
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
# All Rights Reserved
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contact a Free Software
# Service Company.
#
# 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/>.
#
##############################################################################

61
web_readonly_bypass/__openerp__.py

@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Nemry Jonathan & Laetitia Gangloff
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
# All Rights Reserved
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contact a Free Software
# Service Company.
#
# 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': 'Read Only ByPass',
'version': '1.0',
"author": "ACSONE SA/NV",
"maintainer": "ACSONE SA/NV",
"website": "http://www.acsone.eu",
'category': 'Technical Settings',
'depends': [
'base',
'web',
],
'description': """
Read Only ByPass
================
This Module provides a solution to the problem of the interaction between
'readonly' attribute and 'on_change' attribute when used together
Behavior: add `readonly_fields` changed by `on_change` into the fields passing
into an update or create. If `filter_out_readonly` is into the context and set
True then apply native behavior.
""",
'images': [],
'data': [
'views/readonly_bypass.xml',
],
'qweb': [
],
'css': [],
'demo': [],
'test': [],
'installable': True,
'auto_install': False,
}

109
web_readonly_bypass/static/src/js/readonly_bypass.js

@ -0,0 +1,109 @@
/*
* Allow to bypass readonly fi the value is changed
*/
openerp.readonly_bypass = function(instance) {
var QWeb = instance.web.qweb, _t = instance.web._t;
/**
* ignore readonly: place options['readonly_fields'] into the data
* if nothing is specified into the context
*
* create mode: remove read-only keys having a 'false' value
*
* @param boolean mode: True case of create, false case of write
* @param {Object} context->filter_out_readonly
* @param {Object} data field values to possibly be updated
* @param {Object} options Dictionary that can contain the following keys:
* - readonly_fields: Values from readonly fields to merge into the data object
*/
function ignore_readonly(data, options, mode, context){
if (options){
if (!('filter_out_readonly' in context && context['filter_out_readonly'] == true
&& 'readonly_fields' in options && options['readonly_fields'])) {
if(mode){
$.each( options.readonly_fields, function( key, value ) {
if(value==false){
delete(options.readonly_fields[key]);
}
});
}
data = $.extend(data,options['readonly_fields'])
}
}
};
instance.web.BufferedDataSet.include({
init : function() {
this._super.apply(this, arguments);
},
/**
* Creates Overriding
*
* @param {Object} data field values to set on the new record
* @param {Object} options Dictionary that can contain the following keys:
* - readonly_fields: Values from readonly fields that were updated by
* on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
* @returns super {$.Deferred}
*/
create : function(data, options) {
var self = this;
ignore_readonly(data, options, true, self.context);
return self._super(data,options);
},
/**
* Creates Overriding
*
* @param {Object} data field values to set on the new record
* @param {Object} options Dictionary that can contain the following keys:
* - readonly_fields: Values from readonly fields that were updated by
* on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
* @returns super {$.Deferred}
*/
write : function(id, data, options) {
var self = this;
ignore_readonly(data, options, false, self.context);
return self._super(id,data,options);
},
});
instance.web.DataSet.include({
/*
BufferedDataSet: case of 'add an item' into a form view
*/
init : function() {
this._super.apply(this, arguments);
},
/**
* Creates Overriding
*
* @param {Object} data field values to set on the new record
* @param {Object} options Dictionary that can contain the following keys:
* - readonly_fields: Values from readonly fields that were updated by
* on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
* @returns super {$.Deferred}
*/
create : function(data, options) {
var self = this;
ignore_readonly(data, options, true, self.context);
return self._super(data,options);
},
/**
* Creates Overriding
*
* @param {Object} data field values to set on the new record
* @param {Object} options Dictionary that can contain the following keys:
* - readonly_fields: Values from readonly fields that were updated by
* on_changes. Only used by the BufferedDataSet to make the o2m work correctly.
* @returns super {$.Deferred}
*/
write : function(id, data, options) {
var self = this;
ignore_readonly(data, options, false, self.context);
return self._super(id,data,options);
},
});
};

12
web_readonly_bypass/views/readonly_bypass.xml

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- vim:fdn=3:
-->
<openerp>
<data>
<template id="assets_backend" name="readonly_bypass" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/readonly_bypass/static/src/js/readonly_bypass.js"></script>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save