explore2.jsp 47.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!DOCTYPE html>

<%@include file="/WEB-INF/jsp/init.jsp" %>
<spring:message code='filter.internal.message.between' var="between" arguments=" "/>
<spring:message code='filter.internal.message.and' var="varEnd" arguments=" "/>
<spring:message code='filter.internal.message.more' var="moreThan" arguments=" "/>
<spring:message code='filter.internal.message.less' var="lessThan" arguments=" "/>
<spring:message code='filter.internal.message.like' var="like" arguments=" "/>
<spring:message code='boolean.true' var="varTrue"/>
<spring:message code='boolean.false' var="varFalse"/>
<spring:message code='boolean.null' var="varNull"/>

<html>
<head>
    <title><spring:message code="accession.page.data.title"/></title>
</head>

Taisiya Glushko's avatar
Taisiya Glushko committed
18
<body class="explore-page">
19
20
21
22
23
24
25
<cms:informative-h1 title="accession.page.data.title" fancy="${pagedData.number eq 0}"
                    info="accession.page.data.intro"/>
<!-- Begin page content -->
    <div class="container-fluid">
        <div id="dialog" class="row"></div>
        <div class="" typeof="">
            <!--Filters-->
Matija Obreza's avatar
Matija Obreza committed
26
27
28
29
				<filters:group>
					<filters:panel id="crops" title="filter.crops">
						<filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="crops" appliedFilters="${appliedFilters}" type="select" cropList="${crops}" currentCrop="${crop}" />
					</filters:panel>
30

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
31
32
33
34
35
36
37
                    <filters:panel id="lists" title="filter.lists">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="lists" appliedFilters="${appliedFilters}" type="like" />
                    </filters:panel>

                    <filters:panel id="sampstat" title="filter.sampStat">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="sampStat" appliedFilters="${appliedFilters}" type="option" />
                    </filters:panel>
38

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
39
40
					<filters:panel id="genus" title="filter.taxonomy.genus">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="taxonomy.genus" appliedFilters="${appliedFilters}" type="autocomplete" />
Matija Obreza's avatar
Matija Obreza committed
41
					</filters:panel>
42

Matija Obreza's avatar
Matija Obreza committed
43
					<filters:panel id="species" title="filter.taxonomy.species">
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
44
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="taxonomy.species" appliedFilters="${appliedFilters}" type="autocomplete" />
Matija Obreza's avatar
Matija Obreza committed
45
46
					</filters:panel>

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
47
48
                            <filters:panel id="subtaxa" title="filter.taxonomy.subtaxa">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="taxonomy.subtaxa" appliedFilters="${appliedFilters}" type="autocomplete" />
Matija Obreza's avatar
Matija Obreza committed
49
50
51
					</filters:panel>

					<filters:panel id="sciname" title="filter.taxonomy.sciName">
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
52
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="taxonomy.sciName" appliedFilters="${appliedFilters}" type="autocomplete" />
Matija Obreza's avatar
Matija Obreza committed
53
					</filters:panel>
54

Matija Obreza's avatar
Matija Obreza committed
55
					<filters:panel id="origcty" title="filter.orgCty.iso3">
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
56
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="orgCty.iso3" appliedFilters="${appliedFilters}" type="autocomplete" />
Matija Obreza's avatar
Matija Obreza committed
57
					</filters:panel>
58

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
59
60
					<filters:panel id="instcountry" title="filter.institute.country.iso3">
						<filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="institute.country.iso3" appliedFilters="${appliedFilters}" type="autocomplete" />
Matija Obreza's avatar
Matija Obreza committed
61
					</filters:panel>
62

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
63
64
65
                    <filters:panel id="geolatitude" title="filter.geo.latitude">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="geo.latitude" appliedFilters="${appliedFilters}" type="range" />
                    </filters:panel>
66

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
67
68
69
                    <filters:panel id="institutenetworks" title="filter.institute.networks">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="institute.networks" appliedFilters="${appliedFilters}" type="like" />
                    </filters:panel>
70

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
                    <filters:panel id="institutecode" title="filter.institute.code">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="institute.code" appliedFilters="${appliedFilters}" type="autocomplete" />
                    </filters:panel>

                    <filters:panel id="acceNumb" title="filter.acceNumb">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="acceNumb" appliedFilters="${appliedFilters}" type="like" />
                    </filters:panel>

                    <filters:panel id="seqNo" title="filter.seqNo">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="seqNo" appliedFilters="${appliedFilters}" type="range" />
                    </filters:panel>

                    <filters:panel id="alias" title="filter.alias">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="alias" appliedFilters="${appliedFilters}" type="like" />
                    </filters:panel>

                    <filters:panel id="sgsv" title="filter.sgsv">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="sgsv" appliedFilters="${appliedFilters}" type="boolean" />
                    </filters:panel>
90

Matija Obreza's avatar
Matija Obreza committed
91
92
93
					<filters:panel id="mlsStatus" title="filter.mlsStatus">
						<filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="mlsStatus" appliedFilters="${appliedFilters}" type="boolean" />
					</filters:panel>
