PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/ext3/src/error-checking.js

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