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