explore2.jsp 47.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!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>
Maxim's avatar
Maxim committed
16
17
    <script type="text/javascript" src="<c:url value="/html/1/js/browse.js" />"></script>
    <script type="text/javascript" src="<c:url value="/explore/i18n.js"/>"></script>
18
19
</head>

Taisiya Glushko's avatar
Taisiya Glushko committed
20
<body class="explore-page">
21
22
23
24
<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">
25

Maxim's avatar
Maxim committed
26
27
28
29
30
31
32
33
        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content"></div>
            </div>
        </div>
        <!--End modal-->

34
35
        <div id="loading-popup-id" class="loading-popup">
            <div class="loading-popup-content">
Matija Obreza's avatar
Matija Obreza committed
36
                <p><spring:message code="prompt.loading-data" /></p>
37
38
39
40
41
42
            </div>
        </div>

        <div id="error-loading-popup-id" class="error-loading-popup">
            <div class="error-loading-popup-content">
                <span class="close"><span class="glyphicon glyphicon-remove"></span></span>
Matija Obreza's avatar
Matija Obreza committed
43
                <p><spring:message code="prompt.loading-data-failed" /></p>
44
45
46
            </div>
        </div>

47
        <div id="dialog" class="row"></div>
48
        <div class="">
49
            <!--Filters-->
Maxim's avatar
Maxim committed
50
            <filters:filter-list availableFilters="${availableFilters}" filters="${filters}"
Maxim's avatar
Maxim committed
51
52
                                 additionalFilters="${additionalFilters}" appliedFilters="${appliedFilters}"
                                 crops="${crops}" crop="${crop}"/>
Maxim's avatar
Maxim committed
53
            <!--List-->
Taisiya Glushko's avatar
Taisiya Glushko committed
54
            <div class="col-lg-10 col-md-9 col-sm-9 col-xs-12 main-col-header">
55
56
57
                <div class="nav-header clearfix">
                    <!-- Links -->
                    <div class="pull-right list-view-controls">
Maxim's avatar
Maxim committed
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
                        <div class="btn-group" id="displayColumns">
                            <ul class="nav nav-pills">
                                <li class="dropdown form-horizontal" id="selectColumns">
                                    <a class="dropdown-toggle btn btn-default" href="#">
                                        <b class="glyphicon glyphicon-th-list"></b>
                                        <spring:message code="columns.add"/>
                                    </a>
                                    <ul class="dropdown-menu view-columns">
                                        <li>
                                            <a id="columnsApply" style="margin-bottom: 10px" type="submit"
                                               + class="btn btn-default"><spring:message code="columns.apply"/>
                                            </a>
                                        </li>
                                        <li class="dropdown-header">
                                            <spring:message code="columns.availableColumns"/>
                                        </li>
                                        <c:forEach items="${availableColumns}" var="columnName">
                                            <li>
                                                <label class="column-enable" for="cb-${columnName}">
                                                    <c:choose>
                                                        <c:when test="${selectedColumns.contains(columnName)}">
                                                            <input id="cb-${columnName}" type="checkbox"
                                                                   + checked="checked" name="${columnName}"/>
                                                        </c:when>
                                                        <c:otherwise>
                                                            <input id="cb-${columnName}" type="checkbox"
                                                                   + name="${columnName}"/>
                                                        </c:otherwise>
                                                    </c:choose>
                                                    <spring:message code="accession.${columnName}"/>
                                                </label>
                                            </li>
                                        </c:forEach>
                                    </ul>
                                </li>
                            </ul>
                        </div>

96
                        <div class="btn-group" id="shareLink">
Taisiya Glushko's avatar
Taisiya Glushko committed
97
                            <a type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
Maxim's avatar
Maxim committed
98
99
100
                               aria-haspopup="true" aria-expanded="false" id="menuShareLink">
                                <span class="glyphicon glyphicon-share"></span>
                                <span><spring:message code="share.link"/></span>
