Engine.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. Ext.ns('App');
  2. App.Engine = function(modules) {
  3. this.map = {};
  4. this.setup(modules);
  5. };
  6. App.Engine.prototype = {
  7. setup: function(modules) {
  8. modules = modules ? modules : {};
  9. for (var key in modules) {
  10. var obj = modules[key];
  11. this.reg(key, obj);
  12. }
  13. this.createSecurity(modules.security);
  14. this.init();
  15. },
  16. reg: function(key, obj) {
  17. this.map[key] = {
  18. title: obj.title,
  19. content: key,
  20. fn: null,
  21. iconCls: obj.iconCls,
  22. notConstructor: true,
  23. items: []
  24. };
  25. for (var i = 0; i < obj.items.length; i++) {
  26. var item = obj.items[i];
  27. if (typeof item == 'function') {
  28. this.map[key].items.push({
  29. content: item.prototype.id,
  30. fn: item,
  31. iconCls: item.prototype.iconCls,
  32. notConstructor: false,
  33. title: item.prototype.title
  34. });
  35. } else if (typeof item == 'object') {
  36. this.map[key].items.push({
  37. content: item.content,
  38. fn: item.fn,
  39. iconCls: item.iconCls,
  40. notConstructor: item.notConstructor,
  41. title: item.title
  42. });
  43. }
  44. }
  45. },
  46. createSecurity: function(security) {
  47. if (!security) {
  48. security = [];
  49. for (var key in this.map) {
  50. var obj = this.map[key];
  51. var parent = {
  52. text: obj.title,
  53. leaf: false,
  54. content: key,
  55. children: []
  56. };
  57. for (var i = 0; i < obj.items.length; i++) {
  58. var item = obj.items[i];
  59. parent.children.push({
  60. text: item.title,
  61. leaf: true,
  62. content: item.content
  63. });
  64. }
  65. security.push(parent);
  66. }
  67. }
  68. App.view = new Ext.ux.Workbench(security);
  69. },
  70. init: function() {
  71. for (var key in this.map) {
  72. var obj = this.map[key];
  73. App.view.register(obj.content, obj.fn, obj.iconCls, obj.notConstructor);
  74. for (var i = 0; i < obj.items.length; i++) {
  75. var item = obj.items[i];
  76. App.view.register(item.content, item.fn, item.iconCls, item.notConstructor);
  77. }
  78. }
  79. App.view.init();
  80. }
  81. }