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 // @ngInject
function PublishAnnotationBtnController($scope) { function PublishAnnotationBtnController($scope, localStorage) {
var vm = this; var vm = this;
vm.group = { vm.group = {
name: $scope.group.name, name: $scope.group.name,
type: $scope.group.public ? 'public' : 'group' type: $scope.group.public ? 'public' : 'group'
...@@ -14,12 +19,25 @@ function PublishAnnotationBtnController($scope) { ...@@ -14,12 +19,25 @@ function PublishAnnotationBtnController($scope) {
$scope.onSave(); $scope.onSave();
}; };
this.setShared = function () { this.setPrivacy = function (level) {
$scope.onSetPrivacy({level: 'shared'}); localStorage.setItem(STORAGE_KEY, level);
$scope.onSetPrivacy({level: level});
} }
this.setPrivate = function () { $scope.$watch('isShared', function () {
$scope.onSetPrivacy({level: 'private'}); 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() { function updatePublishActionLabel() {
...@@ -29,11 +47,15 @@ function PublishAnnotationBtnController($scope) { ...@@ -29,11 +47,15 @@ function PublishAnnotationBtnController($scope) {
vm.publishDestination = vm.privateLabel; 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 () { module.exports = function () {
return { return {
controller: PublishAnnotationBtnController, controller: PublishAnnotationBtnController,
...@@ -42,6 +64,7 @@ module.exports = function () { ...@@ -42,6 +64,7 @@ module.exports = function () {
scope: { scope: {
group: '=', group: '=',
isShared: '=', isShared: '=',
isNew: '=',
onSave: '&', onSave: '&',
onSetPrivacy: '&' onSetPrivacy: '&'
}, },
......
...@@ -116,6 +116,7 @@ ...@@ -116,6 +116,7 @@
class="dropdown-menu-btn"><i class="h-icon-check btn-icon"></i> Delete</button> class="dropdown-menu-btn"><i class="h-icon-check btn-icon"></i> Delete</button>
<publish-annotation-btn <publish-annotation-btn
group="vm.group()" group="vm.group()"
is-new="vm.action == 'create'"
is-shared="vm.isShared()" is-shared="vm.isShared()"
on-save="vm.save()" on-save="vm.save()"
on-set-privacy="vm.setPrivacy(level)"></publish-annotation-btn> on-set-privacy="vm.setPrivacy(level)"></publish-annotation-btn>
......
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
dropdown-menu-label="Change annotation sharing setting"> dropdown-menu-label="Change annotation sharing setting">
</dropdown-menu-btn> </dropdown-menu-btn>
<ul class="dropdown-menu pull-right publish-annotation-btn__dropdown-menu" role="menu"> <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=""> <a href="">
<i class="small" <i class="small"
ng-class="'h-icon-' + vm.group.type"></i> ng-class="'h-icon-' + vm.group.type"></i>
<span ng-bind="vm.group.name"></span> <span ng-bind="vm.group.name"></span>
</a> </a>
</li> </li>
<li ng-click="vm.setPrivate()"> <li ng-click="vm.setPrivacy('private')">
<a href=""> <a href="">
<i class="small h-icon-lock"></i> <i class="small h-icon-lock"></i>
<span ng-bind="vm.privateLabel"></span> <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