fixed rendering of news and views
authorSven Arnold <sven@schnuppe.(none)>
Mon, 13 Apr 2009 16:07:03 +0000 (18:07 +0200)
committerSven Arnold <sven@schnuppe.(none)>
Mon, 13 Apr 2009 16:07:03 +0000 (18:07 +0200)
grails-app/conf/BootStrap.groovy
grails-app/controllers/NewsController.groovy
grails-app/controllers/PageController.groovy
grails-app/domain/News.groovy
grails-app/domain/Page.groovy

index 293350b..ce47abf 100644 (file)
@@ -7,10 +7,6 @@ class BootStrap {
     switch (GrailsUtil.environment) {
       case "development":
         
-        // initialize configuration
-        def config = new PortalConfiguration(name: "default", title: "Schnuppe Portal", motto: "A new star is born", theme: "grey")
-        assert config.save()
-
         // some top level pages
         def root1 = new Page(title: "Home", author: "sven", language: "en", content: "My Home is my castle.")
         def root2 = new Page(title: "About Me", author: "sven", language: "en", content: "I am drunk and sick.")
index f9474c7..0a6148a 100644 (file)
 
 class NewsController {
     
-    def index = { redirect(action:list,params:params) }
+       def scaffold = News
 
-    // the delete, save and update actions only accept POST requests
-    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
-
-    def list = {
-        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
-        [ newsInstanceList: News.list( params ), newsInstanceTotal: News.count() ]
-    }
-
-    def show = {
-        def newsInstance = News.get( params.id )
-
-        if(!newsInstance) {
-            flash.message = "News not found with id ${params.id}"
-            redirect(action:list)
-        }
-        else { return [ newsInstance : newsInstance ] }
-    }
-
-    def delete = {
-        def newsInstance = News.get( params.id )
-        if(newsInstance) {
-            try {
-                newsInstance.delete()
-                flash.message = "News ${params.id} deleted"
-                redirect(action:list)
-            }
-            catch(org.springframework.dao.DataIntegrityViolationException e) {
-                flash.message = "News ${params.id} could not be deleted"
-                redirect(action:show,id:params.id)
-            }
-        }
-        else {
-            flash.message = "News not found with id ${params.id}"
-            redirect(action:list)
-        }
-    }
-
-    def edit = {
-        def newsInstance = News.get( params.id )
-
-        if(!newsInstance) {
-            flash.message = "News not found with id ${params.id}"
-            redirect(action:list)
-        }
-        else {
-            return [ newsInstance : newsInstance ]
-        }
-    }
-
-    def update = {
-        def newsInstance = News.get( params.id )
-        if(newsInstance) {
-            if(params.version) {
-                def version = params.version.toLong()
-                if(newsInstance.version > version) {
-                    
-                    newsInstance.errors.rejectValue("version", "news.optimistic.locking.failure", "Another user has updated this News while you were editing.")
-                    render(view:'edit',model:[newsInstance:newsInstance])
-                    return
-                }
-            }
-            newsInstance.properties = params
-            if(!newsInstance.hasErrors() && newsInstance.save()) {
-                flash.message = "News ${params.id} updated"
-                redirect(action:show,id:newsInstance.id)
-            }
-            else {
-                render(view:'edit',model:[newsInstance:newsInstance])
-            }
-        }
-        else {
-            flash.message = "News not found with id ${params.id}"
-            redirect(action:edit,id:params.id)
-        }
-    }
-
-    def create = {
-        def newsInstance = new News()
-        newsInstance.properties = params
-        return ['newsInstance':newsInstance]
-    }
-
-    def save = {
-        def newsInstance = new News(params)
-        if(!newsInstance.hasErrors() && newsInstance.save()) {
-            flash.message = "News ${newsInstance.id} created"
-            redirect(action:show,id:newsInstance.id)
-        }
-        else {
-            render(view:'create',model:[newsInstance:newsInstance])
-        }
-    }
-
-  def display = {
-    params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
-    [ newsInstanceList: News.list( params ), newsInstanceTotal: News.count() ]    
-  }
+       def display = {
+               params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
+               [ newsInstanceList: News.list( params ), newsInstanceTotal: News.count() ]    
+       }
 }
index 3143946..a80df35 100644 (file)
 class PageController {
 
-  def index = { redirect(action: list, params: params) }
-
-  // the delete, save and update actions only accept POST requests
-  static allowedMethods = [delete: 'POST', save: 'POST', update: 'POST']
-
-  def list = {
-    params.max = Math.min(params.max ? params.max.toInteger() : 10, 100)
-    [pageInstanceList: Page.list(params), pageInstanceTotal: Page.count()]
-  }
-
-  def show = {
-    def pageInstance = Page.get(params.id)
-
-    if (!pageInstance) {
-      flash.message = "Page not found with id ${params.id}"
-      redirect(action: list)
-    }
-    else { return [pageInstance: pageInstance] }
-  }
-
-
-  def delete = {
-    def pageInstance = Page.get(params.id)
-    if (pageInstance) {
-      try {
-        pageInstance.delete()
-        flash.message = "Page ${params.id} deleted"
-        redirect(action: list)
-      }
-      catch (org.springframework.dao.DataIntegrityViolationException e) {
-        flash.message = "Page ${params.id} could not be deleted"
-        redirect(action: show, id: params.id)
-      }
-    }
-    else {
-      flash.message = "Page not found with id ${params.id}"
-      redirect(action: list)
-    }
-  }
-
-  def edit = {
-    def pageInstance = Page.get(params.id)
-
-    if (!pageInstance) {
-      flash.message = "Page not found with id ${params.id}"
-      redirect(action: list)
-    }
-    else {
-      return [pageInstance: pageInstance]
-    }
-  }
-
-  def update = {
-    def pageInstance = Page.get(params.id)
-    if (pageInstance) {
-      if (params.version) {
-        def version = params.version.toLong()
-        if (pageInstance.version > version) {
-
-          pageInstance.errors.rejectValue("version", "page.optimistic.locking.failure", "Another user has updated this Page while you were editing.")
-          render(view: 'edit', model: [pageInstance: pageInstance])
-          return
-        }
-      }
-      pageInstance.properties = params
-      if (!pageInstance.hasErrors() && pageInstance.save()) {
-        flash.message = "Page ${params.id} updated"
-        redirect(action: show, id: pageInstance.id)
-      }
-      else {
-        render(view: 'edit', model: [pageInstance: pageInstance])
-      }
-    }
-    else {
-      flash.message = "Page not found with id ${params.id}"
-      redirect(action: edit, id: params.id)
-    }
-  }
-
-  def create = {
-    def pageInstance = new Page()
-    pageInstance.properties = params
-    return ['pageInstance': pageInstance]
-  }
-
-  def save = {
-    def pageInstance = new Page(params)
-    if (!pageInstance.hasErrors() && pageInstance.save()) {
-      flash.message = "Page ${pageInstance.id} created"
-      redirect(action: show, id: pageInstance.id)
-    }
-    else {
-      render(view: 'create', model: [pageInstance: pageInstance])
-    }
-  }
-
-
-  def display = {
-    
-    def pageInstance = Page.get(params.id)
-
-    if (!pageInstance) {
-      flash.message = "Page not found with id ${params.id}"
-      redirect(action: list)
-    }
-    else {
-//    if (pageInstance instanceof ControllerPage) {
-//      redirect(controller: pageInstance.controller, action: 'list')
-//    }
-
-      if (pageInstance.hasControllerName())  {
-        chain(controller: pageInstance.controllerName, action: 'display', model: [pageInstance: pageInstance, subNavigation: pageInstance.getNavigationPages() ])
-      } else {
-        return [pageInstance: pageInstance, subNavigation: pageInstance.getNavigationPages() ]
-      }
-    }
-  }
+       def scaffold = Page     
+       
+       def display = {
+       
+               def pageInstance = Page.get(params.id)
+               
+               if (!pageInstance) {
+                       flash.message = "Page not found with id ${params.id}"
+                       redirect(action: list)
+               }
+               else {
+                       //    if (pageInstance instanceof ControllerPage) {
+                       //      redirect(controller: pageInstance.controller, action: 'list')
+                       //    }
+                       
+                       if (pageInstance.hasControllerName())  {
+                               chain(controller: pageInstance.controllerName, action: 'display', model: [pageInstance: pageInstance, subNavigation: pageInstance.navigationPages() ])
+                       } else {
+                               return [pageInstance: pageInstance, subNavigation: pageInstance.navigationPages() ]
+                       }
+               }
+       }
 }
index 8907c8b..00b2225 100644 (file)
@@ -7,5 +7,7 @@ class News {
   String content
 
   static constraints = {
+         title(nullable: false)
+         content(widget: 'textarea')
   }
 }
index d4eea64..a97a003 100644 (file)
@@ -21,7 +21,7 @@ class Page implements Comparable {
     ordinal()
     author(nullable: false)
     language(nullable:true)
-    content(nullable:true)
+    content(nullable:true, widget: 'textarea')
     controllerName(nullable:true)
   }
   
@@ -29,29 +29,29 @@ class Page implements Comparable {
     ordinal.compareTo(obj.ordinal)
   }
 
-  def getRoot() {
+  def findRoot() {
     if (parent)
-      return parent.getRoot()
+      return parent.findRoot()
     else
       return this
   }
 
-  def getSiblings() {
+  def siblings() {
     if (parent)
       return Page.findAllByParent(parent)
     else
       return this
   }
 
-  def getChildren() {
+  def children() {
     return Page.findAllByParent(this)
   }
 
-  def getNavigationPages() {
+  def navigationPages() {
     if (parent == null)
-      return getChildren()
+      return children()
     else
-      return getSiblings()
+      return siblings()
   }
 
   boolean isAncestor(Page page) {