PageRenderTime 34ms CodeModel.GetById 12ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/ext-3.4.1/src/error-checking.js

https://github.com/ouzo12/tvheadend
JavaScript | 378 lines | 329 code | 29 blank | 20 comment | 65 complexity | 8b303fc97dc282268c6291d245900ae3 MD5 | raw file
  1/*
  2This file is part of Ext JS 3.4
  3
  4Copyright (c) 2011-2013 Sencha Inc
  5
  6Contact:  http://www.sencha.com/contact
  7
  8GNU General Public License Usage
  9This file may be used under the terms of the GNU General Public License version 3.0 as
 10published by the Free Software Foundation and appearing in the file LICENSE included in the
 11packaging of this file.
 12
 13Please review the following information to ensure the GNU General Public License version 3.0
 14requirements will be met: http://www.gnu.org/copyleft/gpl.html.
 15
 16If you are unsure which license is appropriate for your use, please contact the sales department
 17at http://www.sencha.com/contact.
 18
 19Build date: 2013-04-03 15:07:25
 20*/
 21Ext.ns('Ext.debug');
 22Ext.debug.Assistant = function(){
 23    var enabled = true;
 24        
 25    return {
 26        enable: function(){
 27            enabled = true;
 28        },
 29        
 30        disable: function(){
 31            enabled = false;
 32        },
 33        
 34        init : function(classes){
 35            var klass,
 36                intercept = false,
 37                fn,
 38                method;
 39            Ext.each(classes, function(cls){
 40                if(this.namespaceExists(cls.name)){
 41                    klass = this.getClass(cls.name);
 42                    method = cls.instance ? this.addInstanceCheck : this.addPrototypeCheck;
 43                    Ext.each(cls.checks, function(check){
 44                        intercept = check.intercept == true;
 45                        fn = method.call(this, klass, check.name, check.fn, check.intercept == true);
 46                        if(check.after){
 47                            check.after(fn);
 48                        }
 49                    }, this);
 50                }
 51            }, this);  
 52        },
 53        
 54        namespaceExists: function(name){
 55            var parent = window,
 56                exists = true;
 57                
 58            Ext.each(name.split('.'), function(n){
 59                if(!Ext.isDefined(parent[n])){
 60                    exists = false;
 61                    return false;
 62                }
 63                parent = parent[n];
 64            });
 65            return exists;
 66        },
 67        
 68        getClass : function(name){
 69            var parent = window;
 70            Ext.each(name.split('.'), function(n){
 71                parent = parent[n];
 72            });  
 73            return parent;
 74        },
 75        
 76        warn: function(){
 77            if(enabled && window.console){
 78                console.warn.apply(console, arguments);
 79            }
 80        },
 81        
 82        error: function(){
 83            if(enabled && window.console){
 84                console.error.apply(console, arguments);
 85            }
 86        },
 87        
 88        addPrototypeCheck : function(cls, method, fn, intercept){
 89            return (cls.prototype[method] = cls.prototype[method][intercept ? 'createInterceptor' : 'createSequence'](fn));
 90        },
 91        
 92        addInstanceCheck : function(cls, method, fn, intercept){
 93            return (cls[method] = cls[method][intercept ? 'createInterceptor' : 'createSequence'](fn));
 94        }
 95    };
 96}();
 97
 98(function(){
 99    var A = Ext.debug.Assistant,
100        cls = [];
101        
102    cls.push({
103        name: 'Ext.util.Observable',
104        checks: [{
105            name: 'addListener',
106            intercept: true,
107            fn: function(eventName, fn){
108                if(typeof eventName == 'object'){
109                    var ev, o;
110                    for(ev in eventName){
111                        if(!this.filterOptRe.test(ev)){
112                            o = eventName[ev];
113                            o = o && o.fn ? o.fn : o;
114                            if(!Ext.isFunction(o)){
115                                A.error('Non function passed to event listener', this, ev);
116                                return false;
117                            }
118                        }
119                    }
120                }else{
121                    if(!Ext.isFunction(fn)){
122                        A.error('Non function passed to event listener', this, eventName);
123                    }
124                }
125            },
126            after: function(method){
127                Ext.util.Observable.prototype.on = method;
128            }
129        }]
130    });
131    
132    cls.push({
133        name: 'Ext.Component',
134        checks: [{
135            name: 'render',
136            intercept: true,
137            fn: function(container, position){
138                if(!container && !this.el){
139                    A.error('Unable to render to container', this, container);
140                }
141            
142                if(this.contentEl){
143                    var el = Ext.getDom(this.contentEl);
144                    if(!el){
145                        A.error('Specified contentEl does not exist', this, this.contentEl);
146                        return false;
147                    }
148                }
149            }
150        }]
151    });
152    
153    cls.push({
154        name: 'Ext.Container',
155        checks: [{
156            name: 'onBeforeAdd',
157            intercept: true,
158            fn: function(c){
159                if(c.isDestroyed){
160                    A.warn('Adding destroyed component to container', c, this);
161                }
162                if(c.renderTo){
163                    A.warn('Using renderTo while adding an item to a Container. You should use the add() method or put the item in the items configuration', c, this);
164                }
165                if(c.applyTo){
166                    A.warn('Using applyTo while adding an item to a Container. You should use the add() method or put the item in the items configuration', c, this);
167                }
168                
169                var type = this.layout.type;
170                if(type == 'container' || type == 'auto'){
171                    A.warn('A non sizing layout is being used in a container that has child components. This means the child components will not be sized.', this);
172                }
173            }
174        },{
175            name: 'lookupComponent',
176            intercept: true,
177            fn: function(c){
178                var valid = true;
179                if(Ext.isEmpty(c)){
180                    valid = false;
181                }
182                if(Ext.isString(c)){
183                    c = Ext.ComponentMgr.get(comp);
184                    valid = !Ext.isEmpty(c);
185                }
186                if(!valid){
187                    A.error('Adding invalid component to container', this, c);
188                    return false;
189                }
190            }
191        }]
192    });
193    
194    cls.push({
195        name: 'Ext.DataView',
196        checks: [{
197            name: 'initComponent',
198            fn: function(){
199                if(!this.itemSelector){
200                    A.error('No itemSelector specified', this);
201                }
202            }
203        },{
204            name: 'afterRender',
205            fn: function(){
206                if(!this.store){
207                    A.error('No store attached to DataView', this);
208                } 
209            }
210        }]
211    });
212    
213    cls.push({
214        name: 'Ext.Window',
215        checks: [{
216            name: 'show',
217            intercept: true,
218            fn: function(){
219                if(this.isDestroyed){
220                    A.error('Trying to show a destroyed window. If you want to reuse the window, look at the closeAction configuration.', this);
221                    return false;
222                } 
223            }
224        }]
225    });
226    
227    cls.push({
228        name: 'Ext.grid.GridPanel',
229        checks: [{
230            name: 'initComponent',
231            fn: function(){
232                if(!this.colModel){
233                    A.error('No column model specified for grid', this);
234                }
235                if(!this.store){
236                    A.error('No store specified for grid', this);
237                }
238            }
239        }]
240    });
241    
242    cls.push({
243        name: 'Ext.grid.GridView',
244        checks: [{
245            name: 'autoExpand',
246            intercept: true,
247            fn: function(){
248                var g = this.grid, 
249                cm = this.cm;
250                if(!this.userResized && g.autoExpandColumn){
251                    var tw = cm.getTotalWidth(false), 
252                        aw = this.grid.getGridEl().getWidth(true) - this.getScrollOffset();
253                    if(tw != aw){
254                        var ci = cm.getIndexById(g.autoExpandColumn);
255                        if(ci == -1){
256                            A.error('The autoExpandColumn does not exist in the column model', g, g.autoExpandColumn);
257                            return false;
258                        }
259                    }
260                }
261            }
262        }]
263    });
264    
265    cls.push({
266        name: 'Ext.chart.Chart',
267        checks: [{
268            name: 'initComponent',
269            fn: function(){
270                if(!this.store){
271                    A.error('No store specified for chart', this);
272                }
273            }
274        }]
275    });
276    
277    cls.push({
278        name: 'Ext.tree.TreePanel',
279        checks: [{
280            name: 'afterRender',
281            intercept: true,
282            fn: function(){
283                if(!this.root){
284                    A.error('No root node specified for tree', this);
285                    return false;
286                }
287            }
288        }]
289    });
290    
291    cls.push({
292        name: 'Ext',
293        instance: true,
294        checks: [{
295            name: 'extend',
296            intercept: true,
297            fn: function(){
298                if(arguments.length == 2 && !arguments[0]){
299                    A.error('Invalid base class passed to extend', arguments[0]);
300                    return false;
301                }    
302                if(arguments.length == 3){
303                    if(!arguments[0]){
304                        A.error('Invalid class to extend', arguments[0]);
305                        return false;    
306                    }else if(!arguments[1]){
307                        A.error('Invalid base class passed to extend', arguments[1]);
308                        return false;
309                    }
310                }
311            }
312        },{
313            name: 'override',
314            intercept: true,
315            fn: function(c){
316                if(!c){
317                    A.error('Invalid class passed to override', c);
318                    return false;
319                }
320            }
321        }]    
322    });
323    
324    cls.push({
325        name: 'Ext.ComponentMgr',
326        instance: true,
327        checks: [{
328            name: 'register',
329            intercept: true,
330            fn: function(c){
331                if(this.all.indexOfKey(c.id) > -1){
332                    A.warn('A component with this id already exists', c, c.id);
333                }
334            }
335        },{
336            name: 'create',
337            intercept: true,
338            fn: function(config, defaultType){
339                var types = Ext.ComponentMgr.types;
340                if(!config.render){
341                    if(config.xtype){
342                        if(!types[config.xtype]){
343                            A.error('Unknown xtype specified', config, config.xtype);
344                            return false;
345                        }
346                    }else{
347                        if(!types[defaultType]){
348                            A.error('Unknown defaultType specified', config, defaultType);
349                            return false;
350                        }
351                    }
352                }
353            }
354        }]
355    });
356    
357    cls.push({
358        name: 'Ext.layout.FitLayout',
359        checks: [{
360            name: 'onLayout',
361            intercept: true,
362            fn: function(){
363                var ct = this.container;
364                if(ct.items.getCount() > 1){
365                    A.warn('More than 1 item in the container. A fit layout will only display a single item.', ct);
366                }
367            }
368        }]
369    });
370    
371    if(Ext.BLANK_IMAGE_URL == 'http:/' + '/www.extjs.com/s.gif'){
372        A.warn('You should set the Ext.BLANK_IMAGE_URL to reference a local copy.');
373    }
374    
375    A.init(cls);
376    
377        
378})();