101
                                <span class="caret"></span>
Taisiya Glushko's avatar
Taisiya Glushko committed
102
                            </a>
103
104
105
106
107
108
109
110
111
                            <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>

Maxim's avatar
Maxim committed
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

                        <div class="btn-group" id="downloadLink"
                             <c:if test="${pagedData.totalElements ge 200000}">style="display: none"</c:if>>

                            <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>
                        </div>

149
                        <a class="btn btn-default" id="overviewLink"
Maxim's avatar
Maxim committed
150
                           style=${(empty additionalFilters)? "'display: inline'": "'display: none'" }
Maxim's avatar
Maxim committed
151
152
153
154
                           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>
155
156
                        <a class="btn btn-default" id="mapLink"
                           href="<c:url value="/explore/map"><c:param name="filter">${jsonFilter}</c:param></c:url>"><span
Maxim's avatar
Maxim committed
157
158
159
                                class="glyphicon glyphicon-globe"></span>
                            <span><spring:message code="maps.view-map"/></span>
                        </a>
160
161
162
163
164
                    </div>
                    <!--Pagination-->
                    <filters:pagination pagedData="${pagedData}" jsonFilter="${jsonFilter}"/>
                </div>
            </div>
Taisiya Glushko's avatar
Taisiya Glushko committed
165
            <div id="content-area" class="col-lg-10 col-md-9 col-sm-9 col-xs-12 explore-table">
166
167
168
                <table class="accessions">
                    <thead>
                    <tr>
Taisiya Glushko's avatar
Taisiya Glushko committed
169
170
                        <td class="idx-col"><p></p></td>
                        <td><p></p></td>
171
                        <td><p><spring:message code="accession.accessionName" /></p></td>
Taisiya Glushko's avatar
Taisiya Glushko committed
172
                        <c:forEach items="${selectedColumns}" var="column" varStatus="i">
173
                            <c:choose>
Taisiya Glushko's avatar
Taisiya Glushko committed
174
                                <c:when test="${i.count eq 1}">
175
176
                                    <td><p><spring:message code="accession.${column}"/></p></td>
                                </c:when>
Taisiya Glushko's avatar
Taisiya Glushko committed
177
                                <c:when test="${i.count eq 2}">
178
179
                                    <td class="notimportant hidden-xs"><p><spring:message code="accession.${column}"/></p></td>
                                </c:when>
Taisiya Glushko's avatar
Taisiya Glushko committed
180
181
182
                                <c:when test="${column eq 'taxonomy.species'}">
                                    <td class="notimportant hidden-sm hidden-xs"><p><spring:message code="accession.${column}"/></p></td>
                                </c:when>
183
184
185
186
187
188
189
190
191
192
193
                                <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
194
                            <td><span class="sel" x-aid="${accession.id}" title="<spring:message code="selection.checkbox" />"></span></td>
195
                            <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
196
                            <c:forEach items="${selectedColumns}" var="col" varStatus="i">
197
198
                                <c:choose>
                                    <c:when test="${col eq 'taxonomy.sciName'}">
Matija Obreza's avatar
Matija Obreza committed
199
                                        <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 escapeXml="false" value="${accession.taxonomy.sciNameHtml}"/></span></p></td>
200
201
                                    </c:when>
                                    <c:when test="${col eq 'orgCty'}">
Taisiya Glushko's avatar
Taisiya Glushko committed
202
                                        <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>
203
                                    </c:when>
204
205
206
                                    <c:when test="${col eq 'cropName'}">
                                        <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="${accession.cropName}"/></p></td>
                                    </c:when>
207
                                    <c:when test="${col eq 'sampStat'}">
Taisiya Glushko's avatar
Taisiya Glushko committed
208
                                        <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>
209
                                    </c:when>
