| 3 | | - ''tbw'' |
| | 3 | EdenMobile is a single-page application (SPA), i.e. it only has a single page {{{www/index.html}}} which is loaded when the app starts, and has parts of its contents replaced as the user interacts with it. |
| | 4 | |
| | 5 | Instead of "pages" to display different application views, EdenMobile implements application '''states'''. Each state has its own "view template" that defines the inner HTML of the front-page, and a controller that supplies data and processing methods for the UI widgets. |
| | 6 | |
| | 7 | == Routing == |
| | 8 | |
| | 9 | The routing of user actions to the different app states is provided by the [https://github.com/angular-ui/ui-router/wiki AngularJS UI Router]. |
| | 10 | |
| | 11 | States have names to reference them, and state references can additionally contain parameters to pass to the state controller. |
| | 12 | |
| | 13 | States can be entered either by using {{{$state.go()}}} (=similar to Sahana Eden's {{{redirect()}}}, just without leaving the page): |
| | 14 | {{{#!js |
| | 15 | $state.go('data.update', {resourceName: resourceName, recordID: recordID}, {location: 'replace', reload: true}); |
| | 16 | }}} |
| | 17 | |
| | 18 | ...or by HTML links using fragment identifiers to encode the state reference: |
| | 19 | {{{#!xml |
| | 20 | <a href="#/data/update/{{resourceName}}/{{recordID}}">Edit Record</a> |
| | 21 | }}} |
| | 22 | |
| | 23 | Either variant would be resolved against this entry in {{{www/config/routing.py}}}: |
| | 24 | {{{#!js |
| | 25 | .state('data.update', { |
| | 26 | url: '/{resourceName}/{recordID:int}', |
| | 27 | views: { |
| | 28 | 'data': { |
| | 29 | templateUrl: 'views/data/update.html', |
| | 30 | controller: "EMDataUpdate" |
| | 31 | } |
| | 32 | } |
| | 33 | }) |
| | 34 | }}} |
| | 35 | |
| | 36 | ...and let the UI router: |
| | 37 | - replace the contents of the {{{<ion-nav-view>}}} directive on the {{{www/index.html}}} front-page with {{{www/views/data/update.html}}} (executing any directives) |
| | 38 | - invoke the {{{EMDataUpdate}}} controller (defined in {{{wwww/controllers/update.js}}}) |
| | 39 | - pass the {{{resourceName}}} and {{{recordID}}} parameters to the {{{$stateParams}}}, from where the controller can access them |
| | 40 | |
| | 41 | == View and Controller == |
| | 42 | |
| | 43 | The role of controllers and views is equivalent to controllers/views in the Sahana Eden web application. |
| | 44 | |
| | 45 | The view template is rendered once when the state is entered the first time (unless reloading is enforced in $state.go), and the state controller executed every time when the state is entered. |
| | 46 | |
| | 47 | State controllers live in the www/controllers folder, and view templates in www/views. |