Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added more ajax for adding a comment

  • Loading branch information...
commit 0cca13311843220cbcc8e1327975a70387706ef0 1 parent dc31688
@jettro authored
View
2  application.properties
@@ -1,5 +1,5 @@
#Grails Metadata file
-#Sun Nov 22 11:39:08 CET 2009
+#Mon Nov 30 14:18:12 CET 2009
app.grails.version=1.2-M4
app.name=myserverpark
app.servlet.version=2.4
View
31 grails-app/controllers/OverviewController.groovy
@@ -3,40 +3,51 @@ class OverviewController {
def commentService
def show = {
- redirect(uri:"/server/show/${params.id}")
+ redirect(uri: "/server/show/${params.id}")
}
def comments = {
def currentServer = Server.findById(params.id.toLong())
def allComments = Comment.withCriteria {
server {
- eq("id",currentServer.id)
+ eq("id", currentServer.id)
}
}
- render(template:"/shared/comment",model:[comments:allComments, server:currentServer])
+ 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])
+ render(view: 'newComment', model: [comment: comment, server: comment.server])
return
}
- commentService.createComment(comment.server.id,comment.name,comment.content)
- redirect(action:'index')
+ commentService.createComment(comment.server.id, comment.name, comment.content)
+ flash.message = "Comment is created for server ${comment.server.toString()}"
+ redirect(action: 'index')
+ }
+
+ 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()}"
+ }
}
def newComment = {
def currentServer = Server.findById(params.serverid)
if (!currentServer) {
flash.error = "You need to provide a server to be able to create new comment"
-
- render(action:'index')
+
+ render(action: 'index')
}
- [server:currentServer]
+ [server: currentServer]
}
def index = {
def environments = Environment.list()
- [environments:environments]
+ [environments: environments]
}
}
View
47 grails-app/views/layouts/main.gsp
@@ -1,23 +1,40 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
<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"/>
+ <title><g:layoutTitle default="Grails"/></title>
+ <link rel="stylesheet" href="http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css" type="text/css">
+ <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="scriptaculous"/>
</head>
<body>
<div id="spinner" class="spinner" style="display:none;">
- <img src="${resource(dir: 'images', file: 'spinner.gif')}" alt="Spinner"/>
+ <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/>
+<div id="doc3">
+ <div id="hd">
+ <img src="${resource(dir: 'images', file: 'serverpark_logo.png')}" alt="ServerPark"/><span>MyServerpark</span>
+ </div>
+ <div id="bd">
+ <div class="yui-b">
+ <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>
+ </div>
+ <div id="yui-main">
+ <div class="yui-b">
+ <g:layoutBody/>
+ </div>
+ </div>
+ </div>
+ <div id="ft" role="contentinfo"><p>Footer</p></div>
+</div>
+
</body>
</html>
View
57 grails-app/views/overview/index.gsp
@@ -1,17 +1,16 @@
-<%--
- Created by IntelliJ IDEA.
- User: jettropro
- Date: Nov 5, 2009
- Time: 8:49:07 AM
- To change this template use File | Settings | File Templates.
---%>
-
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<title>Simple GSP page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="main"/>
+ <g:javascript>
+ function addComment(e,divId) {
+ $(divId).value = e.responseText;
+ window.alert($(divId).value);
+ }
+ </g:javascript>
+
</head>
<body>
<div class="nav">
@@ -20,28 +19,30 @@
<span class="menuButton"><g:link controller="server">Servers</g:link></span>
<span class="menuButton"><g:link controller="vlan">Vlans</g:link></span>
</div>
-<div id="environments">
<g:each in="${environments}" status="i" var="environment">
- <div class="environment">
- <span class="title"><g:link action="show" controller="environment" id="${environment.id}">${environment.name}</g:link>
- - (last depoy : ${environment.lastDeploy.format('dd-MMM-yyyy HH:mm')})
- <g:each in="${environment.links.sort {a, b -> a.title.compareToIgnoreCase b.title}}" var="link"><a href="${link.url}" title="${link.title}">${link.title}</a>&nbsp;</g:each>
- </span>
- <g:each in="${environment.servers.sort { a, b -> a.name.compareToIgnoreCase b.name }}" var="server">
- <div class="server ${server.status.name.toLowerCase()}">
- <g:link action="show" id="${server.id}">${fieldValue(bean: server, field: 'name')}</g:link>
- <ul>
- <li>${server.function}</li>
- <g:each in="${server.networks.sort { a, b -> a.vlan.name.compareToIgnoreCase b.vlan.name }}" status="j" var="network">
- <li>${network.vlan} (${network.ipAddress})</li>
- </g:each>
- </ul>
- <g:remoteLink action="comments" params="[id:server.id]" update="comments${i}">comments</g:remoteLink>
- </div>
- </g:each>
- <div id="comments${i}" class="comments"></div>
+ <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>
+ - (last depoy : ${environment.lastDeploy.format('dd-MMM-yyyy HH:mm')})
+ <g:each in="${environment.links.sort {a, b -> a.title.compareToIgnoreCase b.title}}" var="link"><a href="${link.url}" title="${link.title}">${link.title}</a>&nbsp;</g:each>
+ </span>
+ <g:each in="${environment.servers.sort { a, b -> a.name.compareToIgnoreCase b.name }}" var="server">
+ <div class="server ${server.status.name.toLowerCase()}">
+ <g:link action="show" id="${server.id}">${fieldValue(bean: server, field: 'name')}</g:link>
+ <ul>
+ <li>${server.function}</li>
+ <g:each in="${server.networks.sort { a, b -> a.vlan.name.compareToIgnoreCase b.vlan.name }}" status="j" var="network">
+ <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>
+ </div>
+ </g:each>
+ </div>
+ <div class="yui-u">
+ <div id="comments${i}" class="comments"></div>
+ </div>
</div>
</g:each>
-</div>
</body>
</html>
View
26 grails-app/views/shared/_comment.gsp
@@ -1,12 +1,22 @@
%{-- 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="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>
- <span class="content">${comment.content}</span>
- </div>
- <div><g:link controller="comment" action="edit" params="[id:comment.id]">edit</g:link></div>
- </g:each>
+ <span class="title">${server.name}</span>
+ <div id="newComment${environmentId}">
+ <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:form>
+ </div>
+ <div id="showComments${environmentId}">
+ <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>
+ </g:each>
+ </div>
</div>
View
18 web-app/css/main.css
@@ -4,17 +4,11 @@ html * {
}
/* SPECIFIC FOR MY APP */
-#environments {
- width:80%;
- float:left;
-}
div.environment {
border: 1px solid black;
- width:100%;
- float:left;
}
-div.environment span.title {
+span.title {
display:block;
font-weight:bold;
}
@@ -127,11 +121,11 @@ input, select, textarea {
select {
padding: 2px 2px 2px 0;
}
-textarea {
- width: 250px;
- height: 150px;
- vertical-align: top;
-}
+/*textarea {*/
+ /*width: 250px;*/
+ /*height: 150px;*/
+ /*vertical-align: top;*/
+/*}*/
input:focus, select:focus, textarea:focus {
border: 1px solid #b2d1ff;
View
62 web-app/plugins/db-util-0.4/css/dbUtil.css
@@ -1,62 +0,0 @@
-h1 {
- color: #006dba;
- font-weight: normal;
- font-size: 26px;
- margin: .8em 0 .3em 0;
-}
-
-a:link, a:visited, a:hover {
- font: 16px verdana, arial, helvetica, sans-serif;
- color: #FFF;
- font-weight: bold;
- text-decoration: none;
- padding: 5px;
- margin: 1px;
- background-color: #CCC;
- border-left: 2px solid #000;
- border-right: 2px solid #000;
-}
-
-table {
- border: 1px solid #ccc;
- width: 100%
-}
-
-tr {
- border: 1px solid #ccc;
-}
-
-td, th {
- font: 11px verdana, arial, helvetica, sans-serif;
- line-height: 12px;
- padding: 5px 6px;
- text-align: left;
- vertical-align: top;
-}
-
-th {
- color: #666;
- font-size: 11px;
- font-weight: bold;
- line-height: 17px;
- padding: 2px 6px;
-}
-
-#inside {
- margin: 10px 10px 0px 10px;
- padding-top: 10px;
- padding-bottom: 10px;
-}
-
-#main-content {
- background: white;
- min-height: 480px;
- padding-top: 5px;
-}
-
-#header {
- overflow: hidden;
- display: inline;
- height: 30px;
- margin: 0px;
-}
Please sign in to comment.
Something went wrong with that request. Please try again.