210
211
212
213
214
215
                                    <c:when test="${col eq 'acceName'}">
                                        <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="${accession.acceName}"/></p></td>
                                    </c:when>
                                    <c:when test="${col eq 'donorNumb'}">
                                        <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="${accession.donorNumb}"/></p></td>
                                    </c:when>
216
                                    <c:when test="${col eq 'institute.code'}">
Taisiya Glushko's avatar
Taisiya Glushko committed
217
                                        <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
218
219
220
                                                value="${accession.institute.code}"/></a></p></td>
                                    </c:when>
                                    <c:when test="${col eq 'taxonomy.genus'}">
Matija Obreza's avatar
Matija Obreza 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><span dir="ltr" class="sci-name"><i><c:out value="${accession.taxonomy.genus}"/></i></span></p></td>
222
223
                                    </c:when>
                                    <c:when test="${col eq 'taxonomy.species'}">
Matija Obreza's avatar
Matija Obreza committed
224
                                        <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"><i><c:out value="${accession.taxonomy.species}"/></i></span></p></td>
225
226
                                    </c:when>
                                    <c:when test="${col eq 'taxonomy.subtaxa'}">
Matija Obreza's avatar
Matija Obreza committed
227
                                        <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"><i><c:out value="${accession.taxonomy.subtaxa}"/></i></span></p></td>
228
229
230
                                    </c:when>
                                    <c:when test="${col eq 'crops'}">
                                        <c:if test="${fn:length(accession.crops) == 0}">
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>"></td>
232
233
                                        </c:if>
                                        <c:forEach items="${jspHelper.getCrops(accession.crops)}" var="crop">
Taisiya Glushko's avatar
Taisiya Glushko committed
234
                                            <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
235
236
237
238
                                                    value="${crop.getName(pageContext.response.locale)}"
                                                    /></a></p></td>
                                        </c:forEach>
                                    </c:when>
239
240
241
                                    <c:when test="${col eq 'pdci.score'}">
                                        <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><fmt:formatNumber value="${accession.pdciScore}"/></p></td>
                                    </c:when>
242
243
244
245
246
247
248
249
250
251
252
253
254
255
                                    <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
256
257
258
259
260
261
262
263
264
                    <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>
265
266
267
268
269
270
271
272
273
274
                                <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
275
276
277
278
                                </li>
                            </ul>
                        </nav>
                    </div>
279
            </div>
Taisiya Glushko's avatar
Taisiya Glushko committed
280
281
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12"></div>

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

286
287
288
289
290
291
292
293
294

<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
295
296
        var cropNames = [];

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

        var headerSelects = [];

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

        var lastWindowWidth;