94

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
95
96
97
98
                    <filters:panel id="art15" title="filter.art15">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="art15" appliedFilters="${appliedFilters}" type="boolean" />
                    </filters:panel>

Matija Obreza's avatar
Matija Obreza committed
99
100
101
					<filters:panel id="available" title="filter.available">
						<filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="available" appliedFilters="${appliedFilters}" type="boolean" />
					</filters:panel>
102

Matija Obreza's avatar
Matija Obreza committed
103
104
105
106
107
108
109
110
					<filters:panel id="historic" title="filter.historic">
						<filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="historic" appliedFilters="${appliedFilters}" type="boolean" />
					</filters:panel>
					
					<filters:panel id="collMissId" title="filter.coll.collMissId">
						<filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="coll.collMissId" appliedFilters="${appliedFilters}" type="like" />
					</filters:panel>

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
111
112
113
                    <filters:panel id="storage" title="filter.storage">
                        <filters:filter availableFilters="${availableFilters}" filterMap="${filters}" filterKey="storage" appliedFilters="${appliedFilters}" type="option" />
                    </filters:panel>
Matija Obreza's avatar
Matija Obreza committed
114
115
				</filters:group>
				<!--List-->
Taisiya Glushko's avatar
Taisiya Glushko committed
116
            <div class="col-lg-10 col-md-9 col-sm-9 col-xs-12 main-col-header">
117
118
119
120
                <div class="nav-header clearfix">
                    <!-- Links -->
                    <div class="pull-right list-view-controls">
                        <div class="btn-group" id="shareLink">
Taisiya Glushko's avatar
Taisiya Glushko committed
121
                            <a type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
122
123
124
                                    aria-haspopup="true" aria-expanded="false" id="menuShareLink">
                                <span class="glyphicon glyphicon-share"></span><span><spring:message code="share.link"/></span>
                                <span class="caret"></span>
Taisiya Glushko's avatar
Taisiya Glushko committed
125
                            </a>
126
127
128
129
130
131
132
133
134
135
                            <ul class="dropdown-menu">
                                <li class="padding10">
                                    <p><spring:message code="share.link.text"/></p>
                                    <input id="shortLink" type="text"
                                           placeholder="<spring:message code="share.link.placeholder" />" value=""/>
                                </li>
                            </ul>
                        </div>


Taisiya Glushko's avatar
Taisiya Glushko committed
136
                        <!--<div class="btn-group" id="downloadLink" <c:if test="${pagedData.totalElements ge 200000}">style="display: none"</c:if>>
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
                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
                                    aria-haspopup="true" aria-expanded="false">
                                <span class="glyphicon glyphicon-download"></span><span><spring:message
                                    code="download"/></span> <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu">
                                <security:authorize access="isAuthenticated()">
                                    <li>
                                        <form style="display: inline-block" method="post"
                                              action="<c:url value="/download/explore/download/mcpd" />">
                                            <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
                                            <input type="hidden" name="filter" value="<c:out value="${jsonFilter}" />"/>
                                            <button class="btn btn-inline" type="submit"><span><spring:message
                                                    code="filter.download-mcpd"/></span></button>
                                        </form>
                                    </li>
                                </security:authorize>
                                <li>
                                    <form style="display: inline-block" method="post"
                                          action="<c:url value="/download/explore/dwca" />">
                                        <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
                                        <input type="hidden" name="filter" value="<c:out value="${jsonFilter}" />"/>
                                        <button class="btn btn-inline" type="submit"><span><spring:message
                                                code="filter.download-dwca"/></span></button>
                                    </form>
                                </li>
                            </ul>
Taisiya Glushko's avatar
Taisiya Glushko committed
164
                        </div>-->
165
166
167
168
169
170
171
172
173
174
175
176
177

                        <a class="btn btn-default" id="overviewLink"
                           href="<c:url value="/explore/overview"><c:param name="filter">${jsonFilter}</c:param></c:url>"><span
                                class="glyphicon glyphicon-eye-open"></span><span><spring:message
                                code="data-overview.short"/></span></a>
                        <a class="btn btn-default" id="mapLink"
                           href="<c:url value="/explore/map"><c:param name="filter">${jsonFilter}</c:param></c:url>"><span
                                class="glyphicon glyphicon-globe"></span><span><spring:message code="maps.view-map"/></span></a>
                    </div>
                    <!--Pagination-->
                    <filters:pagination pagedData="${pagedData}" jsonFilter="${jsonFilter}"/>
                </div>
            </div>
Taisiya Glushko's avatar
Taisiya Glushko committed
178
            <div id="explore-table" class="col-lg-10 col-md-9 col-sm-9 col-xs-12">
179
180
181
                <table class="accessions">
                    <thead>
                    <tr>
Taisiya Glushko's avatar
Taisiya Glushko committed
182
183
                        <td class="idx-col"><p></p></td>
                        <td><p></p></td>
184
                        <td><p><spring:message code="accession.accessionName" /></p></td>
Taisiya Glushko's avatar
Taisiya Glushko committed
185
                        <c:forEach items="${selectedColumns}" var="column" varStatus="i">
186
                            <c:choose>
