From: Sven Arnold Date: Mon, 13 Apr 2009 16:07:03 +0000 (+0200) Subject: fixed rendering of news and views X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9230da76f44b1abf41406c5051e293132a650f10;p=Grails-CMS.git fixed rendering of news and views --- diff --git a/grails-app/conf/BootStrap.groovy b/grails-app/conf/BootStrap.groovy index 293350b..ce47abf 100644 --- a/grails-app/conf/BootStrap.groovy +++ b/grails-app/conf/BootStrap.groovy @@ -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.") diff --git a/grails-app/controllers/NewsController.groovy b/grails-app/controllers/NewsController.groovy index f9474c7..0a6148a 100644 --- a/grails-app/controllers/NewsController.groovy +++ b/grails-app/controllers/NewsController.groovy @@ -2,103 +2,10 @@ 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() ] + } } diff --git a/grails-app/controllers/PageController.groovy b/grails-app/controllers/PageController.groovy index 3143946..a80df35 100644 --- a/grails-app/controllers/PageController.groovy +++ b/grails-app/controllers/PageController.groovy @@ -1,120 +1,25 @@ 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() ] + } + } + } } diff --git a/grails-app/domain/News.groovy b/grails-app/domain/News.groovy index 8907c8b..00b2225 100644 --- a/grails-app/domain/News.groovy +++ b/grails-app/domain/News.groovy @@ -7,5 +7,7 @@ class News { String content static constraints = { + title(nullable: false) + content(widget: 'textarea') } } diff --git a/grails-app/domain/Page.groovy b/grails-app/domain/Page.groovy index d4eea64..a97a003 100644 --- a/grails-app/domain/Page.groovy +++ b/grails-app/domain/Page.groovy @@ -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) {