NIHVIVO-2343 Create accountProxyCommon.js to partition the code, and add filtering to prevent duplicates.
This commit is contained in:
parent
0a951807d3
commit
61d059423a
4 changed files with 130 additions and 81 deletions
90
webapp/web/js/account/accountProxyCommon.js
Normal file
90
webapp/web/js/account/accountProxyCommon.js
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A collection of building blocks for the proxy-management UI.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* proxyInfoElement
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* Display information about an entity according to the template. The entity
|
||||||
|
* can be either:
|
||||||
|
* a profile -- Individual to be edited.
|
||||||
|
* a proxy -- User Account to do the editing, optionally with info from a
|
||||||
|
* profile associated with that individual.
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* The template must inlude
|
||||||
|
* 1) a link with attribute templatePart="remove"
|
||||||
|
* 2) a link with attribute templatePart="restore"
|
||||||
|
* 3) a hidden field with attribute templatePart="uriField" and value="%uri%" see below
|
||||||
|
*
|
||||||
|
* The template may include tokens to be replaced, from the following:
|
||||||
|
* %uri% -- the URI of the individual being displayed
|
||||||
|
* %label& -- the label of the individual.
|
||||||
|
* %classLabel% -- the label of the most specific class of the individual.
|
||||||
|
* %imageUrl% -- the URL that will fetch the image of the individual,
|
||||||
|
* or a placeholder image.
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
function proxyInfoElement(template, uri, label, classLabel, imageUrl, existing) {
|
||||||
|
this.uri = uri;
|
||||||
|
|
||||||
|
var existed = existing;
|
||||||
|
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() {
|
||||||
|
return "proxyInfoElement: " + content;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.element = function() {
|
||||||
|
var element = $("<div name='proxyInfoElement'>" + content + "</div>");
|
||||||
|
var removeLink = $("[templatePart='remove']", element).first();
|
||||||
|
var restoreLink = $("[templatePart='restore']", element).first();
|
||||||
|
var proxyUriField = $("[templatePart='uriField']", element);
|
||||||
|
|
||||||
|
var setClass = function(r) {
|
||||||
|
if (r) {
|
||||||
|
element.removeClass('new existing').addClass('removed')
|
||||||
|
} else if (existed) {
|
||||||
|
element.removeClass('new removed').addClass('existing')
|
||||||
|
} else {
|
||||||
|
element.removeClass('removed existing').addClass('new')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var setRemoved = function(r) {
|
||||||
|
removed = r;
|
||||||
|
if (r) {
|
||||||
|
removeLink.hide();
|
||||||
|
restoreLink.show();
|
||||||
|
proxyUriField.attr('disabled', 'disabled');
|
||||||
|
setClass(r);
|
||||||
|
} else {
|
||||||
|
removeLink.show();
|
||||||
|
restoreLink.hide();
|
||||||
|
proxyUriField.attr('disabled', '');
|
||||||
|
setClass(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeLink.click(function(event) {
|
||||||
|
setRemoved(true);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
restoreLink.click(function(event) {
|
||||||
|
setRemoved(false);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
setRemoved(removed);
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,12 +33,12 @@ function proxyProxiesPanel(p) {
|
||||||
var label = $("p[name='label']", data).text();
|
var label = $("p[name='label']", data).text();
|
||||||
var classLabel = $("p[name='classLabel']", data).text();
|
var classLabel = $("p[name='classLabel']", data).text();
|
||||||
var imageUrl = $("p[name='imageUrl']", data).text();
|
var imageUrl = $("p[name='imageUrl']", data).text();
|
||||||
this.proxyData.push(new proxyProxy(this.templateHtml, uri, label, classLabel, imageUrl, true));
|
this.proxyData.push(new proxyInfoElement(this.templateHtml, uri, label, classLabel, imageUrl, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.displayProxyData = function() {
|
this.displayProxyData = function() {
|
||||||
$("div[name='proxyActual']", this.proxyDataDiv).remove();
|
$("div[name='proxyInfoElement']", this.proxyDataDiv).remove();
|
||||||
|
|
||||||
for (i = 0; i < this.proxyData.length; i++) {
|
for (i = 0; i < this.proxyData.length; i++) {
|
||||||
this.proxyData[i].element().appendTo(this.proxyDataDiv);
|
this.proxyData[i].element().appendTo(this.proxyDataDiv);
|
||||||
|
@ -63,64 +63,6 @@ function proxyProxiesPanel(p) {
|
||||||
this.setupAutoCompleteFields();
|
this.setupAutoCompleteFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
function proxyProxy(template, uri, label, classLabel, imageUrl, existing) {
|
|
||||||
var existed = existing;
|
|
||||||
|
|
||||||
var content = template.replace(/%uri%/g, uri)
|
|
||||||
.replace(/%label%/g, label)
|
|
||||||
.replace(/%classLabel%/g, classLabel)
|
|
||||||
.replace(/%imageUrl%/g, imageUrl);
|
|
||||||
|
|
||||||
this.toString = function() {
|
|
||||||
return "ProxyProxy: " + content;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.element = function() {
|
|
||||||
var element = $("<div name='proxyActual'>" + content + "</div>");
|
|
||||||
var removeLink = $("[name='removeProxy']", element).first();
|
|
||||||
var restoreLink = $("[name='restoreProxy']", element).first();
|
|
||||||
var proxyUriField = $("[name='proxyUri']", element);
|
|
||||||
|
|
||||||
var setClass = function(r) {
|
|
||||||
if (r) {
|
|
||||||
element.removeClass('new existing').addClass('removed')
|
|
||||||
} else if (existed) {
|
|
||||||
element.removeClass('new removed').addClass('existing')
|
|
||||||
} else {
|
|
||||||
element.removeClass('removed existing').addClass('new')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var setRemoved = function(r) {
|
|
||||||
if (r) {
|
|
||||||
removeLink.hide();
|
|
||||||
restoreLink.show();
|
|
||||||
proxyUriField.attr('disabled', 'disabled');
|
|
||||||
setClass(r);
|
|
||||||
} else {
|
|
||||||
removeLink.show();
|
|
||||||
restoreLink.hide();
|
|
||||||
proxyUriField.attr('disabled', '');
|
|
||||||
setClass(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
removeLink.click(function(event) {
|
|
||||||
setRemoved(true);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
restoreLink.click(function(event) {
|
|
||||||
setRemoved(false);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
setRemoved(false);
|
|
||||||
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function proxyAutocomplete(parent) {
|
function proxyAutocomplete(parent) {
|
||||||
var cache = [];
|
var cache = [];
|
||||||
|
|
||||||
|
@ -139,11 +81,29 @@ function proxyAutocomplete(parent) {
|
||||||
+ "ORDER BY ASC(?lastName) ASC(?firstName) \n"
|
+ "ORDER BY ASC(?lastName) ASC(?firstName) \n"
|
||||||
+ "LIMIT 25 \n";
|
+ "LIMIT 25 \n";
|
||||||
|
|
||||||
|
var filterResults = function(parsed, data) {
|
||||||
|
var filtered = [];
|
||||||
|
for (var p = 0; p < parsed.length; p++) {
|
||||||
|
var dupe = false;
|
||||||
|
for (var d = 0; d < data.length; d++) {
|
||||||
|
if (data[d].uri == parsed[p].uri) {
|
||||||
|
dupe = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!dupe) {
|
||||||
|
filtered.push(parsed[p]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
|
||||||
this.minLength = 3,
|
this.minLength = 3,
|
||||||
|
|
||||||
this.source = function(request, response) {
|
this.source = function(request, response) {
|
||||||
if (request.term in cache) {
|
if (request.term in cache) {
|
||||||
response(cache[request.term]);
|
var filtered = filterResults(cache[request.term], parent.proxyData);
|
||||||
|
response(filtered);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -157,28 +117,18 @@ function proxyAutocomplete(parent) {
|
||||||
var results = $.parseJSON(xhr.responseText);
|
var results = $.parseJSON(xhr.responseText);
|
||||||
var parsed = sparqlUtils.parseSparqlResults(results);
|
var parsed = sparqlUtils.parseSparqlResults(results);
|
||||||
cache[request.term] = parsed;
|
cache[request.term] = parsed;
|
||||||
response(parsed);
|
var filtered = filterResults(parsed, parent.proxyData);
|
||||||
|
response(filtered);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.select = function(event, ui) {
|
this.select = function(event, ui) {
|
||||||
parent.proxyData.unshift(new proxyProxy(parent.templateHtml, ui.item.uri, ui.item.label, "", "", false));
|
parent.proxyData.unshift(new proxyInfoElement(parent.templateHtml, ui.item.uri, ui.item.label, "", "", false));
|
||||||
parent.displayProxyData();
|
parent.displayProxyData();
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function dump(msg, obj) {
|
|
||||||
var out = '';
|
|
||||||
for (var i in obj) {
|
|
||||||
out += i + ": " + obj[i] + "\n";
|
|
||||||
}
|
|
||||||
console.log(msg, out);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$("div[name='proxyProxiesPanel']").each(function(i) {
|
$("div[name='proxyProxiesPanel']").each(function(i) {
|
||||||
var ppp = new proxyProxiesPanel(this);
|
var ppp = new proxyProxiesPanel(this);
|
||||||
|
|
|
@ -59,6 +59,8 @@
|
||||||
|
|
||||||
<section id="my-account" role="region">
|
<section id="my-account" role="region">
|
||||||
<form id="main-form" method="POST" action="${formUrls.myAccount}" class="customForm" role="my account">
|
<form id="main-form" method="POST" action="${formUrls.myAccount}" class="customForm" role="my account">
|
||||||
|
<#include "userAccounts-myProxiesPanel.ftl">
|
||||||
|
|
||||||
<label for="email-address">Email address<span class="requiredHint"> *</span></label>
|
<label for="email-address">Email address<span class="requiredHint"> *</span></label>
|
||||||
<input type="text" name="emailAddress" value="${emailAddress}" id="email-address" role="input" />
|
<input type="text" name="emailAddress" value="${emailAddress}" id="email-address" role="input" />
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,11 @@ ${stylesheets.add('<link rel="stylesheet" href="${urls.base}/css/account/proxy.c
|
||||||
|
|
||||||
<#--
|
<#--
|
||||||
Each proxy will be shown using the HTML inside this div.
|
Each proxy will be shown using the HTML inside this div.
|
||||||
One of the links "removeProxy" and "restoreProxy" will show at a time.
|
It must contain at least:
|
||||||
The hidden input field named "proxyUri" is required.
|
1) a link with templatePart="remove"
|
||||||
|
2) a link with templatePart="restore"
|
||||||
|
3) a hidden input field with templatePart="uriField"
|
||||||
|
One of the links "remove" and "restore" will show at a time.
|
||||||
-->
|
-->
|
||||||
<div name="template" style="display: none">
|
<div name="template" style="display: none">
|
||||||
<table>
|
<table>
|
||||||
|
@ -37,11 +40,14 @@ ${stylesheets.add('<link rel="stylesheet" href="${urls.base}/css/account/proxy.c
|
||||||
<img width="90" alt="%label%" src="%imageUrl%">
|
<img width="90" alt="%label%" src="%imageUrl%">
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
<div>
|
||||||
%label% | %classLabel%
|
%label% | %classLabel%
|
||||||
<br>
|
</div>
|
||||||
<a href="." name="removeProxy">remove</a>
|
<div>
|
||||||
<a href="." name="restoreProxy">restore</a>
|
<a href="." templatePart="remove">remove</a>
|
||||||
<input type="hidden" name="proxyUri" value="%uri%" >
|
<a href="." templatePart="restore">restore</a>
|
||||||
|
<input type="hidden" name="proxyUri" templatePart="uriField" value="%uri%" >
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
@ -51,4 +57,5 @@ ${stylesheets.add('<link rel="stylesheet" href="${urls.base}/css/account/proxy.c
|
||||||
|
|
||||||
${scripts.add('<script type="text/javascript" src="${urls.base}/js/jquery.js"></script>',
|
${scripts.add('<script type="text/javascript" src="${urls.base}/js/jquery.js"></script>',
|
||||||
'<script type="text/javascript" src="${urls.base}/js/sparqlUtils.js"></script>',
|
'<script type="text/javascript" src="${urls.base}/js/sparqlUtils.js"></script>',
|
||||||
|
'<script type="text/javascript" src="${urls.base}/js/account/accountProxyCommon.js"></script>',
|
||||||
'<script type="text/javascript" src="${urls.base}/js/account/accountProxyProxiesPanel.js"></script>')}
|
'<script type="text/javascript" src="${urls.base}/js/account/accountProxyProxiesPanel.js"></script>')}
|
||||||
|
|
Loading…
Add table
Reference in a new issue