305
306
        $(document).ready(function () {

Maxim's avatar
Maxim committed
307
308
309
310
311
312
313
314
315
316
            if (jsonData.crops != null && jsonData.crops.length > 0) {
                $("#panel_additional_id").show();
            }

            $.each(jsonData, function(key) {
                if(key.startsWith('gm:')) {
                    $("#panel_additional_id").show();
                }
            });

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

329
330
331
332
333
334
            $("body").on("keypress", ".string-type", function (e) {
                if (e.keyCode == 13) {
                    var btn = $(this).parent().find("button");
                    var selectedValue = $(this).parent().parent().find(".like-switcher option:selected").val();

                    if (selectedValue == "like") {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
335
                        GenesysFilter.filterLike(btn, jsonData, BrowseUtil.i18nFilterMessage);
336
337
338
339
340
341
342
343
                    } else {
                        GenesysFilter.filterAutocomplete(btn, jsonData);
                    }
                }
            });

            $("body").on("click", ".filter-auto", function () {
                if (jsonData[$(this).attr("i-key")] === undefined) {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
344
                    BrowseUtil.enableFilter(this, jsonData);
345
346
347
348
                }

                var selectedValue = $(this).parent().parent().parent().find(".like-switcher option:selected").val();
                if (selectedValue == "like") {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
349
                    GenesysFilter.filterLike($(this), jsonData, BrowseUtil.i18nFilterMessage);
350
351
352
353
354
                } else {
                    GenesysFilter.filterAutocomplete($(this), jsonData);
                }
            });

Maxim's avatar
Maxim committed
355
356
            $("body").on("click", ".filter-list", function () {
                if (jsonData[$(this).attr("i-key")] === undefined) {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
357
                    BrowseUtil.enableFilter(this, jsonData);
Maxim's avatar
Maxim committed
358
359
                }
                var text = $(this).parent().text();
Maxim's avatar
Maxim committed
360
361
362
                var text2 = $.trim(text);
                var text3 = text2.substring(0, text2.indexOf('('));
                GenesysFilter.filterList($(this), jsonData, text3);
Maxim's avatar
Maxim committed
363
364
            });

365
366
            $("body").on("click", ".filter-range", function () {
                if (jsonData[$(this).attr("i-key")] === undefined) {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
367
                    BrowseUtil.enableFilter(this, jsonData);
368
                }
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
369
                GenesysFilter.filterRange($(this), jsonData, BrowseUtil.i18nFilterMessage);
370
371
372
373
            });

            $("body").on("click", ".filter-bool", function () {
                if (jsonData[$(this).attr("i-key")] === undefined) {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
374
                    BrowseUtil.enableFilter(this, jsonData);
375
                }
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
376
                GenesysFilter.filterBoolean($(this), jsonData, BrowseUtil.i18nFilterMessage);
377
378
            });

379
            $('body').on('click', '.filter-crop', function () {
380
381
382
383
                GenesysFilter.filterCrop($(this), jsonData);
            });

            $("body").on("click", ".applyBtn", function () {
Maxim's avatar
Maxim committed
384
385
386
387
388
389
390
                $(this).parent().parent().find("button.filter-auto, button.filter-range").trigger("click");
                applyFilters();
                BrowseUtil.applySuggestions(jsonData, messages);
            });

            $("body").on("click", ".removeFilterBtn", function () {
                var className = $(this).parent().parent().attr("class");
Maxim's avatar
Maxim committed
391
392
                var filterId = "#panel_" + className.replace(" col-xs-12", "");
                var filter = className.replace("gm_", "gm:").replace("_id", "").replace(" col-xs-12", "");
Maxim's avatar
Maxim committed
393
394
395
396
397
398
399
400
401
402
403

                delete jsonData[filter];
                $(filterId).remove();

                if (!isExistAdditionalFilters()) {
                    $("#overviewLink").show();

                    if (jsonData.crops == null || jsonData.crops.length == 0) {
                        $("#panel_additional_id").hide();
                    }
                }
404

405
                applyFilters();
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
406
                BrowseUtil.applySuggestions(jsonData, messages);
407
408
            });

Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
409
            BrowseUtil.applySuggestions (jsonData, messages);
410
411
412
413
414
415
416
417
418
419
420

            $("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();
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
421
                BrowseUtil.applySuggestions(jsonData, messages);
422
423

                $(this).remove();
Maxim's avatar
Maxim committed
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
                $('input[i-key="' + key + '"][value="' + value + '"]').prop('checked', false);

                if (jsonData["crops"].length === 0) {
                    delete jsonData["crops"];
                    $("#panel_additional_id").hide();
                }
            });

            $("body").on("click", ".addFiltersBtn", function () {
                $.ajax("<c:url value="/modal" />", {
                    type: 'GET',
                    data: "shortName=" + jsonData.crops,
                    success: function (data) {
                        $(".modal-content").empty();
                        $(".modal-content").append(data);

                        for (var additionalFilterName in jsonData) {
                            $(".modal-body .filter-block label > input[value='" + additionalFilterName + "']").prop("checked", true);
                        }
                    },
                    error: function (error) {
                        console.log(error);
                    }
                });
            });

            $("body").on("click", ".additional", function () {
                var id = $(this).attr("id");
                var filterId = "#panel_" + id.replace("_id", "");
                var filter = id.replace("gm_", "gm:").replace("_id", "");

                if ($(this).is(":checked")) {
                    GenesysFilterUtil.appendFilter(filter, filterId, jsonData);
                    $("#overviewLink").hide();
                }
                else {
                    delete jsonData[filter];
                    $(filterId).remove();
                    $("#overviewLink").show();
                }
464
465
466
467
468
469
470
471
            });

            $("#menuShareLink").on("click", function () {
                if ($('#shortLink').val() === '') {
                    $.ajax({
                        type: 'POST',
                        url: '/explore/shorten-url',
                        data: {
Maxim's avatar
Maxim committed
472
                            'page': 1, 'filter': JSON.stringify(jsonData), browser: "explorer"
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
                        },
                        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">
521
                <c:set var="normalizedAppliedFilter" value="${appliedFilter.key.replace(':', '_')}"/>
Maxim's avatar
Maxim committed
522
523
524
525
                var collapseDiv = $(this).find($("div[id*='${normalizedAppliedFilter}']"));
                if (collapseDiv[0] !== undefined) {
                    $(this).collapse("show");
                }
526
527
                </c:forEach>
            });
Maxim's avatar
Maxim committed
528
529
530
531

            $('li#selectColumns a').on('click', function (event) {
                event.preventDefault();
                $(this).parent().toggleClass('open');
532
            });
Taisiya Glushko's avatar
Taisiya Glushko committed
533

Maxim's avatar
Maxim committed
534
535
536
537
538
539
            $('#columnsApply').on('click', function () {
                var columns = [];
                [].forEach.call($('.view-columns li'), function (el) {
                    if ($(el).find('input:checkbox').is(':checked')) {
                        columns.push($(el).find('input:checkbox').prop('name'));
                    }
540
                });
Maxim's avatar
Maxim committed
541
542
543
                var filter = JSON.stringify(jsonData);
                var url = '<c:url value="/explore" />' + '?filter=' + filter + "&columns=" + columns.toString();
                window.location.href = encodeURI(url);
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
            });

            $(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);
                        }
                    });
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
563
                    BrowseUtil.applySuggestions(jsonData, messages);
564
565
566
567
568
569
570
571
572
573
574
575
576
577
                } else {
                    location.reload();
                }
            });

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

            $.ajax({
                url: "/explore/booleanSuggestions",
                method: 'get',
                data: {
                    filter: JSON.stringify(jsonData)
                },
                success: function (response) {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
578
                    BrowseUtil.renderBooleanSuggestions(response);
579
580
                }
            });
