2011-10-27 14:49:48 +00:00
|
|
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
|
|
|
|
|
|
function proxyProxiesPanel(p) {
|
2011-10-27 21:55:41 +00:00
|
|
|
var query = ""
|
|
|
|
+ "PREFIX fn: <http://www.w3.org/2005/xpath-functions#> \n"
|
2011-10-27 20:50:47 +00:00
|
|
|
+ "PREFIX auth: <http://vitro.mannlib.cornell.edu/ns/vitro/authorization#> \n"
|
|
|
|
+ "\n"
|
|
|
|
+ "SELECT DISTINCT ?uri ?label ?externalAuthId \n"
|
|
|
|
+ "WHERE { \n"
|
|
|
|
+ " ?uri a auth:UserAccount ; \n"
|
|
|
|
+ " auth:firstName ?firstName ; \n"
|
|
|
|
+ " auth:lastName ?lastName . \n"
|
|
|
|
+ " LET ( ?label := fn:concat(?lastName, ', ', ?firstName) )"
|
|
|
|
+ " OPTIONAL { ?uri auth:externalAuthId ?externalAuthId } \n"
|
|
|
|
+ " FILTER (REGEX(?label, '^%term%', 'i')) \n"
|
|
|
|
+ "} \n"
|
|
|
|
+ "ORDER BY ASC(?lastName) ASC(?firstName) \n"
|
|
|
|
+ "LIMIT 25 \n";
|
|
|
|
|
2011-10-27 21:55:41 +00:00
|
|
|
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";
|
|
|
|
|
2011-10-27 14:49:48 +00:00
|
|
|
var self = this;
|
|
|
|
|
2011-10-30 17:15:53 +00:00
|
|
|
var excludedUris = [proxyMechanism.myAccountUri];
|
|
|
|
|
2011-10-28 19:31:49 +00:00
|
|
|
var removeProxyInfo = function(info) {
|
|
|
|
self.removeProxyInfo(info)
|
|
|
|
}
|
|
|
|
|
2011-10-27 14:49:48 +00:00
|
|
|
this.disableFormInUnsupportedBrowsers = function() {
|
|
|
|
var disableWrapper = $('#ie67DisableWrapper');
|
|
|
|
|
|
|
|
// Check for unsupported browsers only if the element exists on the page
|
|
|
|
if (disableWrapper.length) {
|
|
|
|
if (vitro.browserUtils.isIELessThan8()) {
|
|
|
|
disableWrapper.show();
|
|
|
|
$('.noIE67').hide();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.parseProxyTemplate = function() {
|
|
|
|
var templateDiv = $("div[name='template']", this.proxyDataDiv)
|
|
|
|
this.templateHtml = templateDiv.html();
|
|
|
|
templateDiv.remove();
|
|
|
|
};
|
|
|
|
|
2011-10-28 19:31:49 +00:00
|
|
|
this.removeProxyInfo = function(info) {
|
|
|
|
var idx = self.proxyData.indexOf(info);
|
|
|
|
if (idx != -1) {
|
|
|
|
self.proxyData.splice(idx, 1);
|
|
|
|
}
|
|
|
|
self.displayProxyData();
|
|
|
|
}
|
|
|
|
|
2011-10-27 14:49:48 +00:00
|
|
|
this.parseProxyData = function() {
|
|
|
|
var datas = $("div[name='data']", this.proxyDataDiv)
|
|
|
|
|
|
|
|
this.proxyData = []
|
|
|
|
for (i = 0; i < datas.length; i++) {
|
|
|
|
var data = datas[i];
|
|
|
|
var uri = $("p[name='uri']", data).text();
|
|
|
|
var label = $("p[name='label']", data).text();
|
|
|
|
var classLabel = $("p[name='classLabel']", data).text();
|
|
|
|
var imageUrl = $("p[name='imageUrl']", data).text();
|
2011-10-28 19:31:49 +00:00
|
|
|
this.proxyData.push(new proxyInfoElement(this.templateHtml, uri, label, classLabel, imageUrl, removeProxyInfo));
|
2011-10-27 14:49:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.displayProxyData = function() {
|
2011-10-27 17:26:29 +00:00
|
|
|
$("div[name='proxyInfoElement']", this.proxyDataDiv).remove();
|
2011-10-27 14:49:48 +00:00
|
|
|
|
|
|
|
for (i = 0; i < this.proxyData.length; i++) {
|
|
|
|
this.proxyData[i].element().appendTo(this.proxyDataDiv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.disableFormInUnsupportedBrowsers()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-10-27 21:55:41 +00:00
|
|
|
|
|
|
|
this.getAdditionalInfo = function(info, externalAuthId) {
|
|
|
|
$.ajax({
|
2011-10-30 16:54:23 +00:00
|
|
|
url: proxyMechanism.sparqlQueryUrl,
|
2011-10-27 21:55:41 +00:00
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
2011-10-30 16:54:23 +00:00
|
|
|
query: moreInfoQuery.replace("%matchingProperty%", proxyMechanism.matchingProperty)
|
|
|
|
.replace("%externalAuthId%", externalAuthId)
|
2011-10-27 21:55:41 +00:00
|
|
|
},
|
|
|
|
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]) {
|
2011-10-30 16:54:23 +00:00
|
|
|
info.imageUrl = proxyMechanism.baseUrl + parsed[0].imageUrl;
|
2011-10-27 21:55:41 +00:00
|
|
|
}
|
|
|
|
self.displayProxyData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-10-27 14:49:48 +00:00
|
|
|
|
|
|
|
this.panel = p;
|
|
|
|
this.proxyDataDiv = $("div[name='proxyData']", this.panel).first();
|
|
|
|
this.addAutoCompleteField = $("input[name='proxySelectorAC']", this.panel).first();
|
2011-10-28 18:13:21 +00:00
|
|
|
this.searchStatusField = $("span[name='proxySelectorSearchStatus']", this.panel).first();
|
2011-10-27 14:49:48 +00:00
|
|
|
|
|
|
|
this.parseProxyTemplate();
|
|
|
|
this.parseProxyData();
|
|
|
|
this.displayProxyData();
|
|
|
|
|
2011-10-27 20:50:47 +00:00
|
|
|
this.getProxyInfos = function() {
|
|
|
|
return self.proxyData;
|
|
|
|
}
|
2011-10-27 14:49:48 +00:00
|
|
|
|
2011-10-27 21:55:41 +00:00
|
|
|
this.addProxyInfo = function(selection) {
|
2011-10-28 19:31:49 +00:00
|
|
|
var info = new proxyInfoElement(self.templateHtml, selection.uri, selection.label, "", "", removeProxyInfo)
|
2011-10-27 21:55:41 +00:00
|
|
|
self.proxyData.unshift(info);
|
|
|
|
self.getAdditionalInfo(info, selection.externalAuthId)
|
2011-10-27 20:50:47 +00:00
|
|
|
self.displayProxyData();
|
2011-10-27 17:26:29 +00:00
|
|
|
}
|
|
|
|
|
2011-10-28 18:13:21 +00:00
|
|
|
|
2011-10-27 20:50:47 +00:00
|
|
|
this.setupAutoCompleteFields = function() {
|
|
|
|
var parms = {
|
|
|
|
query: query,
|
|
|
|
model: "userAccounts",
|
2011-10-30 16:54:23 +00:00
|
|
|
url: proxyMechanism.sparqlQueryUrl
|
2011-10-27 20:50:47 +00:00
|
|
|
};
|
2011-10-28 18:13:21 +00:00
|
|
|
var reportSearchStatus = new searchStatusField(this.searchStatusField, 3).setText;
|
2011-10-30 17:15:53 +00:00
|
|
|
this.addAutoCompleteField.autocomplete(new proxyAutocomplete(parms, excludedUris, this.getProxyInfos, this.addProxyInfo, reportSearchStatus));
|
2011-10-27 14:49:48 +00:00
|
|
|
}
|
2011-10-27 20:50:47 +00:00
|
|
|
|
|
|
|
this.setupAutoCompleteFields();
|
2011-10-27 14:49:48 +00:00
|
|
|
}
|
|
|
|
|
2011-10-28 18:13:21 +00:00
|
|
|
function searchStatusField(element, minLength) {
|
|
|
|
var emptyText = element.text();
|
|
|
|
var moreCharsText = element.attr('moreCharsText');
|
|
|
|
var noMatchText = element.attr('noMatchText');
|
|
|
|
|
|
|
|
this.setText = function(searchTermLength, numberOfResults) {
|
|
|
|
if (numberOfResults > 0) {
|
|
|
|
element.text = '';
|
|
|
|
} else if (searchTermLength == 0) {
|
|
|
|
element.text(emptyText);
|
|
|
|
} else if (searchTermLength < minLength) {
|
|
|
|
element.text(moreCharsText);
|
|
|
|
} else {
|
|
|
|
element.text(noMatchText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-27 14:49:48 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
$("div[name='proxyProxiesPanel']").each(function(i) {
|
|
|
|
var ppp = new proxyProxiesPanel(this);
|
|
|
|
this["ppp"]=ppp;
|
|
|
|
});
|
|
|
|
});
|