1 | define([
|
2 | 'directives/ng-directives',
|
3 | 'directives/datatable',
|
4 |
|
5 | 'services/ng-services',
|
6 | 'services/log',
|
7 | 'services/ng-session',
|
8 |
|
9 | 'views/settings',
|
10 | 'views/tournament',
|
11 | 'views/scoresheet',
|
12 | 'views/scores',
|
13 |
|
14 | 'angular-bootstrap',
|
15 | 'angular-touch',
|
16 | 'angular-animate',
|
17 | 'angular-sanitize',
|
18 | 'angular-storage',
|
19 | 'angular'
|
20 |
|
21 | ],function(directives, datatable, services, log, session, settings, tournament, scoresheet, scores) {
|
22 |
|
23 | log('device ready');
|
24 |
|
25 |
|
26 |
|
27 | angular.module('main',['ngAnimate']).controller('mainCtrl',[
|
28 | '$scope', '$session', '$location',
|
29 | function($scope, $session, $location) {
|
30 | log('init main ctrl');
|
31 |
|
32 | const PAGES = [
|
33 | { name: 'scoresheet', title: 'Scoresheet', icon: 'check' },
|
34 | { name: 'scores', title: 'Scores', icon: 'list' },
|
35 | { name: 'tournament', title: 'Tournament', icon: 'people' },
|
36 | { name: 'settings', title: 'Settings', icon: 'settings' }
|
37 | ];
|
38 |
|
39 | const pageLoader = angular.element('.viewMain .dimmer');
|
40 |
|
41 | $scope.drawer = 'views/drawer.html';
|
42 | $scope.scoringPages = ['scoresheet','settings'];
|
43 | $scope.validationErrors = [];
|
44 | $scope.drawerVisible = false;
|
45 |
|
46 | $session.load().then(function(session) {
|
47 | if(session['passport']) {
|
48 | $scope.user = session['passport'].user;
|
49 | $scope.pages = PAGES.filter(page => $scope.user.pages.includes(page.name));
|
50 | } else {
|
51 | $scope.pages = PAGES;
|
52 | }
|
53 |
|
54 | $scope.pages.forEach(page => {
|
55 | page.route = `views/pages/${page.name}.html`;
|
56 | page.classes = `page view-${page.name}${($scope.pages.length === 1 ? ' only-page' : '')}`;
|
57 | });
|
58 |
|
59 | let urlPath = $location.path();
|
60 | let pageFromURL = $scope.pages.find(page => `/${page.name}` === urlPath);
|
61 |
|
62 | $scope.setPage(pageFromURL || $scope.pages[0]);
|
63 | });
|
64 |
|
65 | $scope.toggleDrawer = function(set) {
|
66 | if (set !== undefined) {
|
67 | $scope.drawerVisible = set;
|
68 | } else {
|
69 | $scope.drawerVisible = !$scope.drawerVisible;
|
70 | }
|
71 | };
|
72 |
|
73 | $scope.setPage = function(page) {
|
74 | if($scope.currentPage) {
|
75 | $scope.currentPage.scope = undefined;
|
76 | }
|
77 | $scope.currentPage = page;
|
78 | $location.path(page.name);
|
79 | pageLoader.removeClass('disabled');
|
80 | $scope.drawerVisible = false;
|
81 | };
|
82 |
|
83 | $scope.goTo = function(pageName, callback) {
|
84 | var page = $scope.pages.find(page => page.name === pageName);
|
85 | if(page) {
|
86 | $scope.pageLoadCallback = callback;
|
87 | setPage(page);
|
88 | }
|
89 | }
|
90 |
|
91 | $scope.pageLoaded = function() {
|
92 | if($scope.pageLoadCallback) {
|
93 | $scope.pageLoadCallback($scope.currentPage.scope);
|
94 | $scope.pageLoadCallback = undefined;
|
95 | }
|
96 | pageLoader.addClass('disabled');
|
97 | };
|
98 |
|
99 | $scope.initPage = function(pageName, pageScope) {
|
100 | log(`init ${pageName} page`);
|
101 | $scope.pages.find(page => page.name === pageName).scope = pageScope;
|
102 | }
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | if (navigator.appVersion.indexOf("Mac")!=-1) {
|
108 | angular.element('body').addClass('ios');
|
109 | }
|
110 |
|
111 | }
|
112 | ]);
|
113 | angular.module('main').config(function($compileProvider){
|
114 |
|
115 | $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|data):/);
|
116 | });
|
117 | angular.bootstrap(document.body,[
|
118 | 'main',
|
119 | 'ui.bootstrap',
|
120 | 'ngSanitize',
|
121 | 'ngTouch',
|
122 | settings.name,
|
123 | tournament.name,
|
124 | scoresheet.name,
|
125 | scores.name,
|
126 | services.name,
|
127 | directives.name
|
128 | ]);
|
129 | });
|