Commit 15a486d0 authored by Robert Knight's avatar Robert Knight

Implement the sticky privacy behavior in the new annotation publish button

Re-implement the behavior where new annotations
use the last-used privacy setting by default.

This was previously implemented in privacy.js
and the logic now lives in the replacement component,
publish-annotation-btn.js. However, the defaults
really shouldn't be set in the view but earlier when
the new annotation is created.

Card 89
parent 79ddba82
'use strict';
var STORAGE_KEY = 'hypothesis.privacy';
// @ngInject
function PublishAnnotationBtnController($scope) {
function PublishAnnotationBtnController($scope, localStorage) {
var vm = this;
vm.group = {
name: $scope.group.name,
type: $scope.group.public ? 'public' : 'group'
......@@ -14,12 +19,25 @@ function PublishAnnotationBtnController($scope) {
$scope.onSave();
};
this.setShared = function () {
$scope.onSetPrivacy({level: 'shared'});
this.setPrivacy = function (level) {
localStorage.setItem(STORAGE_KEY, level);
$scope.onSetPrivacy({level: level});
}
this.setPrivate = function () {
$scope.onSetPrivacy({level: 'private'});
$scope.$watch('isShared', function () {
updatePublishActionLabel();
});
if ($scope.isNew) {
// set the privacy level for new annotations.
// FIXME - This should be done at the time the annotation is created,
// not by this control
var defaultLevel = localStorage.getItem(STORAGE_KEY);
if (defaultLevel !== 'private' &&
defaultLevel !== 'shared') {
defaultLevel = 'shared';
}
this.setPrivacy(defaultLevel);
}
function updatePublishActionLabel() {
......@@ -29,11 +47,15 @@ function PublishAnnotationBtnController($scope) {
vm.publishDestination = vm.privateLabel;
}
}
$scope.$watch('isShared', function () {
updatePublishActionLabel();
});
}
/**
* @ngdoc directive
* @name publishAnnotationBtn
* @description Displays a combined privacy/selection post button to post
* a new annotation
*/
// @ngInject
module.exports = function () {
return {
controller: PublishAnnotationBtnController,
......@@ -42,6 +64,7 @@ module.exports = function () {
scope: {
group: '=',
isShared: '=',
isNew: '=',
onSave: '&',
onSetPrivacy: '&'
},
......
......@@ -116,6 +116,7 @@
class="dropdown-menu-btn"><i class="h-icon-check btn-icon"></i> Delete</button>
<publish-annotation-btn
group="vm.group()"
is-new="vm.action == 'create'"
is-shared="vm.isShared()"
on-save="vm.save()"
on-set-privacy="vm.setPrivacy(level)"></publish-annotation-btn>
......
......@@ -7,14 +7,14 @@
dropdown-menu-label="Change annotation sharing setting">
</dropdown-menu-btn>
<ul class="dropdown-menu pull-right publish-annotation-btn__dropdown-menu" role="menu">
<li ng-click="vm.setShared()">
<li ng-click="vm.setPrivacy('shared')">
<a href="">
<i class="small"
ng-class="'h-icon-' + vm.group.type"></i>
<span ng-bind="vm.group.name"></span>
</a>
</li>
<li ng-click="vm.setPrivate()">
<li ng-click="vm.setPrivacy('private')">
<a href="">
<i class="small h-icon-lock"></i>
<span ng-bind="vm.privateLabel"></span>
......
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