|
112 | 112 |
|
113 | 113 | $.post("${createLink(controller: "editor", action: 'editRecord')}", thisFormData, function(data, textStatus, jqXHR) {
|
114 | 114 | $(modal).modal('hide');
|
115 |
| - alert(jqXHR.responseText); |
116 |
| - window.location.reload(true); |
| 115 | + var idItem = thisFormData.find(o=>o.name === "id"); |
| 116 | + var rawScientificName = thisFormData.find(o=>o.name === "rawScientificName")?.value; |
| 117 | + if (idItem) { |
| 118 | + var id = idItem.value; |
| 119 | + var row = $("tr#row_"+ id); |
| 120 | + //Only change rawScientificName, and KVP |
| 121 | + thisFormData.forEach(item=>{ |
| 122 | + var td = row.find("td."+item.name); |
| 123 | + if (td.length > 0) { |
| 124 | + td.html("<div>"+ item.value +"</div>"); |
| 125 | + } |
| 126 | + }); |
| 127 | + |
| 128 | + var speciesUrl = "${createLink(controller: "ws", action: 'findSpeciesByName')}" |
| 129 | + $.get(speciesUrl,{ name: rawScientificName, id:id}, function( result ) { |
| 130 | + var guid = result.guid; |
| 131 | + if (guid === "" || guid === null || guid === undefined){ |
| 132 | + //raw name |
| 133 | + var google = "http://google.com/search?q=" + rawScientificName; |
| 134 | + var biocache = "${grailsApplication.config.biocache.baseURL}/occurrences/search?q="+rawScientificName; |
| 135 | + var guidText= rawScientificName + "<br>(unmatched - try <a href='" + google +"' target='google' class='btn btn-primary btn-xs'>Google</a>," + |
| 136 | + "<a href='" + biocache +" target='biocache' class='btn btn-success btn-xs'>${message(code:'generic.lists.button.Occurrences.label', default:'Occurrences')}</a>)"; |
| 137 | +
|
| 138 | + row.find("td.rawScientificName").html(guidText); |
| 139 | + row.find("td.matchedName").html(result.matchedName); |
| 140 | + row.find("td.imageUrl").html(""); |
| 141 | + } else { |
| 142 | + var bie = "<a href=${bieUrl}/species/" + guid + " title='click to view species page'>"+result.matchedName + "</a>" |
| 143 | + row.find("td.matchedName").html(bie) |
| 144 | +
|
| 145 | + if(result.imageUrl === "" || result.imageUrl === null || result.imageUrl === undefined) { |
| 146 | + row.find("td.imageUrl").html(""); |
| 147 | + } else { |
| 148 | + var image_url ="<a href=${bieUrl}/species/"+guid+" title='click to view species page'><img src="+result.imageUrl+" class='smallSpeciesImage'/></a>"; |
| 149 | + row.find("td.imageUrl").html(image_url); |
| 150 | + } |
| 151 | + } |
| 152 | +
|
| 153 | + row.find("td.author").text(result.author); |
| 154 | + var terms = ["commonName", "family","kingdom"]; |
| 155 | + terms.forEach( function(item) { |
| 156 | + var td = row.find("td."+item); |
| 157 | + if ( td.length>0 ) { |
| 158 | + td.text(result[item]); |
| 159 | + td[0].id= td[0].id.substring(0,3) + guid; |
| 160 | + } |
| 161 | + }) |
| 162 | + }) |
| 163 | + } |
117 | 164 | }).error(function(jqXHR, textStatus, error) {
|
118 | 165 | alert("An error occurred: " + error + " - " + jqXHR.responseText);
|
119 | 166 | $(modal).modal('hide');
|
|
942 | 989 | </tr>
|
943 | 990 | </thead>
|
944 | 991 | <tbody>
|
| 992 | +%{-- <div v-scope="SpeciesList(JSON.parse('${json_results}'))" @vue:mounted="mounted"></div>--}% |
| 993 | +
|
945 | 994 | <g:each var="result" in="${results}" status="i">
|
946 | 995 | <g:set var="recId" value="${result.id}"/>
|
947 | 996 | %{-- <g:set var="bieTitle">${message(code:'public.lists.view.table.tooltip03', default:'species page for')} <i>${result.rawScientificName}</i></g:set>--}%
|
|
981 | 1030 | ${result.matchedName}
|
982 | 1031 | </g:else>
|
983 | 1032 | </td>
|
984 |
| - <td id="img_${result.guid}"> |
| 1033 | + <td id="img_${result.guid}" class="imageUrl"> |
985 | 1034 | <g:if test="${result.imageUrl}">
|
986 | 1035 | <a href="${bieUrl}/species/${result.guid}" title="click to view species page"><img
|
987 | 1036 | src="${result.imageUrl}"
|
988 | 1037 | class="smallSpeciesImage"/></a>
|
989 | 1038 | </g:if>
|
990 | 1039 | </td>
|
991 |
| - <td>${result.author}</td> |
992 |
| - <td id="cn_${result.guid}">${result.commonName}</td> |
993 |
| - <td id="fm_${result.guid}">${result.family}</td> |
994 |
| - <td id="kn_${result.guid}">${result.kingdom}</td> |
| 1040 | + <td class="author">${result.author}</td> |
| 1041 | + <td id="cn_${result.guid}" class="commonName" >${result.commonName}</td> |
| 1042 | + <td id="fm_${result.guid}" class="family">${result.family}</td> |
| 1043 | + <td id="kn_${result.guid}" class="kingdom">${result.kingdom}</td> |
995 | 1044 | <g:each in="${keys}" var="key">
|
996 | 1045 | <g:set var="kvp" value="${result.kvpValues.find { it.key == key }}"/>
|
997 | 1046 | <g:set var="val" value="${kvp?.vocabValue ?: kvp?.value}"/>
|
998 |
| - <td class="kvp ${val?.length() > 35 ? 'scrollWidth' : ''}"><div>${val}</div> |
| 1047 | + <td class="kvp ${key} ${val?.length() > 35 ? 'scrollWidth' : ''}"><div>${val}</div> |
999 | 1048 | </td>
|
1000 | 1049 | </g:each>
|
1001 | 1050 | </tr>
|
|
1133 | 1182 | });
|
1134 | 1183 | });
|
1135 | 1184 | </asset:script>
|
| 1185 | +
|
| 1186 | +<script type="module"> |
| 1187 | + import { createApp } from 'https://unpkg.com/petite-vue?module' |
| 1188 | + function SpeciesList(data) { |
| 1189 | + return { |
| 1190 | + $template: '#display-species-list', |
| 1191 | + speciesList: data, |
| 1192 | + mounted() { |
| 1193 | +
|
| 1194 | + }, |
| 1195 | +
|
| 1196 | + click() { |
| 1197 | + alert("i am vue") |
| 1198 | + }, |
| 1199 | +
|
| 1200 | + save() { |
| 1201 | + alert("saved") |
| 1202 | + } |
| 1203 | +
|
| 1204 | + } |
| 1205 | + } |
| 1206 | +
|
| 1207 | + createApp({ |
| 1208 | + SpeciesList |
| 1209 | + }).mount() |
| 1210 | +</script> |
| 1211 | +<template id="display-species-list"> |
| 1212 | +
|
| 1213 | + <table> |
| 1214 | + <tr v-for="(species, i) in speciesList" :id="'row_'+species.id"> |
| 1215 | + <td class="action"> |
| 1216 | + <div class="btn-group action-btn-group-width" role="group"> |
| 1217 | + <a class="btn btn-default btn-xs viewRecordButton" href="#viewRecord" |
| 1218 | + title="${message(code:'public.lists.view.table.tooltip01', default:'view record')}" :data-id="species.id"><i |
| 1219 | + class="glyphicon glyphicon-info-sign"></i></a> |
| 1220 | + <g:if test="${userCanEditData}"> |
| 1221 | + <a class="btn btn-default btn-xs" href="#" title="${message(code:'public.lists.view.table.tooltip04', default:'edit')}" |
| 1222 | + :data-remote-url="'${createLink(controller: 'editor', action: 'editRecordScreen')}?id=' + species.id" |
| 1223 | + :data-target="'#editRecord_'+species.id" data-toggle="modal"><i |
| 1224 | + class="glyphicon glyphicon-pencil"></i></a> |
| 1225 | + <a class="btn btn-default btn-xs" href="#" title="${message(code:'public.lists.view.table.tooltip05', default:'delete')}" |
| 1226 | + :data-target="'#deleteRecord_'+species.id" data-toggle="modal"><i |
| 1227 | + class="glyphicon glyphicon-trash"></i></a> |
| 1228 | + </g:if> |
| 1229 | + </div> |
| 1230 | + </td> |
| 1231 | + <td class="rawScientificName"> |
| 1232 | + {{species.rawScientificName}} |
| 1233 | + <p v-if="species.guid == null"> |
| 1234 | + <br/>(unmatched - try <a |
| 1235 | + :href="'http://google.com/search?q=' + species.rawScientificName.trim()}" |
| 1236 | + target="google" class="btn btn-primary btn-xs">Google</a>, |
| 1237 | + <a href="'${grailsApplication.config.biocache.baseURL}/occurrences/search?q='+species.rawScientificName.trim()" |
| 1238 | + target="biocache" class="btn btn-success btn-xs">${message(code:'generic.lists.button.Occurrences.label', default:'Occurrences')}</a>) |
| 1239 | + </p> |
| 1240 | + </td> |
| 1241 | + </tr> |
| 1242 | + </table> |
| 1243 | +
|
| 1244 | +</template> |
| 1245 | +
|
| 1246 | +
|
1136 | 1247 | </body>
|
1137 | 1248 | </html>
|
0 commit comments