Taisiya Glushko's avatar
Taisiya Glushko committed
187
                                <c:when test="${i.count eq 1}">
188
189
                                    <td><p><spring:message code="accession.${column}"/></p></td>
                                </c:when>
Taisiya Glushko's avatar
Taisiya Glushko committed
190
                                <c:when test="${i.count eq 2}">
191
192
                                    <td class="notimportant hidden-xs"><p><spring:message code="accession.${column}"/></p></td>
                                </c:when>
Taisiya Glushko's avatar
Taisiya Glushko committed
193
194
195
                                <c:when test="${column eq 'taxonomy.species'}">
                                    <td class="notimportant hidden-sm hidden-xs"><p><spring:message code="accession.${column}"/></p></td>
                                </c:when>
196
197
198
199
200
201
202
203
204
205
206
                                <c:otherwise>
                                    <td class="notimportant hidden-sm hidden-xs"><p><spring:message code="accession.${column}"/></p></td>
                                </c:otherwise>
                            </c:choose>
                        </c:forEach>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${pagedData.content}" var="accession" varStatus="status">
                        <tr class="acn ${status.count % 2 == 0 ? 'even' : 'odd'} ${accession.historic ? 'historic-record' : ''}">
                            <td class="idx-col"><p>${status.count + pagedData.size * pagedData.number}</p></td>
Taisiya Glushko's avatar
Taisiya Glushko committed
207
                            <td><span class="sel" x-aid="${accession.id}" title="<spring:message code="selection.checkbox" />"></span></td>
208
                            <td><p><a href="<c:url value="/acn/id/${accession.id}" />"><b><c:out value="${accession.acceNumb}"/></b></a></p></td>
Taisiya Glushko's avatar
Taisiya Glushko committed
209
                            <c:forEach items="${selectedColumns}" var="col" varStatus="i">
210
211
                                <c:choose>
                                    <c:when test="${col eq 'taxonomy.sciName'}">
Taisiya Glushko's avatar
Taisiya Glushko committed
212
                                        <td class="<c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"><p><span dir="ltr" class="sci-name"><c:out value="${accession.taxonomy.sciName}"/></span></p></td>
213
214
                                    </c:when>
                                    <c:when test="${col eq 'orgCty'}">
Taisiya Glushko's avatar
Taisiya Glushko committed
215
                                        <td class="notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"><p><c:out value="${jspHelper.getCountry(accession.orgCty.iso3).getName(pageContext.response.locale)}"/></p></td>
216
217
                                    </c:when>
                                    <c:when test="${col eq 'sampStat'}">
Taisiya Glushko's avatar
Taisiya Glushko committed
218
                                        <td class="notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"><p><spring:message code="accession.sampleStatus.${accession.sampStat}"/></p></td>
219
220
                                    </c:when>
                                    <c:when test="${col eq 'institute.code'}">
Taisiya Glushko's avatar
Taisiya Glushko committed
221
                                        <td class="notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"><p><a href="<c:url value="/wiews/${accession.institute.code}" />"><c:out
222
223
224
                                                value="${accession.institute.code}"/></a></p></td>
                                    </c:when>
                                    <c:when test="${col eq 'taxonomy.genus'}">
Taisiya Glushko's avatar
Taisiya Glushko committed
225
                                        <td class="notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"><p><span dir="ltr" class="sci-name"><c:out value="${accession.taxonomy.genus}"/></span></p></td>
226
227
                                    </c:when>
                                    <c:when test="${col eq 'taxonomy.species'}">
Taisiya Glushko's avatar
Taisiya Glushko committed
228
                                        <td class="notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"><p><span dir="ltr" class="sci-name"><c:out value="${accession.taxonomy.species}"/></span></p></td>
229
230
                                    </c:when>
                                    <c:when test="${col eq 'taxonomy.subtaxa'}">
Taisiya Glushko's avatar
Taisiya Glushko committed
231
                                        <td class="notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"><p><span dir="ltr" class="sci-name"><c:out value="${accession.taxonomy.subtaxa}"/></span></p></td>
232
233
234
                                    </c:when>
                                    <c:when test="${col eq 'crops'}">
                                        <c:if test="${fn:length(accession.crops) == 0}">
Taisiya Glushko's avatar
Taisiya Glushko committed
235
                                            <td class="notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"></td>
236
237
                                        </c:if>
                                        <c:forEach items="${jspHelper.getCrops(accession.crops)}" var="crop">
Taisiya Glushko's avatar
Taisiya Glushko committed
238
                                            <td class="notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"><p><a href="<c:url value="/c/${crop.shortName}" />"><c:out
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
                                                    value="${crop.getName(pageContext.response.locale)}"
                                                    /></a></p></td>
                                        </c:forEach>
                                    </c:when>
                                    <c:otherwise>
                                        <c:set var="elVal" value="${accession}" />
                                        <c:forTokens items="${col}" delims="." var="item">
                                            <c:set var="elVal" value="${elVal[item]}" />
                                        </c:forTokens>
                                        <td class="notimportant hidden-sm hidden-xs"><p><c:out value="${elVal}"/></p></td>
                                        <c:remove var="elVal"/>
                                    </c:otherwise>
                                </c:choose>
                            </c:forEach>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
