/ext-4.1.0_b3/docs/source/Application.html

https://bitbucket.org/srogerf/javascript · HTML · 287 lines · 242 code · 45 blank · 0 comment · 0 complexity · 45c9b965872711cb7b4e0c719759fd7e MD5 · raw file

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-app-Application'>/**
  19. </span> * Represents an Ext JS 4 application, which is typically a single page app using a {@link Ext.container.Viewport Viewport}.
  20. * A typical Ext.app.Application might look like this:
  21. *
  22. * Ext.application({
  23. * name: 'MyApp',
  24. * launch: function() {
  25. * Ext.create('Ext.container.Viewport', {
  26. * items: {
  27. * html: 'My App'
  28. * }
  29. * });
  30. * }
  31. * });
  32. *
  33. * This does several things. First it creates a global variable called 'MyApp' - all of your Application's classes (such
  34. * as its Models, Views and Controllers) will reside under this single namespace, which drastically lowers the chances
  35. * of colliding global variables.
  36. *
  37. * When the page is ready and all of your JavaScript has loaded, your Application's {@link #launch} function is called,
  38. * at which time you can run the code that starts your app. Usually this consists of creating a Viewport, as we do in
  39. * the example above.
  40. *
  41. * # Telling Application about the rest of the app
  42. *
  43. * Because an Ext.app.Application represents an entire app, we should tell it about the other parts of the app - namely
  44. * the Models, Views and Controllers that are bundled with the application. Let's say we have a blog management app; we
  45. * might have Models and Controllers for Posts and Comments, and Views for listing, adding and editing Posts and Comments.
  46. * Here's how we'd tell our Application about all these things:
  47. *
  48. * Ext.application({
  49. * name: 'Blog',
  50. * models: ['Post', 'Comment'],
  51. * controllers: ['Posts', 'Comments'],
  52. *
  53. * launch: function() {
  54. * ...
  55. * }
  56. * });
  57. *
  58. * Note that we didn't actually list the Views directly in the Application itself. This is because Views are managed by
  59. * Controllers, so it makes sense to keep those dependencies there. The Application will load each of the specified
  60. * Controllers using the pathing conventions laid out in the [application architecture guide][mvc] - in this case
  61. * expecting the controllers to reside in app/controller/Posts.js and app/controller/Comments.js. In turn, each
  62. * Controller simply needs to list the Views it uses and they will be automatically loaded. Here's how our Posts
  63. * controller like be defined:
  64. *
  65. * Ext.define('MyApp.controller.Posts', {
  66. * extend: 'Ext.app.Controller',
  67. * views: ['posts.List', 'posts.Edit'],
  68. *
  69. * //the rest of the Controller here
  70. * });
  71. *
  72. * Because we told our Application about our Models and Controllers, and our Controllers about their Views, Ext JS will
  73. * automatically load all of our app files for us. This means we don't have to manually add script tags into our html
  74. * files whenever we add a new class, but more importantly it enables us to create a minimized build of our entire
  75. * application using the Ext JS 4 SDK Tools.
  76. *
  77. * For more information about writing Ext JS 4 applications, please see the [application architecture guide][mvc].
  78. *
  79. * [mvc]: #/guide/application_architecture
  80. *
  81. * @docauthor Ed Spencer
  82. */
  83. Ext.define('Ext.app.Application', {
  84. extend: 'Ext.app.Controller',
  85. requires: [
  86. 'Ext.ModelManager',
  87. 'Ext.data.Model',
  88. 'Ext.data.StoreManager',
  89. 'Ext.tip.QuickTipManager',
  90. 'Ext.ComponentManager',
  91. 'Ext.app.EventBus'
  92. ],
  93. <span id='Ext-app-Application-cfg-name'> /**
  94. </span> * @cfg {String} name
  95. * The name of your application. This will also be the namespace for your views, controllers
  96. * models and stores. Don't use spaces or special characters in the name.
  97. */
  98. <span id='Ext-app-Application-cfg-controllers'> /**
  99. </span> * @cfg {String[]} controllers
  100. * Names of controllers that the app uses.
  101. */
  102. <span id='Ext-app-Application-cfg-scope'> /**
  103. </span> * @cfg {Object} scope
  104. * The scope to execute the {@link #launch} function in. Defaults to the Application instance.
  105. */
  106. scope: undefined,
  107. <span id='Ext-app-Application-cfg-enableQuickTips'> /**
  108. </span> * @cfg {Boolean} enableQuickTips
  109. * True to automatically set up Ext.tip.QuickTip support.
  110. */
  111. enableQuickTips: true,
  112. <span id='Ext-app-Application-cfg-defaultUrl'> /**
  113. </span> * @cfg {String} defaultUrl
  114. * When the app is first loaded, this url will be redirected to.
  115. */
  116. <span id='Ext-app-Application-cfg-appFolder'> /**
  117. </span> * @cfg {String} appFolder
  118. * The path to the directory which contains all application's classes.
  119. * This path will be registered via {@link Ext.Loader#setPath} for the namespace specified
  120. * in the {@link #name name} config.
  121. */
  122. appFolder: 'app',
  123. <span id='Ext-app-Application-cfg-autoCreateViewport'> /**
  124. </span> * @cfg {Boolean} autoCreateViewport
  125. * True to automatically load and instantiate AppName.view.Viewport before firing the launch function.
  126. */
  127. autoCreateViewport: false,
  128. <span id='Ext-app-Application-method-constructor'> /**
  129. </span> * Creates new Application.
  130. * @param {Object} [config] Config object.
  131. */
  132. constructor: function(config) {
  133. config = config || {};
  134. Ext.apply(this, config);
  135. var requires = config.requires || [];
  136. Ext.Loader.setPath(this.name, this.appFolder);
  137. if (this.paths) {
  138. var paths = this.paths,
  139. path;
  140. for (var ns in paths) {
  141. if (paths.hasOwnProperty(ns)) {
  142. path = paths[ns];
  143. Ext.Loader.setPath(ns, path);
  144. }
  145. }
  146. }
  147. this.callParent(arguments);
  148. this.eventbus = new Ext.app.EventBus;
  149. var controllers = Ext.Array.from(this.controllers),
  150. ln = controllers &amp;&amp; controllers.length,
  151. i, controller;
  152. this.controllers = new Ext.util.MixedCollection();
  153. if (this.autoCreateViewport) {
  154. requires.push(this.getModuleClassName('Viewport', 'view'));
  155. }
  156. for (i = 0; i &lt; ln; i++) {
  157. requires.push(this.getModuleClassName(controllers[i], 'controller'));
  158. }
  159. Ext.require(requires);
  160. Ext.onReady(function() {
  161. for (i = 0; i &lt; ln; i++) {
  162. controller = this.getController(controllers[i]);
  163. controller.init(this);
  164. }
  165. this.onBeforeLaunch.call(this);
  166. }, this);
  167. },
  168. control: function(selectors, listeners, controller) {
  169. this.eventbus.control(selectors, listeners, controller);
  170. },
  171. <span id='Ext-app-Application-method-launch'> /**
  172. </span> * @method
  173. * @template
  174. * Called automatically when the page has completely loaded. This is an empty function that should be
  175. * overridden by each application that needs to take action on page load.
  176. * @param {String} profile The detected {@link #profiles application profile}
  177. * @return {Boolean} By default, the Application will dispatch to the configured startup controller and
  178. * action immediately after running the launch function. Return false to prevent this behavior.
  179. */
  180. launch: Ext.emptyFn,
  181. <span id='Ext-app-Application-method-onBeforeLaunch'> /**
  182. </span> * @private
  183. */
  184. onBeforeLaunch: function() {
  185. var me = this;
  186. if (me.enableQuickTips) {
  187. Ext.tip.QuickTipManager.init();
  188. }
  189. if (me.autoCreateViewport) {
  190. me.getView('Viewport').create();
  191. }
  192. me.launch.call(this.scope || this);
  193. me.launched = true;
  194. me.fireEvent('launch', this);
  195. var controllers = me.controllers.items,
  196. c,
  197. cLen = controllers.length,
  198. controller;
  199. for (c = 0; c &lt; cLen; c++) {
  200. controller = controllers[c];
  201. controller.onLaunch(this);
  202. }
  203. },
  204. getModuleClassName: function(name, type) {
  205. var namespace = Ext.Loader.getPrefix(name);
  206. if (namespace.length &gt; 0 &amp;&amp; namespace !== name) {
  207. return name;
  208. }
  209. return this.name + '.' + type + '.' + name;
  210. },
  211. getController: function(name) {
  212. var controller = this.controllers.get(name);
  213. if (!controller) {
  214. controller = Ext.create(this.getModuleClassName(name, 'controller'), {
  215. application: this,
  216. id: name
  217. });
  218. this.controllers.add(controller);
  219. }
  220. return controller;
  221. },
  222. getStore: function(name) {
  223. var store = Ext.StoreManager.get(name);
  224. if (!store) {
  225. store = Ext.create(this.getModuleClassName(name, 'store'), {
  226. storeId: name
  227. });
  228. }
  229. return store;
  230. },
  231. getModel: function(model) {
  232. model = this.getModuleClassName(model, 'model');
  233. return Ext.ModelManager.getModel(model);
  234. },
  235. getView: function(view) {
  236. view = this.getModuleClassName(view, 'view');
  237. return Ext.ClassManager.get(view);
  238. }
  239. });
  240. </pre>
  241. </body>
  242. </html>