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';
// @ngInject
function PrimaryActionBtnController($scope, $timeout) {
function DropdownMenuBtnController($scope, $timeout) {
this.toggleDropdown = function($event) {
$event.stopPropagation();
$timeout(function () {
......@@ -12,10 +12,11 @@ function PrimaryActionBtnController($scope, $timeout) {
module.exports = function () {
return {
controller: PrimaryActionBtnController,
controller: DropdownMenuBtnController,
controllerAs: 'vm',
restrict: 'E',
scope: {
isDisabled: '=',
label: '=',
dropdownMenuLabel: '@',
onToggleDropdown: '&',
......
......@@ -63,6 +63,7 @@ module.exports = function () {
restrict: 'E',
scope: {
group: '=',
canPost: '=',
isShared: '=',
isNew: '=',
onSave: '&',
......
......@@ -116,4 +116,20 @@ describe('publishAnnotationBtn', function () {
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);
});
});
<!--
Uses a <div> rather than a <button> so that hover states for child elements work
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>
<div class="dropdown-menu-btn">
<button class="dropdown-menu-btn__label" ng-bind="label" ng-disabled="isDisabled"></button>
<button
class="dropdown-menu-btn__dropdown-arrow"
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-indicator">
<div></div>
......
......@@ -4,7 +4,8 @@
ng-click="vm.save()"
on-toggle-dropdown="vm.showDropdown = !vm.showDropdown"
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>
<ul class="dropdown-menu pull-right publish-annotation-btn__dropdown-menu" role="menu">
<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