PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/ext3/docs/source/error-checking.html

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