Taisiya Glushko's avatar
Taisiya Glushko committed
257
258
259
260
261
262
263
264
265
                    <div class="nav-header bottom-pagination-wrapper clearfix">
                        <!--Pagination-->
                        <filters:pagination pagedData="${pagedData}" jsonFilter="${jsonFilter}"/>
                        <nav class="text-center pull-right">
                            <ul class="pagination">
                                <li>
                                    <span><spring:message code="paged.resultsPerPage" /></span>
                                </li>
                                <li>
266
267
268
269
270
271
272
273
274
275
                                <span>
                                    <select class="form-control results-per-page">
                                        <option value="10" ${pagedData.size == 10 ? "selected" : ""}>10</option>
                                        <option value="20" ${pagedData.size == 20 ? "selected" : ""}>20</option>
                                        <option value="40" ${pagedData.size == 40 ? "selected" : ""}>40</option>
                                        <option value="50" ${pagedData.size == 50 ? "selected" : ""}>50</option>
                                        <option value="75" ${pagedData.size == 75 ? "selected" : ""}>75</option>
                                        <option value="100" ${pagedData.size == 100 ? "selected" : ""}>100</option>
                                    </select>
                                </span>
Taisiya Glushko's avatar
Taisiya Glushko committed
276
277
278
279
                                </li>
                            </ul>
                        </nav>
                    </div>
280
            </div>
Taisiya Glushko's avatar
Taisiya Glushko committed
281
282
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12"></div>

283
284
285
            <!--End of List-->
        </div>
    </div>
Taisiya Glushko's avatar
Taisiya Glushko committed
286

287
288
289
290
291
292
293
294
295

<content tag="javascript">
    <script type="text/javascript">
        var jsonData = ${jsonFilter};

        var page = ${pagedData.number};

        var results = ${pagedData.size};

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
296
297
        var cropNames = [];

Taisiya Glushko's avatar
Taisiya Glushko committed
298
299
300
301
302
303
304
305
        var headersCopy = $(".accessions").find("thead td").clone();

        var headerSelects = [];

        var rowsCopy = $(".accessions").find("tbody tr").clone();

        var lastWindowWidth;

