-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path_projectFinder.gsp
854 lines (786 loc) · 42.5 KB
/
_projectFinder.gsp
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
<%@ page import="au.org.ala.merit.SettingPageType" expressionCodec="none"%>
<div id="projectExplorer">
<g:if test="${flash.error || results.error}">
<g:set var="error" value="${flash.error?:results.error}"/>
<div class="row">
<div class="col-sm-12 p-3 alert alert-danger large-space-before searchError">
<button type="button" class="close" data-dismiss="alert">×</button>
<span>Error: ${error?.encodeAsHTML()}</span>
</div>
</div>
</g:if>
<g:elseif test="${results?.hits?.total?:0 > 0}">
<div class="row">
<div id="facetsCol" class="bg-white" style="display:none;">
<g:set var="reqParams" value="query,sort,order,max,fq,fromDate,toDate,isFilterByCompletedProjects"/>
<div class="visible-phone pull-right" style="margin-top: 5px;">
<a href="#" id="toggleFacetDisplay" rel="facetsContent" role="button" class="btn btn-sm btn-inverse" style="color:white;">
<span>show</span> options
<b class="caret"></b>
</a>
</div>
<h3 style="margin-bottom:0;">Filter results</h3>
<div class="row">
<div id="facetFilter">
<div class="col-sm-4" >
<button class="btn btn-sm facetSearch"><i class="fa fa-filter"></i> Refine</button>
</div>
</div>
<div id="facetClear">
<div class="col-sm-4">
<button class="btn btn-sm clearFacet"><i class="fa fa-remove"></i> Clear all</button>
</div>
</div>
</div>
<g:if test="${params.fq}">
<div class="currentFilters">
<h4>Current filters</h4>
<ul>
<%-- convert either Object and Object[] to a list, in case there are multiple params with same name --%>
<g:set var="fqList" value="${[params.fq].flatten().findAll { it != null }}"/>
<g:each var="f" in="${fqList}">
<g:set var="fqBits" value="${f?.tokenize(':')}"/>
<g:set var="newUrl"><fc:formatParams params="${params}" requiredParams="${reqParams}" excludeParam="${f}"/></g:set>
<li><g:message code="label.${fqBits[0]}" default="${fqBits[0]?.encodeAsHTML()}"/>: <g:message code="label.${fqBits[1]}" default="${fqBits[1]?.encodeAsHTML()?.capitalize()}"/>
<a href="${newUrl?:"?"}" class="btn btn-inverse btn-mini tooltips" title="remove filter" aria-label="remove filter">
<i class="text-white fa fa-remove"></i></a>
</li>
</g:each>
</ul>
</div>
</g:if>
<div id="facetsContent" class="hidden-phone">
<g:set var="baseUrl"><fc:formatParams params="${params}" requiredParams="${reqParams}"/></g:set>
<g:set var="fqLink" value="${g.createLink(controller: 'home', action: 'projectExplorer') + (baseUrl?:"?")}"/>
<!-- fqLink = ${fqLink} -->
<div class="accordion">
<div class="card customCard">
<div class="card-header collapsed" data-toggle="collapse" href="#facet-dates" id="projectDates">
<a><h4>Project Dates <fc:iconHelp helpTextCode="project.dates.help" container="body"/></h4></a>
</div>
<div id="facet-dates" data-name="projectDates" class="collapse facetItems validationEngineContainer">
<div class="card-body cardBody">
<select style="margin-bottom: 10px" data-bind="options:ranges, optionsText:'display', value:selectedRange"></select>
<div class="input-group" style="margin-bottom: 10px"><label for="fromDate" class="dataClass">From:</label><fc:datePicker targetField="fromDate.date" bs4="bs4" class="dateControl form-control form-control-sm" name="fromDate" data-validation-engine="validate[date]" autocomplete="off"/></div>
<div class="input-group" style="margin-bottom: 10px"><label for="fromDate" class="dataClass">To:</label><fc:datePicker targetField="toDate.date" bs4="bs4" class="dateControl form-control form-control-sm" name="toDate" data-validation-engine="validate[date,future[fromDate]]" autocomplete="off"/></div>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="isFilterByCompletedProjectsOption" data-bind="checked: isFilterByCompletedProjects" value="true">
<label class="form-check-label" for="isFilterByCompletedProjectsOption">
Project start and end dates are within the selected range.
</label>
</div>
<div><button data-bind="click:clearDates, enable:fromDate() || toDate()" class="btn btn-sm clearDates"><i class="fa fa-remove"></i> Clear dates</button></div>
</div>
</div>
</div>
</div>
<div id="facet-list">
<facet-filter params="'facetsList' : facetsList, results: results, fqLink: fqLink, baseUrl: baseUrl, projectExplorerUrl: projectExplorerUrl"></facet-filter>
</div>
</div>
</div>
<div class="col-sm-11">
<div class="accordion" id="project-display-options">
<div class="card cardSection">
<div class="card-header collapsed" id="mapHeading" href="#accordionMapView" data-toggle="collapse">
<a class="text-left text-uppercase">Map</a>
</div>
<div id="accordionMapView" class="collapseItems collapse" aria-labelledby="mapHeading" data-parent="#project-display-options">
<div class="card-body pt-0">
<div class="row">
<div class="col-sm-4">
<span class="facet-holder"></span>
</div>
<div class="col-sm-8">
<g:render template="searchResultsSummary"/>
<g:render template="/shared/sites" model="${[projectCount:results?.hits?.total?:0]}"/>
</div>
</div>
</div>
</div>
</div> <!-- Map Section -->
<div class="card cardSection">
<div class="card-header collapsed" id="projectHeading" href="#projectsView" data-toggle="collapse">
<a class="text-left text-uppercase">Projects</a>
</div>
<div id="projectsView" class="collapse collapseItems" aria-labelledby="projectHeading" data-parent="#project-display-options">
<div class="card-body pt-0">
<div class="row">
<div class="col-sm-4">
<span class="facet-holder"></span>
</div>
<div class="col-sm-8">
<p><g:render template="searchResultsSummary"/></p>
<div class="scroll-list clearfix" id="projectList">
<table class="table w-100" id="projectTable" data-offset="0" data-max="25">
<thead>
<tr>
<th id="projectName" data-sort="nameSort" scope="col" data-order="ASC" class="header"> Project name</th>
<th id="lastUpdated" data-sort="lastUpdated" scope="col" data-order="DESC" class="header"> Last updated</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<div id="paginateTable" class="d-none" style="text-align: center">
<span id="paginationInfo"></span>
<div class="btn-group">
<button class="btn btn-sm prev"><i class="fa fa-chevron-left" style="margin-top: 2px"></i> previous</button>
<button class="btn btn-sm next">next <i class="fa fa-chevron-right"></i></button>
</div>
</div>
</div> <!-- table -->
%{-- template for jQuery DOM injection --}%
<table id="projectRowTempl" class="d-none">
<tr>
<td class="td1">
<div class="accordion mb-0">
<div class="card mb-0 border-0 p-0">
<div>
<a class="projectTitle collapsed" id="proj_" href="#a_" data-toggle="collapse" title="click to show/hide details">
<span class="showHideCaret">► </span><span class="projectTitleName">$name</span>
</a>
<a href="#" class="managementUnitLine pull-right">
<small><i class="managementUnitName"></i></small>
</a>
</div>
<div class="projectInfo collapse pl-2 pt-1" id="a_" aria-labelledby="proj_">
<div class="card-body pt-0 pl-0 pb-0">
<div class="homeLine">
<i class="fa fa-home"></i>
<a href="">View project page</a>
</div>
<div class="orgLine">
<i class="fa fa-user" data-toggle="tooltip" title="Organisation"></i>
</div>
<div class="associatedProgramLine">
<i class="fa fa-bookmark" data-toggle="tooltip" title="Associated program / sub program"></i>
<span></span>
<i class="associatedSubProgram"></i>
</div>
<div class="descLine">
<i class="fa fa-info"></i>
</div>
<g:if test="${fc.userIsSiteAdmin()}">
<div class="downloadLine">
<i class="fa fa-download"></i>
<a href="" target="_blank">Download (.xlsx)</a>
</div>
<div class="downloadJSONLine">
<i class="fa fa-download"></i>
<a href="" target="_blank">Download (.json)</a>
</div>
</g:if>
</div>
</div>
</div> <!-- end of card -->
</div>
</td>
<td class="td2">$date</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div> <!-- Project View -->
<div class="card cardSection">
<div class="card-header collapsed" id="dashboardHeading" href="#reportView" data-toggle="collapse">
<a class="text-left text-uppercase">Dashboard</a>
</div>
<div id="reportView" class="collapse collapseItems" aria-labelledby="dashboardHeading" data-parent="#project-display-options">
<div class="card-body pt-0">
<div class="row">
<div class="col-sm-4 d-none" data-hidden="true">
<span class="facet-holder" data-hidden="true"></span>
</div>
<div class="col-sm-12">
<div>
<div class="row" style="margin-top:5px;">
<button class="btn facets-toggle" type="button" style="margin-right: 0.7rem;"><i class="fa fa-bars"></i></button>
<span style="margin-top: 0.6em;">
<g:render template="searchResultsSummary"/>
</span>
</div>
</div>
<div class="reportDropdown">
<g:if test="${fc.userIsAlaOrFcAdmin()}">
<h4>Report: </h4>
<select id="dashboardType" class="dashboardSelect" name="dashboardType">
<option value="dashboard">Activity Outputs</option>
<option value="announcements">Announcements</option>
<option value="outputTargets">Output Targets By Programme</option>
<option value="reef2050PlanActionSelection">Reef 2050 Plan Dashboard</option>
</select>
</g:if>
<g:else>
<select id="dashboardType" class="dashboardSelect" name="dashboardType">
<option value="dashboard">Activity Outputs</option>
<option value="reef2050PlanActionSelection">Reef 2050 Plan Dashboard</option>
</select>
</g:else>
</div>
<div class="loading-message">
<asset:image dir="images" src="loading.gif" alt="saving icon"/> Loading...
</div>
<div id="dashboard-content"></div>
</div> <!-- col-sm-8 -->
</div>
</div>
</div>
</div> <!-- Dashboard -->
<g:if test="${includeDownloads}">
<div class="card cardSection">
<div class="card-header collapsed" id="downloadHeading" href="#downloadView" data-toggle="collapse">
<a class="text-left text-uppercase">Download</a>
</div>
<div id="downloadView" class="collapse collapseItems" aria-labelledby="downloadHeading" data-parent="#project-display-options">
<div class="card-body pt-0">
<div class="row">
<div class="col-sm-4">
<span class="facet-holder"></span>
</div>
<div class="col-sm-8">
<g:render template="searchResultsSummary"/>
<div class="alert alert-warning" role="alert">Please do not run more than one download at a time as they can place a lot of load on the system</div>
<h3>Download data for a filtered selection of projects</h3>
<table class="table">
<thead>
<tr>
<th colspan="2"><b>Project, Site, Activity & Output</b></th>
</tr>
</thead>
<tbody>
<tr>
<td width="50%"><g:render template="downloadAllAsXlsx"/></td>
<td width="50%"><a target="_blank" href="${grailsApplication.config.getProperty('grails.serverURL')}/search/downloadAllData<fc:formatParams params="${params}"/>&view=json">JSON</a></td>
</tr>
</tbody>
</table>
<table style="width: 100%;">
<thead>
<tr>
<th><b>Site data (Project Sites)</b></th>
</tr>
</thead>
<tbody>
<tr>
<td width="100%">
<a id="shapefile-download" target="_blank" href='<g:createLink controller="search" action="downloadShapefile" params="${params}"/>'>Shapefile</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div> <!-- Download -->
</g:if>
</div> <!-- accordion -->
</div> <!-- col-sm-11 -->
</div> <!-- End of Row -->
</g:elseif>
<g:else>
<div class="row">
<div class="col-sm-12">
<div class="alert alert-danger large-space-before">
Error: search index returned 0 results
</div>
</div>
</div>
</g:else>
</div>
<asset:script>
var sectionMapping = {
projects:'#projectsView',
map:'#accordionMapView',
dashboard:'#reportView',
download:'#downloadView'
};
var reportMapping = {
activities:'dashboard',
reef2050:'reef2050PlanActionSelection'
};
<g:if test="${fc.userIsAlaOrFcAdmin()}">
reportMapping['announcements']='announcements';
reportMapping['targets']='outputTargets';
</g:if>
var selectedSection = sectionMapping['${params.section?:''}'];
var selectedReport = reportMapping['${params.subsection?:''}'];
var projectListIds = [], facetList = [], mapDataHasChanged = false, mapBounds, projectSites; // globals
var facetModelViewArgs = {
facetsList : ${raw((facetsList as grails.converters.JSON).toString())},
results: ${raw((results as grails.converters.JSON).toString())},
fqLink: "${fqLink}",
baseUrl: "${baseUrl}",
projectExplorerUrl: "${g.createLink(controller:'home', action:'projectExplorer')}"
};
$(function(){
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
var loadReportRequest = null;
var loadReport = function(reportType) {
var $content = $('#dashboard-content');
var $loading = $('.loading-message');
$content.hide();
$loading.show();
if (loadReportRequest) {
loadReportRequest.abort();
}
loadReportRequest = $.get(fcConfig.dashboardUrl,{report:reportType}, function(data) {
loadReportRequest = null;
$content.show();
$loading.hide();
$content.html(data);
$('#reportView .helphover').popover({animation: true, trigger:'hover', container:'body'});
});
};
function toggleFacets() {
var $holder = $('#facetsCol').parent().parent();
var hidden = $holder.data('hidden');
$holder.data('hidden', !hidden);
var $content = $holder.next();
if (!hidden) {
$holder.animate({width:"toggle" }, function() {
$holder.addClass('d-none');
$content.removeClass('col-sm-8').addClass('col-sm-12')
});
}
else {
$holder.animate({width:"toggle" }, function() {
$holder.removeClass('d-none');
$content.removeClass('col-sm-12').addClass('col-sm-8');
});
}
}
$(".facets-toggle").on('click', function(){
toggleFacets();
});
/**
* Update the project table DOM using a plain HTML template (cloned)
*
* @param data
*/
function populateTable(data) {
//console.log("populateTable", data);
$.each(data.hits.hits, function(i, el) {
//console.log(i, "el", el);
var id = el._id;
var src = el._source
var $tr = $('#projectRowTempl tr').clone(); // template
$tr.find(".projectTitle").attr("href", "#a_"+id)
$tr.find(".projectTitle").attr("id", "proj_"+id)
$tr.find(".projectInfo").attr("aria-labelledby", "proj_"+id)
$tr.find('.projectInfo').attr("id", "a_" + id)
$tr.find('.td1 .projectTitleName').text(src.name); // projectTitleName
if(src.managementUnitName){
$tr.find('.td1 .managementUnitName').text(src.managementUnitName);
$tr.find('.td1 a.managementUnitLine').attr("href", "${createLink(controller: 'managementUnit')}/" + src.managementUnitId);
}
if(src.associatedProgram){
if (src.programId){
$tr.find('.td1 .associatedProgramLine span').text(src.associatedProgram);
//$tr.find('.td1 .associatedProgramLine a').attr("href", "${createLink(controller: 'program')}/" + src.programId);
}
else{
//$tr.find('.td1 .associatedProgramLine a').attr("href", "#");
$tr.find('.td1 .associatedProgramLine a').replaceWith('<span>'+ src.associatedProgram +'</span>')
}
if (src.associatedSubProgram)
$tr.find('.td1 .associatedProgramLine i.associatedSubProgram').text( " - "+src.associatedSubProgram )
}
// $tr.find('.projectInfo').attr("id", "proj_" + id);
$tr.find('.homeLine a').attr("href", "${createLink(controller: 'project')}/" + id);
$tr.find('a.zoom-in').data("id", id);
$tr.find('a.zoom-out').data("id", id);
var organisations = '';
if (src.associatedOrgs) {
for (var i=0; i<src.associatedOrgs.length; i++) {
if (organisations.length > 0) {
organisations = organisations + ', ';
}
organisations = organisations + src.associatedOrgs[i].name;
}
}
$tr.find('.orgLine').text(organisations);
$tr.find('.descLine').text(src.description);
<g:if test="${fc.userIsSiteAdmin()}">
$tr.find('.downloadLine a').attr("href", "${createLink(controller: 'project',action: 'downloadProjectData')}" + "?id="+id+"&view=xlsx");
$tr.find('.downloadJSONLine a').attr("href", "${createLink(controller: 'project',action: 'downloadProjectData')}" + "?id="+id+"&view=json");
</g:if>
$tr.find('.td2').text(formatDate(Date.parse(src.lastUpdated))); // relies on the js_iso8601 resource
//console.log("appending row", $tr);
$('#projectTable tbody').append($tr);
});
}
/**
* Dynamically update the project list table via AJAX
*
* @param facetFilters (an array)
*/
function updateProjectTable(facetFilters) {
var url = "${createLink(controller:'nocas', action:'geoService')}";
var sort = $('#projectTable').data("sort");
var order = $('#projectTable').data("order");
var offset = $('#projectTable').data("offset");
var max = $('#projectTable').data("max");
var params = "max="+max+"&offset="+offset;
var query = '${params.query?.encodeAsJavaScript() ?: ""}';
if (sort) {
params += "&sort="+sort+"&order="+order;
}
else if (!query) {
// Sort by date if no query term has been entered.
var defaultSort = "&sort=lastUpdated&order=DESC";
params += defaultSort;
}
if (projectListIds.length > 0) {
params += "&ids=" + projectListIds.join(",");
} else {
params += "&query="+encodeURIComponent(query || '*:*');
}
if (facetFilters) {
params += "&fq=" + facetFilters.join("&fq=");
}
<g:if test="${params.fq}">
<g:set var="fqList" value="${[params.fq].flatten()}"/>
params += "&fq=${fqList.collect{it.encodeAsURL()}.join('&fq=')}";
</g:if>
<g:if test="${params.fromDate}">
params += '&fromDate='+'${params.fromDate.encodeAsURL()}';
</g:if>
<g:if test="${params.toDate}">
params += '&toDate='+'${params.toDate.encodeAsURL()}';
</g:if>
<g:if test="${params.isFilterByCompletedProjects}">
params += '&isFilterByCompletedProjects=' + ${params.isFilterByCompletedProjects.encodeAsJavaScript()};
</g:if>
params += "&clientTimeZone=" + encodeURIComponent(moment.tz.guess() || '');
$.post(url, params).done(function(data1) {
//console.log("getJSON data", data);
var data
if (data1.resp) {
data = data1.resp;
} else if (data1.hits) {
data = data1;
}
if (data.error) {
console.error("Error: " + data.error);
} else {
var total = data.hits.total;
$("numberOfProjects").html(total);
$('#projectTable').data("total", total);
$('#paginateTable').show();
if (total == 0) {
$('#paginationInfo').html("Nothing found");
} else {
var max = data.hits.hits.length
$('#paginationInfo').html((offset+1)+" to "+(offset+max) + " of "+total);
$("#paginateTable").removeClass("d-none");
if (offset == 0) {
$('#paginateTable .prev').addClass("disabled");
} else {
$('#paginateTable .prev').removeClass("disabled");
}
if (offset >= (total - max) ) {
$('#paginateTable .next').addClass("disabled");
} else {
$('#paginateTable .next').removeClass("disabled");
}
}
$('#projectTable tbody').empty();
populateTable(data);
}
}).fail(function (request, status, error) {
//console.error("AJAX error", status, error);
$('#paginationInfo').html("AJAX error:" + status + " - " + error);
});
}
var VIEW_STATE_KEY = 'homepage-tab-state';
var initialisedReport = false, initialisedMap = false, initialisedProjects = false;
var initialiseContentSection = function(section){
if (section === '#accordionMapView' && !initialisedMap) {
generateMap(facetList);
initialisedMap = true;
}
else if (section === '#projectsView' && !initialisedProjects) {
updateProjectTable();
initialisedProjects = true;
}
else if (section === '#reportView' && !initialisedReport) {
initialisedReport = true;
var reportType = selectedReport || amplify.store('report-type-state');
var $reportSelector = $('#dashboardType');
if (reportType) {
$reportSelector.val(reportType);
}
$reportSelector.change(function() {
var reportType = $reportSelector.val();
amplify.store('report-type-state', reportType);
loadReport(reportType);
}).trigger('change');
}
};
var urlWithoutDates = '<fc:formatParams params="${params}" requiredParams="query,sort,order,max,fq"/>';
var fromDate = '${params.fromDate?.encodeAsJavaScript()?:''}';
var toDate = '${params.toDate?.encodeAsJavaScript()?:''}';
var isFilterByCompletedProjects = ${params.isFilterByCompletedProjects?.encodeAsJavaScript() ?: false };
var error = "${error?.encodeAsJavaScript()}";
if(!error){
ko.applyBindings(new DatePickerModel(fromDate, toDate, isFilterByCompletedProjects, urlWithoutDates, window.location), document.getElementById('facet-dates'));
}
function FacetFilterViewModel (params) {
this.facetsList = params.facetsList;
this.results = params.results;
this.fqLink = params.fqLink;
this.baseUrl = params.baseUrl;
this.projectExplorerUrl = params.projectExplorerUrl;
}
if(!error){
ko.applyBindings(new FacetFilterViewModel(facetModelViewArgs), document.getElementById('facet-list'));
}
$('#facet-dates').validationEngine('attach', {scroll:false});
$('.helphover').popover({animation: true, trigger:'hover', container:'body'});
$("#facetsContent").on("shown.bs.collapse", function(e){
var $target = $(e.target);
var targetId = "#"+e.target.id;
var facetValue = amplify.store('facetToggleState') || [];
if(!facetValue.includes(targetId)){
facetValue.push(targetId)
}
var section = facetValue;
amplify.store('facetToggleState', section);
});
$("#facetsContent").on("hidden.bs.collapse", function(e){
var targetId = "#"+e.target.id;
var facetStoredTab = amplify.store('facetToggleState') || [];
var updatedFacetList = [];
facetStoredTab.forEach(function(tab){
if(tab !== targetId){
updatedFacetList.push(tab)
}
})
if(updatedFacetList.length > 1){
amplify.store('facetToggleState', updatedFacetList)
}else{
amplify.store('facetToggleState', null);
}
});
// retain accordion state for future re-visits
function restoreFacetSelections() {
if ($('#facetsContent').is(':visible')) {
var expandedToggles = amplify.store('facetToggleState') || [];
if (expandedToggles) {
expandedToggles.forEach(function(section){
$(section).collapse('show');
});
}
}
}
// re-establish the previous view state
var storedTab = selectedSection || amplify.store(VIEW_STATE_KEY) || '#accordionMapView';
if (!$('#project-display-options '+storedTab)[0]) {
storedTab = '#accordionMapView';
}
$('#project-display-options '+storedTab).collapse({parent:'#project-display-options'});
$('#project-display-options').on("shown.bs.collapse", function(e){
var $target = $(e.target)
var targetId;
if($target.hasClass('collapseItems')){
targetId = e.target.id
var section = '#'+targetId
amplify.store(VIEW_STATE_KEY, section);
initialiseContentSection(section);
}
// Because the facets use accordion and are inside the main accordion view we need to filter them out.
$('#facetsCol').appendTo($(section).find('.facet-holder'));
$('#facetsCol').show();
restoreFacetSelections();
});
$(".clearFacet").click(function(e){
amplify.store('facetToggleState', null);
window.location.href = facetModelViewArgs.projectExplorerUrl;
});
$('#shapefile-download').click(function(e) {
e.preventDefault();
var url = $('#shapefile-download').attr('href');
$.get(url).done(function() {
bootbox.alert("The download may take several minutes to complete. Once it is complete, an email will be sent to your registed email address.")
}).fail(function() {
bootbox.alert("There was an error requesting the download");
});
});
// project list filter
$('.filterinput').keyup(function() {
//console.log("filter keyup");
var a = $(this).val(),
target = $(this).attr('data-target');
var qList;
if (a.length > 1) {
$('#' + target + '-filter-warning').show();
var qList = [ "_all:" + a.toLowerCase() ]
} else {
$('#' + target + '-filter-warning').hide();
qList = null;
}
delay(function(){
//console.log('Time elapsed!');
$("#projectTable").data("offset", 0);
updateProjectTable( qList );
}, 1000 );
return false;
});
$('.clearFilterBtn').click(function () {
var $filterInput = $(this).prev(),
target = $filterInput.attr('data-target');
//console.log("clear button");
$('#' + target + '-filter-warning').hide();
$filterInput.val('');
$("#projectTable").data("offset", 0);
updateProjectTable();
});
// highlight icon on map when project name is clicked
var prevFeatureId;
$('#projectTable').on("click", ".projectTitle", function(el) {
//console.log("projectHighlight", $(this).data("id"), alaMap.featureIndex);
el.preventDefault();
var thisEl = this;
var fId = $(this).data("id");
//if (prevFeatureId) alaMap.unAnimateFeatureById(prevFeatureId);
projectSites = alaMap.animateFeatureById(fId);
$(thisEl).tooltip('hide');
//console.log("toggle", prevFeatureId, fId);
if (!prevFeatureId) {
$("#proj_" + fId).slideToggle();
$(thisEl).find(".showHideCaret").html("▼");
} else if (prevFeatureId != fId) {
if ($("#proj_" + prevFeatureId).is(":visible")) {
// hide prev selected, show this
$("#proj_" + prevFeatureId).slideUp();
$("#a_" + prevFeatureId).find(".showHideCaret").html("►");
$("#proj_" + fId).slideDown();
$("#a_" + fId).find(".showHideCaret").html("▼");
} else {
//show this, hide others
$("#proj_" + fId).slideToggle();
$(thisEl).find(".showHideCaret").html("▼");
$("#proj_" + prevFeatureId).slideUp();
$("#a_" + prevFeatureId).find(".showHideCaret").html("►");
}
alaMap.unAnimateFeatureById(prevFeatureId);
} else {
$("#proj_" + fId).slideToggle();
if ($("#proj_" + fId).is(':visible')) {
$(thisEl).find(".showHideCaret").html("►");
} else {
$(thisEl).find(".showHideCaret").html("▼");
}
alaMap.unAnimateFeatureById(fId);
}
prevFeatureId = fId;
});
// zoom in/out to project points via +/- buttons
var initCentre, initZoom;
$('#projectTable').on("click", "a.zoom-in",function(el) {
el.preventDefault();
if (!projectSites) {
alert("No sites found for project");
return false;
}
if (!initCentre && !initZoom) {
initCentre = alaMap.map.getCenter();
initZoom = alaMap.map.getZoom();
}
var projectId = $(this).data("id");
var delay = 0;
if (!alaMap.map || alaMap.map.zoom == 0) {
// maps not loaded yet (lazy loading and maps tab not yet clicked) - add delay
// so that map data can be loaded #HACK
delay = 2000;
}
//$('#accordionMapView').tab('show');
setTimeout(
function() {
//var fId = $(this).data("id");
alaMap.animateFeatureById(projectId);
var bounds = alaMap.getExtentByFeatureId(projectId);
alaMap.map.fitBounds(bounds);
}, delay
);
});
// Tooltips
$('.projectTitle').tooltip({
placement: "right",
container: "#projectTable",
delay: 400
});
$('.tooltips').tooltip({placement: "right"});
// sorting project table
$("#projectTable .header").click(function(el) {
var sort = $(this).data("sort");
var order = $(this).data("order");
var prevSort = $("#projectTable").data("sort");
var newOrder = (prevSort != sort) ? order : ((order == "ASC") ? "DESC" :"ASC");
// update new data attrs in table
$("#projectTable").data("sort", sort);
$("#projectTable").data("order", newOrder); // toggle
$("#projectTable").data("offset", 0); // always start at page 1
$(this).data("order", newOrder);
// update CSS classes
$("#projectTable .header").removeClass("headerSortDown").removeClass("headerSortUp"); // remove all sort classes first
$(this).addClass((newOrder == "ASC") ? "headerSortDown" : "headerSortUp");
// $(this).removeClass((newOrder == "ASC") ? "headerSortUp" : "headerSortDown");
updateProjectTable();
});
// next/prev buttons in project list table
$("#paginateTable .btn").not(".clearFilterBtn").click(function(el) {
// Don't trigger if button is disabled
if (!$(this).hasClass("disabled")) {
//var prevOrNext = (this).hasClass("next") ? "next" : "prev";
var offset = $("#projectTable").data("offset");
var max = $("#projectTable").data("max");
var newOffset = $(this).hasClass("next") ? (offset + max) : (offset - max);
$("#projectTable").data("offset", newOffset);
//console.log("offset", offset, newOffset, $("#projectTable").data("offset"));
updateProjectTable();
}
});
// in mobile view toggle display of facets
$("#toggleFacetDisplay").click(function(e) {
e.preventDefault();
$(this).find("i").toggleClass("icon-chevron-down icon-chevron-right");
if ($("#" + $(this).attr('rel')).is(":visible")) {
$("#" + $(this).attr('rel')).addClass("hidden-phone");
$(this).find("span").text("show");
} else {
$("#" + $(this).attr('rel')).removeClass("hidden-phone");
$(this).find("span").text("hide");
}
});
});
/**
* Sort a list by its li elements using the data-foo (dataEl) attribute of the li element
*
* @param $list
* @param dataEl
* @param op
*/
function sortList($list, dataEl, op) {
//console.log("args",$list, dataEl, op);
$list.find("li").sort(function(a, b) {
var comp;
if (op == ">") {
comp = ($(a).data(dataEl)) > ($(b).data(dataEl)) ? 1 : -1;
} else {
comp = ($(a).data(dataEl)) < ($(b).data(dataEl)) ? 1 : -1;
}
return comp;
}).appendTo($list);
}
</asset:script>