Commit fb34c3e4 authored by Robert Knight's avatar Robert Knight

Add can-post attribute to <publish-annotation-btn> to control whether it is enabled

When false, both the dropdown menu and the post button are disabled.

Card 89
parent 4a1f8e3c
'use strict'; 'use strict';
// @ngInject // @ngInject
function PrimaryActionBtnController($scope, $timeout) { function DropdownMenuBtnController($scope, $timeout) {
this.toggleDropdown = function($event) { this.toggleDropdown = function($event) {
$event.stopPropagation(); $event.stopPropagation();
$timeout(function () { $timeout(function () {
...@@ -12,10 +12,11 @@ function PrimaryActionBtnController($scope, $timeout) { ...@@ -12,10 +12,11 @@ function PrimaryActionBtnController($scope, $timeout) {
module.exports = function () { module.exports = function () {
return { return {
controller: PrimaryActionBtnController, controller: DropdownMenuBtnController,
controllerAs: 'vm', controllerAs: 'vm',
restrict: 'E', restrict: 'E',
scope: { scope: {
isDisabled: '=',
label: '=', label: '=',
dropdownMenuLabel: '@', dropdownMenuLabel: '@',
onToggleDropdown: '&', onToggleDropdown: '&',
......
...@@ -63,6 +63,7 @@ module.exports = function () { ...@@ -63,6 +63,7 @@ module.exports = function () {
restrict: 'E', restrict: 'E',
scope: { scope: {
group: '=', group: '=',
canPost: '=',
isShared: '=', isShared: '=',
isNew: '=', isNew: '=',
onSave: '&', onSave: '&',
......
...@@ -116,4 +116,20 @@ describe('publishAnnotationBtn', function () { ...@@ -116,4 +116,20 @@ describe('publishAnnotationBtn', function () {
assert.equal(privacyChangedSpy.callCount, 2); assert.equal(privacyChangedSpy.callCount, 2);
}); });
it('should disable post buttons when posting is not possible', function () {
var element = util.createDirective(document, 'publishAnnotationBtn', {
group: {
name: 'Research Lab',
type: 'group'
},
canPost: false,
isShared: true,
isNew: false,
onSave: function () {},
onSetPrivacy: function () {}
});
var disabledBtns = element.find('button[disabled]');
assert.equal(disabledBtns.length, 2);
});
}); });
<!-- <div class="dropdown-menu-btn">
Uses a <div> rather than a <button> so that hover states for child elements work <button class="dropdown-menu-btn__label" ng-bind="label" ng-disabled="isDisabled"></button>
in Firefox. See https://bugzilla.mozilla.org/show_bug.cgi?id=843003
!-->
<div aria-role="button" tabindex="0" class="dropdown-menu-btn">
<button class="dropdown-menu-btn__label" ng-bind="label"></button>
<button <button
class="dropdown-menu-btn__dropdown-arrow" class="dropdown-menu-btn__dropdown-arrow"
title="{{dropdownMenuLabel}}" title="{{dropdownMenuLabel}}"
ng-click="vm.toggleDropdown($event)"> ng-click="vm.toggleDropdown($event)"
ng-disabled="isDisabled">
<div class="dropdown-menu-btn__dropdown-arrow-separator"></div> <div class="dropdown-menu-btn__dropdown-arrow-separator"></div>
<div class="dropdown-menu-btn__dropdown-arrow-indicator"> <div class="dropdown-menu-btn__dropdown-arrow-indicator">
<div></div> <div></div>
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
ng-click="vm.save()" ng-click="vm.save()"
on-toggle-dropdown="vm.showDropdown = !vm.showDropdown" on-toggle-dropdown="vm.showDropdown = !vm.showDropdown"
title="Publish this annotation to {{vm.publishDestination}}" title="Publish this annotation to {{vm.publishDestination}}"
dropdown-menu-label="Change annotation sharing setting"> dropdown-menu-label="Change annotation sharing setting"
is-disabled="!canPost">
</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.setPrivacy('shared')"> <li ng-click="vm.setPrivacy('shared')">
......
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