function liveUpdateTags(){ if($('.analysisdetail').length > 0){ analysisDetailReloadBlock = true; var tags = $('.container.tag-list-selected .internal-name').map(function(e) { return $(this).text(); }).get(); var data = { "tags": tags, "webid": DATA.webid, }; $.ajax({ url:urlFor['postTags'], type: "POST", data: data, success: function() { analysisDetailReloadBlock = false; }, error: function(jqXHR) { $("#updateTagsError .modal-body").html("Operation failed: " + jqXHR.responseText + " (the page will reload now)"); $("#updateTagsError").modal(); setTimeout(function(){ location.reload(); }, 3000); } }); } }; var inputElement, inputElementId; (function($){ $.fn.smartSelection = function() { inputElement = this; inputElementId = this.attr('id'); var selectedTags = $('#'+inputElementId+'-selectedTags'); var emptySystemsText = this.find('.smartSelectionSearch input').val(); var isTag = this.hasClass('tagSelection'); function toggleAutoAnalysisSystem(){ if(inputElement.find('.noSystemSelected').length > 0){ if(inputElement.find('.smartSelectionSelectedItems .smartSelectionSelectedItem').length == 0) { inputElement.find('.noSystemSelected').show(); inputElement.find('.noSystemSelected input').attr('value', '1'); }else{ inputElement.find('.noSystemSelected').hide(); inputElement.find('.noSystemSelected input').attr('value', '0'); } } }; function updateCurrentSelection($element, removeTag){ if($element.closest('.smartSelection').hasClass('tagSelection') && removeTag){ inputElement = $element.closest('.smartSelection').parent().find('.tagSelectionLive'); }else{ inputElement = $element.closest('.smartSelection'); }; inputElementId = inputElement.attr('id'); selectedTags = $('#'+inputElementId+'-selectedTags'); emptySystemsText = $element.find('.smartSelectionSearch input').val(); isTag = inputElement.hasClass('tagSelection'); }; function closeSystemWrapper(){ if(inputElement.find('.smartSelectionSearch').hasClass('open')){ inputElement.find('.whiteBorder').hide(); inputElement.find('.smartSelectionWrapper').hide(); inputElement.find('.smartSelectionSearch').removeClass('open'); if(inputElement.find('.smartSelectionSearch').find('input').val() == ''){ inputElement.find('.smartSelectionSearch').find('input').val(emptySystemsText); } } }; function showEmptySystems(){ if(inputElement.find('.smartSelectionWrapper li:visible').length == 0) { inputElement.find('.smartSelectionWrapper h3').hide(); inputElement.find('.smartSelectionNoItemsFound').show(); inputElement.find('.smartSelectionWrapperScroll').css('overflow-y', 'visible'); }else{ inputElement.find('.smartSelectionWrapper h3').show(); inputElement.find('.smartSelectionWrapperScroll').css('overflow-y', 'scroll'); inputElement.find('.smartSelectionNoItemsFound').hide(); } }; function checkMaxSystemsThreshold(){ if(isTag){ return; } let numberOfSelectedElements = inputElement.find('.smartSelectionWrapper li.selected').length; if (numberOfSelectedElements >= DATA.max_analysis_systems){ inputElement.find('.smartSelectionWrapper li').each(function () { if(!$(this).data('system-disabled-basic')) { $(this).addClass('disabled'); $(this).attr('title', 'Please select a maximum of ' + DATA.max_analysis_systems + ' systems only to allow fair use of resources'); } }); } else { inputElement.find('.smartSelectionWrapper li').each(function () { if(!$(this).data('system-disabled-basic')) { $(this).removeClass('disabled'); $(this).removeAttr('title'); } }); } } $(window).click(function(){ closeSystemWrapper(); }); this.find('.smartSelectionSearch').bind('click', function(event, data){ $('html, body').animate({ scrollTop: $(this).offset().top - $('.navbar-fixed-top').height() - 33 }, 'slow'); updateCurrentSelection($(this), false); $(this).addClass('open'); inputElement.find('.whiteBorder').show(); if(inputElement.find('.smartSelectionSearch input').val() == emptySystemsText){ inputElement.find('input[type="text"]').val(''); } inputElement.find('input').select(); inputElement.find('.smartSelectionWrapper').show(); showEmptySystems(); event.stopPropagation(); event.stopImmediatePropagation(); }); this.find('.smartSelectionSearch input').keyup(function(){ updateCurrentSelection($(this), false); var searchTermOrigin = $(this).val(); if(searchTermOrigin.includes('Select up to') || searchTermOrigin.includes('Select one or')){ searchTermOrigin = ''; } var searchTerm = searchTermOrigin.toLowerCase().replace(/ /g,''); inputElement.find('.smartSelectionWrapper li').each(function(){ var systemText = $(this).text().toLowerCase().replace(/ /g,''); if(systemText.indexOf(searchTerm) >= 0){ if(!$(this).hasClass('selected')){ $(this).show(); } }else{ $(this).hide(); } }); showEmptySystems(); inputElement.find('.smartSelectionWrapper ul').each(function(){ var listItemsLength = $(this).find('li:visible').length; if($(this).prev()[0]){ var nodeName = $(this).prev()[0].nodeName; if(listItemsLength == 0){ if(nodeName == 'H3'){ $(this).prev().hide(); } }else{ if(nodeName == 'H3'){ $(this).prev().show(); } } } }); }); $(document).on('click', '#'+inputElementId+' .smartSelectionWrapper li', function(){ if($(this).hasClass('disabled')){ return; } var $smartSelectionSelectedItem = $(this).clone(); var internalName = $smartSelectionSelectedItem.find('.internal-name').text(); $smartSelectionSelectedItem.find('.internal-name').append('
'); if(isTag){ selectedTags.find('.smartSelectionSelectedItems .container').append('