NIHVIVO-2819 Rewrite accountAssociateProfile.js to improve the logic and enhance the function - mostly in preserving user choices in a re-display of the form.
This commit is contained in:
parent
7f4e15256c
commit
424fc2b17e
5 changed files with 161 additions and 75 deletions
|
@ -21,6 +21,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.PermissionSet;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
|
@ -141,9 +142,9 @@ public abstract class UserAccountsPage {
|
|||
String seedClassUri = PERSON_CLASS_URI;
|
||||
List<String> classUris = vclassDao.getAllSubClassURIs(seedClassUri);
|
||||
classUris.add(seedClassUri);
|
||||
|
||||
|
||||
SortedMap<String, String> types = new TreeMap<String, String>();
|
||||
for (String classUri: classUris) {
|
||||
for (String classUri : classUris) {
|
||||
VClass vclass = vclassDao.getVClassByURI(classUri);
|
||||
if (vclass != null) {
|
||||
types.put(classUri, vclass.getName());
|
||||
|
@ -188,8 +189,41 @@ public abstract class UserAccountsPage {
|
|||
}
|
||||
|
||||
protected String getSiteName() {
|
||||
ApplicationBean appBean = vreq.getAppBean();
|
||||
return appBean.getApplicationName();
|
||||
ApplicationBean appBean = vreq.getAppBean();
|
||||
return appBean.getApplicationName();
|
||||
}
|
||||
|
||||
protected ProfileInfo buildProfileInfo(String uri) {
|
||||
Individual ind = indDao.getIndividualByURI(uri);
|
||||
if (ind == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new ProfileInfo(ind.getRdfsLabel(), uri,
|
||||
UrlBuilder.getIndividualProfileUrl(uri, vreq));
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProfileInfo {
|
||||
private final String label;
|
||||
private final String uri;
|
||||
private final String url;
|
||||
|
||||
public ProfileInfo(String label, String uri, String url) {
|
||||
this.label = label;
|
||||
this.uri = uri;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -195,6 +195,11 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
|||
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, newProfileClassUri);
|
||||
body.put("formUrls", buildUrlsMap());
|
||||
|
||||
if (!associatedProfileUri.isEmpty()) {
|
||||
body.put("associatedProfileInfo",
|
||||
buildProfileInfo(associatedProfileUri));
|
||||
}
|
||||
|
||||
if (!errorCode.isEmpty()) {
|
||||
body.put(errorCode, Boolean.TRUE);
|
||||
}
|
||||
|
|
|
@ -4,12 +4,14 @@ package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
|
@ -187,6 +189,11 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
|||
body.put("lastName", lastName);
|
||||
body.put("selectedRole", selectedRoleUri);
|
||||
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, newProfileClassUri);
|
||||
|
||||
if (!associatedProfileUri.isEmpty()) {
|
||||
body.put("associatedProfileInfo",
|
||||
buildProfileInfo(associatedProfileUri));
|
||||
}
|
||||
} else {
|
||||
body.put("emailAddress", userAccount.getEmailAddress());
|
||||
body.put("externalAuthId", userAccount.getExternalAuthId());
|
||||
|
@ -194,6 +201,13 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
|||
body.put("lastName", userAccount.getLastName());
|
||||
body.put("selectedRole", getExistingRoleUri());
|
||||
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, "");
|
||||
|
||||
List<Individual> associatedInds = SelfEditingConfiguration.getBean(
|
||||
vreq).getAssociatedIndividuals(indDao, userAccount);
|
||||
if (!associatedInds.isEmpty()) {
|
||||
body.put("associatedProfileInfo",
|
||||
buildProfileInfo(associatedInds.get(0).getURI()));
|
||||
}
|
||||
}
|
||||
|
||||
if (!isRootUser()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue