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.")
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() ]
+ }
}
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() ]
+ }
+ }
+ }
}
String content
static constraints = {
+ title(nullable: false)
+ content(widget: 'textarea')
}
}
ordinal()
author(nullable: false)
language(nullable:true)
- content(nullable:true)
+ content(nullable:true, widget: 'textarea')
controllerName(nullable:true)
}
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) {