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