Commit 9e656c0f authored by gergely-ujvari's avatar gergely-ujvari

Merge pull request #1580 from hypothesis/unsubscribe

Ability to unsubscribe from notifications
parents 37c65e79 3927770c
......@@ -2,6 +2,8 @@ class AccountController
@inject = ['$scope', '$filter', 'flash', 'session', 'identity', 'formHelpers']
constructor: ($scope, $filter, flash, session, identity, formHelpers) ->
persona_filter = $filter('persona')
$scope.subscriptionDescription =
reply: 'Receive notification emails when: - Someone replies to one of my annotations'
onSuccess = (form, response) ->
# Fire flash messages.
......@@ -28,6 +30,11 @@ class AccountController
$scope.$broadcast 'formState', form.$name, '' # Update status btn
$scope.tab = 'Account'
session.profile({user_id: $scope.persona}).$promise
.then (result) =>
$scope.subscriptions = result.subscriptions
# Data for each of the forms
$scope.editProfile = {}
$scope.changePassword = {}
......@@ -66,6 +73,17 @@ class AccountController
promise = session.edit_profile(packet)
promise.$promise.then(successHandler, errorHandler)
$scope.updated = (index, form) ->
packet =
username: $scope.persona
subscriptions: JSON.stringify $scope.subscriptions[index]
successHandler = angular.bind(null, onSuccess, form)
errorHandler = angular.bind(null, onError, form)
promise = session.edit_profile(packet)
promise.$promise.then(successHandler, errorHandler)
angular.module('h.auth')
.controller('AccountController', AccountController)
......@@ -111,6 +111,12 @@ configure = [
method: 'GET'
withCredentials: true
sessionProvider.actions.profile =
method: 'GET'
params:
__formid__: 'profile'
withCredentials: true
for action in AUTH_SESSION_ACTIONS
sessionProvider.actions[action] =
method: 'POST'
......
<div class="tabbable" ng-controller="AccountController">
<div class="tabbable"
ng-controller="AccountController"
ng-model="tab"
>
<div class="tab-pane" title="Account">
<form class="account-form form" name="changePasswordForm" ng-submit="submit(changePasswordForm)" novalidate form-validate>
<form class="account-form form"
name="changePasswordForm"
ng-submit="submit(changePasswordForm)"
novalidate form-validate>
<h2 class="form-heading"><span>Change Your Password</span></h2>
<div class="form-field">
......@@ -66,4 +72,15 @@
</div>
</form>
</div>
<div class="tab-pane" title="Notifications">
<form class="account-form form" name="notificationsForm">
<p class="form-description">Recieve notification emails for:</p>
<div class="form-field form-checkbox-list">
<div class="form-checkbox-item" ng-repeat="subscription in subscriptions">
<input id="checkbox-{{$index}}" type="checkbox" ng-model="subscription.active" ng-change="updated($index, notificationsForm)" />
<label class="form-label" for="checkbox-{{$index}}">{{subscriptionDescription[subscription.type]}}</label>
</div>
</div>
</form>
</div>
</div>
......@@ -10,6 +10,7 @@ describe 'h.auth.AccountController', ->
fakeFormHelpers = null
editProfilePromise = null
disableUserPromise = null
profilePromise = null
createController = null
beforeEach module('h.auth')
......@@ -37,8 +38,10 @@ describe 'h.auth.AccountController', ->
disableUserPromise = {then: sandbox.stub()}
editProfilePromise = {then: sandbox.stub()}
profilePromise = {then: sandbox.stub()}
fakeSession.edit_profile = sandbox.stub().returns($promise: editProfilePromise)
fakeSession.disable_user = sandbox.stub().returns($promise: disableUserPromise)
fakeSession.profile = sandbox.stub().returns($promise: profilePromise)
createController = ->
$controller('AccountController', {$scope: $scope})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment