Permalink
Browse files

more ajax and a delete option

  • Loading branch information...
1 parent 0cca133 commit f9e7b92711987b16393b75b582ca54ad37a1a78d @jettro committed Dec 2, 2009
View
22 grails-app/controllers/OverviewController.groovy
@@ -12,30 +12,26 @@ class OverviewController {
server {
eq("id", currentServer.id)
}
+ order("dateCreated","desc")
}
- render(template: "/shared/comment",
- model: [comments: allComments, server: currentServer, environmentId: params.environmentId])
- }
-
- def addComment = {Comment comment ->
- if (!comment.validate()) {
- render(view: 'newComment', model: [comment: comment, server: comment.server])
- return
- }
- commentService.createComment(comment.server.id, comment.name, comment.content)
- flash.message = "Comment is created for server ${comment.server.toString()}"
- redirect(action: 'index')
+ render(template: "comment", model: [comments: allComments, server: currentServer])
}
def addCommentAjax = {Comment comment ->
if (!comment.validate()) {
render "notGood"
} else {
commentService.createComment(comment.server.id, comment.name, comment.content)
- render "Comment is created for server ${comment.server.toString()}"
+ redirect(action:"comments",id:comment.server.id)
}
}
+ def removeCommentAjax = {
+ def currentComment = Comment.findById(params.id.toLong())
+ currentComment.delete()
+ redirect(action:"comments",id:currentComment.server.id)
+ }
+
def newComment = {
def currentServer = Server.findById(params.serverid)
if (!currentServer) {
View
5 grails-app/domain/Comment.groovy
@@ -1,11 +1,16 @@
+import org.joda.time.DateTime
+import org.joda.time.contrib.hibernate.PersistentDateTime
+
class Comment {
String name
String content
+ DateTime dateCreated
static belongsTo = [server:Server]
static mapping = {
content type: "text"
+ dateCreated type: PersistentDateTime, lazy: false
}
static constraints = {
View
2 grails-app/domain/Server.groovy
@@ -7,7 +7,7 @@ class Server {
Status status
static hasMany = [networks:NetworkDefinition]
- static belongsTo = Environment
+ static belongsTo = [environment:Environment]
static constraints = {
name(blank:false, maxSize:50)
View
15 grails-app/views/shared/_comment.gsp → grails-app/views/overview/_comment.gsp
@@ -1,22 +1,25 @@
-%{-- Do something with pagination--}%
-%{-- Use ajax to load and commit the form --}%
<div class="comment">
<span class="title">${server.name}</span>
- <div id="newComment${environmentId}">
+ <div id="newComment${server.environment.id}">
<g:form>
<g:hiddenField name="server.id" value="${server.id}"/>
Name :<br/><g:textField name="name" value="${comment?.name}"/><br/>
Content :<br/><g:textArea name="content" value="${comment?.content}" rows="2" cols="20"/><br/>
- <g:submitToRemote action="addCommentAjax" value="New Comment" onSuccess="addComment(e,'showComments${environmentId}')"/>
+ <g:submitToRemote action="addCommentAjax" value="New Comment" update="comments${server.environment.id}"/>
</g:form>
</div>
- <div id="showComments${environmentId}">
+ <div id="showComments${server.environment.id}">
<g:each in="${comments}" status="i" var="comment">
<div>
<span class="author">${comment.name}</span>
<span class="content">${comment.content}</span>
</div>
- <div><g:link controller="comment" action="edit" params="[id:comment.id]">edit</g:link></div>
+ <div>
+ <g:link controller="comment" action="edit" params="[id:comment.id]">edit</g:link>&nbsp;
+ <g:remoteLink action="removeCommentAjax" params="[id:comment.id]"
+ update="comments${server.environment.id}">remove</g:remoteLink>
+ </div>
+
</g:each>
</div>
</div>
View
16 grails-app/views/overview/comments.gsp
@@ -1,16 +0,0 @@
-<%@ page contentType="text/html;charset=UTF-8" %>
-<html>
-<head>
- <title>Server comments</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- <meta name="layout" content="main"/>
-</head>
-<body>
-<div class="nav">
- <span class="menuButton"><a class="home" href="${resource(dir: '')}">Home</a></span>
-</div>
-<div>
- <g:render template="/shared/comment" model="comments"/>
-</div>
-</body>
-</html>
View
6 grails-app/views/overview/index.gsp
@@ -19,7 +19,7 @@
<span class="menuButton"><g:link controller="server">Servers</g:link></span>
<span class="menuButton"><g:link controller="vlan">Vlans</g:link></span>
</div>
- <g:each in="${environments}" status="i" var="environment">
+ <g:each in="${environments}" var="environment">
<div class="yui-ge environment">
<div class="yui-u first">
<span class="title"><g:link action="show" controller="environment" id="${environment.id}">${environment.name}</g:link>
@@ -35,12 +35,12 @@
<li>${network.vlan} (${network.ipAddress})</li>
</g:each>
</ul>
- <g:remoteLink action="comments" params="[id:server.id, environmentId:environment.id]" update="comments${i}">comments</g:remoteLink>
+ <g:remoteLink action="comments" params="[id:server.id]" update="comments${environment.id}">comments</g:remoteLink>
</div>
</g:each>
</div>
<div class="yui-u">
- <div id="comments${i}" class="comments"></div>
+ <div id="comments${environment.id}" class="comments"></div>
</div>
</div>
</g:each>

0 comments on commit f9e7b92

Please sign in to comment.