NIHVIVO-142 Add/edit/delete blurb on front end

This commit is contained in:
rjy7 2010-03-23 17:28:11 +00:00
parent bcbe290c51
commit 54c5019347
4 changed files with 98 additions and 47 deletions

View file

@ -38,12 +38,22 @@ public class StringUtils {
return join(list, false, ",");
}
public static String quotedList(List<?> list, String glue) {
public static String quotedList(List<?> list, String glue) {
return join(list, true, glue);
}
// Because we can't use Java 1.6 String.isEmpty()
public static boolean isEmpty(String s) {
return s == null || s.length() <= 0;
}
public static boolean equalsOneOf(String s, String... strings) {
for (String item : strings) {
if (item.equals(s)) {
return true;
}
}
return false;
}
}

View file

@ -71,4 +71,14 @@ public class StringUtilsTest extends AbstractTestClass {
Assert.assertEquals("\"apple\"|\"banana\"|\"orange\"", StringUtils.quotedList(stringList, "|"));
Assert.assertEquals("\"apple\",\"banana\",\"orange\"", StringUtils.quotedList(stringList, null));
}
@Test
public void testEqualsOneOf() {
String s1 = "cat";
Assert.assertTrue(StringUtils.equalsOneOf(s1, "dog", "mouse", "cat", "horse"));
Assert.assertTrue(StringUtils.equalsOneOf(s1, "cat"));
Assert.assertFalse(StringUtils.equalsOneOf(s1, "dog", "mouse", "horse"));
Assert.assertFalse(StringUtils.equalsOneOf(s1));
}
}

View file

@ -2,7 +2,6 @@
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.Arrays"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="com.hp.hpl.jena.rdf.model.Literal"%>
<%@ page import="com.hp.hpl.jena.rdf.model.Model"%>
@ -21,9 +20,18 @@
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="v" uri="http://vitro.mannlib.cornell.edu/vitro/tags" %>
<%!
private String getInputType(String propertyName) {
String inputType = StringUtils.equalsOneOf(propertyName, "blurb", "description") ? "textarea" : "text";
return inputType;
}
String thisPage = "defaultVitroNsPropForm.jsp";
String inThisPage = " in " + thisPage;
%>
<%
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms.defaultVitroNsPropForm.jsp");
log.debug("Starting defaultVitroNsPropForm.jsp");
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("edu.cornell.mannlib.vitro.jsp.edit.forms." + thisPage);
log.debug("Starting " + thisPage);
VitroRequest vreq = new VitroRequest(request);
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
@ -40,7 +48,7 @@
Individual subject = (Individual)vreq.getAttribute("subject");
if( subject == null ) {
throw new Error("In defaultVitroNsPropForm.jsp, could not find subject " + subjectUri);
throw new Error("In " + thisPage + ", could not find subject " + subjectUri);
}
Model model = (Model)application.getAttribute("jenaOntModel");
@ -53,17 +61,17 @@
rangeDatatypeUri = dps.getDatatypeURI();
if (rangeDatatypeUri == null) {
log.debug("no range datatype uri set on vitro namespace property statement for property " + predicateUri + " in defaultVitroNsPropForm.jsp");
log.debug("no range datatype uri set on vitro namespace property statement for property " + predicateUri + inThisPage);
} else {
log.debug("range datatype uri of [" + rangeDatatypeUri + "] on vitro namespace property statement for property " + predicateUri + " in defaultVitroNsPropForm.jsp");
log.debug("range datatype uri of [" + rangeDatatypeUri + "] on vitro namespace property statement for property " + predicateUri + inThisPage);
}
rangeLang = dps.getLanguage();
if( rangeLang == null ) {
log.debug("no language attribute on vitro namespace property statement for property " + predicateUri + " in defaultVitroNsPropForm.jsp");
log.debug("no language attribute on vitro namespace property statement for property " + predicateUri + inThisPage);
rangeLang = "";
} else {
log.debug("language attribute of ["+rangeLang+"] on vitro namespace property statement for property " + predicateUri + " in defaultVitroNsPropForm.jsp");
log.debug("language attribute of ["+rangeLang+"] on vitro namespace property statement for property " + predicateUri + inThisPage);
}
} else {
@ -161,18 +169,26 @@
editConfig.prepareForDataPropUpdate(model,dps);
}
String propertyLabel = propertyName == "label" ? "name" : propertyName;
// Configure form
String propertyLabel = propertyName.equals("label") ? "name" : propertyName;
String actionText = dps == null ? "Add new " : "Edit ";
String submitLabel = actionText + propertyName;
String title = actionText + propertyName + " for " + subject.getName();
String submitLabel = actionText + propertyLabel;
String title = actionText + "<em>" + propertyLabel + "</em> for " + subject.getName();
String inputType = getInputType(propertyName);
log.debug(propertyName + " needs input type " + inputType + inThisPage);
boolean useTinyMCE = inputType.equals("textarea");
log.debug( (useTinyMCE ? "" : "not ") + "using tinyMCE to edit " + propertyName + inThisPage);
%>
<jsp:include page="${preForm}"/>
<jsp:include page="${preForm}">
<jsp:param name="useTinyMCE" value="<%= useTinyMCE %>"/>
</jsp:include>
<h2><%= title %></h2>
<form action="<c:url value="/edit/processDatapropRdfForm.jsp"/>" >
<v:input type="text" id="${propertyName}" size="30" />
<v:input type="<%= inputType %>" id="${propertyName}" size="30" />
<input type="hidden" name="vitroNsProp" value="true" />
<p class="submit"><v:input type="submit" id="submit" value="<%= submitLabel %>" cancel="${param.subjectUri}"/></p>
</form>

View file

@ -111,6 +111,8 @@ RY Description not working - FIX
<p><a href="${backToSubjectLink}">&larr; return to ${relatedSubject.name}</a></p>
</c:when>
<c:otherwise>
<%-- Label --%>
<div class="datatypePropertyValue" id="label">
<div class="statementWrap">
<h2><p:process>${entity.name}</p:process></h2>
@ -120,12 +122,12 @@ RY Description not working - FIX
</c:if>
</div>
</div>
<%-- For moniker, only wrap in the div if editing. Otherwise, displays inline next to label. --%>
<%-- Moniker. Wrap in the div only if editing. If not editing, displays inline next to label. --%>
<c:if test="${showEdits}">
<div id="dprop-vitro-moniker" class="propsItem editing" style="display:block;">
<h3 class="propertyName">moniker</h3>
<c:if test="${showEdits}"><edLnk:editLinks item="<%= VitroVocabulary.MONIKER %>" icons="false"/></c:if>
<%-- Here's where we add the plus link, but only if there isn't already a moniker. --%>
<edLnk:editLinks item="<%= VitroVocabulary.MONIKER %>" icons="false"/>
</c:if>
<c:if test="${!empty entity.moniker}">
<div class="datatypeProperties">
@ -140,10 +142,12 @@ RY Description not working - FIX
</div>
</div>
</c:if>
<c:if test="${showEdits}"></div></c:if>
<c:if test="${showEdits}"></div></c:if> <%-- end dprop-vitro-moniker --%>
</c:otherwise>
</c:choose>
</div><!-- end labelAndMoniker -->
<%-- Links --%>
<c:if test="${ (!empty entity.anchor) || (!empty entity.linksList) }">
<div class="datatypePropertyValue">
<div class="statementWrap">
@ -179,6 +183,8 @@ RY Description not working - FIX
</div>
</div>
</c:if>
<%-- Thumbnail --%>
<c:if test="${!empty entity.imageThumb}">
<div class="thumbnail">
<c:if test="${!empty entity.imageFile}">
@ -189,6 +195,7 @@ RY Description not working - FIX
<img src="<c:out value="${imageSrc}"/>" title="click to view larger image in new window" alt="" width="150"/>
<c:if test="${!empty entity.imageFile}"></a></c:if>
</div>
<%-- Citation --%>
<c:if test="${!empty entity.citation}">
<div class="datatypePropertyValue">
<div class="statementWrap">
@ -202,19 +209,32 @@ RY Description not working - FIX
</div>
</c:if>
</c:if>
<p:process>
<c:if test="${!empty entity.blurb}">
<div class="datatypePropertyValue">
<div class="statementWrap">
<div class="description">${entity.blurb}</div>
<%--
<c:if test="${showEdits}">
<c:set var="editLinks"><edLnk:editLinks item="<%= VitroVocabulary.BLURB %>" data="${entity.blurb}" icons="false"/></c:set>
<c:if test="${!empty editLinks}"><span class="editLinks">${editLinks}</span></c:if>
</c:if> --%>
<%-- Blurb --%>
<div id="dprop-vitro-blurb" class="propsItem ${editingClass}" style="display:block;">
<c:if test="${showEdits}">
<h3 class="propertyName">blurb</h3>
<edLnk:editLinks item="<%= VitroVocabulary.BLURB %>" icons="false"/>
</c:if>
<c:if test="${!empty entity.blurb}">
<div class="datatypeProperties">
<div class="datatypePropertyValue">
<div class="statementWrap">
<div class="description">${entity.blurb}</div>
<c:if test="${showEdits}">
<c:set var="editLinks"><edLnk:editLinks item="<%= VitroVocabulary.BLURB %>" data="${entity.blurb}" icons="false"/></c:set>
<c:if test="${!empty editLinks}"><span class="editLinks">${editLinks}</span></c:if>
</c:if>
</div>
</div>
</div>
</div>
</div>
</c:if>
</c:if>
</div>
<%-- Description --%>
<c:if test="${!empty entity.description}">
<div class="datatypePropertyValue">
<div class="statementWrap">
@ -228,24 +248,19 @@ RY Description not working - FIX
</div>
</c:if>
</p:process>
<c:choose>
<c:when test="${showEdits}">
<c:import url="${entityMergedPropsListJsp}">
<c:param name="mode" value="edit"/>
<c:param name="grouped" value="false"/>
<%-- unless a value is provided, properties not assigned to a group will not have a tab or appear on the page --%>
<c:param name="unassignedPropsGroupName" value=""/>
</c:import>
</c:when>
<c:otherwise>
<c:import url="${entityMergedPropsListJsp}">
<c:param name="grouped" value="false"/>
<%-- unless a value is provided, properties not assigned to a group will not have a tab or appear on the page --%>
<c:param name="unassignedPropsGroupName" value=""/>
</c:import>
</c:otherwise>
</c:choose>
<%-- Properties --%>
<c:import url="${entityMergedPropsListJsp}">
<%-- <c:param name="mode" value="edit"/> --%>
<c:param name="grouped" value="false"/>
<%-- unless a value is provided, properties not assigned to a group will not have a tab or appear on the page --%>
<c:param name="unassignedPropsGroupName" value=""/>
</c:import>
<p:process>
<%-- Citation, if no thumbnail --%>
<c:if test="${(!empty entity.citation) && (empty entity.imageThumb)}">
<div class="datatypePropertyValue">
<div class="statementWrap">