Taisiya Glushko's avatar
Taisiya Glushko committed
581

Maxim's avatar
Maxim committed
582
583
584
585
586
587
588
589
590
591
            function isExistAdditionalFilters() {
                for(var filter in jsonData) {
                    if(filter.toString().startsWith("gm:")) {
                        return true;
                    }
                }
                return false;
            }


Taisiya Glushko's avatar
Taisiya Glushko committed
592
593
594
595
596
597
598
599
600
            function restoreHeaders() {
                $.each($("select.column-changer"), function () {
                    var index = $(this).attr("x-id");
                    var oldHeader = $(headersCopy[index]).html();
                    $(this).parent().html(oldHeader);
                });
            }

            function resize() {
601
                if (window.innerWidth < 992) {
Taisiya Glushko's avatar
Taisiya Glushko committed
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
                    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);
                    }
                }

657
                lastWindowWidth = window.innerWidth;
Taisiya Glushko's avatar
Taisiya Glushko committed
658
659
660
661
662
663
664
            }

            resize();

            $(window).resize(function () {
                resize();
            });
665
666
        });

Maxim's avatar
Maxim committed
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
        function applyFilters (path) {
            document.getElementById('loading-popup-id').style.display = "block";
            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);
                    document.getElementById('loading-popup-id').style.display = "none";
                    $.each($("select.column-changer"), function () {
                        $(this).change();
                    });
                },
                error: function () {
                    document.getElementById('error-loading-popup-id').style.display = "block";
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
                }
            });
        }

        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) {
Maxim's avatar
Maxim committed
718
            $("#shortLink").val('');
719
720
721
722
723
724
725
726
727
728
729
730
731
732
            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))));
        }

