From 61316862dcfcf297bc1be147822789aa24490447 Mon Sep 17 00:00:00 2001 From: Andrey Ivanov Date: Sat, 21 Feb 2015 17:47:05 +0200 Subject: [PATCH 1/5] #JC-1373 Add dynamic poll item functionality --- .../jcommune/model/entity/PollItem.java | 2 +- .../jcommune/plugin/api/web/dto/TopicDto.java | 42 +++++++++++++-- .../web/controller/TopicController.java | 7 ++- .../web/view/DynamicPollItemsConfig.java | 32 +++++++++++ .../jcommune/web/view/messages_en.properties | 3 +- .../jcommune/web/view/messages_es.properties | 3 +- .../jcommune/web/view/messages_ru.properties | 3 +- .../jcommune/web/view/messages_uk.properties | 3 +- .../webapp/WEB-INF/jsp/topic/topicForm.jsp | 54 +++++++++++++++---- .../webapp/WEB-INF/template/decorator.jsp | 1 + .../webapp/resources/css/app/application.css | 5 ++ .../resources/javascript/app/pollNewTopic.js | 41 ++++++++++++++ .../resources/javascript/app/pollPreview.js | 24 ++++++--- 13 files changed, 193 insertions(+), 27 deletions(-) create mode 100644 jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/view/DynamicPollItemsConfig.java create mode 100644 jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js diff --git a/jcommune-model/src/main/java/org/jtalks/jcommune/model/entity/PollItem.java b/jcommune-model/src/main/java/org/jtalks/jcommune/model/entity/PollItem.java index 94832f94b5..d667c235c3 100644 --- a/jcommune-model/src/main/java/org/jtalks/jcommune/model/entity/PollItem.java +++ b/jcommune-model/src/main/java/org/jtalks/jcommune/model/entity/PollItem.java @@ -34,7 +34,7 @@ public class PollItem extends Entity { /** * Used only by Hibernate. */ - protected PollItem() { + public PollItem() { } diff --git a/jcommune-plugin-api/src/main/java/org/jtalks/jcommune/plugin/api/web/dto/TopicDto.java b/jcommune-plugin-api/src/main/java/org/jtalks/jcommune/plugin/api/web/dto/TopicDto.java index 99c688f571..cf3f83cc6d 100644 --- a/jcommune-plugin-api/src/main/java/org/jtalks/jcommune/plugin/api/web/dto/TopicDto.java +++ b/jcommune-plugin-api/src/main/java/org/jtalks/jcommune/plugin/api/web/dto/TopicDto.java @@ -14,27 +14,32 @@ */ package org.jtalks.jcommune.plugin.api.web.dto; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.Predicate; +import org.apache.commons.lang.StringUtils; import org.jtalks.jcommune.model.entity.Poll; +import org.jtalks.jcommune.model.entity.PollItem; import org.jtalks.jcommune.model.entity.Post; import org.jtalks.jcommune.model.entity.Topic; import org.jtalks.jcommune.plugin.api.web.validation.annotations.BbCodeAwareSize; import org.jtalks.jcommune.plugin.api.web.validation.annotations.BbCodeNesting; +import org.springframework.util.AutoPopulatingList; import javax.validation.Valid; +import java.util.ArrayList; +import java.util.List; /** * DTO for {@link Topic} objects. Used for validation and binding to form. - * + *- * @author Vitaliy Kravchenko * @author Max Malakhov * @author Eugeny Batov */ public class TopicDto { - @Valid private Topic topic; - @BbCodeAwareSize(min = Post.MIN_LENGTH, max = Post.MAX_LENGTH) @BbCodeNesting private String bodyText; @@ -43,6 +48,14 @@ public class TopicDto { private String unreadIconUrl; private String readIconUrl; private String postUrlPrefix; + /** + * Used for UI only + */ + private List pollItemsValue = new AutoPopulatingList(PollItem.class); + /** + * Contains not empty PollItem + */ + private List pollItems = new ArrayList<>(); /** * Plain object for topic creation @@ -65,10 +78,25 @@ public TopicDto(Topic topic) { /** * @return topic that used as dto between controllers and services */ + @Valid public Topic getTopic() { + copyPollItem(); return topic; } + /** + * Copy PollItem from UI collection to Poll. Need that for correct Poll validation. + */ + private void copyPollItem() { + CollectionUtils.select(pollItemsValue, new Predicate() { + @Override + public boolean evaluate(Object object) { + PollItem pollItem = (PollItem) object; + return StringUtils.isNotEmpty(pollItem.getName()) && !pollItems.contains(pollItem); + } + }, pollItems); + } + /** * Set topic in dto. Used in tests. * @@ -165,4 +193,12 @@ public Topic fillTopic(Topic persistentTopic) { persistentTopic.setSticked(topic.isSticked()); return topic; } + + /** + * @return poll options in string representation. + */ + public List getPollItemsValue() { + topic.getPoll().setPollItems(pollItems); + return pollItemsValue; + } } \ No newline at end of file diff --git a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java index 0111856b34..f5f600d2c1 100644 --- a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java +++ b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java @@ -17,8 +17,6 @@ import org.joda.time.DateTime; import org.jtalks.jcommune.model.entity.*; import org.jtalks.jcommune.plugin.api.exceptions.NotFoundException; -import org.jtalks.jcommune.service.nontransactional.LocationService; -import org.jtalks.jcommune.web.dto.EntityToDtoConverter; import org.jtalks.jcommune.plugin.api.web.dto.PostDto; import org.jtalks.jcommune.plugin.api.web.dto.TopicDto; import org.jtalks.jcommune.plugin.api.web.util.BreadcrumbBuilder; @@ -28,6 +26,7 @@ import org.jtalks.jcommune.web.dto.json.JsonResponse; import org.jtalks.jcommune.web.dto.json.JsonResponseStatus; import org.jtalks.jcommune.web.validation.editors.DateTimeEditor; +import org.jtalks.jcommune.web.view.DynamicPollItemsConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -70,6 +69,7 @@ public class TopicController { public static final String POST_DTO = "postDto"; private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class); public static final String POLL = "poll"; + public static final String POLL_CONFIG = "pollConfig"; private TopicModificationService topicModificationService; private TopicFetchService topicFetchService; @@ -81,6 +81,7 @@ public class TopicController { private LocationService locationService; private SessionRegistry sessionRegistry; private EntityToDtoConverter converter; + private DynamicPollItemsConfig dynamicPollItemsConfig = new DynamicPollItemsConfig(); /** * This method turns the trim binder on. Trim binder @@ -150,6 +151,7 @@ public ModelAndView showNewTopicPage(@RequestParam(BRANCH_ID) Long branchId) thr return new ModelAndView(TOPIC_VIEW) .addObject(TOPIC_DTO, dto) .addObject(BRANCH_ID, branchId) + .addObject(POLL_CONFIG, dynamicPollItemsConfig) .addObject(SUBMIT_URL, "/topics/new?branchId=" + branchId) .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getNewTopicBreadcrumb(branch)); } @@ -172,6 +174,7 @@ public ModelAndView createTopic(@Valid @ModelAttribute TopicDto topicDto, return new ModelAndView(TOPIC_VIEW) .addObject(BRANCH_ID, branchId) .addObject(TOPIC_DTO, topicDto) + .addObject(POLL_CONFIG, dynamicPollItemsConfig) .addObject(SUBMIT_URL, "/topics/new?branchId=" + branchId) .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getForumBreadcrumb(branch)); } diff --git a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/view/DynamicPollItemsConfig.java b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/view/DynamicPollItemsConfig.java new file mode 100644 index 0000000000..f639e2b457 --- /dev/null +++ b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/view/DynamicPollItemsConfig.java @@ -0,0 +1,32 @@ +/** + * Copyright (C) 2011 JTalks.org Team + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +package org.jtalks.jcommune.web.view; + +import org.jtalks.jcommune.model.entity.Poll; + +/** + * Contains configuration for Dynamic Poll Items + * @author Andrey Ivanov + */ +public class DynamicPollItemsConfig { + + public Integer getMaxPollItems(){ + return Poll.MAX_ITEMS_NUMBER; + } + + public Integer getMinPollItems(){ + return Poll.MIN_ITEMS_NUMBER; + } +} diff --git a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_en.properties b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_en.properties index d924ea3de9..b3ac2882dd 100644 --- a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_en.properties +++ b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_en.properties @@ -306,12 +306,13 @@ label.search.header.topic=Topic #new poll page label.poll.header=New Poll label.poll.title=Poll -label.poll.options.title=Option list +label.poll.options.title=Options label.poll.single.title=Single answer label.poll.multiple.title=Multiple answers are allowed label.poll.date=Ending date label.poll.date.set=Click to set date label.poll.current_end_date=Current end date +label.poll.options.addPollItem=Add new poll item #poll label.poll.vote=Vote label.poll.option.vote.info= {0} - {1}% diff --git a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_es.properties b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_es.properties index fb27d5c0dc..6e0341bd1d 100644 --- a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_es.properties +++ b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_es.properties @@ -304,7 +304,7 @@ label.search.header.topic=Tema #new poll page label.poll.header=Nueva Encuesta label.poll.title=Encuesta -label.poll.options.title=Lista de Opciones +label.poll.options.title=Opciones label.poll.single.title=Respuesta simple label.poll.multiple.title=La respuesta m\u00FAltiple est\u00E1 permitida label.poll.date=Fecha de fin @@ -462,3 +462,4 @@ label.branch.header.lastMessage.tooltip=Ver \u00FAltimo mensaje label.topic.section.in=en label.tips.close=Cerrar este tema label.tips.open=Reabrir este tema +label.poll.options.addPollItem=Añadir encuesta artículo diff --git a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_ru.properties b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_ru.properties index ea54dd0679..9dbf2ccadf 100644 --- a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_ru.properties +++ b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_ru.properties @@ -311,7 +311,7 @@ label.errors.not_empty = \u041D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0431\u044 label.poll.header=\u041D\u043E\u0432\u043E\u0435 \u0433\u043E\u043B\u043E\u0441\u043E\u0432\u0430\u043D\u0438\u0435 label.poll.title=\u0413\u043E\u043B\u043E\u0441\u043E\u0432\u0430\u043D\u0438\u0435 -label.poll.options.title=\u0421\u043F\u0438\u0441\u043E\u043A \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432 +label.poll.options.title=\u0412\u0430\u0440\u0438\u0430\u043d\u0442 label.poll.single.title=\u041E\u0434\u0438\u043D \u0432\u0430\u0440\u0438\u0430\u043D\u0442 label.poll.multiple.title=\u0412\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u043D\u0435\u0441\u043A\u043E\u043B\u044C\u043A\u043E \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u043E\u0432 \u043E\u0442\u0432\u0435\u0442\u0430 label.poll.date=\u0414\u0430\u0442\u0430 \u043E\u043A\u043E\u043D\u0447\u0430\u043D\u0438\u044F @@ -460,3 +460,4 @@ label.branch.header.lastMessage.tooltip=\u041F\u0435\u0440\u0435\u0439\u0442\u04 label.topic.section.in=\u0432 label.tips.close=\u0417\u0430\u043A\u0440\u044B\u0442\u044C \u0442\u0435\u043C\u0443 label.tips.open=\u041E\u0442\u043A\u0440\u044B\u0442\u044C \u0442\u0435\u043C\u0443 +label.poll.options.addPollItem=\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 diff --git a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_uk.properties b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_uk.properties index b749da0834..ba11168407 100644 --- a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_uk.properties +++ b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_uk.properties @@ -299,7 +299,7 @@ label.search.header.topic=\u0422\u0435\u043C\u0430 #new poll page label.poll.header=\u041D\u043E\u0432\u0435 \u043E\u043F\u0438\u0442\u0443\u0432\u0430\u043D\u043D\u044F label.poll.title=\u041E\u043F\u0438\u0442\u0443\u0432\u0430\u043D\u043D\u044F -label.poll.options.title=\u0421\u043F\u0438\u0441\u043E\u043A \u0432\u0430\u0440\u0456\u0430\u043D\u0442\u0456\u0432 +label.poll.options.title=\u0412\u0430\u0440\u0456\u0430\u043d\u0442 label.poll.single.title=\u041E\u0434\u0438\u043D\u043E\u0447\u043D\u0430 \u0432\u0456\u0434\u043F\u043E\u0432\u0456\u0434\u044C label.poll.multiple.title=\u0414\u043E\u0437\u0432\u043E\u043B\u0435\u043D\u043E \u0432\u0438\u0431\u0438\u0440\u0430\u0442\u0438 \u043A\u0456\u043B\u044C\u043A\u0430 \u0432\u0430\u0440\u0456\u0430\u043D\u0442\u0456\u0432 label.poll.date=\u0414\u0430\u0442\u0430 \u0437\u0430\u043A\u0456\u043D\u0447\u0435\u043D\u043D\u044F @@ -462,3 +462,4 @@ label.branch.header.lastMessage.tooltip=\u041F\u0435\u0440\u0435\u0439\u0442\u04 label.topic.section.in=\u0432 label.tips.close=\u0417\u0430\u043A\u0440\u0438\u0442\u0438 \u0442\u0435\u043C\u0443 label.tips.open=\u0412\u0456\u0434\u043A\u0440\u0438\u0442\u0438 \u0442\u0435\u043C\u0443 +label.poll.options.addPollItem=\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u0438 \u043d\u043e\u0432\u0438\u0439 \u0432\u0430\u0440\u0456\u0430\u043d\u0442 diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp index a935a279e4..d12fc3eca9 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp +++ b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp @@ -97,23 +97,53 @@ + class="post script-confirm-unsaved input-xlarge" disabled="${pollEditing}"/>
- -
- + + + + +
+ +
+
+
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ ${addPollItemLabel} +
+ +
+
- + tabindex="800" value="${poll.multipleAnswer}" disabled="${pollEditing}"/> @@ -122,14 +152,14 @@
-  
- +
<%--Make parent div include floated divs explicitly, or they'll be shown out of parent container--%>
@@ -143,4 +173,8 @@
+ diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/decorator.jsp b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/decorator.jsp index 90503c5c19..f40a1c52cd 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/decorator.jsp +++ b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/decorator.jsp @@ -256,6 +256,7 @@ in the future. + diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/resources/css/app/application.css b/jcommune-view/jcommune-web-view/src/main/webapp/resources/css/app/application.css index e63bb77c6a..921e45eb55 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/resources/css/app/application.css +++ b/jcommune-view/jcommune-web-view/src/main/webapp/resources/css/app/application.css @@ -1147,4 +1147,9 @@ pre.prettyprint { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; +} + +.poll-icon-pull { + margin-left: 4px; + margin-top: 7px; } \ No newline at end of file diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js b/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js new file mode 100644 index 0000000000..7c10b65682 --- /dev/null +++ b/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js @@ -0,0 +1,41 @@ +$(document).ready(function() { + + if ($("div.pollItemsValue").length == maxPollItems) { + $("a#add").hide(); + } + + $( "#sortable" ).sortable({update: function(event, ui) {reIndex()}}); + + var name = $("#sortable").attr("rel"); + + $("a#add").click(function(e){ + e.preventDefault(); + length = $("div.pollItemsValue").length; + if(length < maxPollItems) { + newItem = $(".pollItemsValue:last").clone(); + $(newItem).insertAfter(".pollItemsValue:last"); + $("input[type=text]", newItem).val(""); + reIndex(); + if ($("div.pollItemsValue").length == maxPollItems) { + $("a#add").hide(); + } + } + }); + + $(".pollItemsValue .remove").live("click", function(e){ + e.preventDefault(); + if($("div.pollItemsValue").length > minPollItems) { + $(this).closest('div.pollItemsValue').remove(); + reIndex(); + if ($("div.pollItemsValue").length < maxPollItems) { + $("a#add").show(); + } + } + }); + + function reIndex(){ + $(".pollItemsValue input[type=text]").each(function(index) { + $(this).attr("name", name.replace("__index__", index)); + }); + } +}); \ No newline at end of file diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollPreview.js b/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollPreview.js index ba3bb0231c..5c78f56c35 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollPreview.js +++ b/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollPreview.js @@ -55,7 +55,7 @@ function enterPollPreviewMode() { } function isPollSet() { - return $("#pollTitle").val() || $("#pollItems").val(); + return $("#pollTitle").val() || getPollItemsValue().length > 0; } /** @@ -81,12 +81,22 @@ function prepareTitle() { * @return processed poll items without leading spaces and empty strings. */ function prepareItems() { - var result; - //"normalize" line endings - result = $("#pollItems")[0].value.replace(/(?:\r\n|\r)+/g, "\n"); - result = trim(result); - result = result.split("\n"); - return stringItemsArrayToHtmlItems(result); + return stringItemsArrayToHtmlItems(getPollItemsValue()); +} + +/** + * Collect all value for poll items + * @returns {Array} + */ +function getPollItemsValue(){ + var result = []; + $(".pollItemsValue input[type=text]").each(function(index){ + value = $(this).val(); + if(value != "") { + result.push(value); + } + }); + return result; } /** From 89e515aa88b951112d270706054e2f652f95f6d6 Mon Sep 17 00:00:00 2001 From: Andrey Ivanov Date: Mon, 23 Feb 2015 17:00:32 +0200 Subject: [PATCH 2/5] #JC-1373 Add dynamic poll item functionality * Do refactoring accroding to CR --- .../main/webapp/resources/javascript/app/pollNewTopic.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js b/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js index 7c10b65682..7788789e11 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js +++ b/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js @@ -4,7 +4,7 @@ $(document).ready(function() { $("a#add").hide(); } - $( "#sortable" ).sortable({update: function(event, ui) {reIndex()}}); + $("#sortable").sortable({update: function(event, ui) {reIndex()}}); var name = $("#sortable").attr("rel"); @@ -27,9 +27,7 @@ $(document).ready(function() { if($("div.pollItemsValue").length > minPollItems) { $(this).closest('div.pollItemsValue').remove(); reIndex(); - if ($("div.pollItemsValue").length < maxPollItems) { - $("a#add").show(); - } + $("a#add").show(); } }); From 2e937441c268bd4165bcb00ca6049c36d805d76c Mon Sep 17 00:00:00 2001 From: Andrey Ivanov Date: Tue, 24 Feb 2015 13:17:33 +0200 Subject: [PATCH 3/5] #JC-1373 Add dynamic poll item functionality * Do refactoring according to CR * Add Button for adding or removing poll * Fix markup bugs * Fix typo for UK language --- .../jcommune/web/view/messages_en.properties | 2 + .../jcommune/web/view/messages_es.properties | 2 + .../jcommune/web/view/messages_ru.properties | 2 + .../jcommune/web/view/messages_uk.properties | 4 +- .../webapp/WEB-INF/jsp/topic/topicForm.jsp | 57 +++++++++++-------- .../src/main/webapp/WEB-INF/tags/bbeditor.tag | 5 +- .../webapp/WEB-INF/template/decorator.jsp | 3 + .../webapp/WEB-INF/template/jsMessages.jsp | 4 +- .../webapp/resources/css/lib/bootstrap.css | 8 +++ .../resources/javascript/app/pollNewTopic.js | 14 +++++ .../resources/javascript/app/pollPreview.js | 1 + .../javascript/lib/wysiwyg-bbcode/editor.js | 9 ++- 12 files changed, 81 insertions(+), 30 deletions(-) diff --git a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_en.properties b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_en.properties index b3ac2882dd..e1a0e98dd2 100644 --- a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_en.properties +++ b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_en.properties @@ -38,6 +38,8 @@ label.topic.notify_message=Notify me about the answer label.topic.no_smiles=Don't display smiles label.topic.close=Close label.topic.open=Reopen +label.addPoll=Add Poll +label.removePoll=Remove Poll #subscription label.subscribe=Subscribe label.subscribe.tooltip=Get mail notifications diff --git a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_es.properties b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_es.properties index 6e0341bd1d..f8b41b295d 100644 --- a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_es.properties +++ b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_es.properties @@ -463,3 +463,5 @@ label.topic.section.in=en label.tips.close=Cerrar este tema label.tips.open=Reabrir este tema label.poll.options.addPollItem=Añadir encuesta artículo +label.addPoll=Adicionar enquete +label.removePoll=Remover Poll diff --git a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_ru.properties b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_ru.properties index 9dbf2ccadf..9f52158480 100644 --- a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_ru.properties +++ b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_ru.properties @@ -461,3 +461,5 @@ label.topic.section.in=\u0432 label.tips.close=\u0417\u0430\u043A\u0440\u044B\u0442\u044C \u0442\u0435\u043C\u0443 label.tips.open=\u041E\u0442\u043A\u0440\u044B\u0442\u044C \u0442\u0435\u043C\u0443 label.poll.options.addPollItem=\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 +label.addPoll=\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435 +label.removePoll=\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435 diff --git a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_uk.properties b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_uk.properties index ba11168407..843e469f99 100644 --- a/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_uk.properties +++ b/jcommune-view/jcommune-web-view/src/main/resources/org/jtalks/jcommune/web/view/messages_uk.properties @@ -462,4 +462,6 @@ label.branch.header.lastMessage.tooltip=\u041F\u0435\u0440\u0435\u0439\u0442\u04 label.topic.section.in=\u0432 label.tips.close=\u0417\u0430\u043A\u0440\u0438\u0442\u0438 \u0442\u0435\u043C\u0443 label.tips.open=\u0412\u0456\u0434\u043A\u0440\u0438\u0442\u0438 \u0442\u0435\u043C\u0443 -label.poll.options.addPollItem=\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u0438 \u043d\u043e\u0432\u0438\u0439 \u0432\u0430\u0440\u0456\u0430\u043d\u0442 +label.poll.options.addPollItem=\u0414\u043e\u0434\u0430\u0442\u0438 \u043d\u043e\u0432\u0438\u0439 \u0432\u0430\u0440\u0456\u0430\u043d\u0442 +label.addPoll=\u0414\u043e\u0434\u0430\u0442\u0438 \u043e\u043f\u0438\u0442\u0443\u0432\u0430\u043d\u043d\u044f +label.removePoll=\u0412\u044b\u0434\u0430\u043b\u0438\u0442\u0438 \u043e\u043f\u0438\u0442\u0443\u0432\u0430\u043d\u043d\u044f diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp index d12fc3eca9..758d2ef7bb 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp +++ b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp @@ -78,10 +78,15 @@ postText="${topicDto.bodyText}" bodyParameterName="bodyText" back="${pageContext.request.contextPath}/branches/${branchId}"/> + + "/> + + +


- -
+
@@ -104,16 +109,20 @@
+
-
- -
+
+
+
@@ -138,9 +147,23 @@ +
+
+ + + + +   + +
+ +
- +
+
@@ -148,23 +171,11 @@
- -
- - - - -   - -
- -
- <%--Make parent div include floated divs explicitly, or they'll be shown out of parent container--%> + <%--Make parent div include floated divs explicitly, or they'll be shown out of parent container--%>
+
@@ -173,8 +184,4 @@
- diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/tags/bbeditor.tag b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/tags/bbeditor.tag index 5249746779..848e5c8b02 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/tags/bbeditor.tag +++ b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/tags/bbeditor.tag @@ -161,13 +161,14 @@ - "/> + "/> " onclick="togglePreviewMode(new Array('posts', 'topics'));return null;"/> + diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/decorator.jsp b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/decorator.jsp index f40a1c52cd..977cd63d9b 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/decorator.jsp +++ b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/decorator.jsp @@ -256,6 +256,9 @@ in the future. +
+ + diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/jsMessages.jsp b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/jsMessages.jsp index 13bb77a89d..9686badc55 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/jsMessages.jsp +++ b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/template/jsMessages.jsp @@ -153,4 +153,6 @@ $labelFailedToLoadGroups = ' Date: Thu, 26 Feb 2015 10:44:07 +0200 Subject: [PATCH 4/5] #JC-1373 Add dynamic poll item functionality * Rename poll button id * Rename poll config class --- .../jtalks/jcommune/web/controller/TopicController.java | 8 ++++---- .../{DynamicPollItemsConfig.java => PollItemsConfig.java} | 2 +- .../src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp | 2 +- .../main/webapp/resources/javascript/app/pollNewTopic.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/view/{DynamicPollItemsConfig.java => PollItemsConfig.java} (96%) diff --git a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java index f5f600d2c1..2fd698f456 100644 --- a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java +++ b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/controller/TopicController.java @@ -26,7 +26,7 @@ import org.jtalks.jcommune.web.dto.json.JsonResponse; import org.jtalks.jcommune.web.dto.json.JsonResponseStatus; import org.jtalks.jcommune.web.validation.editors.DateTimeEditor; -import org.jtalks.jcommune.web.view.DynamicPollItemsConfig; +import org.jtalks.jcommune.web.view.PollItemsConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -81,7 +81,7 @@ public class TopicController { private LocationService locationService; private SessionRegistry sessionRegistry; private EntityToDtoConverter converter; - private DynamicPollItemsConfig dynamicPollItemsConfig = new DynamicPollItemsConfig(); + private PollItemsConfig pollItemsConfig = new PollItemsConfig(); /** * This method turns the trim binder on. Trim binder @@ -151,7 +151,7 @@ public ModelAndView showNewTopicPage(@RequestParam(BRANCH_ID) Long branchId) thr return new ModelAndView(TOPIC_VIEW) .addObject(TOPIC_DTO, dto) .addObject(BRANCH_ID, branchId) - .addObject(POLL_CONFIG, dynamicPollItemsConfig) + .addObject(POLL_CONFIG, pollItemsConfig) .addObject(SUBMIT_URL, "/topics/new?branchId=" + branchId) .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getNewTopicBreadcrumb(branch)); } @@ -174,7 +174,7 @@ public ModelAndView createTopic(@Valid @ModelAttribute TopicDto topicDto, return new ModelAndView(TOPIC_VIEW) .addObject(BRANCH_ID, branchId) .addObject(TOPIC_DTO, topicDto) - .addObject(POLL_CONFIG, dynamicPollItemsConfig) + .addObject(POLL_CONFIG, pollItemsConfig) .addObject(SUBMIT_URL, "/topics/new?branchId=" + branchId) .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getForumBreadcrumb(branch)); } diff --git a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/view/DynamicPollItemsConfig.java b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/view/PollItemsConfig.java similarity index 96% rename from jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/view/DynamicPollItemsConfig.java rename to jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/view/PollItemsConfig.java index f639e2b457..4040eda7de 100644 --- a/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/view/DynamicPollItemsConfig.java +++ b/jcommune-view/jcommune-web-controller/src/main/java/org/jtalks/jcommune/web/view/PollItemsConfig.java @@ -20,7 +20,7 @@ * Contains configuration for Dynamic Poll Items * @author Andrey Ivanov */ -public class DynamicPollItemsConfig { +public class PollItemsConfig { public Integer getMaxPollItems(){ return Poll.MAX_ITEMS_NUMBER; diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp index 758d2ef7bb..a8f0c68d7b 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp +++ b/jcommune-view/jcommune-web-view/src/main/webapp/WEB-INF/jsp/topic/topicForm.jsp @@ -79,7 +79,7 @@ bodyParameterName="bodyText" back="${pageContext.request.contextPath}/branches/${branchId}"/> - "/> diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js b/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js index 84c54eeffd..b360531c54 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js +++ b/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/app/pollNewTopic.js @@ -4,7 +4,7 @@ $(document).ready(function() { $("a#add").hide(); } - $("#addPollButton").click(function(){ + $("#pollButton").click(function(){ if($(this).attr("rel") == "add") { $(this).attr("value", $labelRemovePoll); $(this).attr("rel", "delete"); From aaeb7047d0a64e7a1dc41004573f1670697df99b Mon Sep 17 00:00:00 2001 From: Andrey Ivanov Date: Thu, 26 Feb 2015 14:17:07 +0200 Subject: [PATCH 5/5] #JC-1373 Add dynamic poll item functionality * Rename pollButton in any places --- .../javascript/lib/wysiwyg-bbcode/editor.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/lib/wysiwyg-bbcode/editor.js b/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/lib/wysiwyg-bbcode/editor.js index 77cb5ab07d..dcf59161fa 100644 --- a/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/lib/wysiwyg-bbcode/editor.js +++ b/jcommune-view/jcommune-web-view/src/main/webapp/resources/javascript/lib/wysiwyg-bbcode/editor.js @@ -82,7 +82,7 @@ function initEditor(textAreaId, htmlAreaId, baseDivId) { * preview mode. */ function togglePreviewMode(allowedUrls) { - addPollItemButton = $("input#addPollButton"); + pollButton = $("input#pollButton"); if (editorVisible) { // exit preview textboxelement.style.display = ""; htmlcontentelement.style.display = "none"; @@ -92,8 +92,8 @@ function togglePreviewMode(allowedUrls) { $('#preview')[0].value = $labelPreview; $('.keymaps-caption').show(); $('#postBody').focus(); - if(addPollItemButton.length) { - addPollItemButton.removeClass("hide"); + if(pollButton.length) { + pollButton.removeClass("hide"); } } else { // enter preview @@ -172,9 +172,9 @@ function bbcode2html(allowedUrls) { ErrorUtils.removeErrorMessage(elId); //do code highlight prettyPrint(null, '#htmlContent'); - addPollItemButton = $("input#addPollButton"); - if(addPollItemButton.length) { - addPollItemButton.addClass("hide"); + pollButton = $("input#pollButton"); + if(pollButton.length) { + pollButton.addClass("hide"); } } }