~therp-nl/openerp-web/7.0-lp1013636-x2m_honour_required_attribute

« back to all changes in this revision

Viewing changes to addons/web/static/lib/novajs/src/nova.js

[MERGE] from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    lib.internal = {};
29
29
 
30
30
    /*
31
 
     * (Almost) unmodified John Resig's inheritance
 
31
     * (Almost) unmodified John Resig's inheritance.
 
32
     *
 
33
     * Defines The Class object. That object can be used to define and inherit classes using
 
34
     * the extend() method.
 
35
     *
 
36
     * Example:
 
37
     *
 
38
     * var Person = nova.Class.extend({
 
39
     *  init: function(isDancing){
 
40
     *     this.dancing = isDancing;
 
41
     *   },
 
42
     *   dance: function(){
 
43
     *     return this.dancing;
 
44
     *   }
 
45
     * });
 
46
     *
 
47
     * The init() method act as a constructor. This class can be instancied this way:
 
48
     *
 
49
     * var person = new Person(true);
 
50
     * person.dance();
 
51
     *
 
52
     * The Person class can also be extended again:
 
53
     *
 
54
     * var Ninja = Person.extend({
 
55
     *   init: function(){
 
56
     *     this._super( false );
 
57
     *   },
 
58
     *   dance: function(){
 
59
     *     // Call the inherited version of dance()
 
60
     *     return this._super();
 
61
     *   },
 
62
     *   swingSword: function(){
 
63
     *     return true;
 
64
     *   }
 
65
     * });
 
66
     *
 
67
     * When extending a class, each re-defined method can use this._super() to call the previous
 
68
     * implementation of that method.
32
69
     */
33
 
    /*
34
 
     * Simple JavaScript Inheritance By John Resig http://ejohn.org/ MIT
35
 
     * Licensed.
 
70
    /* Simple JavaScript Inheritance
 
71
     * By John Resig http://ejohn.org/
 
72
     * MIT Licensed.
36
73
     */
37
74
    // Inspired by base2 and Prototype
