[imp] switched to nivjs

bzr revid: nicolas.vanhoren@openerp.com-20120223161041-mymbna11fsp3bo9m
This commit is contained in:
niv-openerp 2012-02-23 17:10:41 +01:00
parent 2b73fb4a6a
commit fa510462f4
3 changed files with 101 additions and 130 deletions

View File

@ -36,6 +36,7 @@
"static/lib/underscore/underscore.string.js", "static/lib/underscore/underscore.string.js",
"static/lib/labjs/LAB.src.js", "static/lib/labjs/LAB.src.js",
"static/lib/py.parse/lib/py.js", "static/lib/py.parse/lib/py.js",
"static/lib/nivjs/src/niv.js",
"static/src/js/boot.js", "static/src/js/boot.js",
"static/src/js/core.js", "static/src/js/core.js",
"static/src/js/dates.js", "static/src/js/dates.js",

View File

@ -24,17 +24,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
niv = (function() { niv = (function() {
var niv = {}; var lib = {};
/* /*
* Simple JavaScript Inheritance By John Resig http://ejohn.org/ MIT * Simple JavaScript Inheritance By John Resig http://ejohn.org/ MIT
* Licensed. * Licensed.
*/ */
// Inspired by base2 and Prototype // Inspired by base2 and Prototype
(function(){ (function() {
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; var initializing = false, fnTest = /xyz/.test(function() {
xyz;
}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing) // The base Class implementation (does nothing)
this.Class = function(){}; this.Class = function() {
};
// Create a new Class that inherits from this class // Create a new Class that inherits from this class
this.Class.extend = function(prop) { this.Class.extend = function(prop) {
@ -47,11 +50,11 @@ niv = (function() {
initializing = false; initializing = false;
// Copy the properties over onto the new prototype // Copy the properties over onto the new prototype
for (var name in prop) { for ( var name in prop) {
// Check if we're overwriting an existing function // Check if we're overwriting an existing function
prototype[name] = typeof prop[name] == "function" && prototype[name] = typeof prop[name] == "function"
typeof _super[name] == "function" && fnTest.test(prop[name]) ? && typeof _super[name] == "function"
(function(name, fn){ && fnTest.test(prop[name]) ? (function(name, fn) {
return function() { return function() {
var tmp = this._super; var tmp = this._super;
@ -66,14 +69,13 @@ niv = (function() {
return ret; return ret;
}; };
})(name, prop[name]) : })(name, prop[name]) : prop[name];
prop[name];
} }
// The dummy class constructor // The dummy class constructor
function Class() { function Class() {
// All construction is actually done in the init method // All construction is actually done in the init method
if ( !initializing && this.init ) if (!initializing && this.init)
this.init.apply(this, arguments); this.init.apply(this, arguments);
} }
@ -88,41 +90,43 @@ niv = (function() {
return Class; return Class;
}; };
}).call(niv); }).call(lib);
niv.ParentedMixin = { lib.ParentedMixin = {
__parented_mixin: true, __parented_mixin : true,
setParent: function(parent) { setParent : function(parent) {
if(this.getParent()) { if (this.getParent()) {
if (this.getParent().__parented_mixin) { if (this.getParent().__parented_mixin) {
this.getParent().__parented_children = _.without(this.getParent().getChildren(), this); this.getParent().__parented_children = _.without(this
.getParent().getChildren(), this);
} }
this.__parented_parent = undefined; this.__parented_parent = undefined;
} }
this.__parented_parent = parent; this.__parented_parent = parent;
if(parent && parent.__parented_mixin) { if (parent && parent.__parented_mixin) {
if (!parent.getChildren()) if (!parent.__parented_children)
parent.__parented_children = []; parent.__parented_children = [];
parent.getChildren().push(this); parent.__parented_children.push(this);
} }
}, },
getParent: function() { getParent : function() {
return this.__parented_parent; return this.__parented_parent;
}, },
getChildren: function() { getChildren : function() {
return this.__parented_children ? _.clone(this.__parented_children) : []; return this.__parented_children ? _.clone(this.__parented_children)
: [];
}, },
isDestroyed: function() { isDestroyed : function() {
return this.__parented_stopped; return this.__parented_destroyed;
}, },
destroy: function() { destroy : function() {
_.each(this.getChildren(), function(el) { _.each(this.getChildren(), function(el) {
el.destroy(); el.destroy();
}); });
this.setParent(undefined); this.setParent(undefined);
this.__parented_stopped = true; this.__parented_destroyed = true;
}, }
}; };
return niv; return lib;
})(); })();

View File

@ -925,40 +925,6 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp.
} }
}); });
openerp.web.ParentedMixin = {
__parented_mixin: true,
setParent: function(parent) {
if(this.getParent()) {
if (this.getParent().__parented_mixin) {
this.getParent().__parented_children = _.without(this.getParent().getChildren(), this);
}
this.__parented_parent = undefined;
}
this.__parented_parent = parent;
if(parent && parent.__parented_mixin) {
if (!parent.__parented_children)
parent.__parented_children = [];
parent.__parented_children.push(this);
}
},
getParent: function() {
return this.__parented_parent;
},
getChildren: function() {
return this.__parented_children ? _.clone(this.__parented_children) : [];
},
isDestroyed: function() {
return this.__parented_destroyed;
},
destroy: function() {
_.each(this.getChildren(), function(el) {
el.destroy();
});
this.setParent(undefined);
this.__parented_destroyed = true;
},
};
/** /**
* Base class for all visual components. Provides a lot of functionalities helpful * Base class for all visual components. Provides a lot of functionalities helpful
* for the management of a part of the DOM. * for the management of a part of the DOM.
@ -1007,7 +973,7 @@ openerp.web.ParentedMixin = {
* *
* That will kill the widget in a clean way and erase its content from the dom. * That will kill the widget in a clean way and erase its content from the dom.
*/ */
openerp.web.Widget = openerp.web.CallbackEnabled.extend(openerp.web.ParentedMixin).extend(/** @lends openerp.web.Widget# */{ openerp.web.Widget = openerp.web.CallbackEnabled.extend(niv.ParentedMixin).extend(/** @lends openerp.web.Widget# */{
/** /**
* The name of the QWeb template that will be used for rendering. Must be * The name of the QWeb template that will be used for rendering. Must be
* redefined in subclasses or the default render() method can not be used. * redefined in subclasses or the default render() method can not be used.