2 Copyright (c) 2011, OpenERP S.A.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /* Simple JavaScript Inheritance
30 * By John Resig http://ejohn.org/
33 // Inspired by base2 and Prototype
35 var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
36 // The base Class implementation (does nothing)
37 this.Class = function(){};
39 // Create a new Class that inherits from this class
40 this.Class.extend = function(prop) {
41 var _super = this.prototype;
43 // Instantiate a base class (but only create the instance,
44 // don't run the init constructor)
46 var prototype = new this();
49 // Copy the properties over onto the new prototype
50 for (var name in prop) {
51 // Check if we're overwriting an existing function
52 prototype[name] = typeof prop[name] == "function" &&
53 typeof _super[name] == "function" && fnTest.test(prop[name]) ?
56 var tmp = this._super;
58 // Add a new ._super() method that is the same method
59 // but on the super-class
60 this._super = _super[name];
62 // The method only need to be bound temporarily, so we
63 // remove it when we're done executing
64 var ret = fn.apply(this, arguments);
69 })(name, prop[name]) :
73 // The dummy class constructor
75 // All construction is actually done in the init method
76 if ( !initializing && this.init )
77 this.init.apply(this, arguments);
80 // Populate our constructed prototype object
81 Class.prototype = prototype;
83 // Enforce the constructor to be what we expect
84 Class.prototype.constructor = Class;
86 // And make this class extendable
87 Class.extend = arguments.callee;
94 __parented_mixin: true,
95 setParent: function(parent) {
96 if(this.getParent()) {
97 if (this.getParent().__parented_mixin) {
98 this.getParent().__parented_children = _.without(this.getParent().getChildren(), this);
100 this.__parented_parent = undefined;
102 this.__parented_parent = parent;
103 if(parent && parent.__parented_mixin) {
104 if (!parent.getChildren())
105 parent.__parented_children = [];
106 parent.getChildren().push(this);
109 getParent: function() {
110 return this.__parented_parent;
112 getChildren: function() {
113 return this.__parented_children || [];
115 isDestroyed: function() {
116 return this.__parented_stopped;