38
 
    (function() {
39
 
        var initializing = false, fnTest = /xyz/.test(function() {
40
 
            xyz;
41
 
        }) ? /\b_super\b/ : /.*/;
42
 
        // The base Class implementation (does nothing)
43
 
        this.Class = function() {
44
 
        };
45
 
 
46
 
        // Create a new Class that inherits from this class
47
 
        this.Class.extend = function(prop) {
 
75
    (function(){
 
76
      var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
 
77
      // The base Class implementation (does nothing)
 
78
      this.Class = function(){};
 
79
      
 
80
      // Create a new Class that inherits from this class
 
81
      this.Class.extend = function(prop) {
48
82
        var _super = this.prototype;
49
 
 
50
 
        // Instantiate a web class (but only create the instance,
 
83
        
 
84
        // Instantiate a base class (but only create the instance,
51
85
        // don't run the init constructor)
52
86
        initializing = true;
53
87
        var prototype = new this();
54
88
        initializing = false;
55
 
 
 
89
        
56
90
        // Copy the properties over onto the new prototype
57
91
        for (var name in prop) {
58
 
            // Check if we're overwriting an existing function
59
 
            prototype[name] = typeof prop[name] == "function" &&
60
 
                              typeof _super[name] == "function" &&
61
 
                              fnTest.test(prop[name]) ?
62
 
                    (function(name, fn) {
63
 
                        return function() {
64
 
                            var tmp = this._super;
65
 
 
66
 
                            // Add a new ._super() method that is the same
67
 
                            // method but on the super-class
68
 
                            this._super = _super[name];
69
 
 
70
 
                            // The method only need to be bound temporarily, so
71
 
                            // we remove it when we're done executing
72
 
                            var ret = fn.apply(this, arguments);
73
 
                            this._super = tmp;
74
 
 
75
 
                            return ret;
76
 
                        };
77
 
                    })(name, prop[name]) :
78
 
                    prop[name];
 
92
          // Check if we're overwriting an existing function
 
93
          prototype[name] = typeof prop[name] == "function" && 
 
94
            typeof _super[name] == "function" && fnTest.test(prop[name]) ?
 
95
            (function(name, fn){
 
96
              return function() {
 
97
                var tmp = this._super;
 
98
                
 
99
                // Add a new ._super() method that is the same method
 
100
                // but on the super-class
 
101
                this._super = _super[name];
 
102
                
 
103
                // The method only need to be bound temporarily, so we
 
104
                // remove it when we're done executing
 
105
                var ret = fn.apply(this, arguments);        
 
106
                this._super = tmp;
 
107
                
 
108
                return ret;
 
109
              };
 
110
            })(name, prop[name]) :
 
111
            prop[name];
79
112
        }
80
 
 
 
113
        
81
114
        // The dummy class constructor
82
115
        function Class() {
83
 
            // All construction is actually done in the init method
84
 
            if (!initializing && this.init) {
85
 
                var ret = this.init.apply(this, arguments);
86
 
                if (ret) { return ret; }
87
 
            }
88
 
            return this;
 
116
          // All construction is actually done in the init method
 
117
          if ( !initializing && this.init )
 
118
            this.init.apply(this, arguments);
89
119
        }
90
 
        Class.include = function (properties) {
91
 
            for (var name in properties) {
92
 
                if (typeof properties[name] !== 'function'
93
 
                        || !fnTest.test(properties[name])) {
94
 
                    prototype[name] = properties[name];
95
 
                } else if (typeof prototype[name] === 'function'
96
 
                           && prototype.hasOwnProperty(name)) {
97
 
                    prototype[name] = (function (name, fn, previous) {
98
 
                        return function () {
99
 
                            var tmp = this._super;
100
 
                            this._super = previous;
101
 
                            var ret = fn.apply(this, arguments);
102
 
                            this._super = tmp;
103
 
                            return ret;
104
 
                        }
105
 
                    })(name, properties[name], prototype[name]);
106
 
                } else if (typeof _super[name] === 'function') {
107
 
                    prototype[name] = (function (name, fn) {
108
 
                        return function () {
109
 
                            var tmp = this._super;
110
 
                            this._super = _super[name];
111
 
                            var ret = fn.apply(this, arguments);
112
 
                            this._super = tmp;
113
 
                            return ret;
114
 
                        }
115
 
                    })(name, properties[name]);
116
 
                }
117
 
            }
118
 
        };
119
 
 
 
120
        
120
121
        // Populate our constructed prototype object
121
122
        Class.prototype = prototype;
122
 
 
 
123
        
123
124
        // Enforce the constructor to be what we expect
124
 
        Class.constructor = Class;
125
 
 
 
125
        Class.prototype.constructor = Class;
 
126
    
126
127
        // And make this class extendable
127
 
        Class.extend = arguments.callee;
128
 
 
 
128
        for(el in this) {
 
129
            Class[el] = this[el];
 
130
        }
 
131
        
129
132
        return Class;
130
 
        };
 
133
      };
131
134
    }).call(lib);
132
135
    // end of John Resig's code
133
136
 
 
137
    /**
 
138
     * Mixin to express the concept of destroying an object.
 
139
     * When an object is destroyed, it should release any resource
 
140
     * it could have reserved before.
 
141
     */
134
142
    lib.DestroyableMixin = {
135
143
        init: function() {
136
144
            this.__destroyableDestroyed = false;
137
145
        },
 
146
        /**
 
147
         * Returns true if destroy() was called on the current object.
 
148
         */
138
149
        isDestroyed : function() {
139
150
            return this.__destroyableDestroyed;
140
151
        },
 
152
        /**
 
153
         * Inform the object it should destroy itself, releasing any
 
154
         * resource it could have reserved.
 
155
         */
141
156
        destroy : function() {
142
157
            this.__destroyableDestroyed = true;
143
158
        }
144
159
    };
145
160
 
 
161
    /**
 
162
     * Mixin to structure objects' life-cycles folowing a parent-children
 
163
     * relationship. Each object can a have a parent and multiple children.
 
164
     * When an object is destroyed, all its children are destroyed too.
 
165
     */
146
166
    lib.ParentedMixin = _.extend({}, lib.DestroyableMixin, {
147
167
        __parentedMixin : true,
148
168
        init: function() {
150
170
            this.__parentedChildren = [];
151
171
            this.__parentedParent = null;
152
172
        },
 
173
        /**
 
174
         * Set the parent of the current object. When calling this method, the
 
175
         * parent will also be informed and will return the current object
 
176
         * when its getChildren() method is called. If the current object did
 
177
         * already have a parent, it is unregistered before, which means the
 
178
         * previous parent will not return the current object anymore when its
 
179
         * getChildren() method is called.
 
180
         */
153
181
        setParent : function(parent) {
154
182
            if (this.getParent()) {
155
183
                if (this.getParent().__parentedMixin) {
162
190
                parent.__parentedChildren.push(this);
163
191
            }
164
192
        },
 
193
        /**
 
194
         * Return the current parent of the object (or null).
 
195
         */
165
196
        getParent : function() {
166
197
            return this.__parentedParent;
167
198
        },
 
199
        /**
 
200
         * Return a list of the children of the current object.
 
201
         */
168
202
        getChildren : function() {
169
203
            return _.clone(this.__parentedChildren);
170
204
        },