306
307
308
309
310
311
312
313
314
315
316
317
318
        $(document).ready(function () {

            var i18nFilterMessage = {
                between: 'Between  ',
                varEnd: '  and  ',
                moreThan: 'More than  ',
                lessThan: 'Less than  ',
                like: 'Like  ',
                varTrue: 'Yes',
                varFalse: 'No',
                varNull: 'Unknown'
            };

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
319
320
321
322
323
324
325
326
327
328
329
330
            cropNames = function(){
                var data = null;
                $.ajax({
                    url: "/explore/getCrops",
                    method: 'get',
                    async: false
                }).done(function (response) {
                    data = response;
                });
                return data;
            }();

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
            $("body").on("keypress", ".string-type", function (e) {
                if (e.keyCode == 13) {
                    var btn = $(this).parent().find("button");
                    console.log(btn);
                    var selectedValue = $(this).parent().parent().find(".like-switcher option:selected").val();

                    if (selectedValue == "like") {
                        GenesysFilter.filterLike(btn, jsonData, i18nFilterMessage);
                    } else {
                        GenesysFilter.filterAutocomplete(btn, jsonData);
                    }
                }
            });

            $("body").on("click", ".filter-list", function () {
                if (jsonData[$(this).attr("i-key")] === undefined) {
                    enableFilter(this);
                }
                var text = $(this).parent().text();
                text = text.substring(0, text.indexOf('('));
                GenesysFilter.filterList($(this), jsonData, text);
            });

            $("body").on("click", ".filter-auto", function () {
                if (jsonData[$(this).attr("i-key")] === undefined) {
                    enableFilter(this);
                }

                var selectedValue = $(this).parent().parent().parent().find(".like-switcher option:selected").val();
                if (selectedValue == "like") {
                    GenesysFilter.filterLike($(this), jsonData, i18nFilterMessage);
                } else {
                    GenesysFilter.filterAutocomplete($(this), jsonData);
                }
            });

            $("body").on("click", ".filter-range", function () {
                if (jsonData[$(this).attr("i-key")] === undefined) {
                    enableFilter(this);
                }
                GenesysFilter.filterRange($(this), jsonData, i18nFilterMessage);
            });

            $("body").on("click", ".filter-bool", function () {
                if (jsonData[$(this).attr("i-key")] === undefined) {
                    enableFilter(this);
                }
                GenesysFilter.filterBoolean($(this), jsonData, i18nFilterMessage);
            });

381
            $('body').on('click', '.filter-crop', function () {
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
                GenesysFilter.filterCrop($(this), jsonData);
            });

            $("body").on("click", ".applyBtn", function () {
                applyFilters();
                applySuggestions();
            });

            function applyFilters (path) {
                cleanJsonData();
                var filter = JSON.stringify(jsonData);
                var requestUrl = '//' + location.host + location.pathname + "/json" +
                        (path !== undefined ? path : "?page=1&" + "filter=" + encodeURIComponent(filter));
                requestUrl += "&results=" + results;
                var displayUrl = requestUrl.replace('/json', '');

                window.history.pushState(requestUrl, '', displayUrl);
                $.ajax({
                    url: requestUrl,
                    method: 'get',
                    success: function (response) {
                        renderData(response);
Taisiya Glushko's avatar
Taisiya Glushko committed
404
405
406
                        $.each($("select.column-changer"), function () {
                            $(this).change();
                        });
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
                    }
                });
            }

            function applySuggestions () {
                $.ajax({
                    url: "/explore/listFilterSuggestions",
                    method: 'get',
                    data: {
                        filter: JSON.stringify(jsonData)
                    },
                    success: function (response) {
                        renderListFilterSuggestions(response);
                    }
                });

                $.ajax({
                    url: "/explore/booleanSuggestions",
                    method: 'get',
                    data: {
                        filter: JSON.stringify(jsonData)
                    },
                    success: function (response) {
                        renderBooleanSuggestions(response);
                    }
                });

                $.ajax({
                    url: "/explore/cropSuggestions",
                    method: 'get',
                    data: {
                        filter: JSON.stringify(jsonData)
                    },
                    success: function (response) {
                        renderCropSuggestions(response);
                    }
                });
            }

            function renderListFilterSuggestions (filters) {
                $.each(filters, function (option) {
                    $("div." + option).find("div[class!='panel-body'][class!='filtval complex']").remove();
                    if (filters[option].options[0] == null) {
                        $("div." + option).find("button.applyBtn").before("<div>No suggestions</div>");
                    } else {
                        $.each(filters[option].options, function (index) {
Taisiya Glushko's avatar
Taisiya Glushko committed
453
                            var div = '<div class="checkbox-wrapper">' +
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
                                    '<label>' +
                                    '<input class="filter-list"' +
                                    'id="' + option + this.value + '_input"' +
                                    ($("div.filtval[x-key='" + option + this.value + "']")[0] != null ? 'checked ' : '') +
                                    'norm-key="' + option + '"' +
                                    'i-key="' + option + '" type="checkbox"' +
                                    'value="' + this.value + '"/>' +
                                    messages[this.name] +
                                    ' (' + filters[option].counts[index] + ')' +
                                    '</label>' +
                                    '</div>';
                            var filtval = $("div.filtval[x-key^='" + option + "']");
                            var attach = filtval[0] != null ? filtval[0] : $("div." + option).find("button.applyBtn");
                            $(attach).before(div);
                        });
                    }
                });
            }

            function renderBooleanSuggestions(filters) {
                $.each(filters, function (filter) {
                    $.each($("input[type='checkbox'][i-key='" + filter + "']"), function (index) {
                        var val = filters[filter][index === 0 ? "T" : "F"];
                        if (val === undefined) {
                            val = 0;
                        }
                        var text = $(this).parent().html();
                        var idx = text.indexOf("(");
                        if (idx !== -1) {
                            text = text.substring(0, idx);
                        }
                        $(this).parent().html(text + " (" + val + ")");
                        if ($("div[x-key='" + filter + $(this).val() + "']")[0] != null) {
                            $($("input[type='checkbox'][i-key='" + filter + "']")[index]).prop("checked", true);
                        }
                    });
                });
            }

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
//            function renderCropSuggestions(filters) {
//                var cropSelect = $("select[i-key='crops']");
//                var currentCrop = $("div.filtval[i-key='crops']");
//                cropSelect.html("");
//                var option = $("<option disabled>Select crop</option>");
//                if (currentCrop[0] == null) {
//                    option.prop('selected', true);
//                }
//                cropSelect.append(option);
//                $.each(filters, function (name, value) {
//                    var key = Object.keys(this)[0];
//                    option = $('<option value="' + name + '">' +
//                            key + ' (' + value[key] + ')</option>');
//                    if (currentCrop[0] != null && name === currentCrop.html()) {
//                        option.prop('selected', true);
//                    }
//                    cropSelect.append(option);
//                });
//            }

513
            function renderCropSuggestions(filters) {
514
                $(".radio-wrapper").remove();
515
                $.each(filters, function (name, value) {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
516
517
518
519
520
521
522
523
524
525
                    var input = $("<input/>", {
                        type: 'radio',
                        name: 'crops',
                        id: 'crops_' + name,
                        'i-key': 'crops',
                        'class': 'filter-crop',
                        value: name
                    });
                    if ($("div.filtval[x-key='crops" + name + "']")[0] != null) {
                        input.prop('checked', true);
526
                    }
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
527
528
529
530
531
                    var key = Object.keys(this)[0];
                    var label = $("<label/>", {
                        'for': 'crops_' + name,
                        text: key + " (" + value[key] + ")"
                    });
532
533
534
535
                    var wrapper = $("<div/>", {'class': "radio-wrapper"});
                    wrapper.append(input);
                    wrapper.append(label);
                    $(attach).before(wrapper);
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
                });
            }

            $("body").on("click", ".filtval", function (event) {
                event.preventDefault();

                var key = $(this).attr("i-key");
                var normKey = GenesysFilter.normKey(key);
                var value = $(this).attr("x-key").replace(normKey, "");

                if (value == "null") value = null;
                GenesysFilterUtil.removeValue(value, key, jsonData);
                applyFilters();
                applySuggestions();

                $(this).remove();
                $('input[i-key=" + normKey + "][value=" + value + "]').prop('checked', false);
            });

            $("#menuShareLink").on("click", function () {
                if ($('#shortLink').val() === '') {
                    $.ajax({
                        type: 'POST',
                        url: '/explore/shorten-url',
                        data: {
                            'page': 1, 'filter': JSON.stringify(jsonData)
                        },
                        success: function (response) {
                            var inp = $("#shortLink");
                            inp.val(response.shortUrl);
                            inp.select();
                        }
                    });
                } else {
                    console.log('No repeat.');
                }
            });

            $("body").on("change", "#more-filters", function() {
                var key = $(this).val();
                var normKey = GenesysFilterUtil.normKey(key);
                var input = $(this).parent().find("input[type='text']");
                input.attr('id', normKey + "_input");
                if (key == "institute.country.iso3") {
                    input.attr('x-source', "/explore/ac/orgCty.iso3");
                } else {
                    input.attr('x-source', "/explore/ac/" + key);
                }

                var btn = $(this).parent().find("button.filter-auto");
                btn.attr("norm-key", normKey);
                btn.attr("i-key", key);
                jsonData[key] = [];
            });

            $.each([$(".firstPage"), $(".previousPage"), $(".nextPage"), $(".lastPage")], function () {
                $(this).find("a").on("click", function (e) {
                    e.preventDefault();
                    applyFilters($(e.target).attr("href"));
                });
            });

            $("nav.text-center").find("form").on("submit", function (e) {
                e.preventDefault();
                applyFilters("?" + $(this).serialize());
            });

            $(".results-per-page").on("change", function () {
                results = $(this).val();
                applyFilters();
            });

            $.each($('#collapseFilters').find("div.panel-collapse"), function () {
                <c:forEach items="${appliedFilters}" var="appliedFilter">
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
610
611
                    var collapseDiv = $(this).find($("div[id*='${appliedFilter.key}']"));
                    if (collapseDiv[0] !== undefined) {
612
613
614
615
616
617
618
619
620
                        $(this).collapse("show");
                    }
                </c:forEach>
            });
            $('#collapseFilters').on('hidden.bs.collapse', function () {
                $("#explore-table").addClass('fullwidth')
            }).children().on('hidden.bs.collapse', function() {
                return false;
            });
Taisiya Glushko's avatar
Taisiya Glushko committed
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
            $('#collapseFilters').on('show.bs.collapse', function () {
                $("#explore-table").removeClass('fullwidth');
            }).children().on('show.bs.collapse', function(child) {
                $.each($(child.target).children().find("*[i-key]"), function () {
                    enableFilter(this);
                });
                return true;
            });

            $(window).on("popstate", function(e) {
                if (e.originalEvent.state !== null) {
                    jsonData = JSON.parse(decodeURIComponent((new RegExp('[?|&]filter=' + '([^&;]+?)(&|#|;|$)').exec(location.search)
                            || [null, ''])[1].replace(/\+/g, '%20'))) || [];
                    page = decodeURIComponent((new RegExp('[?|&]page=' + '([^&;]+?)(&|#|;|$)').exec(location.search)
                            || [null, ''])[1].replace(/\+/g, '%20')) || 1;
                    results = decodeURIComponent((new RegExp('[?|&]results=' + '([^&;]+?)(&|#|;|$)').exec(location.search)
                            || [null, ''])[1].replace(/\+/g, '%20')) || 50;
                    var filter = JSON.stringify(jsonData);
                    var requestUrl = '//' + location.host + location.pathname + "/json?page=" + page + "&filter=" + filter + "&results=" + results;
                    $.ajax({
                        url: requestUrl,
                        method: 'get',
                        success: function (response) {
                            renderData(response);
                        }
                    });
                    applySuggestions();
                } else {
                    location.reload();
                }
            });

            GenesysFilterUtil.registerAutocomplete(".filters", jsonData);

            $.ajax({
                url: "/explore/booleanSuggestions",
                method: 'get',
                data: {
                    filter: JSON.stringify(jsonData)
                },
                success: function (response) {
                    renderBooleanSuggestions(response);
                }
            });
Taisiya Glushko's avatar
Taisiya Glushko committed
666
667
668
669
670
671
672
673
674
675

            function restoreHeaders() {
                $.each($("select.column-changer"), function () {
                    var index = $(this).attr("x-id");
                    var oldHeader = $(headersCopy[index]).html();
                    $(this).parent().html(oldHeader);
                });
            }

            function resize() {
676
                if (window.innerWidth < 992) {
Taisiya Glushko's avatar
Taisiya Glushko committed
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
                    var headers = $(".accessions").find("thead td");
                    $.each(headersCopy, function (index) {
                        if (index >= 3 && headerSelects[index] != true) {
                            var select = $("<select/>", {
                                'class': 'column-changer',
                                'x-id': index
                            });

                            var selectedOption = $("<option/>", {
                                value: $(this).text(),
                                text: $(this).text(),
                                'x-id': index,
                                selected: true
                            });
                            selectedOption.appendTo(select);

                            for (var i = 3; i < headers.length; i++) {
                                if ($(headers[i]).text() !== $(headers[index]).text()) {
                                    var option = $("<option/>", {
                                        value: $(headersCopy[i]).text(),
                                        text: $(headersCopy[i]).text(),
                                        'x-id': i
                                    });

                                    option.appendTo(select);
                                }
                            }

                            $(headers[index]).html(select);
                            select.after('<span class="glyphicon glyphicon-menu-down"></span>');
                            headerSelects[index] = true;
                        }
                    });

                    $.each($("select.column-changer"), function () {
                        $(this).on("change", function() {
                            var cols;
                            var from = $(this).find("option:selected").attr("x-id");
                            var to = $(this).attr("x-id");
                            $.each($(".accessions").find("tbody tr"), function(index) {
                                cols = $(this).children('td');
                                var val = $(rowsCopy[index]).children().eq(from).html();
                                cols.eq(to).html(val);
                            });
                        });
                    });
                } else {
                    restoreHeaders();
                    headerSelects = [];
                    if (lastWindowWidth < 992) {
                        var path = "?page=" + (page + 1) + "&" + "filter=" + encodeURIComponent(JSON.stringify(jsonData));
                        applyFilters(path);
                    }
                }

732
                lastWindowWidth = window.innerWidth;
Taisiya Glushko's avatar
Taisiya Glushko committed
733
734
735
736
737
738
739
            }

            resize();

            $(window).resize(function () {
                resize();
            });
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
        });

        function enableFilter (btn) {
            var key = $(btn).attr("i-key");
            var normKey = GenesysFilter.normKey(key);
            jsonData[key] = [];
        }

        function cleanJsonData() {
            $.each(jsonData, function (key) {
                if ($(this).length == 0) {
                    delete jsonData[key];
                }
            });
        }

        function renderData(pagedData) {
            page = pagedData.number;
            renderPagination(pagedData);
            renderLinks(pagedData);
            renderTableBody(pagedData);
        }

        function renderPagination (pagedData) {
            var re = /\B(?=(\d{3})+(?!\d))/g;
            var totalElements = pagedData.totalElements.toString().replace(re, ",");
            var totalPages = pagedData.totalPages.toString().replace(re, ",");
            $('nav').find(".results").html(messages["accessions.number"].replace("{0}", totalElements));
            $('.pagination').find(".totalPages").html(messages["paged.ofPages"].replace("{0}", totalPages));
            setPageUrl($(".firstPage"), 1);
            setPageUrl($(".previousPage"), page == 0 ? 1 : page);
            setPageUrl($(".nextPage"), page + 2);
            setPageUrl($(".lastPage"), pagedData.totalPages);
            $(".pagination-input").find("input").val(page + 1);
            $("input[name='filter']").val(JSON.stringify(jsonData));
        }

        function setPageUrl (element, page) {
            $(element).find("a").attr("href", "?page=" + page + "&filter=" + encodeURI(JSON.stringify(jsonData)));
        }

        function renderLinks (pagedData) {
            var downloadLink = $("#downloadLink");
            if (pagedData.totalElements <= 200000) {
                downloadLink.show();
                $.each($("#downloadLink").find("input[name='filter']"), function () {
                    $(this).val(JSON.stringify(jsonData));
                });
            } else {
                downloadLink.hide();
            }
            var re = /filter=(.*)/;
            $("#overviewLink").attr("href", $("#overviewLink").attr("href").replace(re, "filter=" + encodeURIComponent(JSON.stringify(jsonData))));
            $("#mapLink").attr("href", $("#mapLink").attr("href").replace(re, "filter=" + encodeURIComponent(JSON.stringify(jsonData))));
        }

        function renderTableBody(pagedData) {
            $("table").find("tbody").remove();
            var tbody = $("<tbody/>");
Taisiya Glushko's avatar
Taisiya Glushko committed
799
            rowsCopy = [];
800
801
802
803
804
805
806
807
808
            for (var i = 0; i < pagedData.numberOfElements; i++) {
                var row = $("<tr/>", {
                    'class': "acn " + (i % 2 == 0 ? 'odd' : 'even') + (pagedData.content[i].historic ? ' historic-record' : '')
                });
                $("<p/>", {
                    text: (i + 1) + pagedData.size * pagedData.number
                }).appendTo($("<td/>", {
                    'class': "idx-col"
                }).appendTo(row));
Taisiya Glushko's avatar
Taisiya Glushko committed
809
                $("<span/>", {
810
811
812
                    'class': "sel",
                    'x-aid': pagedData.content[i].id,
                    'title': "<spring:message code="selection.checkbox" />"
Taisiya Glushko's avatar
Taisiya Glushko committed
813
                }).appendTo($("<td/>").appendTo(row));
814
815
816
817
                $("<b/>", {
                    text: pagedData.content[i].acceNumb
                }).appendTo(
                $("<a/>", {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
818
                    href: '<c:url value="/acn/id/" />' + pagedData.content[i].id
819
820
                }).appendTo($("<p/>").appendTo($("<td/>").appendTo(row))));

Taisiya Glushko's avatar
Taisiya Glushko committed
821
                <c:forEach items="${selectedColumns}" var="col" varStatus="i">
822
823
824
825
826
827
                    <c:choose>
                        <c:when test="${col eq 'taxonomy.sciName'}">
                            $("<span/>", {
                                dir: 'ltr',
                                'class': 'sci-name',
                                text: pagedData.content[i].taxonomy.sciName
Taisiya Glushko's avatar
Taisiya Glushko committed
828
                            }).appendTo($("<p></p>").appendTo($("<td class='<c:if test="${i.count ge 2}">hidden-xs</c:if> <c:if test="${i.count gt 2}">hidden-sm</c:if>'></td>").appendTo(row)));
829
830
831
832
833
                        </c:when>
                        <c:when test="${col eq 'orgCty'}">
                            $("<p/>", {
                                text: messages['geo.iso3166-3.' + pagedData.content[i].orgCty.iso3]
                            }).appendTo($("<td/>", {
Taisiya Glushko's avatar
Taisiya Glushko committed
834
                                'class': "notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"
835
836
837
838
839
840
                            }).appendTo(row));
                        </c:when>
                        <c:when test="${col eq 'sampStat'}">
                            $("<p/>", {
                                text: messages["accession.sampleStatus." + pagedData.content[i].sampStat]
                            }).appendTo($("<td/>", {
Taisiya Glushko's avatar
Taisiya Glushko committed
841
                                'class': "notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"
842
843
844
845
                            }).appendTo(row));
                        </c:when>
                        <c:when test="${col eq 'institute.code'}">
                            $("<a/>", {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
846
                                href: '<c:url value="/wiews/" />' + pagedData.content[i].institute.code,
847
                                text: pagedData.content[i].institute.code
Taisiya Glushko's avatar
Taisiya Glushko committed
848
849
                            }).appendTo($("<p></p>").appendTo($("<td/>", {
                                'class': "notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"
850
851
852
853
854
855
856
                            }).appendTo(row)));
                        </c:when>
                        <c:when test="${col eq 'taxonomy.genus'}">
                            $("<span/>", {
                                dir: "ltr",
                                'class': "sci-name",
                                text: pagedData.content[i].taxonomy.genus
Taisiya Glushko's avatar
Taisiya Glushko committed
857
858
                            }).appendTo($("<p></p>").appendTo($("<td/>", {
                                'class': "notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"
859
860
861
862
863
864
865
                            }).appendTo(row)));
                        </c:when>
                        <c:when test="${col eq 'taxonomy.species'}">
                            $("<span/>", {
                                dir: "ltr",
                                'class': "sci-name",
                                text: pagedData.content[i].taxonomy.species
Taisiya Glushko's avatar
Taisiya Glushko committed
866
867
                            }).appendTo($("<p></p>").appendTo($("<td/>", {
                                'class': "notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"
868
869
870
871
872
873
874
                            }).appendTo(row)));
                        </c:when>
                        <c:when test="${col eq 'taxonomy.subtaxa'}">
                            $("<span/>", {
                                dir: "ltr",
                                'class': "sci-name",
                                text: pagedData.content[i].taxonomy.subtaxa
Taisiya Glushko's avatar
Taisiya Glushko committed
875
876
                            }).appendTo($("<p></p>").appendTo($("<td/>", {
                                'class': "notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"
877
878
879
                            }).appendTo(row)));
                        </c:when>
                        <c:when test="${col eq 'crops'}">
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
880
                            var cropNamesTd = $("<td/>", {
Taisiya Glushko's avatar
Taisiya Glushko committed
881
                                'class': "notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
882
883
884
885
886
887
888
                            });
                            if (pagedData.content[i].crops != null) {
                                $.each(pagedData.content[i].crops, function (index, shortName) {
                                    $("<a/>", {
                                        href: '<c:url value="/c/" />' + shortName,
                                        text: cropNames[shortName]
                                    }).appendTo(cropNamesTd);
889
890
                                });
                            }
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
891
                            cropNamesTd.appendTo(row);
892
893
894
895
896
                        </c:when>
                    </c:choose>
                </c:forEach>

                row.appendTo(tbody);
Taisiya Glushko's avatar
Taisiya Glushko committed
897
                rowsCopy.push($(row).clone());
898
899
900
901
902
            }

            tbody.appendTo($("table"));
        }
    </script>
Taisiya Glushko's avatar
Taisiya Glushko committed
903
904
905
906
907
908
909
910
911
912
    <script>
        $(document).ready(function () {
            $('#collapseFilters').on('hidden.bs.collapse', function () {
                $('#collapseFilters').prev('.panel-heading').addClass('no-border');
            })
            $('#collapseFilters').on('show.bs.collapse', function () {
                $('#collapseFilters').prev('.panel-heading').removeClass('no-border');
            })
        });
    </script>
913
914
915
916
917
918
919
    <script type="text/javascript" src="<c:url value="/explore/i18n.js"/>"></script>
</content>

</body>
</html>