forked from sequentech/voting-booth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·199 lines (177 loc) · 5.75 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/**
* This file is part of agora-gui-booth.
* Copyright (C) 2015-2016 Agora Voting SL <[email protected]>
* agora-gui-booth is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License.
* agora-gui-booth is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with agora-gui-booth. If not, see <http://www.gnu.org/licenses/>.
**/
window.avConfigData.base = '/booth';
angular.module(
'agora-gui-booth',
['ui.bootstrap',
'ui.utils',
'ui.router',
'ngAnimate',
'ngResource',
'ngCookies',
'ipCookie',
'ngSanitize',
'infinite-scroll',
'angularMoment',
'avConfig',
'jm.i18next',
'avUi',
'avBooth',
'avTest',
'avCrypto',
'angularFileUpload',
'dndLists',
'angularLoad',
'angular-date-picker-polyfill',
'ng-autofocus',
'agora-gui-common'
]);
angular.module('jm.i18next').config(function ($i18nextProvider, ConfigServiceProvider) {
// note that we do not send the language: by default, it will try the language
// supported by the web browser
$("#no-js").hide();
$i18nextProvider.options = _.extend(
{
useCookie: true,
useLocalStorage: false,
fallbackLng: 'en',
cookieName: 'lang',
detectLngQS: 'lang',
lngWhitelist: ['en', 'es', 'gl', 'ca'],
resGetPath: '/booth/locales/__lng__.json',
defaultLoadingValue: '' // ng-i18next option, *NOT* directly supported by i18next
},
ConfigServiceProvider.i18nextInitOptions);
});
angular.module('agora-gui-booth').config(function($sceDelegateProvider, ConfigServiceProvider) {
$sceDelegateProvider.resourceUrlWhitelist(ConfigServiceProvider.resourceUrlWhitelist);
});
angular.module('agora-gui-booth').config(
function(
$stateProvider,
$urlRouterProvider,
$httpProvider,
$locationProvider,
ConfigServiceProvider)
{
// CSRF verification
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
$urlRouterProvider.otherwise(ConfigServiceProvider.defaultRoute);
// use the HTML5 History API
$locationProvider.html5Mode(ConfigServiceProvider.locationHtml5mode);
/* App states and urls are defined here */
$stateProvider
.state('election', {
abstract: true,
url: '/booth',
template: '<div ui-view></div>'
})
.state('election.booth', {
url: '/:id/vote/:hmac/:message',
templateUrl: 'avBooth/booth.html',
controller: "BoothController"
})
.state('election.booth-nohmac', {
url: '/:id/vote',
templateUrl: 'avBooth/booth.html',
controller: "BoothController"
})
.state('election.public.show.home.simple', {
template: '<div ave-simple-question></div>'
})
.state('election.public.show.home.plurality-at-large', {
template: '<div av-plurality-at-large-results></div>',
})
.state('election.public.show.home.borda', {
template: '<div av-borda-results></div>',
})
.state('election.public.show.logout', {
url: '/logout',
controller: "LogoutController"
})
.state('election.results.show.home.borda', {
template: '<div av-borda-results></div>',
})
.state('election.results.show.plurality-at-large', {
template: '<div av-plurality-at-large-results></div>',
});
$stateProvider
.state('unit-test-e2e', {
url: '/unit-test-e2e',
templateUrl: 'test/unit_test_e2e.html',
controller: "UnitTestE2EController"
});
});
angular.module('agora-gui-booth').run(function($http, $rootScope, ConfigService) {
$rootScope.boothTitle = ConfigService.webTitle;
$rootScope.safeApply = function(fn) {
var phase = $rootScope.$$phase;
if (phase === '$apply' || phase === '$digest') {
if (fn && (typeof(fn) === 'function')) {
fn();
}
} else {
this.$apply(fn);
}
};
$rootScope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams) {
console.log("change start from " + fromState.name + " to " + toState.name);
$("#angular-preloading").show();
});
$rootScope.$on('$stateChangeSuccess',
function(event, toState, toParams, fromState, fromParams) {
console.log("change success");
$("#angular-preloading").hide();
});
});
/*
This directive allows us to pass a function in on an enter key to do what we want.
*/
angular.module('agora-gui-booth').directive('ngEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
};
});
/**
* Truncate Filter
* @Param text
* @Param length, default is 10
* @Param end, default is "..."
* @return string
*/
angular.module('agora-gui-booth').filter('truncate', function () {
return function (text, length, end) {
if (isNaN(length)) {
length = 10;
}
if (end === undefined) {
end = "...";
}
if (text.length <= length || text.length - end.length <= length) {
return text;
}
else {
return String(text).substring(0, length-end.length) + end;
}
};
});