Commit 8726494e authored by Matija Obreza's avatar Matija Obreza
Browse files

Edit ActivityPost on separate page

parent 37cf9f81
......@@ -75,4 +75,10 @@ public interface ContentService {
Article createGlobalArticle(String slug, Locale locale, String title, String body);
ActivityPost getActivityPost(long id);
ActivityPost updateActivityPost(long id, String title, String body);
void deleteActivityPost(long id);
}
......@@ -148,7 +148,7 @@ public class ContentServiceImpl implements ContentService {
@PreAuthorize("hasRole('ADMINISTRATOR')")
public Article updateArticle(Class<?> clazz, Long id, String slug, String title, String body, Locale locale) {
Article article = getArticle(clazz, id, slug, locale);
if (article == null || ! article.getLang().equals(locale.getLanguage())) {
if (article == null || !article.getLang().equals(locale.getLanguage())) {
article = new Article();
article.setClassPk(ensureClassPK(clazz));
article.setTargetId(id);
......@@ -189,21 +189,42 @@ public class ContentServiceImpl implements ContentService {
return classPk;
}
@Override
public ActivityPost getActivityPost(long id) {
return postRepository.findOne(id);
}
/**
* Sanitize content and persist new {@link ActivityPost}
* Create and persist a new {@link ActivityPost}
*/
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
public ActivityPost createActivityPost(String title, String body) {
ActivityPost newPost = new ActivityPost();
newPost.setTitle(htmlSanitizer.sanitize(title));
newPost.setBody(htmlSanitizer.sanitize(body));
newPost.setPostDate(GregorianCalendar.getInstance());
return updatePostData(newPost, title, body);
}
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
public ActivityPost updateActivityPost(long id, String title, String body) {
ActivityPost post = postRepository.findOne(id);
return updatePostData(post, title, body);
}
private ActivityPost updatePostData(ActivityPost post, String title, String body) {
post.setTitle(htmlSanitizer.sanitize(title));
post.setBody(htmlSanitizer.sanitize(body));
return postRepository.save(post);
}
postRepository.save(newPost);
LOG.info("Added new: " + newPost);
return newPost;
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
public void deleteActivityPost(long id) {
postRepository.delete(id);
}
}
......@@ -14,7 +14,6 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.controller;
import java.util.Calendar;
......@@ -22,12 +21,16 @@ import java.util.Calendar;
import net.sf.oval.constraint.NotEmpty;
import net.sf.oval.constraint.NotNull;
import org.genesys2.server.model.impl.ActivityPost;
import org.genesys2.server.service.ContentService;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -35,15 +38,55 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/content/activity")
@RequestMapping("/content/activitypost")
public class ActivityPostController extends BaseController {
@Autowired
private ContentService contentService;
@RequestMapping(value = "/add-post-x", method = { RequestMethod.POST })
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("/new")
public String newPost(ModelMap model) {
model.addAttribute("activityPost", new ActivityPost());
return "/content/activitypost-edit";
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("{id}/edit")
public String update(ModelMap model, @PathVariable("id") long id) {
ActivityPost activityPost = contentService.getActivityPost(id);
if (activityPost == null) {
throw new ResourceNotFoundException();
}
model.addAttribute("activityPost", activityPost);
return "/content/activitypost-edit";
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping("{id}/delete")
public String delete(ModelMap model, @PathVariable("id") long id) {
contentService.deleteActivityPost(id);
return "redirect:/";
}
@PreAuthorize("hasRole('ADMINISTRATOR')")
@RequestMapping(value = "/update", params = { "id" }, method = { RequestMethod.POST })
public String updatePost(ModelMap model, @RequestParam("id") long id, @RequestParam("title") String title, @RequestParam("body") String body) {
contentService.updateActivityPost(id, title, body);
return "redirect:/";
}
@RequestMapping(value = "/update", method = { RequestMethod.POST })
public String postPost(ModelMap model, @RequestParam("title") String title, @RequestParam("body") String body) {
contentService.createActivityPost(title, body);
return "redirect:/";
}
......
......@@ -50,7 +50,7 @@ add=Add
edit=Edit
save=Save
cancel=Cancel
sample.message.delete=Delete
delete=Delete
#JS messages
sample.js.message.confirm.deleting=Do you really want to remove this item?
......@@ -229,10 +229,10 @@ menu.report-an-issue=Report an issue
menu.scm=Source code
menu.translate=Translate Genesys
activitypost=Activity post
activitypost.add-new-post=Add new post
activitypost.post-title=Post title
activitypost.post-body=Body
activitypost.add-post=Add post
blurp.admin-no-blurp-here=No blurp here.
blurp.blurp-title=Blurp title
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<sec:authorize access="hasRole('ADMINISTRATOR')">
<html>
<head>
<title>${acitivtypost.title}</title>
<script type="text/javascript" src="/html/js/tinymce/tinymce.min.js"></script>
</head>
<body>
<h1>
<spring:message code="activitypost" />
</h1>
<form role="form" class="" action="<c:url value="/content/activity/add-post-x" />" method="post">
<form role="form" class="" action="<c:url value="/content/activitypost/update" />" method="post">
<c:if test="${activityPost.id ne null}">
<input type="hidden" name="id" value="${activityPost.id}" />
</c:if>
<div class="form-group">
<label for="post-title" class="control-label"><spring:message code="activitypost.post-title" /></label>
<div class="controls">
<input type="text" id="post-title" name="title" class="span9 required html-editor" />
<textarea id="post-title" name="title" class="span9 required html-editor">
<c:out value="${activityPost.title}" escapeXml="false" />
</textarea>
</div>
</div>
<div class="form-group">
<label for="post-body" class="control-label"><spring:message code="activitypost.post-body" /></label>
<div class="controls">
<textarea id="post-body" name="body" class="span9 required html-editor"></textarea>
<textarea id="post-body" name="body" class="span9 required html-editor">
<c:out value="${activityPost.body}" escapeXml="false" />
</textarea>
</div>
</div>
<input type="submit" value="<spring:message code="activitypost.add-post"/>" class="btn btn-primary" />
<input type="submit" value="<spring:message code="save"/>" class="btn btn-primary" />
<c:if test="${activityPost.id ne null}">
<a class="btn btn-default" href="<c:url value="/content/activitypost/${activityPost.id}/delete" />"><spring:message code="delete" /></a>
</c:if>
<a class="btn btn-default" href="<c:url value="/" />"><spring:message code="cancel" /></a>
</form>
<script type="text/javascript">
......@@ -25,16 +46,19 @@
selector : "#post-title.html-editor",
menubar : false,
statusbar : false,
height: 50,
directionality: document.dir
height : 50,
directionality : document.dir
});
tinyMCE.init({
selector : "#post-body.html-editor",
menubar : false,
statusbar : false,
height: 200,
directionality: document.dir
height : 200,
directionality : document.dir
});
});
</script>
</sec:authorize>
</body>
</html>
<%@include file="/WEB-INF/jsp/init.jsp"%>
<div class="activity-post">
<security:authorize access="hasRole('ADMINISTRATOR')">
<a href="<c:url value="/content/activitypost/${activityPost.id}/edit" />" class="close"> <spring:message code="edit" />
</a>
</security:authorize>
<div class="heading">
<c:out value="${activityPost.title}" escapeXml="false" />
</div>
<c:if test="${activityPost.body ne null and activityPost.body.length() gt 0}">
<div class="post-body">
<c:out value="${activityPost.body}" escapeXml="false" />
</div>
</c:if>
<div class="foot">
<fmt:formatDate value="${activityPost.postDate.time}" />
</div>
</div>
\ No newline at end of file
......@@ -10,59 +10,54 @@
<body>
<div id="crops-menu" class="content-block">
<c:if test="${cropList ne null and cropList.size() gt 0}">
<h1><spring:message code="crop.croplist"/></h1>
<sec:authorize access="hasRole('ADMINISTRATOR')">
<form method="post" action="<c:url value="/c/rebuild" />">
<input type="submit" class="btn form-control" value="Rebuild" />
</form>
</sec:authorize>
<ul class="funny-list">
<c:forEach items="${cropList}" var="crop" varStatus="status">
<li><a class="show" href="/c/${crop.shortName}/data"><c:out value="${crop.name}" /></a></li>
</c:forEach>
</ul>
</c:if>
<c:if test="${cropList ne null and cropList.size() gt 0}">
<h1>
<spring:message code="crop.croplist" />
</h1>
<sec:authorize access="hasRole('ADMINISTRATOR')">
<form method="post" action="<c:url value="/c/rebuild" />">
<input type="submit" class="btn form-control" value="Rebuild" />
</form>
</sec:authorize>
<ul class="funny-list">
<c:forEach items="${cropList}" var="crop" varStatus="status">
<li><a class="show" href="/c/${crop.shortName}/data"><c:out value="${crop.name}" /></a></li>
</c:forEach>
</ul>
</c:if>
</div>
<c:if test="${lastNews ne null}">
<div class="content-block" style="overflow: auto;">
<h1><spring:message code="activity.recent-activity"/></h1>
<%@include file="/WEB-INF/jsp/content/include/activity-post.jsp" %>
<c:forEach items="${lastNews}" var="activityPost" varStatus="status">
<div class="activity-post">
<div class="heading">
<c:out value="${activityPost.title}" escapeXml="false" />
</div>
<c:if test="${activityPost.body ne null and activityPost.body.length() gt 0}">
<div class="post-body">
<c:out value="${activityPost.body}" escapeXml="false" />
</div>
</c:if>
<div class="foot">
<fmt:formatDate value="${activityPost.postDate.time}" />
</div>
</div>
</c:forEach>
</div>
<div class="content-block" style="overflow: auto;">
<h1>
<spring:message code="activity.recent-activity" />
<security:authorize access="hasRole('ADMINISTRATOR')">
<a href="<c:url value="/content/activitypost/new" />" class="pull-right close" style=""> <spring:message code="activitypost.add-new-post" />
</a>
</security:authorize>
</h1>
<c:forEach items="${lastNews}" var="activityPost" varStatus="status">
<%@include file="/WEB-INF/jsp/content/include/activitypost.jsp"%>
</c:forEach>
</div>
</c:if>
<script type="text/javascript">
jQuery(document).ready(function() {
// Code to toggle the crops menu in small devices
$("body").on("click", "#crops-menu > h1", function(event) {
event.preventDefault();
var menu=$("#crops-menu .funny-list");
if (menu.attr('washidden') || ! menu.is(":visible")) {
menu.attr('washidden', true);
$("#crops-menu .funny-list").toggle();
}
});
});
</script>
<script type="text/javascript">
jQuery(document).ready(function() {
// Code to toggle the crops menu in small devices
$("body").on("click", "#crops-menu > h1", function(event) {
event.preventDefault();
var menu = $("#crops-menu .funny-list");
if (menu.attr('washidden') || !menu.is(":visible")) {
menu.attr('washidden', true);
$("#crops-menu .funny-list").toggle();
}
});
});
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment