Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves accessibility in categories filter for submissions #3

Open
wants to merge 17 commits into
base: stable-3_3_0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
3fe3b56
Adds a scroll bar to the category list when there are more than 10 ca…
thiagolepidus Jun 14, 2021
7f70be8
Implements function to search categories by name on submission form.
thiagolepidus Jun 15, 2021
d769028
Refactoring the categories search function.
thiagolepidus Jun 15, 2021
12931a9
Add bold to text when category is selected.
thiagolepidus Jun 16, 2021
c348492
Groups the list of categories into assigned and unassigned.
thiagolepidus Jun 16, 2021
fed9bd5
Refactoring to adjust the JavaScript code with the template Smart.
thiagolepidus Jun 17, 2021
c0f161d
Adds a placeholder to category search input.
thiagolepidus Jun 17, 2021
c0d22e5
Merge pull request #1 from thiagolepidus/addScrollingAndSearchOnCateg…
thiagolepidus Jun 21, 2021
16199f0
Creates a file for the categories filter.
thiagolepidus Jun 22, 2021
52eb5f2
Implements a handler for the categories filter
thiagolepidus Jun 22, 2021
bbad6b8
Refactoring to include CategoriesFilterHandler on submission page group
thiagolepidus Jun 22, 2021
e29bc46
Fixes the formatText function description.
thiagolepidus Jun 23, 2021
7ddb2fc
Use variable for font-weight of assigned category labels and remove s…
thiagolepidus Jun 23, 2021
5d8d16c
Adds a label to search categories input.
thiagolepidus Jun 24, 2021
da58304
Merge pull request #2 from lepidus/categoriesFilterForSubmissionsForm…
thiagolepidus Jun 25, 2021
da95595
Fixes search to filter only the unassigned categories.
thiagolepidus Sep 21, 2021
59ebab0
Improves accessibility in categories filter for submissions
thiagolepidus Sep 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions js/pages/submission/SubmissionCategoriesFilterHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* @defgroup js_pages_submission
*/
/**
* @file js/pages/submission/SubmissionCategoriesFilterHandler.js
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class SubmissionCategoriesFilterHandler
* @ingroup js_pages_submission
*
* @brief A handler for the categories filter for submissions
*/
(function($) {

/** @type {Object} */
$.pkp.pages.submission =
$.pkp.pages.submission || {};



/**
* @constructor
*
* @extends $.pkp.classes.Handler
*
* @param {jQueryObject} $widgetWrapper An HTML element that contains the
* widget.
* @param {Object} options Handler options.
*/
$.pkp.pages.submission.SubmissionCategoriesFilterHandler =
function($widgetWrapper, options) {

this.parent($widgetWrapper, options);
var self = this;

$('input:checkbox', $widgetWrapper).on('click',
self.callbackWrapper(self.assignCategory));

$('input:text', $widgetWrapper).on('keyup',
self.callbackWrapper(self.searchCategories));
};
$.pkp.classes.Helper.inherits(
$.pkp.pages.submission.SubmissionCategoriesFilterHandler,
$.pkp.classes.Handler);


//
// Public methods
//

/**
* Assign/Unassign the category item and move it to correct element
*
* @param {HTMLElement} sourceElement The element that
* issued the event.
* @param {Event} event The triggering event.
*/
$.pkp.pages.submission.SubmissionCategoriesFilterHandler.
prototype.assignCategory = function(sourceElement, event) {
if ($(sourceElement).is(':checked')) {
$(sourceElement).parents('li').appendTo('.assigned_categories ul');
} else {
$(sourceElement).parents('li').appendTo('.unassigned_categories ul');
}
};

/**
* Search categories by text
*
* @param {HTMLElement} sourceElement The element that
* issued the event.
* @param {Event} event The triggering event.
*/
$.pkp.pages.submission.SubmissionCategoriesFilterHandler.
prototype.searchCategories = function(sourceElement, event) {
var self = this,
filter = self.formatText(
$(sourceElement).val());
$('.unassigned_categories ul li').filter(function() {
var category = self.formatText(
$('label', this).text());
$(this).toggle(category.indexOf(filter) > -1);
});
};

/**
* Remove accents for text and converts to uppercase
*
* @param {string} text The text that will be formatted
* for the categories search
* @return {string} The text formatted without accents and in uppercase.
*/
$.pkp.pages.submission.SubmissionCategoriesFilterHandler.
prototype.formatText = function(text) {
return text.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toUpperCase();
};

}(jQuery));
20 changes: 19 additions & 1 deletion styles/pages/submission.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,22 @@
#submission-files-container {
margin-bottom: 1rem;
}
}

#categoriesList {
height: 250px;
overflow: hidden;
overflow-y: scroll;
border: @bg-border;
padding: 5px 10px;
display: flex;

.assigned_categories,
.unassigned_categories {
flex: 1;
}

.assigned_categories li label {
font-weight: @bold;
}
}
}
26 changes: 16 additions & 10 deletions templates/submission/form/categories.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@
*
* Include categories for submissions.
*}

{if count($categories)}
{if $readOnly}
{fbvFormSection title="grid.category.categories" list=true}
{if $readOnly}
{fbvFormSection title="grid.category.categories" list=true}
{foreach from=$categories item="category" key="id"}
{if in_array($id, $assignedCategories)}
<li>{$category->getLocalizedTitle()|escape}</li>
{/if}
{/foreach}
{/fbvFormSection}
{else}
{fbvFormSection list=true title="grid.category.categories"}
{foreach from=$categories item="category" key="id"}
{fbvElement type="checkbox" id="categories[]" value=$id checked=in_array($id, $assignedCategories) label=$category translate=false}
{/foreach}
{/fbvFormSection}
{/if}
{/fbvFormSection}
{else}

{if count($categories) > 10}
{include file="submission/form/categoriesFilter.tpl"}
{else}
{fbvFormSection title="grid.category.categories" list=true}
{foreach from=$categories item="category" key="id"}
{fbvElement type="checkbox" id="categories[]" value=$id checked=in_array($id, $assignedCategories) label=$category translate=false}
{/foreach}
{/fbvFormSection}
{/if}
{/if}
{/if}
39 changes: 39 additions & 0 deletions templates/submission/form/categoriesFilter.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{**
* templates/submission/form/categoriesFilter.tpl
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* Categories filter for submissions.
*}
<script>
// Initialise JS handler.
$(function() {ldelim}
$('#pkp_submissionCategories').pkpHandler(
'$.pkp.pages.submission.SubmissionCategoriesFilterHandler'
);
{rdelim});
</script>

{fbvFormArea title="grid.category.categories" id="pkp_submissionCategories"}
{fbvFormSection}
{fbvElement type="text" label="common.search" multilingual="true" name="searchCategories" id="searchCategories" value=$searchCategories maxlength="255" aria-controls="categoriesList"}
{/fbvFormSection}
<div class="categories_list" id="categoriesList" aria-live="true">
{fbvFormSection class="unassigned_categories" list="true"}
{foreach from=$categories item="category" key="id"}
{if !in_array($id, $assignedCategories)}
{fbvElement type="checkbox" id="categories[]" value=$id checked=in_array($id, $assignedCategories) label=$category translate=false}
{/if}
{/foreach}
{/fbvFormSection}
{fbvFormSection class="assigned_categories" list="true"}
{foreach from=$categories item="category" key="id"}
{if in_array($id, $assignedCategories)}
{fbvElement type="checkbox" id="categories[]" value=$id checked=in_array($id, $assignedCategories) label=$category translate=false}
{/if}
{/foreach}
{/fbvFormSection}
</div>
{/fbvFormArea}