Maxim's avatar
Maxim committed
733

734
735
736
        function renderTableBody(pagedData) {
            $("table").find("tbody").remove();
            var tbody = $("<tbody/>");
Taisiya Glushko's avatar
Taisiya Glushko committed
737
            rowsCopy = [];
738
739
740
741
742
743
744
745
746
            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
747
                $("<span/>", {
748
749
750
                    'class': "sel",
                    'x-aid': pagedData.content[i].id,
                    'title': "<spring:message code="selection.checkbox" />"
Taisiya Glushko's avatar
Taisiya Glushko committed
751
                }).appendTo($("<td/>").appendTo(row));
752
753
754
755
                $("<b/>", {
                    text: pagedData.content[i].acceNumb
                }).appendTo(
                $("<a/>", {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
756
                    href: '<c:url value="/acn/id/" />' + pagedData.content[i].id
757
758
                }).appendTo($("<p/>").appendTo($("<td/>").appendTo(row))));

Taisiya Glushko's avatar
Taisiya Glushko committed
759
                <c:forEach items="${selectedColumns}" var="col" varStatus="i">
760
761
762
763
764
                    <c:choose>
                        <c:when test="${col eq 'taxonomy.sciName'}">
                            $("<span/>", {
                                dir: 'ltr',
                                'class': 'sci-name',
Matija Obreza's avatar
Matija Obreza committed
765
766
767
                                html: pagedData.content[i].taxonomy.sciNameHtml
                            }).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)));
768
769
770
771
772
                        </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
773
                                'class': "notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"
774
775
                            }).appendTo(row));
                        </c:when>
776
777
778
779
780
781
782
783
784
785
786
787
788
789
                        <c:when test="${col eq 'acceName'}">
                        $("<p/>", {
                          	text: pagedData.content[i].acceName
                        }).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>"
                        }).appendTo(row));
                    		</c:when>
                        <c:when test="${col eq 'donorNumb'}">
                        $("<p/>", {
                          	text: pagedData.content[i].donorNumb
                        }).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>"
                        }).appendTo(row));
                    		</c:when>
790
791
792
793
                        <c:when test="${col eq 'sampStat'}">
                            $("<p/>", {
                                text: messages["accession.sampleStatus." + pagedData.content[i].sampStat]
                            }).appendTo($("<td/>", {
Taisiya Glushko's avatar
Taisiya Glushko committed
794
                                'class': "notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"
795
796
797
798
                            }).appendTo(row));
                        </c:when>
                        <c:when test="${col eq 'institute.code'}">
                            $("<a/>", {
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
799
                                href: '<c:url value="/wiews/" />' + pagedData.content[i].institute.code,
800
                                text: pagedData.content[i].institute.code
Taisiya Glushko's avatar
Taisiya Glushko committed
801
802
                            }).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>"
803
804
805
                            }).appendTo(row)));
                        </c:when>
                        <c:when test="${col eq 'taxonomy.genus'}">
Matija Obreza's avatar
Matija Obreza committed
806
807
                        	$("<i/>", { text: pagedData.content[i].taxonomy.genus })
                            .appendTo($("<span/>", {
808
                                dir: "ltr",
Matija Obreza's avatar
Matija Obreza committed
809
                                'class': "sci-name"
Taisiya Glushko's avatar
Taisiya Glushko committed
810
811
                            }).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>"
Matija Obreza's avatar
Matija Obreza committed
812
                            }).appendTo(row))));
813
814
                        </c:when>
                        <c:when test="${col eq 'taxonomy.species'}">
