From ff7ef0267fc56cefe94e342aad2f117c746f6ece Mon Sep 17 00:00:00 2001 From: tworrall Date: Wed, 1 Aug 2012 14:03:11 +0000 Subject: [PATCH] merging r4248 into the trunk --- ...listViewConfig-organizationForPosition.xml | 4 +- .../forms/js/managePeopleForOrganization.js | 85 ++++++++++++ .../forms/managePeopleForOrganization.ftl | 55 ++++++++ ...ManagePeopleForOrganizationController.java | 122 ++++++++++++++++++ 4 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 productMods/templates/freemarker/edit/forms/js/managePeopleForOrganization.js create mode 100644 productMods/templates/freemarker/edit/forms/managePeopleForOrganization.ftl create mode 100644 src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManagePeopleForOrganizationController.java diff --git a/productMods/config/listViewConfig-organizationForPosition.xml b/productMods/config/listViewConfig-organizationForPosition.xml index 6bf8fe52..4330cd3b 100644 --- a/productMods/config/listViewConfig-organizationForPosition.xml +++ b/productMods/config/listViewConfig-organizationForPosition.xml @@ -33,7 +33,9 @@ ?dateTimeEndValue core:dateTime ?dateTimeEnd } # Get current positions only: end date is either null or not in the past - } FILTER ( !bound(?dateTimeEnd) || + } + NOT EXISTS { ?position core:hideFromDisplay ?hideThis } + FILTER ( !bound(?dateTimeEnd) || afn:substring(str(?dateTimeEnd), 0, 4) >= afn:substring(str(afn:now()), 0, 4) ) FILTER ( bound(?person) ) diff --git a/productMods/templates/freemarker/edit/forms/js/managePeopleForOrganization.js b/productMods/templates/freemarker/edit/forms/js/managePeopleForOrganization.js new file mode 100644 index 00000000..4a7aaea3 --- /dev/null +++ b/productMods/templates/freemarker/edit/forms/js/managePeopleForOrganization.js @@ -0,0 +1,85 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +var managePeople = { + + /* *** Initial page setup *** */ + + onLoad: function() { + + this.mixIn(); + this.initPage(); + }, + + mixIn: function() { + + // Get the custom form data from the page + $.extend(this, customFormData); + }, + + // Initial page setup. Called only at page load. + initPage: function() { + + this.initPeopleData(); + + this.bindEventListeners(); + + }, + + // On page load, associate data with each list item. Then we don't + // have to keep retrieving data from or modifying the DOM as we manipulate the + // items. + initPeopleData: function() { + $('.pubCheckbox').each(function(index) { + $(this).data(peopleData[index]); + }); + }, + + bindEventListeners: function() { + + $('.pubCheckbox').click(function() { + managePeople.processPeople(this); + //return false; + }); + + }, + + processPeople: function(person) { + + var add = ""; + var retract = ""; + var n3String = "<" + $(person).data('positionUri') + "> \"true\" ." ; + + if ( $(person).is(':checked') ) { + add = n3String; + } + else { + retract = n3String; + } + + $.ajax({ + url: managePeople.processingUrl, + type: 'POST', + data: { + additions: add, + retractions: retract + }, + dataType: 'json', + context: person, // context for callback + complete: function(request, status) { + + if (status === 'success') { + window.status = "The person has been successfully excluded from the organization page."; + + } else { + alert('Error processing request: the person cannot be excluded from the organization page.'); + $(person).removeAttr('checked'); + } + } + }); + }, + +}; + +$(document).ready(function() { + managePeople.onLoad(); +}); diff --git a/productMods/templates/freemarker/edit/forms/managePeopleForOrganization.ftl b/productMods/templates/freemarker/edit/forms/managePeopleForOrganization.ftl new file mode 100644 index 00000000..ded91e46 --- /dev/null +++ b/productMods/templates/freemarker/edit/forms/managePeopleForOrganization.ftl @@ -0,0 +1,55 @@ +<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> + +<#import "lib-vivo-form.ftl" as lvf> + +<#-- Custom form for managing web pages for individuals --> +

Manage People Affiliated with ${subjectName}

+

+Check those people you want to exclude from the profile page. + +

+ +<@lvf.unsupportedBrowser urls.base /> + + + <#list allSubclasses as sub> +

