[IMP] Merged corelib.js and coresetup.js into core.js

bzr revid: nicolas.vanhoren@openerp.com-20130806122623-pq6bpkjk65jx0fnp
This commit is contained in:
niv-openerp 2013-08-06 14:26:23 +02:00
parent 392e9d260b
commit c63a86c593
12 changed files with 231 additions and 241 deletions

View File

@ -46,8 +46,7 @@ This module provides the core of the OpenERP Web Client.
"static/src/js/boot.js",
"static/src/js/testing.js",
"static/src/js/pyeval.js",
"static/src/js/corelib.js",
"static/src/js/coresetup.js",
"static/src/js/core.js",
"static/src/js/dates.js",
"static/src/js/formats.js",
"static/src/js/chrome.js",

View File

@ -58,7 +58,7 @@
* OpenERP Web web module split
*---------------------------------------------------------*/
function init_web_modules() {
var files = ["pyeval", "corelib","coresetup","dates","formats","chrome","data","views","search","list","form","list_editable","web_mobile","view_tree","data_export","data_import"];
var files = ["pyeval","core","dates","formats","chrome","data","views","search","list","form","list_editable","web_mobile","view_tree","data_export","data_import"];
for(var i=0; i<files.length; i++) {
var fct = openerp.web[files[i]];
if(typeof(fct) === "function") {

View File

@ -1,18 +1,195 @@
/*---------------------------------------------------------
* OpenERP Web core
*--------------------------------------------------------*/
var console;
if (!console) {
// Even IE9 only exposes console object if debug window opened
console = {};
('log error debug info warn assert clear dir dirxml trace group'
+ ' groupCollapsed groupEnd time timeEnd profile profileEnd count'
+ ' exception').split(/\s+/).forEach(function(property) {
console[property] = _.identity;
});
}
openerp.web.coresetup = function(instance) {
(function() {
if (typeof(console) === "undefined") {
// Even IE9 only exposes console object if debug window opened
window.console = {};
('log error debug info warn assert clear dir dirxml trace group'
+ ' groupCollapsed groupEnd time timeEnd profile profileEnd count'
+ ' exception').split(/\s+/).forEach(function(property) {
console[property] = _.identity;
});
}
})();
openerp.web.core = function(instance) {
var ControllerMixin = {
/**
* Informs the action manager to do an action. This supposes that
* the action manager can be found amongst the ancestors of the current widget.
* If that's not the case this method will simply return `false`.
*/
do_action: function() {
var parent = this.getParent();
if (parent) {
return parent.do_action.apply(parent, arguments);
}
return false;
},
do_notify: function() {
if (this.getParent()) {
return this.getParent().do_notify.apply(this,arguments);
}
return false;
},
do_warn: function() {
if (this.getParent()) {
return this.getParent().do_warn.apply(this,arguments);
}
return false;
},
rpc: function(url, data, options) {
return this.alive(openerp.session.rpc(url, data, options));
}
};
/**
A class containing common utility methods useful when working with OpenERP as well as the PropertiesMixin.
*/
openerp.web.Controller = openerp.web.Class.extend(openerp.web.PropertiesMixin, ControllerMixin, {
/**
* Constructs the object and sets its parent if a parent is given.
*
* @param {openerp.web.Controller} parent Binds the current instance to the given Controller instance.
* When that controller is destroyed by calling destroy(), the current instance will be
* destroyed too. Can be null.
*/
init: function(parent) {
openerp.web.PropertiesMixin.init.call(this);
this.setParent(parent);
this.session = openerp.session;
},
});
openerp.web.Widget.include(_.extend({}, ControllerMixin, {
init: function() {
this._super.apply(this, arguments);
this.session = openerp.session;
},
}));
instance.web.Registry = instance.web.Class.extend({
/**
* Stores a mapping of arbitrary key (strings) to object paths (as strings
* as well).
*
* Resolves those paths at query time in order to always fetch the correct
* object, even if those objects have been overloaded/replaced after the
* registry was created.
*
* An object path is simply a dotted name from the instance root to the
* object pointed to (e.g. ``"instance.web.Session"`` for an OpenERP
* session object).
*
* @constructs instance.web.Registry
* @param {Object} mapping a mapping of keys to object-paths
*/
init: function (mapping) {
this.parent = null;
this.map = mapping || {};
},
/**
* Retrieves the object matching the provided key string.
*
* @param {String} key the key to fetch the object for
* @param {Boolean} [silent_error=false] returns undefined if the key or object is not found, rather than throwing an exception
* @returns {Class} the stored class, to initialize or null if not found
*/
get_object: function (key, silent_error) {
var path_string = this.map[key];
if (path_string === undefined) {
if (this.parent) {
return this.parent.get_object(key, silent_error);
}
if (silent_error) { return void 'nooo'; }
return null;
}
var object_match = instance;
var path = path_string.split('.');
// ignore first section
for(var i=1; i<path.length; ++i) {
object_match = object_match[path[i]];
if (object_match === undefined) {
if (silent_error) { return void 'noooooo'; }
return null;
}
}
return object_match;
},
/**
* Checks if the registry contains an object mapping for this key.
*
* @param {String} key key to look for
*/
contains: function (key) {
if (key === undefined) { return false; }
if (key in this.map) {
return true;
}
if (this.parent) {
return this.parent.contains(key);
}
return false;
},
/**
* Tries a number of keys, and returns the first object matching one of
* the keys.
*
* @param {Array} keys a sequence of keys to fetch the object for
* @returns {Class} the first class found matching an object
*/
get_any: function (keys) {
for (var i=0; i<keys.length; ++i) {
var key = keys[i];
if (!this.contains(key)) {
continue;
}
return this.get_object(key);
}
return null;
},
/**
* Adds a new key and value to the registry.
*
* This method can be chained.
*
* @param {String} key
* @param {String} object_path fully qualified dotted object path
* @returns {instance.web.Registry} itself
*/
add: function (key, object_path) {
this.map[key] = object_path;
return this;
},
/**
* Creates and returns a copy of the current mapping, with the provided
* mapping argument added in (replacing existing keys if needed)
*
* Parent and child remain linked, a new key in the parent (which is not
* overwritten by the child) will appear in the child.
*
* @param {Object} [mapping={}] a mapping of keys to object-paths
*/
extend: function (mapping) {
var child = new instance.web.Registry(mapping);
child.parent = this;
return child;
},
/**
* @deprecated use Registry#extend
*/
clone: function (mapping) {
console.warn('Registry#clone is deprecated, use Registry#extend');
return this.extend(mapping);
}
});
instance.web.py_eval = function(expr, context) {
return py.eval(expr, _.extend({}, context || {}, {"true": true, "false": false, "null": null}));
};
/*
Some retro-compatibility.

View File

@ -1,208 +0,0 @@
/*
* Copyright (c) 2012, OpenERP S.A.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
openerp.web.corelib = function(instance) {
var ControllerMixin = {
/**
* Informs the action manager to do an action. This supposes that
* the action manager can be found amongst the ancestors of the current widget.
* If that's not the case this method will simply return `false`.
*/
do_action: function() {
var parent = this.getParent();
if (parent) {
return parent.do_action.apply(parent, arguments);
}
return false;
},
do_notify: function() {
if (this.getParent()) {
return this.getParent().do_notify.apply(this,arguments);
}
return false;
},
do_warn: function() {
if (this.getParent()) {
return this.getParent().do_warn.apply(this,arguments);
}
return false;
},
rpc: function(url, data, options) {
return this.alive(openerp.session.rpc(url, data, options));
}
};
/**
A class containing common utility methods useful when working with OpenERP as well as the PropertiesMixin.
*/
openerp.web.Controller = openerp.web.Class.extend(openerp.web.PropertiesMixin, ControllerMixin, {
/**
* Constructs the object and sets its parent if a parent is given.
*
* @param {openerp.web.Controller} parent Binds the current instance to the given Controller instance.
* When that controller is destroyed by calling destroy(), the current instance will be
* destroyed too. Can be null.
*/
init: function(parent) {
openerp.web.PropertiesMixin.init.call(this);
this.setParent(parent);
this.session = openerp.session;
},
});
openerp.web.Widget.include(_.extend({}, ControllerMixin, {
init: function() {
this._super.apply(this, arguments);
this.session = openerp.session;
},
}));
instance.web.Registry = instance.web.Class.extend({
/**
* Stores a mapping of arbitrary key (strings) to object paths (as strings
* as well).
*
* Resolves those paths at query time in order to always fetch the correct
* object, even if those objects have been overloaded/replaced after the
* registry was created.
*
* An object path is simply a dotted name from the instance root to the
* object pointed to (e.g. ``"instance.web.Session"`` for an OpenERP
* session object).
*
* @constructs instance.web.Registry
* @param {Object} mapping a mapping of keys to object-paths
*/
init: function (mapping) {
this.parent = null;
this.map = mapping || {};
},
/**
* Retrieves the object matching the provided key string.
*
* @param {String} key the key to fetch the object for
* @param {Boolean} [silent_error=false] returns undefined if the key or object is not found, rather than throwing an exception
* @returns {Class} the stored class, to initialize or null if not found
*/
get_object: function (key, silent_error) {
var path_string = this.map[key];
if (path_string === undefined) {
if (this.parent) {
return this.parent.get_object(key, silent_error);
}
if (silent_error) { return void 'nooo'; }
return null;
}
var object_match = instance;
var path = path_string.split('.');
// ignore first section
for(var i=1; i<path.length; ++i) {
object_match = object_match[path[i]];
if (object_match === undefined) {
if (silent_error) { return void 'noooooo'; }
return null;
}
}
return object_match;
},
/**
* Checks if the registry contains an object mapping for this key.
*
* @param {String} key key to look for
*/
contains: function (key) {
if (key === undefined) { return false; }
if (key in this.map) {
return true;
}
if (this.parent) {
return this.parent.contains(key);
}
return false;
},
/**
* Tries a number of keys, and returns the first object matching one of
* the keys.
*
* @param {Array} keys a sequence of keys to fetch the object for
* @returns {Class} the first class found matching an object
*/
get_any: function (keys) {
for (var i=0; i<keys.length; ++i) {
var key = keys[i];
if (!this.contains(key)) {
continue;
}
return this.get_object(key);
}
return null;
},
/**
* Adds a new key and value to the registry.
*
* This method can be chained.
*
* @param {String} key
* @param {String} object_path fully qualified dotted object path
* @returns {instance.web.Registry} itself
*/
add: function (key, object_path) {
this.map[key] = object_path;
return this;
},
/**
* Creates and returns a copy of the current mapping, with the provided
* mapping argument added in (replacing existing keys if needed)
*
* Parent and child remain linked, a new key in the parent (which is not
* overwritten by the child) will appear in the child.
*
* @param {Object} [mapping={}] a mapping of keys to object-paths
*/
extend: function (mapping) {
var child = new instance.web.Registry(mapping);
child.parent = this;
return child;
},
/**
* @deprecated use Registry#extend
*/
clone: function (mapping) {
console.warn('Registry#clone is deprecated, use Registry#extend');
return this.extend(mapping);
}
});
instance.web.py_eval = function(expr, context) {
return py.eval(expr, _.extend({}, context || {}, {"true": true, "false": false, "null": null}));
};
};
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:

View File

@ -1,3 +1,27 @@
/*
* Copyright (c) 2012, OpenERP S.A.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
(function() {
/* jshint es3: true */

View File

@ -3,13 +3,12 @@ openerp.testing = {};
(function (testing) {
var dependencies = {
pyeval: [],
corelib: ['pyeval'],
coresetup: ['corelib'],
data: ['corelib', 'coresetup'],
core: ['pyeval'],
data: ['core'],
dates: [],
formats: ['coresetup', 'dates'],
chrome: ['corelib', 'coresetup'],
views: ['corelib', 'coresetup', 'data', 'chrome'],
formats: ['core', 'dates'],
chrome: ['core'],
views: ['core', 'data', 'chrome'],
search: ['views', 'formats'],
list: ['views', 'data'],
form: ['data', 'views', 'list', 'formats'],

View File

@ -1,5 +1,5 @@
openerp.testing.section('eval.types', {
dependencies: ['web.coresetup'],
dependencies: ['web.core'],
setup: function (instance) {
instance.session.uid = 42;
}
@ -562,7 +562,7 @@ openerp.testing.section('eval.edc.nonliterals', {
});
});
openerp.testing.section('eval.contexts', {
dependencies: ['web.coresetup']
dependencies: ['web.core']
}, function (test) {
test('context_recursive', function (instance) {
var context_to_eval = [{
@ -773,7 +773,7 @@ openerp.testing.section('eval.contexts', {
});
});
openerp.testing.section('eval.domains', {
dependencies: ['web.coresetup', 'web.dates']
dependencies: ['web.core', 'web.dates']
}, function (test) {
test('current_date', function (instance) {
var current_date = instance.web.date_to_str(new Date());
@ -802,7 +802,7 @@ openerp.testing.section('eval.domains', {
});
});
openerp.testing.section('eval.groupbys', {
dependencies: ['web.coresetup']
dependencies: ['web.core']
}, function (test) {
test('groupbys_00', function (instance) {
var result = instance.web.pyeval.eval('groupbys', [

View File

@ -1,5 +1,5 @@
openerp.testing.section('server-formats', {
dependencies: ['web.coresetup', 'web.dates']
dependencies: ['web.core', 'web.dates']
}, function (test) {
test('Parse server datetime', function (instance) {
var date = instance.web.str_to_datetime("2009-05-04 12:34:23");

View File

@ -5,7 +5,7 @@ var ropenerp = window.openerp;
var openerp = ropenerp.declare($, _, QWeb2);
ropenerp.testing.section('class', {
dependencies: ['web.corelib']
dependencies: ['web.core']
}, function (test) {
test('Basic class creation', function () {
var C = openerp.Class.extend({

View File

@ -27,8 +27,7 @@
<script src="/web/static/lib/py.js/lib/py.js"></script>
<script src="/web/static/src/js/boot.js"></script>
<script src="/web/static/src/js/corelib.js"></script>
<script src="/web/static/src/js/coresetup.js"></script>
<script src="/web/static/src/js/core.js"></script>
<script src="/web/static/src/js/dates.js"></script>
<script src="/web/static/src/js/formats.js"></script>
<script src="/web/static/src/js/chrome.js"></script>

View File

@ -1,5 +1,5 @@
openerp.testing.section('mutex', {
dependencies: ['web.coresetup'],
dependencies: ['web.core'],
setup: function (instance) {
}
}, function (test) {

View File

@ -1,5 +1,5 @@
openerp.testing.section('registry', {
dependencies: ['web.corelib'],
dependencies: ['web.core'],
setup: function (instance) {
instance.web.Foo = {};
instance.web.Bar = {};