r3534 - in trunk/pollen-ui-struts2/src/main: java/org/chorem/pollen/ui/actions/poll webapp/WEB-INF/jsp/poll webapp/css
Author: tchemit Date: 2012-06-19 17:50:53 +0200 (Tue, 19 Jun 2012) New Revision: 3534 Url: http://chorem.org/repositories/revision/pollen/3534 Log: validate images (at last) + fix summry javascript Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/summary.jsp trunk/pollen-ui-struts2/src/main/webapp/css/summary.css Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-19 15:38:21 UTC (rev 3533) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-19 15:50:53 UTC (rev 3534) @@ -33,6 +33,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -404,9 +405,26 @@ String choiceId = choice.getTopiaId(); String location = imageChoice.getLocation(); - if (StringUtils.isBlank(choiceId) && - !isImageUploadEmpty(imageChoice)) { + boolean needCopy = false; + if (!isImageUploadEmpty(imageChoice)) { + // there is an image in the choice + + if (StringUtils.isBlank(choiceId)) { + + // this is a new choice + needCopy = true; + } else { + + // check that name has not changed + Choice oldChoice = poll.getChoiceByTopiaId(choiceId); + + needCopy = ObjectUtils.notEqual(oldChoice.getName(), imageChoice.getName()); + } + } + + if (needCopy) { + // not persisted choice with an upload // let's copy it somewhere safe @@ -421,6 +439,9 @@ FileUtils.copyFile(uploadedImage, copyImage); imageChoice.setLocation(copyImage.getAbsolutePath()); + + // generate also the thumb file + getPollService().generateThumbIfNeeded(copyImage); } } } @@ -1235,6 +1256,8 @@ case IMAGE: getImageChoices().addAll(pollChoices); + PollService service = getPollService(); + // if images are not still saved in a poll, then thumb // does not exists, must create a temporary one for (Choice choice : pollChoices) { @@ -1242,25 +1265,38 @@ String choiceId = imageChoice.getTopiaId(); File imageChoiceFile = null; - PollService service = getPollService(); if (StringUtils.isBlank(choiceId)) { + // new choice, + if (!isImageUploadEmpty(imageChoice)) { - // new choice, must create the thumb + + // ok there is an upload imageChoiceFile = new File(imageChoice.getLocation()); + } - if (imageChoiceFile.exists()) { + } else { - service.generateThumbIfNeeded(imageChoiceFile); - } + // already persisted choice, check choice has not changed + + Choice oldChoice = + poll.getChoiceByTopiaId(choiceId); + + if (ObjectUtils.equals( + imageChoice.getName(), + oldChoice.getName())) { + + // name has not changed, keep persisted choice + imageChoiceFile = service.getPollChoiceImageFile( + poll.getPollId(), choice.getName()); + } else { + + // use new choice image location + imageChoiceFile = + new File(imageChoice.getLocation()); } - } else { - - // already persisted choice, nothing to do - imageChoiceFile = service.getPollChoiceImageFile( - poll.getPollId(), choice.getName()); } if (imageChoiceFile != null) { Modified: trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/summary.jsp =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/summary.jsp 2012-06-19 15:38:21 UTC (rev 3533) +++ trunk/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/summary.jsp 2012-06-19 15:50:53 UTC (rev 3534) @@ -56,6 +56,29 @@ return false; } + + $(document).ready(function() { + + $('.url').click(function () { + var el = $(this)[0]; + if (/textarea/i.test(el.tagName) || (/input/i.test(el.tagName) && /text/i.test(el.type))) { + el.select(); + } else if (!!window.getSelection) { // FF, Safari, Chrome, Opera + var sel = window.getSelection(); + var range = document.createRange(); + range.selectNodeContents(el); + sel.removeAllRanges(); + sel.addRange(range); + } else if (!!document.selection) { // IE + document.selection.empty(); + var range = document.body.createTextRange(); + range.moveToElementText(el); + range.select(); + } + }); + + }); + </script> <h1 class="titleCreation"><s:property value="poll.title"/></h1> @@ -169,34 +192,3 @@ </div> <sj:dialog id="confirmDialog" autoOpen="false" modal="true" width="500"/> - - - -<script type="text/javascript"> - - var autoSelect = function () { - var el = $(this)[0]; - if (/textarea/i.test(el.tagName) || (/input/i.test(el.tagName) && /text/i.test(el.type))) { - el.select(); - } else if (!!window.getSelection) { // FF, Safari, Chrome, Opera - var sel = window.getSelection(); - var range = document.createRange(); - range.selectNodeContents(el); - sel.removeAllRanges(); - sel.addRange(range); - } else if (!!document.selection) { // IE - document.selection.empty(); - var range = document.body.createTextRange(); - range.moveToElementText(el); - range.select(); - } - }; - - $(document).load(function() { - - - $('.url').click(autoSelect); - - }) - -</script> \ No newline at end of file Modified: trunk/pollen-ui-struts2/src/main/webapp/css/summary.css =================================================================== --- trunk/pollen-ui-struts2/src/main/webapp/css/summary.css 2012-06-19 15:38:21 UTC (rev 3533) +++ trunk/pollen-ui-struts2/src/main/webapp/css/summary.css 2012-06-19 15:50:53 UTC (rev 3534) @@ -22,7 +22,8 @@ */ .ui-widget-content-green { border: 1px solid #aaaaaa; - background: #b0f580 url(images/ui-bg_flat_75_b0f580_40x100.png) 50% 50% repeat-x; + /*background: #b0f580 url(images/ui-bg_flat_75_b0f580_40x100.png) 50% 50% repeat-x;*/ + background-color: #b0f580; color: #222222; } @@ -32,7 +33,8 @@ .ui-widget-content-yellow { border: 1px solid #aaaaaa; - background: #ffffaa url(images/ui-bg_flat_75_ffffaa_40x100.png) 50% 50% repeat-x; + /*background: #ffffaa url(images/ui-bg_flat_75_ffffaa_40x100.png) 50% 50% repeat-x;*/ + background-color: #ffffaa; color: #222222; } @@ -42,7 +44,8 @@ .ui-widget-content-red { border: 1px solid #aaaaaa; - background: #FFAAAA url(images/ui-bg_flat_75_ffffaa_40x100.png) 50% 50% repeat-x; + /*background: #FFAAAA url(images/ui-bg_flat_75_ffffaa_40x100.png) 50% 50% repeat-x;*/ + background-color: #FFAAAA; color: #222222; } @@ -52,7 +55,8 @@ .ui-widget-content-blue { border: 1px solid #dddddd; - background: #A9D4E3 url(images/ui-bg_highlight-hard_100_f2f5f7_1x100.png) 50% top repeat-x; + /*background: #A9D4E3 url(images/ui-bg_highlight-hard_100_f2f5f7_1x100.png) 50% top repeat-x;*/ + background-color: #A9D4E3; color: #362b36; }
participants (1)
-
tchemit@users.chorem.org