X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..3789b528d8dd8aad4558e38e22d775bcab1cbd36:/docs/output/Ext.app.Controller.js?ds=inline diff --git a/docs/output/Ext.app.Controller.js b/docs/output/Ext.app.Controller.js new file mode 100644 index 00000000..60806b85 --- /dev/null +++ b/docs/output/Ext.app.Controller.js @@ -0,0 +1,82 @@ +Ext.data.JsonP.Ext_app_Controller({ + "tagname": "class", + "name": "Ext.app.Controller", + "doc": "
Controllers are the glue that binds an application together. All they really do is listen for events (usually from\nviews) and take some action. Here's how we might create a Controller to manage Users:
\n\nExt.define('MyApp.controller.Users', {\n extend: 'Ext.app.Controller',\n\n init: function() {\n console.log('Initialized Users! This happens before the Application launch function is called');\n }\n});\n
\n\nThe init function is a special method that is called when your application boots. It is called before the\nApplication's launch function is executed so gives a hook point to run any code before\nyour Viewport is created.
\n\nThe init function is a great place to set up how your controller interacts with the view, and is usually used in\nconjunction with another Controller function - control. The control function\nmakes it easy to listen to events on your view classes and take some action with a handler function. Let's update\nour Users controller to tell us when the panel is rendered:
\n\nExt.define('MyApp.controller.Users', {\n extend: 'Ext.app.Controller',\n\n init: function() {\n this.control({\n 'viewport > panel': {\n render: this.onPanelRendered\n }\n });\n },\n\n onPanelRendered: function() {\n console.log('The panel was rendered');\n }\n});\n
\n\nWe've updated the init function to use this.control to set up listeners on views in our application. The control\nfunction uses the new ComponentQuery engine to quickly and easily get references to components on the page. If you\nare not familiar with ComponentQuery yet, be sure to check out THIS GUIDE for a full explanation. In brief though,\nit allows us to pass a CSS-like selector that will find every matching component on the page.
\n\nIn our init function above we supplied 'viewport > panel', which translates to \"find me every Panel that is a direct\nchild of a Viewport\". We then supplied an object that maps event names (just 'render' in this case) to handler\nfunctions. The overall effect is that whenever any component that matches our selector fires a 'render' event, our\nonPanelRendered function is called.
\n\nUsing refs
\n\nOne of the most useful parts of Controllers is the new ref system. These use the new Ext.ComponentQuery to\nmake it really easy to get references to Views on your page. Let's look at an example of this now:
\n\nExt.define('MyApp.controller.Users', {\n extend: 'Ext.app.Controller',\n\n refs: [\n {\n ref: 'list',\n selector: 'grid'\n }\n ],\n\n init: function() {\n this.control({\n 'button': {\n click: this.refreshGrid\n }\n });\n },\n\n refreshGrid: function() {\n this.getList().store.load();\n }\n});\n
\n\nThis example assumes the existence of a Grid on the page, which contains a single button to\nrefresh the Grid when clicked. In our refs array, we set up a reference to the grid. There are two parts to this -\nthe 'selector', which is a ComponentQuery selector which finds any grid on the page and\nassigns it to the reference 'list'.
\n\nBy giving the reference a name, we get a number of things for free. The first is the getList function that we use in\nthe refreshGrid method above. This is generated automatically by the Controller based on the name of our ref, which\nwas capitalized and prepended with get to go from 'list' to 'getList'.
\n\nThe way this works is that the first time getList is called by your code, the ComponentQuery selector is run and the\nfirst component that matches the selector ('grid' in this case) will be returned. All future calls to getList will\nuse a cached reference to that grid. Usually it is advised to use a specific ComponentQuery selector that will only\nmatch a single View in your application (in the case above our selector will match any grid on the page).
\n\nBringing it all together, our init function is called when the application boots, at which time we call this.control\nto listen to any click on a button and call our refreshGrid function (again, this will\nmatch any button on the page so we advise a more specific selector than just 'button', but have left it this way for\nsimplicity). When the button is clicked we use out getList function to refresh the grid.
\n\nYou can create any number of refs and control any number of components this way, simply adding more functions to\nyour Controller as you go. For an example of real-world usage of Controllers see the Feed Viewer example in the\nexamples/app/feed-viewer folder in the SDK download.
\n\nGenerated getter methods
\n\nRefs aren't the only thing that generate convenient getter methods. Controllers often have to deal with Models and\nStores so the framework offers a couple of easy ways to get access to those too. Let's look at another example:
\n\nExt.define('MyApp.controller.Users', {\n extend: 'Ext.app.Controller',\n\n models: ['User'],\n stores: ['AllUsers', 'AdminUsers'],\n\n init: function() {\n var User = this.getUserModel(),\n allUsers = this.getAllUsersStore();\n\n var ed = new User({name: 'Ed'});\n allUsers.add(ed);\n }\n});\n
\n\nBy specifying Models and Stores that the Controller cares about, it again dynamically loads them from the appropriate\nlocations (app/model/User.js, app/store/AllUsers.js and app/store/AdminUsers.js in this case) and creates getter\nfunctions for them all. The example above will create a new User model instance and add it to the AllUsers Store.\nOf course, you could do anything in this function but in this case we just did something simple to demonstrate the\nfunctionality.
\n\nFurther Reading
\n\nFor more information about writing Ext JS 4 applications, please see the \napplication architecture guide. Also see the Ext.app.Application documentation.
\n", + "extends": null, + "mixins": [ + + ], + "alternateClassNames": [ + + ], + "xtype": null, + "author": null, + "docauthor": "Ed Spencer", + "singleton": false, + "private": false, + "cfg": [ + { + "tagname": "cfg", + "name": "id", + "member": "Ext.app.Controller", + "type": "String", + "doc": "The id of this controller. You can use this id when dispatching.
\n", + "private": false, + "filename": "/Users/nick/Projects/sencha/SDK/platform/src/app/Controller.js", + "linenr": 136, + "html_filename": "Controller.html", + "href": "Controller.html#Ext-app-Controller-cfg-id" + } + ], + "method": [ + { + "tagname": "method", + "name": "Controller", + "member": "Ext.app.Controller", + "doc": "\n", + "params": [ + + ], + "return": { + "type": "void", + "doc": "\n" + }, + "private": false, + "static": false, + "filename": "/Users/nick/Projects/sencha/SDK/platform/src/app/Controller.js", + "linenr": 1, + "html_filename": "Controller.html", + "href": "Controller.html#Ext-app-Controller-method-constructor", + "shortDoc": "\n" + } + ], + "property": [ + + ], + "event": [ + + ], + "filename": "/Users/nick/Projects/sencha/SDK/platform/src/app/Controller.js", + "linenr": 1, + "html_filename": "Controller.html", + "href": "Controller.html#Ext-app-Controller", + "cssVar": [ + + ], + "cssMixin": [ + + ], + "component": false, + "superclasses": [ + + ], + "subclasses": [ + "Ext.app.Application" + ], + "mixedInto": [ + + ], + "allMixins": [ + + ] +}); \ No newline at end of file