/
doaj.fieldrender.edges.js
3968 lines (3441 loc) · 190 KB
/
doaj.fieldrender.edges.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
$.extend(true, doaj, {
filters : {
noCharges : function() {
return {
id: "no_charges",
display: "Without fees",
must: [
es.newTermFilter({
field: "bibjson.apc.has_apc",
value: false
}),
es.newTermFilter({
field: "bibjson.other_charges.has_other_charges",
value: false
})
]
}
}
},
facets : {
inDOAJ : function() {
return edges.newRefiningANDTermSelector({
id: "in_doaj",
category: "facet",
field: "admin.in_doaj",
display: "In DOAJ?",
deactivateThreshold: 1,
valueMap : {
1 : "Yes",
0 : "No",
true: "Yes",
false: "No"
},
parseSelectedValueString: function(val) {
// this is needed because ES7 doesn't understand "1" or `1` to be `true`, so
// we convert the string value of the aggregation back to a boolean
return val === "1"
},
filterToAggValue : function(val) {
return val === true ? 1 : 0;
},
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
openOrClosed: function() {
return edges.newRefiningANDTermSelector({
id: "application_type",
category: "facet",
field: "index.application_type.exact",
display: "Open or closed?",
deactivateThreshold : 1,
orderDir: "asc",
valueMap : {
"finished application/update": "Closed",
"update request": "Open",
"new application": "Open"
},
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
applicationStatus : function() {
return edges.newRefiningANDTermSelector({
id: "application_status",
category: "facet",
field: "admin.application_status.exact",
display: "Status",
deactivateThreshold: 1,
valueFunction: doaj.valueMaps.adminStatusMap,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
hasEditorGroup : function() {
return edges.newRefiningANDTermSelector({
id: "has_editor_group",
category: "facet",
field: "index.has_editor_group.exact",
display: "Has editor group?",
deactivateThreshold : 1,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
hasEditor : function() {
return edges.newRefiningANDTermSelector({
id: "has_editor",
category: "facet",
field: "index.has_editor.exact",
display: "Has Associate Editor?",
deactivateThreshold: 1,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
editorGroup : function() {
return edges.newRefiningANDTermSelector({
id: "editor_group",
category: "facet",
field: "admin.editor_group.exact",
display: "Editor group",
deactivateThreshold: 1,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
editor : function() {
return edges.newRefiningANDTermSelector({
id: "editor",
category: "facet",
field: "admin.editor.exact",
display: "Editor",
deactivateThreshold: 1,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
hasAPC : function() {
return edges.newRefiningANDTermSelector({
id: "author_pays",
category: "facet",
field: "index.has_apc.exact",
display: "Publication charges?",
deactivateThreshold: 1,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
classification : function() {
return edges.newRefiningANDTermSelector({
id: "classification",
category: "facet",
field: "index.classification.exact",
display: "Classification",
deactivateThreshold: 1,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
language : function() {
return edges.newRefiningANDTermSelector({
id: "language",
category: "facet",
field: "index.language.exact",
display: "Journal language",
deactivateThreshold: 1,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
countryPublisher : function() {
return edges.newRefiningANDTermSelector({
id: "country_publisher",
category: "facet",
field: "index.country.exact",
display: "Country of publisher",
deactivateThreshold: 1,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
subject : function() {
return edges.newRefiningANDTermSelector({
id: "subject",
category: "facet",
field: "index.subject.exact",
display: "Subject",
deactivateThreshold: 1,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
publisher : function() {
return edges.newRefiningANDTermSelector({
id: "publisher",
category: "facet",
field: "bibjson.publisher.name.exact",
display: "Publisher",
deactivateThreshold: 1,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
},
journalLicence : function() {
return edges.newRefiningANDTermSelector({
id: "journal_license",
category: "facet",
field: "index.license.exact",
display: "Journal license",
deactivateThreshold: 1,
renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
controls: true,
open: false,
togglable: true,
countFormat: doaj.valueMaps.countFormat,
hideInactive: true
})
})
}
},
valueMaps : {
// This must be updated in line with the list in formcontext/choices.py
applicationStatus : {
'update_request' : 'Update Request',
'revisions_required' : 'Revisions Required',
'pending' : 'Pending',
'in progress' : 'In Progress',
'completed' : 'Completed',
'on hold' : 'On Hold',
'ready' : 'Ready',
'rejected' : 'Rejected',
'accepted' : 'Accepted',
'post_submission_review': "Autochecking",
},
adminStatusMap: function(value) {
if (doaj.valueMaps.applicationStatus.hasOwnProperty(value)) {
return doaj.valueMaps.applicationStatus[value];
}
return value;
},
displayYearPeriod : function(params) {
var from = params.from;
var to = params.to;
var field = params.field;
var display = (new Date(parseInt(from))).getUTCFullYear();
return {to: to, toType: "lt", from: from, fromType: "gte", display: display}
},
displayYearMonthPeriod : function(params) {
var from = params.from;
var to = params.to;
var field = params.field;
let d = new Date(parseInt(from))
let display = d.getUTCFullYear().toString() + "-" + doaj.valueMaps.monthPadding(d.getUTCMonth() + 1);
return {to: to, toType: "lt", from: from, fromType: "gte", display: display}
},
schemaCodeToNameClosure : function(tree) {
var nameMap = {};
function recurse(ctx) {
for (var i = 0; i < ctx.length; i++) {
var child = ctx[i];
var entry = {};
nameMap["LCC:" + child.id] = child.text;
if (child.children && child.children.length > 0) {
recurse(child.children);
}
}
}
recurse(tree);
return function(code) {
var name = nameMap[code];
if (name) {
return name;
}
return code;
}
},
countFormat : edges.numFormat({
thousandsSeparator: ","
}),
monthPadding: edges.numFormat({
zeroPadding: 2
})
},
components : {
pager : function(id, category) {
return edges.newPager({
id: id,
category: category,
renderer: edges.bs3.newPagerRenderer({
sizeOptions: [10, 25, 50, 100],
numberFormat: doaj.valueMaps.countFormat,
scroll: false
})
})
},
searchingNotification : function() {
return edges.newSearchingNotification({
id: "searching-notification",
category: "searching-notification",
finishedEvent: "edges:post-render",
renderer : doaj.renderers.newSearchingNotificationRenderer({
scrollOnSearch: true
})
})
},
subjectBrowser : function(params) {
var tree = params.tree;
var hideEmpty = edges.getParam(params.hideEmpty, false);
return edges.newTreeBrowser({
id: "subject",
category: "facet",
field: "index.schema_codes_tree.exact",
tree: function(tree) {
function recurse(ctx) {
var displayTree = [];
for (var i = 0; i < ctx.length; i++) {
var child = ctx[i];
var entry = {};
entry.display = child.text;
entry.value = "LCC:" + child.id;
if (child.children && child.children.length > 0) {
entry.children = recurse(child.children);
}
displayTree.push(entry);
}
displayTree.sort((a, b) => a.display > b.display ? 1 : -1);
return displayTree;
}
return recurse(tree);
}(tree),
pruneTree: true,
size: 9999,
nodeMatch: function(node, match_list) {
for (var i = 0; i < match_list.length; i++) {
var m = match_list[i];
if (node.value === m.key) {
return i;
}
}
return -1;
},
filterMatch: function(node, selected) {
return $.inArray(node.value, selected) > -1;
},
nodeIndex : function(node) {
return node.display.toLowerCase();
},
renderer: doaj.renderers.newSubjectBrowser({
title: "Subjects",
open: true,
hideEmpty: hideEmpty,
showCounts: false
})
})
}
},
templates : {
newPublicSearch: function (params) {
return edges.instantiate(doaj.templates.PublicSearch, params, edges.newTemplate);
},
PublicSearch: function (params) {
this.namespace = "doajpublicsearch";
this.title = edges.getParam(params.title, "");
this.titleBar = edges.getParam(params.titleBar, true);
this.draw = function (edge) {
this.edge = edge;
var titleBarFrag = "";
if (this.titleBar) {
titleBarFrag = '<header class="search__header"> \
<p class="label">Search</p>\n \
<h1>' + this.title + ' \
<span data-feather="help-circle" aria-hidden="true" data-toggle="modal" data-target="#modal-help" type="button"></span><span class="sr-only">Help</span> \
</h1> \
<div class="row">\
<form id="search-input-bar" class="col-md-9" role="search"></form>\
</div>\
</header>';
}
var frag = '<div id="searching-notification"></div>' + titleBarFrag + '\
<p id="share_embed"></p>\
<h2 id="result-count"></h2>\
<div class="row">\
<div class="col-sm-2 col-md-3">\
<aside class="filters">\
<h2 class="filters__heading" type="button" data-toggle="collapse" data-target="#filters" aria-expanded="false">\
<span data-feather="sliders" aria-hidden="true"></span> Refine search results \
</h2>\
<ul class="collapse filters__list" id="filters" aria-expanded="false">\
{{FACETS}}\
</ul>\
</aside>\
</div>\
\
<div class="col-sm-10 col-md-9">\
<aside id="selected-filters"></aside>\
<nav>\
<h3 class="sr-only">Display options</h3>\
<div class="row">\
<form class="col-sm-6" id="sort_by"></form>\
<form class="col-sm-6 flex-end-col" id="rpp"></form>\
</div>\
</nav>\
<nav class="pagination" id="top-pager"></nav>\
<ol class="search-results" id="results"></ol>\
<nav class="pagination" id="bottom-pager"></nav>\
</div>\
</div>';
// add the facets dynamically
var facets = edge.category("facet");
var facetContainers = "";
for (var i = 0; i < facets.length; i++) {
facetContainers += '<li class="filter" id="' + facets[i].id + '"></li>';
}
frag = frag.replace(/{{FACETS}}/g, facetContainers);
edge.context.html(frag);
};
},
newFQWidget: function (params) {
return edges.instantiate(doaj.templates.FQWidget, params, edges.newTemplate);
},
FQWidget: function (params) {
this.namespace = "fqwidget";
this.draw = function (edge) {
this.edge = edge;
var frag = `
<header>
<a href="https://doaj.org/" target="_blank" rel="noopener">
<svg height="30px" viewBox="0 0 149 53" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>DOAJ Logotype</title>
<g id="logotype" fill="#282624" fill-rule="nonzero">
<path d="M0,0.4219 L17.9297,0.4219 C24.8672,0.4688 30.0703,3.3516 33.5391,9.0703 C34.7812,10.9922 35.5664,13.0078 35.8945,15.1172 C36.1523,17.2266 36.2812,20.8711 36.2812,26.0508 C36.2812,31.5586 36.082,35.4023 35.6836,37.582 C35.4961,38.6836 35.2148,39.668 34.8398,40.5352 C34.4414,41.3789 33.9609,42.2578 33.3984,43.1719 C31.8984,45.5859 29.8125,47.5781 27.1406,49.1484 C24.4922,50.8359 21.2461,51.6797 17.4023,51.6797 L0,51.6797 L0,0.4219 Z M7.7695,44.332 L17.0508,44.332 C21.4102,44.332 24.5742,42.8438 26.543,39.8672 C27.4102,38.7656 27.9609,37.3711 28.1953,35.6836 C28.4062,34.0195 28.5117,30.9023 28.5117,26.332 C28.5117,21.8789 28.4062,18.6914 28.1953,16.7695 C27.9141,14.8477 27.2461,13.2891 26.1914,12.0938 C24.0352,9.1172 20.9883,7.6758 17.0508,7.7695 L7.7695,7.7695 L7.7695,44.332 Z"></path>
<path d="M39.5938,26.0508 C39.5938,20.0977 39.7695,16.1133 40.1211,14.0977 C40.4961,12.082 41.0703,10.4531 41.8438,9.2109 C43.0859,6.8438 45.0781,4.7344 47.8203,2.8828 C50.5156,1.0078 53.8789,0.0469 57.9102,0 C61.9883,0.0469 65.3867,1.0078 68.1055,2.8828 C70.8008,4.7344 72.7461,6.8438 73.9414,9.2109 C74.809,10.4531 75.406,12.082 75.734,14.0977 C76.039,16.1133 76.191,20.0977 76.191,26.0508 C76.191,31.9102 76.039,35.8711 75.734,37.9336 C75.406,39.9961 74.809,41.6484 73.9414,42.8906 C72.7461,45.2578 70.8008,47.3438 68.1055,49.1484 C65.3867,51.0234 61.9883,52.0078 57.9102,52.1016 C53.8789,52.0078 50.5156,51.0234 47.8203,49.1484 C45.0781,47.3438 43.0859,45.2578 41.8438,42.8906 C41.4688,42.1172 41.1289,41.3789 40.8242,40.6758 C40.543,39.9492 40.3086,39.0352 40.1211,37.9336 C39.7695,35.8711 39.5938,31.9102 39.5938,26.0508 Z M47.3984,26.0508 C47.3984,31.0898 47.5859,34.5 47.9609,36.2812 C48.2891,38.0625 48.957,39.5039 49.9648,40.6055 C50.7852,41.6602 51.8633,42.5156 53.1992,43.1719 C54.5117,43.9453 56.082,44.332 57.9102,44.332 C59.7617,44.332 61.3672,43.9453 62.7266,43.1719 C64.0156,42.5156 65.0469,41.6602 65.8203,40.6055 C66.8281,39.5039 67.5195,38.0625 67.8945,36.2812 C68.2461,34.5 68.4219,31.0898 68.4219,26.0508 C68.4219,21.0117 68.2461,17.5781 67.8945,15.75 C67.5195,14.0156 66.8281,12.5977 65.8203,11.4961 C65.0469,10.4414 64.0156,9.5625 62.7266,8.8594 C61.3672,8.1797 59.7617,7.8164 57.9102,7.7695 C56.082,7.8164 54.5117,8.1797 53.1992,8.8594 C51.8633,9.5625 50.7852,10.4414 49.9648,11.4961 C48.957,12.5977 48.2891,14.0156 47.9609,15.75 C47.5859,17.5781 47.3984,21.0117 47.3984,26.0508 Z"></path>
<path d="M104.008,33.3281 L96.59,10.9336 L96.449,10.9336 L89.031,33.3281 L104.008,33.3281 Z M106.223,40.2188 L86.781,40.2188 L82.844,51.6797 L74.617,51.6797 L93.25,0.4219 L99.754,0.4219 L118.387,51.6797 L110.195,51.6797 L106.223,40.2188 Z"></path>
<path d="M124.82,40.8867 C125.547,41.8477 126.484,42.6328 127.633,43.2422 C128.781,43.9688 130.129,44.332 131.676,44.332 C133.738,44.3789 135.707,43.6641 137.582,42.1875 C138.496,41.4609 139.211,40.5 139.727,39.3047 C140.266,38.1562 140.535,36.7148 140.535,34.9805 L140.535,0.4219 L148.305,0.4219 L148.305,35.7539 C148.211,40.9102 146.523,44.8945 143.242,47.707 C139.984,50.5898 136.199,52.0547 131.887,52.1016 C125.934,51.9609 121.492,49.7344 118.562,45.4219 L124.82,40.8867 Z"></path>
</g>
</svg>
</a>
<h2 id="result-count"></h2>\
<p class="label label--tertiary">On the Directory of Open Access Journals</p>
<p></p>
</header>
<nav class="search-options">
<form class="colsearch-options__left" id="rpp"></form>
</nav>
<nav class="pagination" id="top-pager"></nav>
<ol class="search-results" id="results"></ol>
<nav class="pagination" id="bottom-pager"></nav>
`
edge.context.html(frag);
};
},
newPublisherApplications: function (params) {
return edges.instantiate(doaj.templates.PublisherApplications, params, edges.newTemplate);
},
PublisherApplications: function (params) {
this.namespace = "doajpublisherapplications";
this.draw = function (edge) {
this.edge = edge;
var frag = '<div class="row">\
<div class="col-md-12">\
<nav class="pagination" id="top-pager"></nav>\
<ol class="search-results" id="results"></ol>\
<nav class="pagination" id="bottom-pager"></nav>\
</div>\
</div>';
edge.context.html(frag);
};
}
},
renderers : {
newSearchingNotificationRenderer: function (params) {
return edges.instantiate(doaj.renderers.SearchingNotificationRenderer, params, edges.newRenderer);
},
SearchingNotificationRenderer: function (params) {
this.scrollTarget = edges.getParam(params.scrollTarget, "body");
this.scrollOnSearch = edges.getParam(params.scrollOnSearch, false);
// namespace to use in the page
this.namespace = "doaj-notification";
this.searching = false;
this.draw = function () {
if (this.component.searching) {
let id = edges.css_id(this.namespace, "loading", this);
this.component.edge.context.css("opacity", "0.3");
var frag = `<div id="` + id + `" class='loading overlay'>
<div></div>
<div></div>
<div></div>
<span class='sr-only'>Loading results…</span>
</div>`
this.component.edge.context.before(frag);
if (this.scrollOnSearch) {
let offset = $(this.scrollTarget).offset().top
window.scrollTo(0, offset);
}
} else {
let that = this;
let idSelector = edges.css_id_selector(this.namespace, "loading", this);
this.component.edge.context.animate(
{
opacity: "1",
},
{
duration: 1000,
always: function() {
$(idSelector).remove();
}
}
);
}
}
},
newSubjectBrowser : function(params) {
return edges.instantiate(doaj.renderers.SubjectBrowser, params, edges.newRenderer);
},
SubjectBrowser : function(params) {
this.title = edges.getParam(params.title, "");
this.selectMode = edges.getParam(params.selectMode, "multiple");
this.hideEmpty = edges.getParam(params.hideEmpty, false);
this.togglable = edges.getParam(params.togglable, true);
this.open = edges.getParam(params.open, false);
this.showCounts = edges.getParam(params.showCounts, false);
this.namespace = "doaj-subject-browser";
this.lastScroll = 0;
this.draw = function() {
// for convenient short references ...
var st = this.component.syncTree;
var namespace = this.namespace;
// var that = this;
// var checkboxClass = edges.css_classes(namespace, "selector", this);
// var countClass = edges.css_classes(namespace, "count", this);
var treeReport = this._renderTree({tree: st, selectedPathOnly: false, showOneLevel: true});
var treeFrag = treeReport.frag;
if (treeFrag === "") {
treeFrag = "Loading…";
}
var toggleId = edges.css_id(namespace, "toggle", this);
var resultsId = edges.css_id(namespace, "results", this);
var searchId = edges.css_id(namespace, "search", this);
var filteredId = edges.css_id(namespace, "filtered", this);
var mainListId = edges.css_id(namespace, "main", this);
var toggle = "";
if (this.togglable) {
toggle = '<span data-feather="chevron-down" aria-hidden="true"></span>';
}
var placeholder = 'Search ' + this.component.nodeCount + ' subjects';
var frag = '<div class="accordion"><h3 class="label label--secondary filter__heading" id="' + toggleId + '"><button class="aria-button" aria-expanded="false">' + this.title + toggle + '</button></h3>\
<div class="filter__body collapse" style="height: 0px" id="' + resultsId + '">\
<label for="' + searchId + '" class="sr-only">' + placeholder + '</label>\
<input type="text" name="' + searchId + '" id="' + searchId + '" class="filter__search" placeholder="' + placeholder + '">\
<ul class="filter__choices" id="' + filteredId + '" style="display:none"></ul>\
<ul class="filter__choices" id="' + mainListId + '">{{FILTERS}}</ul>\
</div></div>';
// substitute in the component parts
frag = frag.replace(/{{FILTERS}}/g, treeFrag);
// now render it into the page
this.component.context.html(frag);
feather.replace();
// trigger all the post-render set-up functions
this.setUIOpen();
var mainListSelector = edges.css_id_selector(namespace, "main", this);
this.component.jq(mainListSelector).scrollTop(this.lastScroll);
var checkboxSelector = edges.css_class_selector(namespace, "selector", this);
edges.on(checkboxSelector, "change", this, "filterToggle");
var toggleSelector = edges.css_id_selector(namespace, "toggle", this);
edges.on(toggleSelector, "click", this, "toggleOpen");
var searchSelector = edges.css_id_selector(namespace, "search", this);
edges.on(searchSelector, "keyup", this, "filterSubjects");
};
this._renderTree = function(params) {
var st = edges.getParam(params.tree, []);
var selectedPathOnly = edges.getParam(params.selectedPathOnly, true);
var showOneLevel = edges.getParam(params.showOneLevel, true);
var that = this;
var checkboxClass = edges.css_classes(this.namespace, "selector", this);
function renderEntry(entry) {
if (that.hideEmpty && entry.count === 0 && entry.childCount === 0) {
return "";
}
var id = edges.safeId(entry.value);
var checked = "";
if (entry.selected) {
checked = ' checked="checked" ';
}
var count = "";
if (that.showCounts) {
var countClass = edges.css_classes(that.namespace, "count", that);
count = ' <span class="' + countClass + '">(' + entry.count + '/' + entry.childCount + ')</span>';
}
var frag = '<input class="' + checkboxClass + '" data-value="' + edges.escapeHtml(entry.value) + '" id="' + id + '" type="checkbox" name="' + id + '"' + checked + '>\
<label for="' + id + '" class="filter__label">' + entry.display + count + '</label>';
return frag;
}
function recurse(tree) {
var selected = tree;
// first check to see if there are any elements at this level that are selected. If there are,
// that is the only element that we'll render
if (selectedPathOnly) {
for (var i = 0; i < tree.length; i++) {
var entry = tree[i];
if (entry.selected) {
selected = [entry];
break;
}
}
}
// now go through either this tree level or just the selected elements, and render the relevant
// bits of the sub-tree
var anySelected = false;
var rFrag = "";
for (var i = 0; i < selected.length; i++) {
var entry = selected[i];
var entryFrag = renderEntry(entry);
if (entryFrag === "") {
continue;
}
if (entry.selected) {
anySelected = true;
}
if (entry.children) {
var childReport = recurse(entry.children);
if (childReport.anySelected) {
anySelected = true;
}
// only attach the children frag if, first any of these are true:
// - one of the children is selected
// - the entry itself is selected
// - we don't want to only show the selected path
if (!selectedPathOnly || childReport.anySelected || entry.selected) {
// Then, another level (separated out to save my brain from the tortuous logic)
// only attach the children frag if, any of these are true:
// - the entry or one of its children is selected
// - we want to show more than one level at a time
if (childReport.anySelected || entry.selected || !showOneLevel) {
var cFrag = childReport.frag;
if (cFrag !== "") {
entryFrag += '<ul class="filter__choices">';
entryFrag += cFrag;
entryFrag += '</ul>';
}
}
}
}
rFrag += '<li>';
rFrag += entryFrag;
rFrag += '</li>';
}
return {frag : rFrag, anySelected: anySelected};
}
return recurse(st);
};
this.setUIOpen = function () {
// the selectors that we're going to use
var resultsSelector = edges.css_id_selector(this.namespace, "results", this);
var toggleSelector = edges.css_id_selector(this.namespace, "toggle", this);
var results = this.component.jq(resultsSelector);
var toggle = this.component.jq(toggleSelector);
if (this.open) {
results.addClass("in").attr("aria-expanded", "true").css({"height": ""});
toggle.removeClass("collapsed").attr("aria-expanded", "true");
} else {
results.removeClass("in").attr("aria-expanded", "false").css({"height" : "0px"});
toggle.addClass("collapsed").attr("aria-expanded", "false");
}
};
this.filterToggle = function(element) {
var mainListSelector = edges.css_id_selector(this.namespace, "main", this);
this.lastScroll = this.component.jq(mainListSelector).scrollTop();
var el = this.component.jq(element);
// var filter_id = this.component.jq(element).attr("id");
var checked = el.is(":checked");
var value = el.attr("data-value");
if (checked) {
this.component.addFilter({value: value});
} else {
this.component.removeFilter({value: value});
}
};
this.toggleOpen = function (element) {
this.open = !this.open;
this.setUIOpen();
};
this.filterSubjects = function(element) {
var st = this.component.syncTree;
var term = $(element).val();
var that = this;
var filterSelector = edges.css_id_selector(this.namespace, "filtered", this);
var mainSelector = edges.css_id_selector(this.namespace, "main", this);
var filterEl = this.component.jq(filterSelector);
var mainEl = this.component.jq(mainSelector);
if (term === "") {
filterEl.html("");
filterEl.hide();
mainEl.show();
return;
}
if (term.length < 3) {
filterEl.html("<li>Enter 3 characters or more to search</li>");
filterEl.show();
mainEl.hide();
return;
}
term = term.toLowerCase();
function entryMatch(entry) {
if (that.hideEmpty && entry.count === 0 && entry.childCount === 0) {
return false;
}
var matchTerm = entry.index;
var includes = matchTerm.includes(term);
if (includes) {
var idx = matchTerm.indexOf(term);
var display = entry.display;
return display.substring(0, idx) + "<strong>" + display.substring(idx, idx + term.length) + "</strong>" + display.substring(idx + term.length);
}
}
function recurse(tree) {
var filteredLayer = [];
for (var i = 0; i < tree.length; i++) {
var entry = tree[i];
var childReport = [];
if (entry.children) {
childReport = recurse(entry.children);
}
var selfMatch = entryMatch(entry);
if (selfMatch || childReport.length > 0) {
var newEntry = $.extend({}, entry);
delete newEntry.children;
if (selfMatch) {
newEntry.display = selfMatch;
}
if (childReport.length > 0) {
newEntry.children = childReport;
}
filteredLayer.push(newEntry);
}
}
return filteredLayer;
}
var filtered = recurse(st);
if (filtered.length > 0) {
var displayReport = this._renderTree({tree: filtered, selectedPathOnly: false, showOneLevel: false});
filterEl.html(displayReport.frag);
mainEl.hide();
filterEl.show();
var checkboxSelector = edges.css_class_selector(this.namespace, "selector", this);
edges.on(checkboxSelector, "change", this, "filterToggle");
} else {
filterEl.html("<li>No subjects match your search</li>");
mainEl.hide();
filterEl.show();
}
};
},
newFullSearchControllerRenderer: function (params) {
return edges.instantiate(doaj.renderers.FullSearchControllerRenderer, params, edges.newRenderer);
},
FullSearchControllerRenderer: function (params) {
// enable the search button
this.searchButton = edges.getParam(params.searchButton, false);
// text to include on the search button. If not provided, will just be the magnifying glass
this.searchButtonText = edges.getParam(params.searchButtonText, false);
// should the clear button be rendered
this.clearButton = edges.getParam(params.clearButton, true);
// set the placeholder text for the search box
this.searchPlaceholder = edges.getParam(params.searchPlaceholder, "Search");
// amount of time between finishing typing and when a query is executed from the search box
this.freetextSubmitDelay = edges.getParam(params.freetextSubmitDelay, 500);
////////////////////////////////////////
// state variables
this.focusSearchBox = false;
this.namespace = "doaj-bs3-search-controller";
this.draw = function () {
var comp = this.component;
var clearClass = edges.css_classes(this.namespace, "reset", this);
var clearFrag = "";
if (this.clearButton) {
clearFrag = '<button type="button" class="tag tag--secondary ' + clearClass + '" title="Clear all search and sort parameters and start again"> \
Clear all \
</button>';
}
// if sort options are provided render the orderer and the order by
var sortOptions = "";
if (comp.sortOptions && comp.sortOptions.length > 0) {
// classes that we'll use
var sortClasses = edges.css_classes(this.namespace, "sort", this);
var directionClass = edges.css_classes(this.namespace, "direction", this);
var sortFieldClass = edges.css_classes(this.namespace, "sortby", this);
sortOptions = '<div class="input-group ' + sortClasses + '"> \
<button type="button" class="input-group__input ' + directionClass + '" title="" href="#"></button> \
<select class="' + sortFieldClass + ' input-group__input">';
for (var i = 0; i < comp.sortOptions.length; i++) {
var field = comp.sortOptions[i].field;
var display = comp.sortOptions[i].display;
sortOptions += '<option value="' + field + '">' + edges.escapeHtml(display) + '</option>';
}
sortOptions += '<option value="_score">Relevance</option>\
</select></div>';
}
// select box for fields to search on
var field_select = "";
if (comp.fieldOptions && comp.fieldOptions.length > 0) {
// classes that we'll use
var searchFieldClass = edges.css_classes(this.namespace, "field", this);
field_select += '<select class="' + searchFieldClass + ' input-group__input">';
field_select += '<option value="">search all</option>';
for (var i = 0; i < comp.fieldOptions.length; i++) {
var obj = comp.fieldOptions[i];
field_select += '<option value="' + obj['field'] + '">' + edges.escapeHtml(obj['display']) + '</option>';
}
field_select += '</select>';
}
// more classes that we'll use
var textClass = edges.css_classes(this.namespace, "text", this);
var searchClass = edges.css_classes(this.namespace, "search", this);
// text search box id
var textId = edges.css_id(this.namespace, "text", this);
var searchFrag = "";
if (this.searchButton) {
var text = '<span class="glyphicon glyphicon-white glyphicon-search"></span>';
if (this.searchButtonText !== false) {
text = this.searchButtonText;
}
searchFrag = '<button type="button" class="input-group__input ' + searchClass + '"> \
' + text + ' \
</button>';
}
var searchClasses = edges.css_classes(this.namespace, "searchcombo", this);
var searchBox = '<div class="input-group ' + searchClasses + '"> \
' + field_select + '\
<input type="text" id="' + textId + '" class="' + textClass + ' form-control input-sm" name="q" value="" placeholder="' + this.searchPlaceholder + '" style="margin-left: -1px; width: 60%;"/> \
' + searchFrag + ' \
</div>';
if (searchBox !== "") {
searchBox = searchBox;
}
if (sortOptions !== "") {
sortOptions = '<div class="col-xs-6">' + sortOptions + '</div>';
}
if (clearFrag !== "") {
clearFrag = '<div class="col-xs-6" style="text-align: right;">' + clearFrag + '</div>';
}
var frag = searchBox + '<div class="container-fluid"><div class="row">' + sortOptions + clearFrag + '</div></div>';
comp.context.html(frag);
// now populate all the dynamic bits