diff --git a/productMods/edit/forms/addAuthorsToInformationResource.jsp b/productMods/edit/forms/addAuthorsToInformationResource.jsp index 9e002499..86bb336c 100644 --- a/productMods/edit/forms/addAuthorsToInformationResource.jsp +++ b/productMods/edit/forms/addAuthorsToInformationResource.jsp @@ -24,7 +24,6 @@ core:authorInAuthorship (Person : Authorship) - inverse of linkedAuthor <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.Arrays" %> <%@ page import="java.util.Collections" %> -<%@ page import="java.net.URLEncoder" %> <%@ page import="com.hp.hpl.jena.rdf.model.Model" %> <%@ page import="com.hp.hpl.jena.vocabulary.XSD" %> @@ -42,6 +41,7 @@ core:authorInAuthorship (Person : Authorship) - inverse of linkedAuthor <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %> +<%@ page import="org.json.JSONObject" %> <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> @@ -397,7 +397,7 @@ SPARQL queries for existing values. --%>
<%-- RY maybe make this a label and input field. See what looks best. --%> -

+

diff --git a/productMods/edit/forms/addPublicationToAuthor.jsp b/productMods/edit/forms/addPublicationToAuthor.jsp index e9bc5d4a..421e7f53 100644 --- a/productMods/edit/forms/addPublicationToAuthor.jsp +++ b/productMods/edit/forms/addPublicationToAuthor.jsp @@ -19,22 +19,17 @@ core:informationResourceInAuthorship (InformationResource : Authorship) - invers <%@ page import="java.util.List" %> <%@ page import="java.util.ArrayList" %> <%@ page import="java.util.Arrays" %> -<%@ page import="java.util.Collections" %> -<%@ page import="java.net.URLEncoder" %> <%@ page import="com.hp.hpl.jena.rdf.model.Model" %> <%@ page import="com.hp.hpl.jena.vocabulary.XSD" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyComparator" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.EditConfiguration" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.PublicationHasAuthorValidator" %> +<%@ page import="edu.cornell.mannlib.vitro.webapp.edit.n3editing.PersonHasPublicationValidator" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.utils.StringUtils" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.JavaScript" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Css" %> @@ -180,6 +175,8 @@ SPARQL queries for existing values. --%> EditConfiguration.putConfigInSession(editConfig,session); } + editConfig.addValidator(new PersonHasPublicationValidator()); + Model model = (Model) application.getAttribute("jenaOntModel"); String objectUri = (String) request.getAttribute("objectUri"); editConfig.prepareForNonUpdate(model); // we're only adding new, not editing existing @@ -203,20 +200,25 @@ SPARQL queries for existing values. --%> request.setAttribute("customCss", customCss); %> + +

Create a new publication entry for <%= subjectName %>

" > -

+
+ "> +
+

<%-- RY maybe make this a label and input field. See what looks best. --%> -

+