${sub}s

+
+ <#assign peeps = people[sub]> +
    + <#list peeps as person> +
  • + checked />${person.name} +
  • + + + +
+
+ + +
+

+ Return to profile page +

+ + + +${stylesheets.add('', + '')} + +${scripts.add('', + '', + '', + '')} + diff --git a/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManagePeopleForOrganizationController.java b/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManagePeopleForOrganizationController.java new file mode 100644 index 00000000..fc53a668 --- /dev/null +++ b/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ManagePeopleForOrganizationController.java @@ -0,0 +1,122 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ +package edu.cornell.mannlib.vitro.webapp.controller.freemarker; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.RequestDispatcher; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.RDFNode; + +import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission; +import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions; +import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.VClass; +import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues; +import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues; +import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils; +import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; + + +public class ManagePeopleForOrganizationController extends FreemarkerHttpServlet { + + private static final Log log = LogFactory.getLog(ManagePeopleForOrganizationController.class.getName()); + private VClassDao vcDao = null; + private static final String TEMPLATE_NAME = "managePeopleForOrganization.ftl"; + private List allSubclasses; + + @Override + protected Actions requiredActions(VitroRequest vreq) { + return SimplePermission.DO_FRONT_END_EDITING.ACTIONS; + } + + @Override + protected ResponseValues processRequest(VitroRequest vreq) { + + Map body = new HashMap(); + + String subjectUri = vreq.getParameter("subjectUri"); + + body.put("subjectUri", subjectUri); + + if (vreq.getAssertionsWebappDaoFactory() != null) { + vcDao = vreq.getAssertionsWebappDaoFactory().getVClassDao(); + } else { + vcDao = vreq.getFullWebappDaoFactory().getVClassDao(); + } + + HashMap>> people = getPeople(subjectUri, vreq); + log.debug("people = " + people); + body.put("people", people); + body.put("allSubclasses", allSubclasses); + + Individual subject = vreq.getWebappDaoFactory().getIndividualDao().getIndividualByURI(subjectUri); + if( subject != null && subject.getName() != null ){ + body.put("subjectName", subject.getName()); + }else{ + body.put("subjectName", null); + } + + return new TemplateResponseValues(TEMPLATE_NAME, body); + } + + + private static String PEOPLE_QUERY = "" + + "PREFIX core: \n" + + "PREFIX rdfs: \n" + + "PREFIX vitro: \n" + + "PREFIX afn: \n" + + "SELECT DISTINCT ?subclass ?position (str(?label) as ?name) ?person ?hideThis WHERE { \n" + + " ?subject core:organizationForPosition ?position . \n" + + " OPTIONAL { ?position core:positionForPerson ?person . " + + " ?person rdfs:label ?label } \n" + + " OPTIONAL { ?position vitro:mostSpecificType ?subclass . \n" + + " ?subclass rdfs:subClassOf core:Position } \n" + + " OPTIONAL { ?position core:hideFromDisplay ?hideThis } \n " + + "} ORDER BY ?subclass ?name"; + + HashMap>> getPeople(String subjectUri, VitroRequest vreq) { + + String queryStr = QueryUtils.subUriForQueryVar(PEOPLE_QUERY, "subject", subjectUri); + log.debug("queryStr = " + queryStr); + HashMap>> subclassToPeople = new HashMap>>(); + try { + ResultSet results = QueryUtils.getQueryResults(queryStr, vreq); + while (results.hasNext()) { + QuerySolution soln = results.nextSolution(); + RDFNode subclassUri= soln.get("subclass"); + if ( subclassUri != null ) { + String subclassUriStr = soln.get("subclass").toString(); + VClass vClass = (VClass) vcDao.getVClassByURI(subclassUriStr); + String subclass = ((vClass.getName() == null) ? subclassUriStr : vClass.getName()); + if(!subclassToPeople.containsKey(subclass)) { + subclassToPeople.put(subclass, new ArrayList>()); + } + List> peopleList = subclassToPeople.get(subclass); + peopleList.add(QueryUtils.querySolutionToStringValueMap(soln)); + } + } + } catch (Exception e) { + log.error(e, e); + } + + allSubclasses = new ArrayList(subclassToPeople.keySet()); + Collections.sort(allSubclasses); + return subclassToPeople; + } +} + +