source: cats/SCHEMAcat/trunk/urn.org.isocat.schemacat.site/site/scripts/modules.js @ 4676

Last change on this file since 4676 was 4676, checked in by andre.moreira@mpi.nl, 10 years ago

Updated client side routing to use HTML5 history API.

File size: 4.1 KB
Line 
1'use strict';
2
3//SCHEMAcat module definition
4var SCHEMAcat = angular.module('SCHEMAcat', ['ui.bootstrap', 'ngRoute', 'ngResource', 'tlaGenerics']);
5
6SCHEMAcat.config(['$routeProvider', '$locationProvider',
7    function($routeProvider, $location) {
8        $location.html5Mode(true).hashPrefix('!');
9        var loadDelay = 250; //ms
10        $routeProvider
11            .when('/index.html/workspace/page/:pageNumber/', {
12                controller: 'WorkspaceCtrl',
13                templateUrl: 'partials/workspace.html',
14
15                /*
16                With this, the $routeProvider will trigger $routeChangeSuccess
17                event if the path part (//workspace/page/:pageNumber/) is not the
18                same as current location, causing angular to reload the controller
19                (flickering the view).
20                Otherwise it will trigger $routeUpdate event which does not reload
21                the controller neither updates the view. We have to listen to this
22                event if we need to update the view when the search part of the
23                route changes.
24                */
25                reloadOnSearch: false,
26                resolve: {
27                    //this will cause a 0.25 second delay to allow CSS fadeOut animation to
28                    //be displayed
29                    delay: ['$q', '$timeout', 'Settings',
30                        function($q, $timeout, Settings) {
31                            if (Settings.getAnimationStatus()) {
32                                var delay = $q.defer();
33                                $timeout(delay.resolve, loadDelay);
34                                return delay.promise;
35                            } else
36                                return;
37                        }
38                    ]
39                }
40            })
41            .when('/index.html/about', {
42                controller: 'AboutPageCtrl',
43                templateUrl: 'partials/about.html',
44                reloadOnSearch: false,
45                resolve: {
46                    delay: ['$q', '$timeout', 'Settings',
47                        function($q, $timeout, Settings) {
48                            if (Settings.getAnimationStatus()) {
49                                var delay = $q.defer();
50                                $timeout(delay.resolve, loadDelay);
51                                return delay.promise;
52                            } else
53                                return;
54                        }
55                    ]
56                }
57            })
58            .when('/index.html/contact', {
59                controller: 'ContactPageCtrl',
60                templateUrl: 'partials/contact.html',
61                reloadOnSearch: false,
62                resolve: {
63                    delay: ['$q', '$timeout', 'Settings',
64                        function($q, $timeout, Settings) {
65                            if (Settings.getAnimationStatus()) {
66                                var delay = $q.defer();
67                                $timeout(delay.resolve, loadDelay);
68                                return delay.promise;
69                            } else
70                                return;
71                        }
72                    ]
73                }
74            })
75            .when('/index.html/accountDetails', {
76                controller: 'AccountDetailsPageCtrl',
77                templateUrl: 'partials/accountDetails.html',
78                reloadOnSearch: false,
79                resolve: {
80                    delay: ['$q', '$timeout', 'Settings',
81                        function($q, $timeout, Settings) {
82                            if (Settings.getAnimationStatus()) {
83                                var delay = $q.defer();
84                                $timeout(delay.resolve, loadDelay);
85                                return delay.promise;
86                            } else
87                                return;
88                        }
89                    ]
90                }
91            })
92            .otherwise({
93                redirectTo: function(routeParams, path, search) {
94                    return '/index.html/workspace/page/1/?schemaIndex=0';
95                }
96            });
97    }
98]);
Note: See TracBrowser for help on using the repository browser.