diff --git a/productMods/edit/forms/css/autocomplete.css b/productMods/edit/forms/css/autocomplete.css index 5e74780d..f771a59e 100644 --- a/productMods/edit/forms/css/autocomplete.css +++ b/productMods/edit/forms/css/autocomplete.css @@ -4,7 +4,7 @@ display: none; } -.acSelectionName { +.acSelectionInfo { background-color: #d9d9d9; padding: .5em 1em; } \ No newline at end of file diff --git a/productMods/edit/forms/css/customFormWithAdvanceTypeSelection.css b/productMods/edit/forms/css/customFormWithAdvanceTypeSelection.css index de2b91b0..9f9b4763 100644 --- a/productMods/edit/forms/css/customFormWithAdvanceTypeSelection.css +++ b/productMods/edit/forms/css/customFormWithAdvanceTypeSelection.css @@ -9,6 +9,11 @@ display: none; } +/* Always hidden, JS or no JS */ +#infoForJs { + display: none; +} + #content form p.inline label { display: inline; clear: none; diff --git a/productMods/edit/forms/js/addAuthorsToInformationResource.js b/productMods/edit/forms/js/addAuthorsToInformationResource.js index f22cbe85..64bad0be 100644 --- a/productMods/edit/forms/js/addAuthorsToInformationResource.js +++ b/productMods/edit/forms/js/addAuthorsToInformationResource.js @@ -226,7 +226,7 @@ var addAuthorForm = { this.hideFields(this.firstNameWrapper); this.hideFields(this.middleNameWrapper); - // Cancel restores form to initial state + // Cancel restores initial form view this.cancel.unbind('click'); this.cancel.bind('click', function() { addAuthorForm.initFormView(); diff --git a/productMods/edit/forms/js/customFormWithAdvanceTypeSelection.js b/productMods/edit/forms/js/customFormWithAdvanceTypeSelection.js index 3dda1215..b9f4514a 100644 --- a/productMods/edit/forms/js/customFormWithAdvanceTypeSelection.js +++ b/productMods/edit/forms/js/customFormWithAdvanceTypeSelection.js @@ -1,6 +1,6 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ -var customFormWATS = { +var customForm = { /* *** Initial page setup *** */ @@ -31,8 +31,7 @@ var customFormWATS = { // These are classed rather than id'd in case we want more than one autocomplete on a form. this.acSelector = this.form.find('.acSelector'); this.acSelection = this.form.find('.acSelection'); - - + }, // Set up the form on page load @@ -40,15 +39,16 @@ var customFormWATS = { this.initFormTypeView(); this.bindEventListeners(); - this.initAutocomplete(); + //this.initAutocomplete(); }, initFormTypeView: function() { + this.hideFields(this.fullViewOnly); this.button.hide(); - this.or.hide(); this.requiredLegend.hide(); + this.or.hide(); this.cancel.unbind('click'); @@ -62,8 +62,10 @@ var customFormWATS = { this.button.show(); this.button.val('Create Publication'); + this.cancel.unbind('click'); this.cancel.click(function() { - customFormWATS.initFormTypeView(); + customForm.initFormTypeView(); + return false; }); }, @@ -82,24 +84,87 @@ var customFormWATS = { labelField = $('#label'); labelFieldLabel = $('label[for=' + labelField.attr('id') + ']'); labelText = labelFieldLabel.html(); - selectedText = $(this).find(':selected').html(); - labelFieldLabel.html(selectedText + ' ' + labelText); + labelFieldLabel.html(customForm.getSelectedTypeName() + ' ' + labelText); - customFormWATS.initFormFullView(); + customForm.initFormFullView(); // set ac type - } + } + // do we need else case? i.e. if user has set back to "select one", we should undo + // above settings? }); }, initAutocomplete: function() { + // Make cache a property of this so we can access it after removing + // an author. + this.acCache = {}; + this.baseAcUrl = $('.acUrl').attr('id'); - // ac selection: disable typeSelector and acSelector + this.acSelector.autocomplete({ + minLength: 3, + source: function(request, response) { + if (request.term in customForm.acCache) { + // console.log('found term in cache'); + response(customForm.acCache[request.term]); + return; + } + // console.log('not getting term from cache'); + + // If the url query params are too long, we could do a post + // here instead of a get. Add the exclude uris to the data + // rather than to the url. + $.ajax({ + url: customForm.acUrl, + dataType: 'json', + data: request, + complete: function(xhr) { + // Not sure why, but we need an explicit json parse here. jQuery + // should parse the response text and return an json object. + var results = jQuery.parseJSON(xhr.responseText); + customForm.acCache[request.term] = results; + response(results); + } + + }); + }, + select: function(event, ui) { + customForm.showAutocompleteSelection(ui); + + } + }); + + }, + + showAutocompleteSelection: function(ui) { + + this.acSelector.hide(); + this.acSelector.attr('disabled', 'disabled'); + + this.acSelection.find('label').html('Selected ' + this.getSelectedTypeName() + ':'); + this.acSelection.show(); + + this.acReceiver.val(ui.item.uri); + this.acSelectionInfo.html(ui.item.label); + + this.button.val('Add Publication'); + + this.cancel.unbind('click'); + this.cancel.click(function() { + // TODO Check out cancel action for authors form. Need to undo/empty some of the stuff above. + // do we do it in the initfullview method, or here? + customForm.initFormFullView(); + return false; + }); + + }, + + getSelectedTypeName: function() { + return this.typeSelector.find(':selected').html(); } - }; $(document).ready(function() { - customFormWATS.onLoad(); + customForm.onLoad(); });