Browse Source
Merge pull request #1 from petrus-v/8.0-web_readonly_bypass-jne
Merge pull request #1 from petrus-v/8.0-web_readonly_bypass-jne
8.0 web readonly bypass jnepull/162/head
Jonathan Nemry (ACSONE)
9 years ago
4 changed files with 252 additions and 40 deletions
-
22web_readonly_bypass/README.rst
-
93web_readonly_bypass/static/src/js/readonly_bypass.js
-
166web_readonly_bypass/static/test/web_readonly_bypass.js
-
9web_readonly_bypass/views/readonly_bypass.xml
@ -0,0 +1,166 @@ |
|||
openerp.testing.section( 'web_readonly_bypass', {}, |
|||
function(test){ |
|||
test('ignore_readonly', function(instance){ |
|||
var data = {}; |
|||
var mode_create = true; |
|||
var options = {}; |
|||
var context = {}; |
|||
instance.web_readonly_bypass.ignore_readonly(data, options, |
|||
mode_create, context); |
|||
deepEqual(data, |
|||
{}, |
|||
"Empty context and options mode create" |
|||
); |
|||
|
|||
mode_create = false; |
|||
data = {}; |
|||
instance.web_readonly_bypass.ignore_readonly(data, options, |
|||
mode_create, context); |
|||
deepEqual(data, |
|||
{}, |
|||
"Empty context and options mode write" |
|||
); |
|||
|
|||
mode_create = false; |
|||
data = {}; |
|||
context = {'readonly_by_pass': true}; |
|||
options = {'readonly_fields': {'field_1': 'va1-1', |
|||
'field_2': false, |
|||
'field_3': 'val-3'}}; |
|||
instance.web_readonly_bypass.ignore_readonly(data, options, |
|||
mode_create, context); |
|||
deepEqual(data, |
|||
{'field_1': 'va1-1', 'field_2': false, 'field_3': 'val-3'}, |
|||
"all fields mode write" |
|||
); |
|||
|
|||
mode_create = true; |
|||
data = {}; |
|||
context = {'readonly_by_pass': true}; |
|||
options = {'readonly_fields': {'field_1': 'va1-1', |
|||
'field_2': false, |
|||
'field_3': 'val-3'}}; |
|||
instance.web_readonly_bypass.ignore_readonly(data, options, |
|||
mode_create, context); |
|||
deepEqual(data, |
|||
{'field_1': 'va1-1', 'field_3': 'val-3'}, |
|||
"all fields mode create (false value are escaped)" |
|||
); |
|||
|
|||
mode_create = true; |
|||
data = {}; |
|||
context = {}; |
|||
options = {'readonly_fields': {'field_1': 'va1-1', |
|||
'field_2': false, |
|||
'field_3': 'val-3'}}; |
|||
instance.web_readonly_bypass.ignore_readonly(data, options, |
|||
mode_create, context); |
|||
deepEqual(data, |
|||
{}, |
|||
"without context, default, we won't save readonly fields" |
|||
); |
|||
}); |
|||
|
|||
test('retrieve_readonly_by_pass_fields', function(instance){ |
|||
var context = {'readonly_by_pass': true} |
|||
var options = {'readonly_fields': {'field_1': 'va1-1', |
|||
'field_2': 'val-2', |
|||
'field_3': 'val-3'}}; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{'field_1': 'va1-1', 'field_2': 'val-2', 'field_3': 'val-3'}, |
|||
"All fields should be accepted!" |
|||
); |
|||
|
|||
context = {'readonly_by_pass': ['field_1', 'field_3']}; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{'field_1': 'va1-1','field_3': 'val-3'}, |
|||
"two field s1" |
|||
); |
|||
|
|||
context = {'readonly_by_pass': ['field_1',]}; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{'field_1': 'va1-1'}, |
|||
"Only field 1" |
|||
); |
|||
|
|||
context = {'readonly_by_pass': []}; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{}, |
|||
"Empty context field" |
|||
); |
|||
|
|||
context = null; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{}, |
|||
"Null context" |
|||
); |
|||
|
|||
context = false; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{}, |
|||
"false context" |
|||
); |
|||
|
|||
context = {'readonly_by_pass': true} |
|||
options = {'readonly_fields': {'field_1': 'va1-1'}}; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{'field_1': 'va1-1'}, |
|||
"Only one option" |
|||
); |
|||
|
|||
|
|||
options = {'readonly_fields': {}}; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{}, |
|||
"Empty readonly_fields option" |
|||
); |
|||
|
|||
options = {}; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{}, |
|||
"Empty option" |
|||
); |
|||
|
|||
options = null; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{}, |
|||
"null option" |
|||
); |
|||
|
|||
options = false; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{}, |
|||
"false option" |
|||
); |
|||
|
|||
context = false; |
|||
deepEqual( |
|||
instance.web_readonly_bypass.retrieve_readonly_by_pass_fields( |
|||
options, context), |
|||
{}, |
|||
"false option and false context" |
|||
); |
|||
}); |
|||
}); |
@ -1,12 +1,15 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- vim:fdn=3: |
|||
--> |
|||
<openerp> |
|||
<data> |
|||
<template id="assets_backend" name="readonly_bypass" inherit_id="web.assets_backend"> |
|||
<template id="assets_backend" name="web_readonly_bypass" inherit_id="web.assets_backend"> |
|||
<xpath expr="." position="inside"> |
|||
<script type="text/javascript" src="/web_readonly_bypass/static/src/js/readonly_bypass.js"></script> |
|||
</xpath> |
|||
</template> |
|||
<template id="qunit_suite" name="web_readonly_bypass" inherit_id="web.qunit_suite"> |
|||
<xpath expr="//head" position="inside"> |
|||
<script type="text/javascript" src="/web_readonly_bypass/static/test/web_readonly_bypass.js"></script> |
|||
</xpath> |
|||
</template> |
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue