diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java index dc07ba775..1165b28ff 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java @@ -49,9 +49,6 @@ public class ImageUploadController extends FreemarkerHttpServlet { .getLog(ImageUploadController.class); private static final String ATTRIBUTE_REFERRING_PAGE = "ImageUploadController.referringPage"; - - public static final String DUMMY_THUMBNAIL_PERSON_URL = "/images/placeholders/person.thumbnail.jpg"; - public static final String DUMMY_THUMBNAIL_NON_PERSON_URL = "/images/placeholders/non.person.thumbnail.jpg"; /** Limit file size to 6 megabytes. */ public static final int MAXIMUM_FILE_SIZE = 6 * 1024 * 1024; @@ -68,6 +65,11 @@ public class ImageUploadController extends FreemarkerHttpServlet { /** The form field of the uploaded file; use as a key to the FileItem map. */ public static final String PARAMETER_UPLOADED_FILE = "datafile"; + + /** The image to use as a placeholder when the individual has no image. Determined + * by the template. + */ + public static final String PARAMETER_PLACEHOLDER_URL = "placeholder"; /** Here is the main image file. Hold on to it. */ public static final String ACTION_UPLOAD = "upload"; @@ -381,23 +383,18 @@ public class ImageUploadController extends FreemarkerHttpServlet { */ private TemplateResponseValues showAddImagePage(VitroRequest vreq, Individual entity) { + + String placeholderUrl = (String) vreq.getParameter(PARAMETER_PLACEHOLDER_URL); + String formAction = (entity == null) ? "" : formAction(entity.getURI(), - ACTION_UPLOAD); + ACTION_UPLOAD, placeholderUrl); String cancelUrl = (entity == null) ? "" : exitPageUrl(vreq, entity.getURI()); TemplateResponseValues rv = new TemplateResponseValues(TEMPLATE_NEW); - - // rjy7 We should not be referencing particular ontology values here, and ideally - // the template would add the placeholder url to the edit link, since it already - // knows which placeholder it's using. However, this requires a significantly more - // complex implementation, so keeping it simple for now. - boolean isPerson = (entity != null) - && entity.isVClass("http://xmlns.com/foaf/0.1/Person"); - String dummyThumbnailUrl = isPerson ? DUMMY_THUMBNAIL_PERSON_URL - : DUMMY_THUMBNAIL_NON_PERSON_URL; - - rv.put(BODY_THUMBNAIL_URL, UrlBuilder.getUrl(dummyThumbnailUrl)); + + + rv.put(BODY_THUMBNAIL_URL, placeholderUrl); rv.put(BODY_FORM_ACTION, formAction); rv.put(BODY_CANCEL_URL, cancelUrl); rv.put(BODY_TITLE, "Upload image" + forName(entity)); @@ -417,11 +414,12 @@ public class ImageUploadController extends FreemarkerHttpServlet { */ private TemplateResponseValues showReplaceImagePage(VitroRequest vreq, Individual entity, ImageInfo imageInfo) { + String placeholderUrl = (String) vreq.getParameter(PARAMETER_PLACEHOLDER_URL); TemplateResponseValues rv = new TemplateResponseValues(TEMPLATE_REPLACE); rv.put(BODY_THUMBNAIL_URL, UrlBuilder.getUrl(imageInfo.getThumbnail() .getBytestreamAliasUrl())); - rv.put(BODY_DELETE_URL, formAction(entity.getURI(), ACTION_DELETE_EDIT)); - rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_UPLOAD)); + rv.put(BODY_DELETE_URL, formAction(entity.getURI(), ACTION_DELETE_EDIT, placeholderUrl)); + rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_UPLOAD, placeholderUrl)); rv.put(BODY_CANCEL_URL, exitPageUrl(vreq, entity.getURI())); rv.put(BODY_TITLE, "Replace image" + forName(entity)); return rv; @@ -444,11 +442,12 @@ public class ImageUploadController extends FreemarkerHttpServlet { */ private TemplateResponseValues showCropImagePage(VitroRequest vreq, Individual entity, String imageUrl, Dimensions dimensions) { + String placeholderUrl = (String) vreq.getParameter(PARAMETER_PLACEHOLDER_URL); TemplateResponseValues rv = new TemplateResponseValues(TEMPLATE_CROP); rv.put(BODY_MAIN_IMAGE_URL, UrlBuilder.getUrl(imageUrl)); rv.put(BODY_MAIN_IMAGE_HEIGHT, dimensions.height); rv.put(BODY_MAIN_IMAGE_WIDTH, dimensions.width); - rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_SAVE)); + rv.put(BODY_FORM_ACTION, formAction(entity.getURI(), ACTION_SAVE, placeholderUrl)); rv.put(BODY_CANCEL_URL, exitPageUrl(vreq, entity.getURI())); rv.put(BODY_TITLE, "Crop Photo" + forName(entity)); return rv; @@ -493,9 +492,9 @@ public class ImageUploadController extends FreemarkerHttpServlet { * back to this controller, along with the desired action and the Entity * URI. */ - private String formAction(String entityUri, String action) { + private String formAction(String entityUri, String action, String placeholderUrl) { UrlBuilder.ParamMap params = new UrlBuilder.ParamMap( - PARAMETER_ENTITY_URI, entityUri, PARAMETER_ACTION, action); + PARAMETER_ENTITY_URI, entityUri, PARAMETER_ACTION, action, PARAMETER_PLACEHOLDER_URL, placeholderUrl); return UrlBuilder.getPath(URL_HERE, params); } diff --git a/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl b/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl index 6140c3332..6699380df 100644 --- a/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl +++ b/webapp/web/templates/freemarker/body/partials/individual/lib-properties.ftl @@ -35,12 +35,12 @@ <#macro objectProperty property editable template=property.template> <#if property.collatedBySubclass> <#-- collated --> - <@p.collatedObjectPropertyList property editable template /> + <@collatedObjectPropertyList property editable template /> <#else> <#-- uncollated --> <#-- We pass property.statements and property.template even though we are also passing property, because objecctPropertyList can get other values, and doesn't necessarily use property.statements and property.template --> - <@p.objectPropertyList property editable property.statements template /> + <@objectPropertyList property editable property.statements template /> @@ -67,7 +67,7 @@ Assumes property is non-null. --> <#local localName = property.localName>

${property.name?capitalize} <@addLink property editable /> <@verboseDisplay property />

@@ -80,22 +80,35 @@ Assumes property is non-null. --> <#-- Some properties usually display without a label. But if there's an add link, we need to also show the property label. If no label is specified, the property name will be used as the label. --> -<#macro addLinkWithLabel property editable label="${property.name?capitalize}"> - <#local addLink><@addLink property editable label /> +<#macro addLinkWithLabel property editable label="${property.name?capitalize}" extraParams=""> + <#local addLink><@addLink property editable label extraParams /> <#if addLink?has_content>

${label} ${addLink} <@verboseDisplay property />

-<#macro addLink property editable label="${property.name}"> +<#macro addLink property editable label="${property.name}" extraParams=""> <#if editable> <#local url = property.addUrl> <#if url?has_content> - add + <@showAddLink property.localName label addParamsToEditUrl(url, extraParams) /> +<#function addParamsToEditUrl url extraParams=""> + <#if extraParams?is_hash_ex> + <#list extraParams?keys as key> + <#local url = "${url}&${key}=${extraParams[key]?url}"> + + + <#return url> + + +<#macro showAddLink propertyLocalName label url> + add + + <#macro propertyLabel property label="${property.name?capitalize}">

${label} <@verboseDisplay property />

@@ -107,27 +120,35 @@ name will be used as the label. --> -<#macro editingLinks propertyLocalName statement editable> +<#macro editingLinks propertyLocalName statement editable extraParams=""> <#if editable> - <@editLink propertyLocalName statement /> - <@deleteLink propertyLocalName statement /> + <@editLink propertyLocalName statement extraParams /> + <@deleteLink propertyLocalName statement extraParams /> -<#macro editLink propertyLocalName statement> +<#macro editLink propertyLocalName statement extraParams=""> <#local url = statement.editUrl> <#if url?has_content> - edit + <@showEditLink propertyLocalName addParamsToEditUrl(url, extraParams) /> -<#macro deleteLink propertyLocalName statement> +<#macro showEditLink propertyLocalName url> + edit + + +<#macro deleteLink propertyLocalName statement extraParams=""> <#local url = statement.deleteUrl> <#if url?has_content> - delete + <@showDeleteLink propertyLocalName addParamsToEditUrl(url, extraParams) /> +<#macro showDeleteLink propertyLocalName url> + delete + + <#macro verboseDisplay property> <#local verboseDisplay = property.verboseDisplay!> <#if verboseDisplay?has_content> @@ -188,14 +209,18 @@ name will be used as the label. --> --> <#macro image individual propertyGroups namespaces editable showPlaceholder="never" placeholder=""> <#local mainImage = propertyGroups.getPropertyAndRemoveFromList("${namespaces.vitroPublic}mainImage")!> + <#local extraParams = ""> + <#if placeholder?has_content> + <#local extraParams = { "placeholder" : placeholder } > + <#local thumbUrl = individual.thumbUrl!> <#-- Don't assume that if the mainImage property is populated, there is a thumbnail image (though that is the general case). If there's a mainImage statement but no thumbnail image, treat it as if there is no image. --> <#if (mainImage.statements)?has_content && thumbUrl?has_content> ${individual.name} - <@p.editingLinks "${mainImage.localName}" mainImage.first editable /> + <@editingLinks "${mainImage.localName}" mainImage.first editable extraParams /> <#else> - <#local imageLabel><@p.addLinkWithLabel mainImage editable "Photo" /> + <#local imageLabel><@addLinkWithLabel mainImage editable "Photo" extraParams /> ${imageLabel} <#if placeholder?has_content> <#if showPlaceholder == "always" || (showPlaceholder="with_add_link" && imageLabel?has_content)> @@ -209,5 +234,5 @@ name will be used as the label. --> <#macro label individual editable> <#local label = individual.nameStatement> ${label.value} - <@p.editingLinks "label" label editable /> + <@editingLinks "label" label editable /> \ No newline at end of file