Matija Obreza's avatar
Matija Obreza committed
815
816
817
818
819
	                    	$("<i/>", { text: pagedData.content[i].taxonomy.species })
	                        .appendTo($("<span/>", {
	                            dir: "ltr",
	                            'class': "sci-name"
	                        }).appendTo($("<p></p>").appendTo($("<td/>", {
Taisiya Glushko's avatar
Taisiya Glushko committed
820
                                'class': "notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"
Matija Obreza's avatar
Matija Obreza committed
821
                            }).appendTo(row))));
822
823
                        </c:when>
                        <c:when test="${col eq 'taxonomy.subtaxa'}">
Matija Obreza's avatar
Matija Obreza committed
824
825
826
827
828
	                        $("<i/>", { text: pagedData.content[i].taxonomy.subtaxa })
	                        .appendTo($("<span/>", {
	                            dir: "ltr",
	                            'class': "sci-name"
	                        }).appendTo($("<p></p>").appendTo($("<td/>", {
Taisiya Glushko's avatar
Taisiya Glushko committed
829
                                'class': "notimportant <c:if test='${i.count ge 2}'>hidden-xs</c:if> <c:if test='${i.count gt 2}'>hidden-sm</c:if>"
Matija Obreza's avatar
Matija Obreza committed
830
                            }).appendTo(row))));
831
832
                        </c:when>
                        <c:when test="${col eq 'crops'}">
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
833
                            var cropNamesTd = $("<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>"
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
835
836
837
838
839
840
841
                            });
                            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);
842
843
                                });
                            }
Aleksandr Sharaban's avatar
Aleksandr Sharaban committed
844
                            cropNamesTd.appendTo(row);
845
                        </c:when>
846
847
848
849
850
851
852
853
854
                        <c:when test="${col eq 'cropName'}">
                        $("<span/>", {
                            dir: "ltr",
                            'class': "sci-name",
                            text: pagedData.content[i].cropName
                        }).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>"
                        }).appendTo(row)));
                    	</c:when>
855
856
857
858
859
860
861
                    	 <c:when test="${col eq 'pdci.score'}">
	                    	 $("<span/>", {
	                         text: ''+pagedData.content[i].pdciScore
		                     }).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>"
		                     }).appendTo(row)));
                   			</c:when>
Maxim's avatar
Maxim committed
862
863
864
865
866
867
868
869
                        <c:when test="${col eq 'geo.latitudeAndLongitude'}">
                        var geoLatitude = "";
                        var geoLongitude = "";
                        if (pagedData.content[i].geo != null) {
                            geoLatitude = pagedData.content[i].geo.latitude;
                            geoLongitude = pagedData.content[i].geo.longitude;
                        }
                        var geoText = "";
Maxim's avatar
Maxim committed
870
                        if (geoLatitude !== null && geoLatitude.toString() != "") {
Maxim's avatar
Maxim committed
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
                            geoText = geoLatitude + ", " + geoLongitude
                        }
                        $("<span/>", {
                            dir: "ltr",
                            'class': "sci-name",
                            text: geoText
                        }).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>"
                        }).appendTo(row)));
                        </c:when>
                        <c:when test="${col eq 'coll.collMissId'}">
                        var collMissIdText = "";
                        if (pagedData.content[i].coll != null) {
                            if (pagedData.content[i].coll.collMissId != null) {
                                collMissIdText = pagedData.content[i].coll.collMissId;
                            }
                        }
                        $("<span/>", {
                            dir: "ltr",
                            'class': "sci-name",
                            text: collMissIdText
                        }).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>"
                        }).appendTo(row)));
                        </c:when>
896
897
898
899
                    </c:choose>
                </c:forEach>

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

            tbody.appendTo($("table"));
        }
905

Taisiya Glushko's avatar
Taisiya Glushko committed
906
    </script>
907
908
909
910
911
</content>
</body>
</html>