Compare View
Commits (2)
Diff
Showing 2 changed files Inline Diff
scripts/SettingsController.js
View file @
b1c6c3a
angular.module('flashy.SettingsController', ['ui.router']). | 1 | 1 | angular.module('flashy.SettingsController', ['ui.router']). | |
2 | 2 | |||
controller('SettingsController', function($rootScope, $resource, $scope, $state, $http, UserService) { | 3 | 3 | controller('SettingsController', function($rootScope, $resource, $scope, $state, $http, UserService) { | |
$scope.error = false; | 4 | 4 | $scope.error = false; | |
$scope.success = false; | 5 | 5 | $scope.success = false; | |
$scope.mismatch = false; | 6 | 6 | $scope.mismatch = false; | |
$scope.unacceptable = false; | 7 | 7 | $scope.unacceptable = false; | |
8 | 8 | |||
$scope.changePassword = function(oldPassword, newPassword, confirmedNewPassword) { | 9 | 9 | $scope.changePassword = function(oldPassword, newPassword, confirmedNewPassword) { | |
console.log('in change password'); | 10 | 10 | console.log('in change password'); | |
11 | ||||
12 | if (newPassword != $scope.confirmedNewPassword) { | |||
13 | $scope.mismatch = true; | |||
14 | console.log('mismatch'); | |||
15 | return; | |||
16 | } | |||
11 | 17 | |||
if (newPassword != $scope.confirmedNewPassword) { | 12 | 18 | $http.patch('/api/me/', { | |
$scope.mismatch = true; | 13 | 19 | 'old_password': oldPassword, | |
console.log('mismatch'); | 14 | 20 | 'new_password': newPassword | |
return; | 15 | 21 | }) | |
} | 16 | 22 | .success(function(data) { | |
17 | 23 | console.log('password successfully changes'); | ||
$http.patch('/api/me/', { | 18 | 24 | Materialize.toast('Your password was successfully changed'); | |
'old_password': oldPassword, | 19 | 25 | $state.go('login'); | |
'new_password': newPassword | 20 | 26 | }) | |
27 | .error(function(data){ | |||
28 | console.log("problem changing the password"); | |||
29 | Materialize.toast('Your old password is not correct'); | |||
30 | $state.go('login'); | |||
31 | }); | |||
}) | 21 | 32 | }; | |
.success(function(data) { | 22 | 33 | ||
console.log('password successfully changes'); | 23 | 34 | $scope.dropClass = function(section) { | |
Materialize.toast('Your password was successfully changed'); | 24 | 35 | $http.post('/api/sections/' + section.id + '/drop/'). | |
$state.go('login'); | 25 | 36 | success(function(data) { | |
}) | 26 | 37 | UserService.dropClass(section.id); | |
.error(function(data){ | 27 | 38 | console.log(section.short_name + ' dropped'); | |
console.log("problem changing the password"); | 28 | 39 | Materialize.toast('Dropped', 3000); | |
Materialize.toast('Your old password is not correct'); | 29 | 40 | }); | |
$state.go('login'); | 30 | 41 | }; | |
}); | 31 | 42 | ||
}; | 32 | 43 | ||
33 | 44 | console.log('checking to see if chrome'); | ||
$scope.dropClass = function(section) { | 34 | 45 | ||
$http.post('/api/sections/' + section.id + '/drop/'). | 35 | 46 | if (typeof(chrome) === 'undefined') { | |
success(function(data) { | 36 | 47 | //pushSwitch.disabled = true; | |
UserService.dropClass(section.id); | 37 | 48 | return; | |
console.log(section.short_name + ' dropped'); | 38 | 49 | } | |
Materialize.toast('Dropped', 3000); | 39 | 50 | ||
}); | 40 | 51 | console.log('chrome'); | |
}; | 41 | 52 | ||
42 | 53 | console.log('executing things outside of module'); | ||
43 | 54 | var PUSH_SERVER_URL = '/api/subscribe/'; | ||
console.log('checking to see if chrome'); | 44 | 55 | var UNPUSH_SERVER_URL = '/api/unsubscribe/'; | |
45 | 56 | |||
if (typeof(chrome) === 'undefined') { | 46 | 57 | function onPushSubscription(pushSubscription) { | |
//pushSwitch.disabled = true; | 47 | 58 | console.log('pushSubscription = ', pushSubscription.endpoint); | |
return; | 48 | 59 | // Here we would normally send the endpoint | |
} | 49 | 60 | // and subscription ID to our server. | |
50 | 61 | // In this demo we just use send these values to | ||
console.log('chrome'); | 51 | 62 | // our server via XHR which sends a push message. | |
52 | 63 | |||
console.log('executing things outside of module'); | 53 | 64 | var endpoint = pushSubscription.endpoint; | |
var PUSH_SERVER_URL = '/api/subscribe/'; | 54 | 65 | var subscriptionId = pushSubscription.subscriptionId; | |
var UNPUSH_SERVER_URL = '/api/unsubscribe/'; | 55 | 66 | ||
56 | 67 | console.log('registration_id: ', subscriptionId); | ||
function onPushSubscription(pushSubscription) { | 57 | 68 | $http.post(PUSH_SERVER_URL, {'registration_id': subscriptionId}); | |
console.log('pushSubscription = ', pushSubscription.endpoint); | 58 | 69 | } | |
// Here we would normally send the endpoint | 59 | 70 | ||
// and subscription ID to our server. | 60 | 71 | function removeSubscription(pushSubscription) { | |
// In this demo we just use send these values to | 61 | 72 | console.log('removing subscription'); | |
// our server via XHR which sends a push message. | 62 | 73 | console.log('pushSubscription endpoint = ', pushSubscription.endpoint); | |
63 | 74 | |||
var endpoint = pushSubscription.endpoint; | 64 | 75 | var subscriptionId = pushSubscription.subscriptionId; | |
var subscriptionId = pushSubscription.subscriptionId; | 65 | 76 | ||
66 | 77 | console.log('registration_id: ', subscriptionId); | ||
console.log('registration_id: ', subscriptionId); | 67 | 78 | $http.post(UNPUSH_SERVER_URL, {'registration_id': subscriptionId}); | |
$http.post(PUSH_SERVER_URL, {'registration_id': subscriptionId}); | 68 | 79 | } | |
} | 69 | 80 | ||
70 | 81 | function subscribeDevice() { | ||
function removeSubscription(pushSubscription) { | 71 | 82 | // We need the service worker registration to access the push manager | |
console.log('removing subscription'); | 72 | 83 | navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | |
console.log('pushSubscription endpoint = ', pushSubscription.endpoint); | 73 | 84 | serviceWorkerRegistration.pushManager.subscribe() | |
74 | 85 | .then(onPushSubscription) | ||
var subscriptionId = pushSubscription.subscriptionId; | 75 | 86 | .catch(function(e) { | |
76 | 87 | console.log('Error in subscribing'); | ||
console.log('registration_id: ', subscriptionId); | 77 | 88 | // Check for a permission prompt issue | |
$http.post(UNPUSH_SERVER_URL, {'registration_id': subscriptionId}); | 78 | 89 | if ('permissions' in navigator) { | |
} | 79 | 90 | navigator.permissions.query({name: 'push', userVisibleOnly: true}) | |
80 | 91 | .then(function(permissionStatus) { | ||
function subscribeDevice() { | 81 | 92 | console.log('subscribe() Error: Push permission status = ', | |
// We need the service worker registration to access the push manager | 82 | 93 | permissionStatus); | |
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | 83 | 94 | if (permissionStatus.status === 'denied') { | |
serviceWorkerRegistration.pushManager.subscribe() | 84 | 95 | pushSwitch.checked = false; | |
.then(onPushSubscription) | 85 | 96 | pushSwitch.disabled = true; | |
.catch(function(e) { | 86 | 97 | // The user blocked the permission prompt | |
console.log('Error in subscribing'); | 87 | 98 | console.log('Ooops Notifications are Blocked', | |
// Check for a permission prompt issue | 88 | 99 | 'Unfortunately you just permanently blocked notifications. ' + | |
if ('permissions' in navigator) { | 89 | 100 | 'Please unblock / allow them to switch on push ' + | |
navigator.permissions.query({name: 'push', userVisibleOnly: true}) | 90 | 101 | 'notifications.'); | |
.then(function(permissionStatus) { | 91 | 102 | } else { | |
console.log('subscribe() Error: Push permission status = ', | 92 | 103 | pushSwitch.checked = false; | |
permissionStatus); | 93 | 104 | console.log('Ooops Push Couldn\'t Register', | |
if (permissionStatus.status === 'denied') { | 94 | 105 | '<p>When we tried to ' + | |
pushSwitch.checked = false; | 95 | 106 | 'get the subscription ID for GCM, something went wrong,' + | |
pushSwitch.disabled = true; | 96 | 107 | ' not sure why.</p>' + | |
// The user blocked the permission prompt | 97 | 108 | '<p>Have you defined "gcm_sender_id" and ' + | |
console.log('Ooops Notifications are Blocked', | 98 | 109 | '"gcm_user_visible_only" in the manifest?</p>' + | |
'Unfortunately you just permanently blocked notifications. ' + | 99 | 110 | '<p>Error message: ' + | |
'Please unblock / allow them to switch on push ' + | 100 | 111 | e.message + | |
'notifications.'); | 101 | 112 | '</p>'); | |
} else { | 102 | 113 | } | |
pushSwitch.checked = false; | 103 | 114 | }).catch(function(err) { | |
console.log('Ooops Push Couldn\'t Register', | 104 | 115 | pushSwitch.checked = false; | |
'<p>When we tried to ' + | 105 | 116 | console.log('Ooops Push Couldn\'t Register', | |
'get the subscription ID for GCM, something went wrong,' + | 106 | 117 | '<p>When we tried to ' + | |
' not sure why.</p>' + | 107 | 118 | 'get the subscription ID for GCM, something went wrong, not ' + | |
'<p>Have you defined "gcm_sender_id" and ' + | 108 | 119 | 'sure why.</p>' + | |
'"gcm_user_visible_only" in the manifest?</p>' + | 109 | 120 | '<p>Have you defined "gcm_sender_id" and ' + | |
'<p>Error message: ' + | 110 | 121 | '"gcm_user_visible_only" in the manifest?</p>' + | |
e.message + | 111 | 122 | '<p>Error message: ' + | |
'</p>'); | 112 | 123 | err.message + | |
} | 113 | 124 | '</p>'); | |
}).catch(function(err) { | 114 | 125 | }); | |
pushSwitch.checked = false; | 115 | 126 | } else { | |
console.log('Ooops Push Couldn\'t Register', | 116 | 127 | // Use notification permission to do something | |
'<p>When we tried to ' + | 117 | 128 | if (Notification.permission === 'denied') { | |
'get the subscription ID for GCM, something went wrong, not ' + | 118 | 129 | pushSwitch.disabled = true; | |
'sure why.</p>' + | 119 | 130 | pushSwitch.checked = false; | |
'<p>Have you defined "gcm_sender_id" and ' + | 120 | 131 | console.log('Ooops Notifications are Blocked', | |
'"gcm_user_visible_only" in the manifest?</p>' + | 121 | 132 | 'Unfortunately you just permanently blocked notifications. ' + | |
'<p>Error message: ' + | 122 | 133 | 'Please unblock / allow them to switch on push notifications.'); | |
err.message + | 123 | 134 | } else { | |
'</p>'); | 124 | 135 | pushSwitch.checked = false; | |
}); | 125 | 136 | console.log('Ooops Push Couldn\'t Register', | |
} else { | 126 | 137 | '<p>When we tried to ' + | |
// Use notification permission to do something | 127 | 138 | 'get the subscription ID for GCM, something went wrong, not ' + | |
if (Notification.permission === 'denied') { | 128 | 139 | 'sure why.</p>' + | |
pushSwitch.disabled = true; | 129 | 140 | '<p>Have you defined "gcm_sender_id" and ' + | |
pushSwitch.checked = false; | 130 | 141 | '"gcm_user_visible_only" in the manifest?</p>' + | |
console.log('Ooops Notifications are Blocked', | 131 | 142 | '<p>Error message: ' + | |
'Unfortunately you just permanently blocked notifications. ' + | 132 | 143 | e.message + | |
'Please unblock / allow them to switch on push notifications.'); | 133 | 144 | '</p>'); | |
} else { | 134 | 145 | } | |
pushSwitch.checked = false; | 135 | 146 | } | |
console.log('Ooops Push Couldn\'t Register', | 136 | 147 | }); | |
'<p>When we tried to ' + | 137 | 148 | }); | |
'get the subscription ID for GCM, something went wrong, not ' + | 138 | 149 | } | |
'sure why.</p>' + | 139 | 150 | ||
'<p>Have you defined "gcm_sender_id" and ' + | 140 | 151 | function unsubscribeDevice() { | |
'"gcm_user_visible_only" in the manifest?</p>' + | 141 | 152 | navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | |
'<p>Error message: ' + | 142 | 153 | serviceWorkerRegistration.pushManager.getSubscription().then( | |
e.message + | 143 | 154 | function(pushSubscription) { | |
'</p>'); | 144 | 155 | // Check we have everything we need to unsubscribe | |
} | 145 | 156 | if (!pushSubscription) { | |
} | 146 | 157 | pushSwitch.checked = false; | |
}); | 147 | 158 | return; | |
}); | 148 | 159 | } | |
} | 149 | 160 | ||
150 | 161 | // TODO: Remove the device details from the server | ||
function unsubscribeDevice() { | 151 | 162 | // i.e. the pushSubscription.subscriptionId and | |
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | 152 | 163 | // pushSubscription.endpoint | |
serviceWorkerRegistration.pushManager.getSubscription().then( | 153 | 164 | var subscriptionId = pushSubscription.subscriptionId; | |
function(pushSubscription) { | 154 | 165 | ||
// Check we have everything we need to unsubscribe | 155 | 166 | pushSubscription.unsubscribe().then(function(successful) { | |
if (!pushSubscription) { | 156 | 167 | console.log('Unsubscribed from push: ', successful); | |
pushSwitch.checked = false; | 157 | 168 | ||
return; | 158 | 169 | if (!successful) { | |
} | 159 | 170 | // The unsubscribe was unsuccessful, but we can | |
160 | 171 | // remove the subscriptionId from our server | ||
// TODO: Remove the device details from the server | 161 | 172 | // and notifications will stop | |
// i.e. the pushSubscription.subscriptionId and | 162 | 173 | // This just may be in a bad state when the user returns | |
// pushSubscription.endpoint | 163 | 174 | pushSwitch.checked = true; | |
var subscriptionId = pushSubscription.subscriptionId; | 164 | 175 | console.error('We were unable to unregister from push, but we removed' + | |
165 | 176 | 'registration id from the server'); | ||
pushSubscription.unsubscribe().then(function(successful) { | 166 | 177 | } | |
console.log('Unsubscribed from push: ', successful); | 167 | 178 | removeSubscription(pushSubscription); | |
168 | 179 | |||
if (!successful) { | 169 | 180 | }).catch(function(e) { | |
// The unsubscribe was unsuccessful, but we can | 170 | 181 | console.log('Unsubscribtion error: ', e); | |
// remove the subscriptionId from our server | 171 | 182 | }); | |
// and notifications will stop | 172 | 183 | }.bind(this)).catch(function(e) { | |
// This just may be in a bad state when the user returns | 173 | 184 | console.error('Error thrown while revoking push notifications. ' + | |
pushSwitch.checked = true; | 174 | 185 | 'Most likely because push was never registered', e); | |
console.error('We were unable to unregister from push, but we removed' + | 175 | 186 | }); | |
'registration id from the server'); | 176 | 187 | }); | |
} | 177 | 188 | } | |
removeSubscription(pushSubscription); | 178 | 189 | ||
179 | 190 | function permissionStatusChange(permissionStatus) { | ||
}).catch(function(e) { | 180 | 191 | console.log('permissionStatusChange = ', permissionStatus); | |
console.log('Unsubscribtion error: ', e); | 181 | 192 | // If the notification permission is denied, it's a permanent block | |
}); | 182 | 193 | switch (permissionStatus.status) { | |
}.bind(this)).catch(function(e) { | 183 | 194 | case 'denied': | |
console.error('Error thrown while revoking push notifications. ' + | 184 | 195 | pushSwitch.disabled = true; | |
'Most likely because push was never registered', e); | 185 | 196 | console.log('Ooops Push has been Blocked', | |
}); | 186 | 197 | 'Unfortunately the user permanently blocked push. Please unblock / ' + | |
}); | 187 | 198 | 'allow them to switch on push notifications.'); | |
} | 188 | 199 | break; | |
189 | 200 | case 'granted': | ||
function permissionStatusChange(permissionStatus) { | 190 | 201 | // Set the state of the push switch | |
console.log('permissionStatusChange = ', permissionStatus); | 191 | 202 | console.log('case granted'); | |
// If the notification permission is denied, it's a permanent block | 192 | 203 | break; | |
switch (permissionStatus.status) { | 193 | 204 | case 'prompt': | |
case 'denied': | 194 | 205 | pushSwitch.checked = false; | |
pushSwitch.disabled = true; | 195 | 206 | console.log('case prompt'); | |
console.log('Ooops Push has been Blocked', | 196 | 207 | break; | |
'Unfortunately the user permanently blocked push. Please unblock / ' + | 197 | 208 | } | |
'allow them to switch on push notifications.'); | 198 | 209 | } | |
break; | 199 | 210 | ||
case 'granted': | 200 | 211 | function setUpPushPermission() { | |
// Set the state of the push switch | 201 | 212 | navigator.permissions.query({name: 'push', userVisibleOnly: true}) | |
console.log('case granted'); | 202 | 213 | .then(function(permissionStatus) { | |
break; | 203 | 214 | // Set the initial state | |
case 'prompt': | 204 | 215 | permissionStatusChange(permissionStatus); | |
pushSwitch.checked = false; | 205 | 216 | ||
console.log('case prompt'); | 206 | 217 | // Handle Permission State Changes | |
break; | 207 | 218 | permissionStatus.onchange = function() { | |
} | 208 | 219 | permissionStatusChange(this); | |
} | 209 | 220 | }; | |
210 | 221 | |||
function setUpPushPermission() { | 211 | 222 | // Check if push is supported and what the current state is | |
navigator.permissions.query({name: 'push', userVisibleOnly: true}) | 212 | 223 | navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | |
.then(function(permissionStatus) { | 213 | 224 | // Let's see if we have a subscription already | |
// Set the initial state | 214 | 225 | serviceWorkerRegistration.pushManager.getSubscription() | |
permissionStatusChange(permissionStatus); | 215 | 226 | .then(function(subscription) { | |
216 | 227 | if (!subscription) { | ||
// Handle Permission State Changes | 217 | 228 | // NOOP | |
permissionStatus.onchange = function() { | 218 | 229 | return; | |
permissionStatusChange(this); | 219 | 230 | } | |
}; | 220 | 231 | ||
221 | 232 | console.log('update current state.'); | ||
// Check if push is supported and what the current state is | 222 | 233 | // Update the current state with the | |
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | 223 | 234 | // subscriptionid and endpoint | |
// Let's see if we have a subscription already | 224 | 235 | onPushSubscription(subscription); | |
serviceWorkerRegistration.pushManager.getSubscription() | 225 | 236 | }) | |
.then(function(subscription) { | 226 | 237 | .catch(function(e) { | |
if (!subscription) { | 227 | 238 | console.log('An error occured while calling getSubscription()', e); | |
// NOOP | 228 | 239 | }); | |
return; | 229 | 240 | }); | |
} | 230 | 241 | }).catch(function(err) { | |
231 | 242 | console.log('Ooops Unable to check the permission', | ||
console.log('update current state.'); | 232 | 243 | 'Unfortunately the permission for push notifications couldn\'t be ' + | |
// Update the current state with the | 233 | 244 | 'checked. Are you on Chrome 43+?'); | |
// subscriptionid and endpoint | 234 | 245 | }); | |
onPushSubscription(subscription); | 235 | 246 | } | |
}) | 236 | 247 | ||
.catch(function(e) { | 237 | 248 | function setUpNotificationPermission() { | |
console.log('An error occured while calling getSubscription()', e); | 238 | 249 | console.log('setting notification setting'); | |
}); | 239 | 250 | ||
}); | 240 | 251 | if (Notification.permission === 'default') { | |
}).catch(function(err) { | 241 | 252 | console.log('notification permissions === default'); | |
console.log('Ooops Unable to check the permission', | 242 | 253 | return; | |
'Unfortunately the permission for push notifications couldn\'t be ' + | 243 | 254 | } | |
'checked. Are you on Chrome 43+?'); | 244 | 255 | ||
}); | 245 | 256 | // Check if push is supported and what the current state is | |
} | 246 | 257 | navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | |
247 | 258 | // Let's see if we have a subscription already | ||
function setUpNotificationPermission() { | 248 | 259 | serviceWorkerRegistration.pushManager.getSubscription() | |
console.log('setting notification setting'); | 249 | 260 | .then(function(subscription) { | |
250 | 261 | if (!subscription) { | ||
if (Notification.permission === 'default') { | 251 | 262 | // NOOP | |
console.log('notification permissions === default'); | 252 | 263 | console.log('not subscription'); | |
return; | 253 | 264 | return; | |
} | 254 | 265 | } | |
255 | 266 | |||
// Check if push is supported and what the current state is | 256 | 267 | // Update the current state with the | |
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | 257 | 268 | // subscriptionid and endpoint | |
// Let's see if we have a subscription already | 258 | 269 | console.log('onpushsubscription should be entered'); | |
serviceWorkerRegistration.pushManager.getSubscription() | 259 | 270 | onPushSubscription(subscription); | |
.then(function(subscription) { | 260 | 271 | }) | |
if (!subscription) { | 261 | 272 | .catch(function(e) { | |
// NOOP | 262 | 273 | console.log('An error occured while calling getSubscription()', e); | |
console.log('not subscription'); | 263 | 274 | }); | |
return; | 264 | 275 | }); | |
} | 265 | 276 | } | |
266 | 277 | |||
// Update the current state with the | 267 | 278 | // Once the service worker is registered set the initial state | |
// subscriptionid and endpoint | 268 | 279 | function initialiseState() { | |
console.log('onpushsubscription should be entered'); | 269 | 280 | // Check if notifications are supported | |
onPushSubscription(subscription); | 270 | 281 | if (!('showNotification' in ServiceWorkerRegistration.prototype)) { | |
}) | 271 | 282 | console.warn('Notifications aren\'t supported.'); | |
.catch(function(e) { | 272 | 283 | return; | |
console.log('An error occured while calling getSubscription()', e); | 273 | 284 | } | |
}); | 274 | 285 | // Check the current Notification permission. | |
}); | 275 | 286 | // If its denied, it's a permanent block until the | |
} | 276 | 287 | // user changes the permission | |
277 | 288 | else if (Notification.permission === 'denied') { | ||
// Once the service worker is registered set the initial state | 278 | 289 | console.log('Ooops Notifications are Blocked', | |
function initialiseState() { | 279 | 290 | 'Unfortunately notifications are permanently blocked. Please unblock / ' + | |
// Check if notifications are supported | 280 | 291 | 'allow them to switch on push notifications.'); | |
if (!('showNotification' in ServiceWorkerRegistration.prototype)) { | 281 | 292 | return; | |
console.warn('Notifications aren\'t supported.'); | 282 | 293 | } | |
return; | 283 | 294 | // Check if push messaging is supported | |
} | 284 | 295 | else if (!('PushManager' in window)) { | |
// Check the current Notification permission. | 285 | 296 | console.warn('Push messaging isn\'t supported.'); | |
// If its denied, it's a permanent block until the | 286 | 297 | return; | |
// user changes the permission | 287 | 298 | } | |
else if (Notification.permission === 'denied') { | 288 | 299 | ||
console.log('Ooops Notifications are Blocked', | 289 | 300 | pushSwitch.disabled = false; | |
'Unfortunately notifications are permanently blocked. Please unblock / ' + | 290 | 301 | // Is the Permissions API supported | |
'allow them to switch on push notifications.'); | 291 | 302 | if ('permissions' in navigator) { | |
return; | 292 | 303 | console.log('setting push permissions'); | |
} | 293 | 304 | setUpPushPermission(); | |
// Check if push messaging is supported | 294 | 305 | return; | |
else if (!('PushManager' in window)) { | 295 | 306 | } else { | |
console.warn('Push messaging isn\'t supported.'); | 296 | 307 | console.log('setting notification permissions'); | |
return; | 297 | 308 | setUpNotificationPermission(); | |
} | 298 | 309 | } | |
299 | 310 | } | ||
pushSwitch.disabled = false; | 300 | 311 | ||
// Is the Permissions API supported | 301 | 312 | var enablePushSwitch = $('.js-checkbox'); | |
if ('permissions' in navigator) { | 302 | 313 | ||
console.log('setting push permissions'); | 303 | 314 | var pushSwitch = document.getElementById('notifbox'); | |
setUpPushPermission(); | 304 | 315 | pushSwitch.disabled = true; | |
return; | 305 | 316 | ||
} else { | 306 | 317 | var ua = navigator.userAgent.toLowerCase(); | |
console.log('setting notification permissions'); | 307 | 318 | var isAndroid = ua.indexOf('android') > -1; //&& ua.indexOf("mobile"); | |
setUpNotificationPermission(); | 308 | 319 | ||
} | 309 | 320 | if (!isAndroid) { | |
} | 310 | 321 | // Do something! | |
311 | 322 | // Redirect to Android-site? | ||
var enablePushSwitch = $('.js-checkbox'); | 312 | 323 | pushSwitch.disabled = true; | |
313 | 324 | console.log('not android'); | ||
var pushSwitch = document.getElementById('notifbox'); | 314 | 325 | return; | |
pushSwitch.disabled = true; | 315 | 326 | } | |
316 | 327 | |||
var ua = navigator.userAgent.toLowerCase(); | 317 | 328 | enablePushSwitch.change(function(e) { | |
var isAndroid = ua.indexOf('android') > -1; //&& ua.indexOf("mobile"); | 318 | 329 | console.log('checkbox changed'); | |
319 | 330 | if (e.target.checked) { |
templates/settings.html
View file @
b1c6c3a
<div class="row"> | 1 | 1 | <div class="row"> | |
<div class="col s12 m8 offset-m2 l6 offset-l3"> | 2 | 2 | <div class="col s12 m8 offset-m2 l6 offset-l3"> | |
<div class="card-panel"> | 3 | 3 | <div class="card-panel"> | |
<h2>Notification Settings</h2> | 4 | 4 | <h2>Notification Settings</h2> | |
<!-- | 5 | 5 | <!-- | |
class="js-checkbox" name="notifbox" value="toggle notifs"> --> | 6 | 6 | class="js-checkbox" name="notifbox" value="toggle notifs"> --> | |
<form action="#"> | 7 | 7 | <form action="#"> | |
<input type="checkbox" id="notifbox" class="js-checkbox"/> | 8 | 8 | <input type="checkbox" id="notifbox" class="js-checkbox"/> | |
<label for="notifbox">Enable notifications</label> | 9 | 9 | <label for="notifbox">Enable notifications</label> | |
</form> | 10 | 10 | </form> | |
</div> | 11 | 11 | </div> | |
</div> | 12 | 12 | </div> | |
</div> | 13 | 13 | </div> | |
14 | 14 | |||
<div class="row"> | 15 | 15 | <div class="row"> | |
<div class="col s12 m8 offset-m2 l6 offset-l3"> | 16 | 16 | <div class="col s12 m8 offset-m2 l6 offset-l3"> | |
<div class="card-panel"> | 17 | 17 | <div class="card-panel"> | |
18 | 18 | |||
<h2>Change Password</h2> | 19 | 19 | <h2>Change Password</h2> | |
20 | 20 | |||
<form name="ChangePasswordForm"> | 21 | 21 | <form name="ChangePasswordForm"> | |
22 | 22 | |||
<div class="row"> | 23 | 23 | <div class="row"> | |
<div class="input-field col s12"> | 24 | 24 | <div class="input-field col s12"> | |
<input id="password" required ng-minlegnth=1 type="password" name="oldpw" ng-model="oldPassword" class="validate"> | 25 | 25 | <input id="password" required ng-minlegnth=1 type="password" name="oldpw" ng-model="oldPassword" class="validate"> | |
<label for="password">Old Password</label> | 26 | 26 | <label for="password">Old Password</label> | |
</div> | 27 | 27 | </div> | |
</div> | 28 | 28 | </div> | |
29 | 29 | |||
30 | ||||
<div class="row"> | 31 | |||
<div class="input-field col s12"> | 32 | |||
<input id="password" required ng-minlength=8 type="password" name="newpw" ng-model="newPassword" | 33 | |||
class="validate"> | 34 | |||
<label for="password">New Password</label> | 35 | 30 | ||
</div> | 36 | 31 | <div class="row"> | |
</div> | 37 | 32 | <div class="input-field col s12"> | |
38 | 33 | <input id="password" required ng-minlength=8 type="password" name="newpw" ng-model="newPassword" | ||
<div role="alert"> | 39 | 34 | class="validate"> | |
<span style="color:#8E2323" class="error" ng-show="ChangePasswordForm.newpw.$error.minlength"> | 40 | 35 | <label for="password">New Password</label> | |
New password must be at least 8 characters. </span> | 41 | 36 | </div> | |
</div> | 42 | 37 | </div> | |
43 | 38 | |||
<div class="row"> | 44 | 39 | <div role="alert"> | |
<div class="input-field col s12"> | 45 | 40 | <span style="color:#8E2323" class="error" ng-show="ChangePasswordForm.newpw.$error.minlength"> | |
<input id="password" required ng-minlength=8 compare-to="newPasword" type="password" name="confirmpw" | 46 | 41 | New password must be at least 8 characters. </span> | |
ng-model="confirmedNewPassword" class="validate"> | 47 | 42 | </div> | |
<label for="password">Confirm New Password</label> | 48 | 43 | ||
</div> | 49 | 44 | <div class="row"> | |
</div> | 50 | 45 | <div class="input-field col s12"> | |
51 | 46 | <input id="password" required ng-minlength=8 compare-to="newPasword" type="password" name="confirmpw" | ||
<div role="alert" ng-show="mismatch && newPassword != confirmPassword"> | 52 | 47 | ng-model="confirmedNewPassword" class="validate"> | |
<span style="color:#8E2323">Passwords do not match!</span> | 53 | 48 | <label for="password">Confirm New Password</label> | |
</div> | 54 | 49 | </div> | |
55 | 50 | </div> | ||
56 | 51 | |||
</form> | 57 | 52 | <div role="alert" ng-show="mismatch && newPassword != confirmPassword"> | |
<a class="waves-effect waves-light btn" id="resetPWButton" | 58 | 53 | <span style="color:#8E2323">Passwords do not match!</span> | |
ng-click="changePassword(oldPassword, newPassword, confirmedNewPassword)">Submit</a> | 59 | |||
</div> | 60 | 54 | </div> | |
</div> | 61 | 55 | ||
</div> | 62 | 56 | ||
63 | 57 | </form> | ||
<div class="row"> | 64 | 58 | <a class="waves-effect waves-light btn" id="resetPWButton" | |
<div class="col s12 m8 offset-m2 l6 offset-l3"> | 65 | 59 | ng-click="changePassword(oldPassword, newPassword, confirmedNewPassword)">Submit</a> | |
<div class="card-panel"> | 66 | 60 | </div> | |
67 | 61 | </div> | ||
<h2>Enrolled Classes</h2> | 68 | 62 | </div> | |
69 | 63 | |||
<div class="row" style="padding: 0px 25px"> | 70 | 64 | <div class="row"> | |
<table class="hoverable responsive-table"> | 71 | 65 | <div class="col s12 m8 offset-m2 l6 offset-l3"> | |
<thead> | 72 | 66 | <div class="card-panel"> | |
<tr> | 73 | 67 | ||
<th data-field="id">Class</th> | 74 | 68 | <h2>Enrolled Classes</h2> | |
<th data-field="drop">Drop</th> | 75 | 69 | ||
</tr> | 76 | 70 | <div class="row" style="padding: 0px 25px"> | |
</thead> | 77 | 71 | <table class="hoverable responsive-table"> | |
78 | 72 | <thead> | ||
<tbody> | 79 | 73 | <tr> | |
<tr ng-repeat="section in UserService.getUserData().sections"> | 80 | 74 | <th data-field="id">Class</th> | |
<td> | 81 | 75 | <th data-field="drop">Drop</th> | |
<span>{{section.short_name}}</span> | 82 | 76 | </tr> | |
83 | 77 | </thead> |