Permalink
Browse files

refactored the new comment form

  • Loading branch information...
1 parent dca22ee commit dc31688257ed069dc8646f296f094359b7eed59b @jettro committed Nov 29, 2009
@@ -2,33 +2,37 @@ import org.joda.time.DateTime
class BootStrap {
def init = {
-// servletContext ->
-// def statussus = ['OK', 'WARNING', 'PROBLEM', 'COLD']
-// statussus.each {
-// statusName ->
-// def newStatus = new Status(name: statusName)
-// newStatus.save()
-// }
-//
-// def vlans = [['Middleware', 'middle_dev'], ['Backend', 'backend_dev'], ['Beheer', 'maint_dev'], ['Backup', 'backup_dev']]
-// vlans.each {
-// vlanFunction, vlanName ->
-// def newVlan = new Vlan(name: vlanName, function: vlanFunction)
-// newVlan.save()
-// }
-//
-// def environments = ['Development', 'Test', 'Acceptation', 'Production']
-// environments.each {
-// name ->
-// def environment = new Environment(name: name, lastDeploy:new DateTime())
-// environment.save()
-// }
-//
-// def okStatus = Status.findByName("OK")
-// def warningStatus = Status.findByName("WARNING")
-// def errorStatus = Status.findByName("PROBLEM")
-// def coldStatus = Status.findByName("COLD")
+ servletContext ->
+ def statussus = ['OK', 'WARNING', 'PROBLEM', 'COLD']
+ statussus.each {
+ statusName ->
+ def newStatus = new Status(name: statusName)
+ newStatus.save()
+ }
+ def vlans = [['Middleware', 'middle_dev'], ['Backend', 'backend_dev'], ['Beheer', 'maint_dev'], ['Backup', 'backup_dev']]
+ vlans.each {
+ vlanFunction, vlanName ->
+ def newVlan = new Vlan(name: vlanName, function: vlanFunction)
+ newVlan.save()
+ }
+
+ def environments = ['Development', 'Test', 'Acceptation', 'Production']
+ environments.each {
+ name ->
+ def environment = new Environment(name: name, lastDeploy:new DateTime())
+ environment.save()
+ }
+
+ def okStatus = Status.findByName("OK")
+ def warningStatus = Status.findByName("WARNING")
+ def errorStatus = Status.findByName("PROBLEM")
+ def coldStatus = Status.findByName("COLD")
+
+ def backend1 = new Server(name:'backend 1',function:'appserver',status:okStatus,externalIp:'127.0.0.1')
+
+ def devEnvironment = Environment.findByName("Development")
+ devEnvironment.addToServers(backend1)
}
def destroy = {
}
@@ -16,9 +16,13 @@ class OverviewController {
render(template:"/shared/comment",model:[comments:allComments, server:currentServer])
}
- def addComment = {
- commentService.createComment(params.serverId.toLong(),params.name,params.content)
- redirect(action:'index')
+ 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)
+ redirect(action:'index')
}
def newComment = {
@@ -17,6 +17,7 @@ class CommentService {
if (comment.save()) {
return comment
} else {
+ log.info "Error while saving a comment"
throw new CommentException (message: 'invalid comment being created', comment:comment)
}
@@ -1,23 +1,23 @@
<html>
- <head>
- <title><g:layoutTitle default="Grails" /></title>
- <link rel="stylesheet" href="${resource(dir:'css',file:'main.css')}" />
- <link rel="shortcut icon" href="${resource(dir:'images',file:'favicon.ico')}" type="image/x-icon" />
- <g:layoutHead />
- <g:javascript library="application" />
- <g:javascript library="prototype" />
- </head>
- <body>
- <div id="spinner" class="spinner" style="display:none;">
- <img src="${resource(dir:'images',file:'spinner.gif')}" alt="Spinner" />
- </div>
- <div class="logo"><img src="${resource(dir:'images',file:'serverpark_logo.png')}" alt="ServerPark" /></div>
- <g:if test="${flash.error}">
- <div class="flasherror">${flash.error}</div>
- </g:if>
- <g:if test="${flash.message}">
- <div class="flash">${flash.message}</div>
- </g:if>
- <g:layoutBody />
- </body>
+<head>
+ <title><g:layoutTitle default="Grails"/></title>
+ <link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}"/>
+ <link rel="shortcut icon" href="${resource(dir: 'images', file: 'favicon.ico')}" type="image/x-icon"/>
+ <g:layoutHead/>
+ <g:javascript library="application"/>
+ <g:javascript library="prototype"/>
+</head>
+<body>
+<div id="spinner" class="spinner" style="display:none;">
+ <img src="${resource(dir: 'images', file: 'spinner.gif')}" alt="Spinner"/>
+</div>
+<div class="logo"><img src="${resource(dir: 'images', file: 'serverpark_logo.png')}" alt="ServerPark"/></div>
+<g:if test="${flash.error}">
+ <div class="flasherror">${flash.error}</div>
+</g:if>
+<g:if test="${flash.message}">
+ <div class="flash">${flash.message}</div>
+</g:if>
+<g:layoutBody/>
+</body>
</html>
@@ -10,10 +10,15 @@
<span class="menuButton"><a class="home" href="${resource(dir: '')}">Home</a></span>
</div>
<span>New comment for ${server.toString()}</span>
+ <g:hasErrors>
+ <div class="errors">
+ <g:renderErrors bean="${comment}" as="list"/>
+ </div>
+ </g:hasErrors>
<g:form action="addComment" method="POST">
- <g:hiddenField name="serverId" value="${server.id}"/>
- Name : <g:textField name="name" value=""/><br/>
- Content : <g:textArea name="content" value=""/><br/>
+ <g:hiddenField name="server.id" value="${server.id}"/>
+ Name : <g:textField name="name" value="${comment?.name}"/><br/>
+ Content : <g:textArea name="content" value="${comment?.content}"/><br/>
<g:actionSubmit value="Add Comment"/>
</g:form>
</body>
@@ -1,13 +1,7 @@
-<%--
- Created by IntelliJ IDEA.
- User: jettropro
- Date: Nov 5, 2009
- Time: 10:46:51 AM
- To change this template use File | Settings | File Templates.
---%>
-
+%{-- Do something with pagination--}%
+%{-- Use ajax to load and commit the form --}%
<div class="comment">
- <span class="title">${server.name}</span><span class="action"><g:link controller="comment" action="create" params="['server.id':server.id]">create comment</g:link><g:link controller="overview" action="newComment" params="['serverid':server.id]">create form</g:link></span>
+ <span class="title">${server.name}</span><span class="action"><g:link controller="overview" action="newComment" params="['serverid':server.id]">create comment</g:link></span>
<g:each in="${comments}" status="i" var="comment">
<div>
<span class="author">${comment.name}</span>

0 comments on commit dc31688

Please sign in to comment.