diff --git a/src/main/webapp/app/controllers/settings/fieldPredicatesController.js b/src/main/webapp/app/controllers/settings/fieldPredicatesController.js index 622edaa36f..23749a7bc0 100644 --- a/src/main/webapp/app/controllers/settings/fieldPredicatesController.js +++ b/src/main/webapp/app/controllers/settings/fieldPredicatesController.js @@ -39,7 +39,9 @@ vireo.controller('FieldPredicatesController', function ($controller, $timeout, $ $scope.selectFieldPredicate = function(index) { $scope.resetFieldPredicates(); - var filtereFieldPredicates = $filter('filter')($scope.fieldPredicates, $scope.dragAndDropTextFilterValue[$scope.dragAndDropSelectedFilter]); + // Filter exactly the way draganddroplist renders the list, otherwise the index + // handed back by the list does not point at the predicate the user acted on. + var filtereFieldPredicates = $filter('filter')($scope.fieldPredicates, $scope.dragAndDropTextFilterValue); $scope.modalData = filtereFieldPredicates[index]; }; diff --git a/src/main/webapp/app/controllers/submission/submissionListController.js b/src/main/webapp/app/controllers/submission/submissionListController.js index b0689e4e37..7686123ccf 100644 --- a/src/main/webapp/app/controllers/submission/submissionListController.js +++ b/src/main/webapp/app/controllers/submission/submissionListController.js @@ -1026,6 +1026,24 @@ vireo.controller("SubmissionListController", function (NgTableParams, $controlle column.status = !column.status ? 'previouslyDisabled' : undefined; }; + // Keyboard accessible equivalent of dragging a column to a new position. See issue #1674. + var moveInList = function(list, index, offset) { + var destination = index + offset; + + if (destination < 0 || destination >= list.length) { + return; + } + + list.splice(destination, 0, list.splice(index, 1)[0]); + updateChange(true); + }; + + $scope.moveColumn = moveInList; + + var moveFilterColumn = function(index, offset) { + moveInList(filterColumns.userFilterColumns, index, offset); + }; + $scope.displayedColumnOptions = createDisplayedColumnOptions(); $scope.disabledColumnOptions = createDisabledColumnOptions(); @@ -1073,6 +1091,7 @@ vireo.controller("SubmissionListController", function (NgTableParams, $controlle "filterColumns": filterColumns, "disableFilter": disableFilter, "enableFilter": enableFilter, + "moveFilterColumn": moveFilterColumn, "displayedFilterColumnOptions": displayedFilterColumnOptions, "disabledFilterColumnOptions": disabledFilterColumnOptions, "saveUserFilters": $scope.saveUserFilters, diff --git a/src/main/webapp/app/directives/dragAndDropListDirective.js b/src/main/webapp/app/directives/dragAndDropListDirective.js index 837b7835c1..9612af815d 100644 --- a/src/main/webapp/app/directives/dragAndDropListDirective.js +++ b/src/main/webapp/app/directives/dragAndDropListDirective.js @@ -24,6 +24,7 @@ vireo.directive("draganddroplist", function($filter) { 'selectedFilter': '=?', 'textFilterValue': '=?', 'passiveFilter': '=?', + 'allowRemove': '=?', 'isEditable': '&', }, controller: function($scope) { @@ -37,6 +38,61 @@ vireo.directive("draganddroplist", function($filter) { if(typeof $scope.itemView == 'undefined') { $scope.itemView = 'views/directives/dragAndDropItem.html'; } + + // Keyboard accessible alternatives to the drag gestures. Drag and drop cannot be + // the only way to reorder or remove an item. See issue #1674. + + $scope.itemControlsView = 'views/directives/dragAndDropItemControls.html'; + + $scope.canReorder = function () { + return !!($scope.listeners && $scope.listeners.canReorder && $scope.listeners.canReorder()); + }; + + // Lists whose items are deleted somewhere other than the trash can (the embargo + // tables delete from their edit modal) opt out with allow-remove="false". + $scope.canRemove = function () { + if ($scope.allowRemove === false) { + return false; + } + return !!($scope.listeners && $scope.listeners.canRemove && $scope.listeners.canRemove()); + }; + + $scope.moveUp = function (index) { + $scope.listeners.moveItem($scope.scopeValue, index, index - 1); + }; + + $scope.moveDown = function (index) { + $scope.listeners.moveItem($scope.scopeValue, index, index + 1); + }; + + $scope.removeItem = function (index) { + $scope.listeners.removeAt(index); + }; + + // Used to give each control an accessible name that identifies the row it acts on, + // so "Remove" is announced as "Remove Masters of Science" rather than just "Remove". + $scope.itemLabel = function (item) { + var parts = []; + + if (item) { + angular.forEach($scope.properties, function (property) { + var value = item[property]; + if (angular.isString(value) || angular.isNumber(value)) { + parts.push(value); + } else if (value && angular.isString(value.name)) { + parts.push(value.name); + } + }); + } + + if (parts.length > 0) { + return parts.join(' '); + } + + // The table list view passes column headings rather than item keys as + // properties, so fall back to whatever the item calls itself. + return (item && (item.name || item.label || item.gloss)) || 'this item'; + }; }, link: function($scope, elem, attr) { $scope.properties = angular.fromJson(attr.properties); diff --git a/src/main/webapp/app/directives/keyboardClickableDirective.js b/src/main/webapp/app/directives/keyboardClickableDirective.js new file mode 100644 index 0000000000..deb5b04344 --- /dev/null +++ b/src/main/webapp/app/directives/keyboardClickableDirective.js @@ -0,0 +1,53 @@ +/** + * Makes a non interactive element that carries an ng-click reachable and operable + * from the keyboard, without changing how it looks. Adds a tab stop and a button + * role when the element does not already declare them, and activates the element + * on Enter or Space the way a native button would. + * + * Use it on clickable spans, images and list items. Native controls (button, a[href], + * input, select, textarea) already do this and do not need the attribute. + */ +vireo.directive("keyboardClickable", function () { + + var ENTER = 13; + var SPACE = 32; + + return { + restrict: 'A', + link: function ($scope, element, attrs) { + + if (attrs.tabindex === undefined) { + element.attr('tabindex', '0'); + } + + if (attrs.role === undefined) { + element.attr('role', 'button'); + } + + var isDisabled = function () { + return element.attr('disabled') !== undefined || element.hasClass('disabled'); + }; + + var onKeydown = function (event) { + if (event.which !== ENTER && event.which !== SPACE) { + return; + } + + if (isDisabled()) { + return; + } + + // Space scrolls the page by default and Enter may submit a surrounding form. + event.preventDefault(); + + element[0].click(); + }; + + element.on('keydown', onKeydown); + + $scope.$on('$destroy', function () { + element.off('keydown', onKeydown); + }); + } + }; +}); diff --git a/src/main/webapp/app/factories/dragAndDropListenerFactory.js b/src/main/webapp/app/factories/dragAndDropListenerFactory.js index 75748e5a39..d2c6c71be7 100644 --- a/src/main/webapp/app/factories/dragAndDropListenerFactory.js +++ b/src/main/webapp/app/factories/dragAndDropListenerFactory.js @@ -51,6 +51,10 @@ vireo.factory('DragAndDropListenerFactory', function($q, ModalService) { }); }; + var relocate = function(list, from, to) { + list.splice(to, 0, list.splice(from, 1)[0]); + }; + var dragControls = { getListener: function () { return listener; @@ -115,6 +119,53 @@ vireo.factory('DragAndDropListenerFactory', function($q, ModalService) { }); } }, + + // Keyboard accessible equivalents of the drag gestures above. These drive the + // per item controls rendered by the draganddroplist directive so that reordering + // and removal never require a pointer. See issue #1674. + + canReorder: function() { + return angular.isFunction(listener.reorder); + }, + + canRemove: function() { + return angular.isFunction(listener.select) && !!listener.confirm.remove.modal; + }, + + // Mirrors dropping an item on the trash can: select it, then hand off to the + // same confirmation modal the drag gesture opens. + removeAt: function(index) { + if(!dragControls.canRemove()) { + return; + } + original = angular.copy(listener.model); + listener.select(index); + updateRequest(); + ModalService.openModal(listener.confirm.remove.modal); + }, + + // Mirrors dragging an item to a new slot. The list passed in is the rendered + // list, which is what the sortable mutates and what the reorder end points + // expect positions against. + moveItem: function(list, from, to) { + if(!dragControls.canReorder() || !angular.isArray(list)) { + return $q.when(); + } + if(from === to || to < 0 || to >= list.length) { + return $q.when(); + } + original = angular.copy(listener.model); + relocate(list, from, to); + updateRequest(); + return listener.reorder(from + 1, to + 1).then(function(res) { + var message = angular.fromJson(res.body); + if (message.meta.status !== "SUCCESS") { + relocate(list, to, from); + angular.extend(listener.model, original); + } + }); + }, + containerPositioning: 'relative', containment: drag.container }; diff --git a/src/main/webapp/app/resources/styles/sass/app.scss b/src/main/webapp/app/resources/styles/sass/app.scss index 1ba8ab43ed..6c2575caae 100644 --- a/src/main/webapp/app/resources/styles/sass/app.scss +++ b/src/main/webapp/app/resources/styles/sass/app.scss @@ -687,8 +687,9 @@ h4 { background: #efefef; border: dashed thick #fefefe; padding-top: 35px; + padding-bottom: 10px; width: 250px; - height: 150px; + min-height: 150px; color: #696969; border-radius: 5px; transition: all 0.35s ease-in; @@ -742,6 +743,13 @@ h4 { cursor: pointer; } +/* The drop zone is also operable from the keyboard through this button, which opens the + file picker, so the focus has to be visible. */ +.upload-drop-zone .invisible-button:focus { + outline: 2px solid #337ab7; + outline-offset: 2px; +} + .upload-drop-zone.dragging .glyphicon-upload, .upload-drop-zone.reject .glyphicon-ban-circle { transition: all 0.35s ease-in; @@ -1482,6 +1490,39 @@ input[type=color]:focus { display: inline-block; } +/* The move buttons are a keyboard alternative to dragging, so unlike the hint arrows + they stay visible rather than waiting for a hover. See issue #1674. */ +.displayed-column, +.disabled-column { + display: flex; + align-items: center; +} + +.displayed-column > [as-sortable-item-handle], +.disabled-column > [as-sortable-item-handle] { + flex: 1 1 auto; + min-width: 0; +} + +.displayed-column > .item-controls, +.disabled-column > .item-controls { + flex: 0 0 auto; + margin-left: 8px; +} + +.displayed-column .item-controls .glyphicon, +.disabled-column .item-controls .glyphicon { + display: inline-block; +} + +.displayed-column .item-controls .item-control:focus, +.disabled-column .item-controls .item-control:focus, +.displayed-column [as-sortable-item-handle]:focus, +.disabled-column [as-sortable-item-handle]:focus { + outline: 2px solid #337ab7; + outline-offset: 2px; +} + .column-background { list-style-type: none; margin: 0; diff --git a/src/main/webapp/app/resources/styles/sass/directives/_dragAndDropList.scss b/src/main/webapp/app/resources/styles/sass/directives/_dragAndDropList.scss index a2aaf8178a..65ccec03dd 100644 --- a/src/main/webapp/app/resources/styles/sass/directives/_dragAndDropList.scss +++ b/src/main/webapp/app/resources/styles/sass/directives/_dragAndDropList.scss @@ -24,3 +24,55 @@ .as-sortable-placeholder { border: 1px solid #dcdcdc; } + +/******************************************************** + * Keyboard accessible alternatives to the drag gestures * + ********************************************************/ + +.list-dragdrop > li > .list-dragdrop-item, +.list-dragdrop > li > .item-controls-wrapper { + display: inline-block; + vertical-align: middle; +} + +.list-dragdrop > li > .item-controls-wrapper { + margin-left: 8px; +} + +.item-controls { + white-space: nowrap; +} + +.item-controls .item-control { + color: #666666; +} + +.item-controls .item-control-remove { + color: #a94442; +} + +.item-controls .item-control[disabled] { + opacity: 0.35; +} + +/* The edit pencil used to appear only while the row was hovered, which put it out of + reach of the keyboard. It is always rendered now and leans on colour for emphasis. */ +.edit-setting-icon { + color: #999999; + margin-left: 6px; +} + +.list-dragdrop > li:hover .edit-setting-icon, +.list-dragdrop > li:focus-within .edit-setting-icon, +.edit-setting-icon:hover, +.edit-setting-icon:focus { + color: #333333; +} + +/* Every control reached by tabbing needs to show where the focus is. */ +.item-controls .item-control:focus, +.edit-setting-icon:focus, +[keyboard-clickable]:focus { + outline: 2px solid #337ab7; + outline-offset: 2px; +} diff --git a/src/main/webapp/app/views/admin/settings/workflow/embargoTypes.html b/src/main/webapp/app/views/admin/settings/workflow/embargoTypes.html index 9a0b349db2..ee53600e85 100644 --- a/src/main/webapp/app/views/admin/settings/workflow/embargoTypes.html +++ b/src/main/webapp/app/views/admin/settings/workflow/embargoTypes.html @@ -10,8 +10,9 @@
| {{header}} | +{{header}} | |||||||
|---|---|---|---|---|---|---|---|---|
|
- {{fieldValue.fileInfo.name | limitTo: 25}}{{fieldValue.fileInfo.name.length > 25 ? '...' : ''}} +{{fieldValue.fileInfo.name | limitTo: 25}}{{fieldValue.fileInfo.name.length > 25 ? '...' : ''}} |
{{fieldValue.fileInfo.size | readableFileSize}} | - + |
|
Customize Filters
- Please select which search filter options should be displayed by dragging into or out of the list of displayed options. +Please select which search filter options should be displayed by dragging into or out of the list of displayed options, or with the buttons beside each option. Displayed Filters
Displayed FiltersDisabled Filters
Customize Results Table
- Please select which columns should be displayed by dragging into or out of the list of displayed columns. +Please select which columns should be displayed by dragging into or out of the list of displayed columns, or with the buttons beside each column. Displayed Columns
Displayed ColumnsDisabled Columns
| ||||