Removed smart annotation filter button disabling, when no results are found for that filter (so that 'no result found' displays instead). [SCI-894]

This commit is contained in:
Matej Zrimšek 2017-01-19 15:26:28 +01:00
parent 1793e2a8f4
commit 54f8b01341

View file

@ -91,59 +91,31 @@ var SmartAnnotation = (function() {
return res; return res;
} }
// check if query has some hits and disables the buttons without it
function resourcesChecker(query, filterTypeTag) {
var $element;
$.getJSON(
FilterTypeEnum.MENU.dataUrl,
{query: query},
function(data){
if(data) {
_.each($('.atwho-header-res .title .btn'), function(el) {
$element = $(el);
if(data[$element.data('filter')].length === 0) {
$element.prop('disabled', true);
$element
.removeClass('btn-primary')
.addClass('btn-default');
$('[data-filter="' + filterTypeTag +'"]')
.removeClass('btn-default')
.addClass('btn-primary');
} else {
$element.prop('disabled', false);
if($element.data('filter') == filterTypeTag) {
$element
.removeClass('btn-default')
.addClass('btn-primary');
} else {
$element
.removeClass('btn-primary')
.addClass('btn-default');
}
}
});
}
});
}
// initialise dropdown dismiss button // initialise dropdown dismiss button
function initDismissButton() { function initDismissButton($currentAtWho) {
$('.atwho-header-res .dismiss').off('click'); $currentAtWho.find('.dismiss').off('click')
$('.atwho-header-res .dismiss').on('click', function() { .on('click', function() {
$(field).atwho('destroy'); $(field).atwho('destroy');
init(); init();
}); });
} }
// Initialize or update filter buttons // Initialize or update dropdown header buttons
function initButtons(query, filterTypeTag) { function updateHeaderButtons(query, filterTypeTag) {
initDismissButton(); var $currentAtWho = $('.atwho-view[style]');
resourcesChecker(query, filterTypeTag); initDismissButton($currentAtWho);
$('.atwho-header-res .title button').off(); // Update the selected filter button when changing smart annotation type
$('.atwho-header-res .title button').on('click', function(e) { $currentAtWho.find('[data-filter]')
// Update the selected filter button .removeClass('btn-primary')
.addClass('btn-default');
$currentAtWho.find('[data-filter="' + filterTypeTag + '"]')
.removeClass('btn-default')
.addClass('btn-primary');
// Update the selected filter button when clicking on one of them
$currentAtWho.find('[data-filter]').off()
.on('click', function(e) {
var $selectedBtn = $(this); var $selectedBtn = $(this);
var $prevBtn = $selectedBtn.closest('.title').children('.btn-primary'); var $prevBtn = $selectedBtn.closest('.title').children('.btn-primary');
$selectedBtn.removeClass('btn-default').addClass('btn-primary'); $selectedBtn.removeClass('btn-default').addClass('btn-primary');
@ -277,8 +249,10 @@ var SmartAnnotation = (function() {
at: at, at: at,
callbacks: { callbacks: {
remoteFilter: function(query, callback) { remoteFilter: function(query, callback) {
var filterTypeTag = $('.atwho-view[style] .btn-primary') var $currentAtWho = $('.atwho-view[style]');
.data('filter'); var filterTypeTag = $currentAtWho
.find('.btn-primary')
.data('filter');
atWhoSwitchHack(filterTypeTag, function() { atWhoSwitchHack(filterTypeTag, function() {
var filterType; var filterType;
@ -298,21 +272,25 @@ var SmartAnnotation = (function() {
} }
if (prevAt != at) { if (prevAt != at) {
// Switching smart annotation type (i.e. chaned input) // Switching smart annotation type (i.e. chaned input)
prevAt = at; prevAt = at;
$('.atwho-view[style]').removeAttr("style");
filterType = defaultFilterType; filterType = defaultFilterType;
// Hide current AtWho
$currentAtWho.removeAttr("style");
} }
$.getJSON( $.getJSON(
filterType.dataUrl, filterType.dataUrl,
{query: query}, {query: query},
function(data) { function(data) {
// Updates dropdown
if (data.res.length < 1) { if (data.res.length < 1) {
callback([{no_results: 1}]); callback([{no_results: 1}]);
} else { } else {
callback(data.res); callback(data.res);
} }
initButtons(query, filterType.tag);
updateHeaderButtons(query, filterType.tag);
} }
); );
}); });