NIHVIVO-2343 Get the additional info for a Proxy.
This commit is contained in:
parent
b9bee8f4aa
commit
505fd4456d
2 changed files with 69 additions and 11 deletions
|
@ -29,19 +29,23 @@
|
||||||
|
|
||||||
function proxyInfoElement(template, uri, label, classLabel, imageUrl, existing) {
|
function proxyInfoElement(template, uri, label, classLabel, imageUrl, existing) {
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
|
this.label = label;
|
||||||
|
this.classLabel = classLabel;
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
|
||||||
var existed = existing;
|
var existed = existing;
|
||||||
var removed = false;
|
var removed = false;
|
||||||
|
|
||||||
var content = template.replace(/%uri%/g, uri).replace(/%label%/g, label)
|
|
||||||
.replace(/%classLabel%/g, classLabel).replace(/%imageUrl%/g,
|
|
||||||
imageUrl);
|
|
||||||
|
|
||||||
this.toString = function() {
|
this.toString = function() {
|
||||||
return "proxyInfoElement: " + content;
|
return "proxyInfoElement: " + content;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.element = function() {
|
this.element = function() {
|
||||||
|
var content = template.replace(/%uri%/g, this.uri)
|
||||||
|
.replace(/%label%/g, this.label)
|
||||||
|
.replace(/%classLabel%/g, this.classLabel)
|
||||||
|
.replace(/%imageUrl%/g, this.imageUrl);
|
||||||
|
|
||||||
var element = $("<div name='proxyInfoElement'>" + content + "</div>");
|
var element = $("<div name='proxyInfoElement'>" + content + "</div>");
|
||||||
var removeLink = $("[templatePart='remove']", element).first();
|
var removeLink = $("[templatePart='remove']", element).first();
|
||||||
var removeText = removeLink.text();
|
var removeText = removeLink.text();
|
||||||
|
@ -87,8 +91,8 @@ function proxyInfoElement(template, uri, label, classLabel, imageUrl, existing)
|
||||||
* that are already present in the list and so should be filtered out of
|
* that are already present in the list and so should be filtered out of
|
||||||
* the autocomplete response.
|
* the autocomplete response.
|
||||||
* addProxyInfo -- a function that we can call when an item is selected.
|
* addProxyInfo -- a function that we can call when an item is selected.
|
||||||
* It will take the uri, label, classLabel, and imageUrl, build a
|
* It will take the selection info, build a proxyInfoElement, and add
|
||||||
* proxyInfoElement, and add it to the panel.
|
* it to the panel.
|
||||||
* ----------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------
|
||||||
* Before executing the AJAX request, the query from the parms map will be modified,
|
* Before executing the AJAX request, the query from the parms map will be modified,
|
||||||
* replacing "%term%" with the current search term.
|
* replacing "%term%" with the current search term.
|
||||||
|
@ -142,7 +146,7 @@ function proxyAutocomplete(parms, getProxyInfos, addProxyInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.select = function(event, ui) {
|
this.select = function(event, ui) {
|
||||||
addProxyInfo(ui.item.uri, ui.item.label, ui.item.classLabel, ui.item.imageUrl);
|
addProxyInfo(ui.item);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.target.value = '';
|
event.target.value = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
function proxyProxiesPanel(p) {
|
function proxyProxiesPanel(p) {
|
||||||
var query = "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> \n"
|
var sparqlQueryUrl = '../ajax/sparqlQuery';
|
||||||
|
var matchingProperty = "http://vivoweb.org/ontology/core#scopusId"
|
||||||
|
var urlContext = 'http://localhost:8080/vivo'
|
||||||
|
|
||||||
|
var query = ""
|
||||||
|
+ "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> \n"
|
||||||
+ "PREFIX auth: <http://vitro.mannlib.cornell.edu/ns/vitro/authorization#> \n"
|
+ "PREFIX auth: <http://vitro.mannlib.cornell.edu/ns/vitro/authorization#> \n"
|
||||||
+ "\n"
|
+ "\n"
|
||||||
+ "SELECT DISTINCT ?uri ?label ?externalAuthId \n"
|
+ "SELECT DISTINCT ?uri ?label ?externalAuthId \n"
|
||||||
|
@ -16,6 +21,30 @@ function proxyProxiesPanel(p) {
|
||||||
+ "ORDER BY ASC(?lastName) ASC(?firstName) \n"
|
+ "ORDER BY ASC(?lastName) ASC(?firstName) \n"
|
||||||
+ "LIMIT 25 \n";
|
+ "LIMIT 25 \n";
|
||||||
|
|
||||||
|
var moreInfoQuery = ""
|
||||||
|
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n"
|
||||||
|
+ "PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n"
|
||||||
|
+ "PREFIX p.1: <http://vitro.mannlib.cornell.edu/ns/vitro/public#> \n"
|
||||||
|
+ " \n"
|
||||||
|
+ "SELECT ?uri ?classLabel ?imageUrl \n"
|
||||||
|
+ "WHERE \n"
|
||||||
|
+ "{ \n"
|
||||||
|
+ " ?uri <%matchingProperty%> '%externalAuthId%'. \n"
|
||||||
|
+ " \n"
|
||||||
|
+ " OPTIONAL { \n"
|
||||||
|
+ " ?uri vitro:mostSpecificType ?type. \n"
|
||||||
|
+ " ?type rdfs:label ?classLabel \n"
|
||||||
|
+ " } \n"
|
||||||
|
+ " \n"
|
||||||
|
+ " OPTIONAL { \n"
|
||||||
|
+ " ?uri p.1:mainImage ?imageUri. \n"
|
||||||
|
+ " ?imageUri p.1:thumbnailImage ?thumbUri. \n"
|
||||||
|
+ " ?thumbUri p.1:downloadLocation ?thumbstreamUri. \n"
|
||||||
|
+ " ?thumbstreamUri p.1:directDownloadUrl ?imageUrl. \n"
|
||||||
|
+ " } \n"
|
||||||
|
+ "} \n"
|
||||||
|
+ "LIMIT 1 \n";
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.disableFormInUnsupportedBrowsers = function() {
|
this.disableFormInUnsupportedBrowsers = function() {
|
||||||
|
@ -64,6 +93,29 @@ function proxyProxiesPanel(p) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.getAdditionalInfo = function(info, externalAuthId) {
|
||||||
|
$.ajax({
|
||||||
|
url: sparqlQueryUrl,
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
query: moreInfoQuery.replace("%matchingProperty%", matchingProperty).replace("%externalAuthId%", externalAuthId)
|
||||||
|
},
|
||||||
|
complete: function(xhr, status) {
|
||||||
|
var results = $.parseJSON(xhr.responseText);
|
||||||
|
var parsed = sparqlUtils.parseSparqlResults(results);
|
||||||
|
if (parsed.length > 0) {
|
||||||
|
if ("classLabel" in parsed[0]) {
|
||||||
|
info.classLabel = parsed[0].classLabel;
|
||||||
|
}
|
||||||
|
if ("imageUrl" in parsed[0]) {
|
||||||
|
info.imageUrl = urlContext + parsed[0].imageUrl;
|
||||||
|
}
|
||||||
|
self.displayProxyData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.panel = p;
|
this.panel = p;
|
||||||
this.proxyDataDiv = $("div[name='proxyData']", this.panel).first();
|
this.proxyDataDiv = $("div[name='proxyData']", this.panel).first();
|
||||||
this.addAutoCompleteField = $("input[name='proxySelectorAC']", this.panel).first();
|
this.addAutoCompleteField = $("input[name='proxySelectorAC']", this.panel).first();
|
||||||
|
@ -76,8 +128,10 @@ function proxyProxiesPanel(p) {
|
||||||
return self.proxyData;
|
return self.proxyData;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addProxyInfo = function(uri, label, junk1, junk2) {
|
this.addProxyInfo = function(selection) {
|
||||||
self.proxyData.unshift(new proxyInfoElement(self.templateHtml, uri, label, "", "", false));
|
var info = new proxyInfoElement(self.templateHtml, selection.uri, selection.label, "", "", false)
|
||||||
|
self.proxyData.unshift(info);
|
||||||
|
self.getAdditionalInfo(info, selection.externalAuthId)
|
||||||
self.displayProxyData();
|
self.displayProxyData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +139,7 @@ function proxyProxiesPanel(p) {
|
||||||
var parms = {
|
var parms = {
|
||||||
query: query,
|
query: query,
|
||||||
model: "userAccounts",
|
model: "userAccounts",
|
||||||
url: '../ajax/sparqlQuery'
|
url: sparqlQueryUrl
|
||||||
};
|
};
|
||||||
this.addAutoCompleteField.autocomplete(new proxyAutocomplete(parms, this.getProxyInfos, this.addProxyInfo));
|
this.addAutoCompleteField.autocomplete(new proxyAutocomplete(parms, this.getProxyInfos, this.addProxyInfo));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue