@@ -2,6 +2,7 @@ $(document).ready(function(){
22
33 var ajaxFail , initExpctyImpcty , initTerms , initSources , initPurposes ,
44 countries = { } , units = { } , terms = { } , purposes = { } , sources = { } ,
5+ euId = '' ,
56 selected_taxa = '' ,
67 is_search_page = $ ( '#form_expert' ) . length > 0 ,
78 is_download_page = $ ( '#net_gross_options' ) . length > 0 ,
@@ -19,14 +20,6 @@ $(document).ready(function(){
1920 $ . jGrowl ( text ) ;
2021 } ;
2122
22- function growlMeSticky ( text ) {
23- $ . jGrowl ( text , { sticky : true } ) ;
24- } ;
25-
26- function notyNormal ( message ) {
27- noty ( { layout : 'topRight' , text : message , timeout : 4000 } ) ;
28- } ;
29-
3023 function notySticky ( message ) {
3124 noty ( { layout : 'top' ,
3225 type : 'information' ,
@@ -75,17 +68,6 @@ $(document).ready(function(){
7568 $ ( 'input,select' ) . keypress ( function ( event ) { return event . keyCode != 13 ; } ) ;
7669 } ;
7770
78- function fixTaxonId ( arr ) {
79- return _ . map ( arr , function ( obj ) {
80- if ( obj . name === 'taxon_concepts_ids[]' ) {
81- return { name : 'taxon_concepts_ids[]' , value : selected_taxa } ;
82- } else {
83- return obj ;
84- }
85- } ) ;
86- }
87-
88-
8971 function parseInputs ( $inputs ) {
9072 var values = { } ;
9173 $inputs . each ( function ( ) {
@@ -104,6 +86,7 @@ $(document).ready(function(){
10486
10587 function getParamsFromInputs ( ) {
10688 var values = parseInputs ( $ ( '#form_expert :input' ) ) ;
89+
10790 return $ . param ( { 'filters' : values } ) ;
10891 }
10992
@@ -183,6 +166,7 @@ $(document).ready(function(){
183166 $ ( '#reset_search' ) . click ( function ( ) {
184167 resetSelects ( ) ;
185168 show_values_selection ( ) ;
169+ setEuDisclaimerVisibility ( ) ;
186170 // Removing the table results on reset
187171 $ ( "#query_results_table" ) . find ( 'thead,tbody' ) . remove ( ) ;
188172 $ ( '#query_results' ) . find ( 'p.info' ) . text ( '' ) ;
@@ -202,17 +186,6 @@ $(document).ready(function(){
202186 hoverColor : '#D2EF9A'
203187 } ) ;
204188
205-
206- function getSelectionTextNew ( source ) {
207- var values = [ ] ;
208-
209- $ ( '#ms-' + source ) . find ( 'div.ms-selection ul.ms-list li' ) . each ( function ( ) {
210- values . push ( $ ( this ) . text ( ) ) ;
211- } ) ;
212-
213- return values . join ( ',' )
214- }
215-
216189 function getSelectionText ( source ) {
217190 myValues = new Array ( ) ;
218191 $ ( '#' + source + ' option:selected' ) . each ( function ( index , value ) {
@@ -231,6 +204,10 @@ $(document).ready(function(){
231204 initCountriesObj = function ( data ) {
232205 _ . each ( data . geo_entities , function ( country ) {
233206 countries [ country . id ] = country ;
207+
208+ if ( country . iso_code2 == 'EU' ) {
209+ euId = country . id . toString ( )
210+ }
234211 } ) ;
235212 unLock ( 'initCountriesObj' ) ;
236213 }
@@ -256,6 +233,35 @@ $(document).ready(function(){
256233 unLock ( 'initSourcesObj' ) ;
257234 }
258235
236+ removeCasingAndDiacritics = function ( value ) {
237+ return value . toString ( )
238+ . normalize ( 'NFD' )
239+ . replace ( / [ \u0300 - \u036F ] / g, '' )
240+ . toLowerCase ( )
241+ }
242+
243+ matchWithDiacritics = function ( term , text ) {
244+ // If there are no search terms, return all of the data
245+ if ( $ . trim ( term ) === '' ) {
246+ return text ;
247+ }
248+
249+ // Do not display the item if there is no 'text' property
250+ if ( typeof text === 'undefined' ) {
251+ return null ;
252+ }
253+
254+ var searchTerm = removeCasingAndDiacritics ( term )
255+ var optionText = removeCasingAndDiacritics ( text )
256+
257+ if ( optionText . indexOf ( searchTerm ) > - 1 ) {
258+ return text ;
259+ }
260+
261+ // Return `null` if the term should not be displayed
262+ return null ;
263+ }
264+
259265 initExpctyImpcty = function ( data ) {
260266 var args = {
261267 data : data . geo_entities ,
@@ -272,7 +278,8 @@ $(document).ready(function(){
272278 $ ( '#expcty' ) . select2 ( {
273279 width : '75%' ,
274280 allowClear : false ,
275- closeOnSelect : false
281+ closeOnSelect : false ,
282+ matcher : matchWithDiacritics
276283 } ) . on ( 'change' , function ( e ) {
277284 var selection = "" ;
278285 if ( e . val . length == 0 ) {
@@ -288,6 +295,7 @@ $(document).ready(function(){
288295 selection = getText ( new_array ) ;
289296 }
290297 $ ( '#expcty_out' ) . text ( selection ) ;
298+ setEuDisclaimerVisibility ( ) ;
291299 } ) ;
292300
293301 populateSelect ( _ . extend ( args , {
@@ -298,7 +306,8 @@ $(document).ready(function(){
298306 $ ( '#impcty' ) . select2 ( {
299307 width : '75%' ,
300308 allowClear : false ,
301- closeOnSelect : false
309+ closeOnSelect : false ,
310+ matcher : matchWithDiacritics
302311 } ) . on ( 'change' , function ( e ) {
303312 selection = "" ;
304313 if ( e . val . length == 0 ) {
@@ -315,6 +324,7 @@ $(document).ready(function(){
315324 selection = getText ( new_array ) ;
316325 }
317326 $ ( '#impcty_out' ) . text ( selection ) ;
327+ setEuDisclaimerVisibility ( ) ;
318328 } ) ;
319329 } ;
320330
@@ -461,11 +471,6 @@ $(document).ready(function(){
461471 function show_values_selection ( ) {
462472 var year_from = $ ( '#qryFrom' ) . val ( ) ;
463473 var year_to = $ ( '#qryTo' ) . val ( ) ;
464- var exp_cty = $ ( '#expctyms2side__dx' ) . text ( ) ;
465- var imp_cty = $ ( '#impctyms2side__dx' ) . text ( ) ;
466- var sources = $ ( '#sourcesms2side__dx' ) . text ( ) ;
467- var purposes = $ ( '#purposesms2side__dx' ) . text ( ) ;
468- var terms = $ ( '#termsms2side__dx' ) . text ( ) ;
469474
470475 $ ( '#year_from > span' ) . text ( year_from ) ;
471476 $ ( '#year_to > span' ) . text ( year_to ) ;
@@ -477,6 +482,30 @@ $(document).ready(function(){
477482 $ ( '#genus_all_id' ) . val ( ) ;
478483 } ;
479484
485+ function setEuDisclaimerVisibility ( ) {
486+ [ 'imp' , 'exp' ] . forEach ( function ( type ) {
487+ const disclaimerEl = $ ( '#eu_disclaimer_' + type )
488+
489+ if ( disclaimerEl . length ) {
490+ hasEuDisclaimer ( type ) ? disclaimerEl . show ( ) : disclaimerEl . hide ( )
491+ }
492+ } )
493+ }
494+
495+ function hasEuDisclaimer ( type ) {
496+ const selections = $ ( '#' + type + 'cty' ) . val ( )
497+
498+ if ( ! selections ) {
499+ return false
500+ }
501+
502+ return isEuInArray ( selections )
503+ }
504+
505+ function isEuInArray ( array ) {
506+ return array . indexOf ( euId ) >= 0
507+ }
508+
480509 $ ( '#side .ui-button, #form .ui-button' ) . hover ( function ( ) {
481510 $ ( this ) . toggleClass ( 'ui-state-hover' ) ;
482511 } ) ;
@@ -510,18 +539,6 @@ $(document).ready(function(){
510539 return taxonDisplayName . replace ( new RegExp ( "(" + term + '|' + termWithHyphens + ")" , "gi" ) , transform ) ;
511540 }
512541
513- function parseTaxonData ( data , term , showSpp ) {
514- var d = data . auto_complete_taxon_concepts ;
515- return _ . map ( d , function ( element , index ) {
516- var displayName = getTaxonDisplayName ( element , showSpp )
517- return {
518- 'value' : element . id ,
519- 'label' : displayName ,
520- 'drop_label' : getTaxonLabel ( displayName , term )
521- } ;
522- } ) ;
523- }
524-
525542 function parseTaxonCascadeData ( data , term , showSpp ) {
526543 var d = data . auto_complete_taxon_concepts ;
527544 var data_by_rank = [ ] ;
@@ -611,14 +628,32 @@ $(document).ready(function(){
611628 }
612629
613630 show_values_selection ( ) ;
631+ setEuDisclaimerVisibility ( ) ;
632+
633+ $ ( '#qryFrom, #qryTo' ) . on ( 'change' , function ( e ) {
634+ year_range = handleYearRangeChange ( e . target . id )
614635
615- $ ( '#qryFrom, #qryTo' ) . on ( 'change' , function ( ) {
616- var y_from = $ ( '#qryFrom' ) . val ( ) ;
617- var y_to = $ ( '#qryTo' ) . val ( ) ;
618- $ ( '#year_from > span' ) . text ( y_from ) ;
619- $ ( '#year_to > span' ) . text ( y_to ) ;
636+ $ ( '#year_from > span' ) . text ( year_range [ 0 ] )
637+ $ ( '#year_to > span' ) . text ( year_range [ 1 ] )
620638 } ) ;
621639
640+ function handleYearRangeChange ( id ) {
641+ var y_from = $ ( '#qryFrom' ) . val ( )
642+ var y_to = $ ( '#qryTo' ) . val ( )
643+
644+ if ( y_from > y_to ) {
645+ if ( id === 'qryFrom' ) {
646+ y_to = y_from
647+ $ ( '#qryTo' ) . val ( y_to )
648+ } else {
649+ y_from = y_to
650+ $ ( '#qryFrom' ) . val ( y_from )
651+ }
652+ }
653+
654+ return [ y_from , y_to ]
655+ }
656+
622657 //Put functions to be executed here
623658 initialiseControls ( ) ;
624659
0 commit comments