1
- /*
2
- * LitbasketsSourcesTopbarController
3
- * Instantiated in index.controller.js as GLOBAL_SOURCES_TOPBAR_CONTROLLER
4
- */
5
- LitbasketsSourcesTopbarController = {
6
- /*
7
- * Inserts rows into the listview on screen 'Sources'
8
- */
9
- populate_journals_in_listview_for_section : function ( given_section ) {
10
- // clear model and view
11
- user_selected_journal_ids_to_inspect = [ ] ;
12
- $ ( "#journalsListView" ) . html ( "" ) ;
13
-
14
- for ( var i = 0 ; i < saved_journals_by_subdivisions . length ; i ++ ) {
15
- var this_subdivision = saved_journals_by_subdivisions [ i ] ;
16
-
17
- // if user selected this subdivision
18
- if ( this . user_selected_subdivision_ids . includes ( this_subdivision . bsd_id ) ) {
19
- for ( var j = 0 ; j < this_subdivision . journals . length ; j ++ ) {
20
- user_selected_journal_ids_to_inspect . push ( this_subdivision . journals [ j ] . journal_id ) ;
21
- }
22
- }
23
- }
24
-
25
- user_selected_journal_ids_to_inspect = _ . uniq ( user_selected_journal_ids_to_inspect ) ;
26
-
27
- for ( var i = 0 ; i < user_selected_journal_ids_to_inspect . length ; i ++ ) {
28
- var this_journal_id = user_selected_journal_ids_to_inspect [ i ] ;
29
- var journal_record = GLOBAL_MODEL_HELPER . get_master_record_by_journal_id ( this_journal_id ) ;
30
-
31
- // ISSN details
32
- var coverage_text = journal_record . scopus_coverage ;
33
- if ( coverage_text . includes ( "," ) ) {
34
- coverage_text = "See Scopus" ;
35
- }
36
- var col3 = GLOBAL_EXTERNAL_LOGIC_HELPER . generate_url_html (
37
- "SCOPUS_SOURCE_LOOKUP" ,
38
- journal_record . scopus_sourceid ,
39
- coverage_text + "<img src='images/external-link.png' />"
40
- ) ;
41
-
42
- var col2 = "<strong>" + journal_record . journal_name + "</strong>" ;
43
- col2 += "<a href='" + journal_record . url + "' target='_blank'><img src='images/external-link.png' /></a>"
44
-
45
- var is_selected = user_selected_journal_ids_to_include . includes ( journal_record . journal_id ) ;
46
- var col1 = '<input style="width: 100%;" id="switch_for_journal_' + journal_record . journal_id + '" class="bootstrap-switch" ' ;
47
- col1 += 'onchange="GLOBAL_SOURCES_CONTROLLER.toggle_inclusion_of_journal_with_id(' + journal_record . journal_id + ')" type="checkbox">' ;
48
-
49
- var html_string = '<tr>' ;
50
- html_string += "<td style='padding: 0px;'>" + col1 + " " + col2 + "</td>"
51
- html_string += "<td>" + col3 + "</td>"
52
- html_string += '</td>' ;
53
-
54
- $ ( "#journalsListView" ) . append ( html_string ) ;
55
- $ ( "#switch_for_journal_" + journal_record . journal_id ) . bootstrapSwitch ( ) ;
56
- if ( is_selected ) {
57
- $ ( "#switch_for_journal_" + journal_record . journal_id ) . bootstrapSwitch ( 'state' , true ) ;
58
- }
59
- }
60
- }
61
-
62
- , download_csv : function ( ) {
63
- var prepared_return = [
64
- [
65
- "Scopus Source ID" ,
66
- "Scopus Coverage" ,
67
- "Journal Name" ,
68
- "Journal ISSN" ,
69
- "Journal ISSN (e)" ,
70
- "Journal Website" ,
71
- "Listing Count"
72
- ]
73
- ] ;
74
- for ( var i = 0 ; i < user_selected_journal_ids_to_include . length ; i ++ ) {
75
- var journal_id = user_selected_journal_ids_to_include [ i ] ;
76
- var journal_record = GLOBAL_MODEL_HELPER . get_master_record_by_journal_id ( journal_id ) ;
77
- prepared_return . push ( [
78
- nvl ( journal_record [ "scopus_sourceid" ] , "" ) ,
79
- nvl ( journal_record [ "scopus_coverage" ] , "" ) ,
80
- nvl ( journal_record [ "journal_name" ] , "" ) ,
81
- nvl ( journal_record [ "issn" ] , "" ) ,
82
- nvl ( journal_record [ "issne" ] , "" ) ,
83
- nvl ( journal_record [ "url" ] , "" ) ,
84
- nvl ( journal_record [ "listing_count" ] , "" )
85
- ] ) ;
86
- }
87
- console . log ( prepared_return ) ;
88
-
89
- // source: https://stackoverflow.com/a/24922761
90
- var processRow = function ( row ) {
91
- var finalVal = '' ;
92
- for ( var j = 0 ; j < row . length ; j ++ ) {
93
- var innerValue = row [ j ] === null ? '' : row [ j ] . toString ( ) ;
94
- if ( row [ j ] instanceof Date ) {
95
- innerValue = row [ j ] . toLocaleString ( ) ;
96
- } ;
97
- var result = innerValue . replace ( / " / g, '""' ) ;
98
- if ( result . search ( / ( " | , | \n ) / g) >= 0 )
99
- result = '"' + result + '"' ;
100
- if ( j > 0 )
101
- finalVal += ',' ;
102
- finalVal += result ;
103
- }
104
- return finalVal + '\n' ;
105
- } ;
106
-
107
- var csvContent = '' ;
108
- for ( var i = 0 ; i < prepared_return . length ; i ++ ) {
109
- csvContent += processRow ( prepared_return [ i ] ) ;
110
- }
111
- download ( csvContent , "Litbaskets Export " + ( new Date ( ) . toISOString ( ) . replace ( ':' , '_' ) ) + ".csv" , "text/csv" ) ;
112
- }
1
+ /*
2
+ * LitbasketsSourcesTopbarController
3
+ * Instantiated in index.controller.js as GLOBAL_SOURCES_TOPBAR_CONTROLLER
4
+ */
5
+ LitbasketsSourcesTopbarController = {
6
+ /*
7
+ * Inserts rows into the listview on screen 'Sources'
8
+ */
9
+ has_been_init : false
10
+
11
+ , init : function ( beforeStarting , afterStarting ) {
12
+ beforeStarting ( ) ;
13
+
14
+ if ( ! GLOBAL_SOURCES_TOPBAR_CONTROLLER . has_been_init ) {
15
+ do_long_task ( "JOURNAL_EXPLORER" ) ;
16
+
17
+ window . setTimeout ( function ( ) {
18
+ GLOBAL_SOURCES_TOPBAR_CONTROLLER . populate_journals_in_listview_for_section ( "journalsListView_2xs" ) ;
19
+ GLOBAL_SOURCES_TOPBAR_CONTROLLER . populate_journals_in_listview_for_section ( "journalsListView_xs" ) ;
20
+ GLOBAL_SOURCES_TOPBAR_CONTROLLER . populate_journals_in_listview_for_section ( "journalsListView_s" ) ;
21
+ GLOBAL_SOURCES_TOPBAR_CONTROLLER . populate_journals_in_listview_for_section ( "journalsListView_m" ) ;
22
+ GLOBAL_SOURCES_TOPBAR_CONTROLLER . populate_journals_in_listview_for_section ( "journalsListView_l" ) ;
23
+ GLOBAL_SOURCES_TOPBAR_CONTROLLER . populate_journals_in_listview_for_section ( "journalsListView_xl" ) ;
24
+ GLOBAL_SOURCES_TOPBAR_CONTROLLER . populate_journals_in_listview_for_section ( "journalsListView_2xl" ) ;
25
+ GLOBAL_SOURCES_TOPBAR_CONTROLLER . populate_journals_in_listview_for_section ( "journalsListView_3xl" ) ;
26
+ GLOBAL_SOURCES_TOPBAR_CONTROLLER . has_been_init = true ;
27
+ finished_long_task ( "JOURNAL_EXPLORER" ) ;
28
+ } , 300 ) ;
29
+ }
30
+
31
+ afterStarting ( ) ;
32
+ }
33
+
34
+ , populate_journals_in_listview_for_section : function ( given_section ) {
35
+ console . log ( "populate_journals_in_listview_for_section: " + given_section ) ;
36
+ // clear model and view
37
+ journals_to_include = [ ] ;
38
+
39
+ for ( var i = 0 ; i < saved_journals_master_data . length ; i ++ ) {
40
+ var this_journal = saved_journals_master_data [ i ] ;
41
+ var include_this_journal = false ;
42
+ var this_listing_count = parseInt ( this_journal . listing_count ) ;
43
+
44
+ if ( given_section == "journalsListView_2xs" && parseInt ( this_journal . is_bo8 ) == 1 ) include_this_journal = true ;
45
+ if ( given_section == "journalsListView_xs" && this_listing_count >= 7 && parseInt ( this_journal . is_bo8 ) != 1 ) include_this_journal = true ;
46
+ if ( given_section == "journalsListView_s" && this_listing_count == 6 ) include_this_journal = true ;
47
+ if ( given_section == "journalsListView_m" && this_listing_count == 5 ) include_this_journal = true ;
48
+ if ( given_section == "journalsListView_l" && this_listing_count == 4 ) include_this_journal = true ;
49
+ if ( given_section == "journalsListView_xl" && this_listing_count == 3 ) include_this_journal = true ;
50
+ if ( given_section == "journalsListView_2xl" && this_listing_count == 2 ) include_this_journal = true ;
51
+ if ( given_section == "journalsListView_3xl" && this_listing_count == 1 ) include_this_journal = true ;
52
+
53
+ if ( include_this_journal ) {
54
+ journals_to_include . push ( this_journal ) ;
55
+ }
56
+ }
57
+
58
+ for ( var i = 0 ; i < journals_to_include . length ; i ++ ) {
59
+ var journal_record = journals_to_include [ i ] ;
60
+ var is_selected = user_selected_journal_ids_to_include . includes ( journal_record . journal_id ) ;
61
+
62
+ console . log ( "bootstrapSwitch: " + journal_record . journal_id ) ;
63
+ if ( is_selected ) {
64
+ $ ( "#switch_for_journal_" + journal_record . journal_id ) . bootstrapSwitch ( 'state' , true ) ;
65
+ } else {
66
+ $ ( "#switch_for_journal_" + journal_record . journal_id ) . bootstrapSwitch ( 'state' , false ) ;
67
+ }
68
+ }
69
+ }
70
+
71
+ , download_csv : function ( ) {
72
+ var prepared_return = [
73
+ [
74
+ "Scopus Source ID" ,
75
+ "Scopus Coverage" ,
76
+ "Journal Name" ,
77
+ "Journal ISSN" ,
78
+ "Journal ISSN (e)" ,
79
+ "Journal Website" ,
80
+ "Listing Count"
81
+ ]
82
+ ] ;
83
+ for ( var i = 0 ; i < user_selected_journals_to_include . length ; i ++ ) {
84
+ var journal_id = user_selected_journals_to_include [ i ] ;
85
+ var journal_record = GLOBAL_MODEL_HELPER . get_master_record_by_journal_id ( journal_id ) ;
86
+ prepared_return . push ( [
87
+ nvl ( journal_record [ "scopus_sourceid" ] , "" ) ,
88
+ nvl ( journal_record [ "scopus_coverage" ] , "" ) ,
89
+ nvl ( journal_record [ "journal_name" ] , "" ) ,
90
+ nvl ( journal_record [ "issn" ] , "" ) ,
91
+ nvl ( journal_record [ "issne" ] , "" ) ,
92
+ nvl ( journal_record [ "url" ] , "" ) ,
93
+ nvl ( journal_record [ "listing_count" ] , "" )
94
+ ] ) ;
95
+ }
96
+ console . log ( prepared_return ) ;
97
+
98
+ // source: https://stackoverflow.com/a/24922761
99
+ var processRow = function ( row ) {
100
+ var finalVal = '' ;
101
+ for ( var j = 0 ; j < row . length ; j ++ ) {
102
+ var innerValue = row [ j ] === null ? '' : row [ j ] . toString ( ) ;
103
+ if ( row [ j ] instanceof Date ) {
104
+ innerValue = row [ j ] . toLocaleString ( ) ;
105
+ } ;
106
+ var result = innerValue . replace ( / " / g, '""' ) ;
107
+ if ( result . search ( / ( " | , | \n ) / g) >= 0 )
108
+ result = '"' + result + '"' ;
109
+ if ( j > 0 )
110
+ finalVal += ',' ;
111
+ finalVal += result ;
112
+ }
113
+ return finalVal + '\n' ;
114
+ } ;
115
+
116
+ var csvContent = '' ;
117
+ for ( var i = 0 ; i < prepared_return . length ; i ++ ) {
118
+ csvContent += processRow ( prepared_return [ i ] ) ;
119
+ }
120
+ download ( csvContent , "Litbaskets Export " + ( new Date ( ) . toISOString ( ) . replace ( ':' , '_' ) ) + ".csv" , "text/csv" ) ;
121
+ }
113
122
} ;
0 commit comments