Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1808a8a
commit c92c242
Showing
13 changed files
with
315 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
SpudCms/grails-app/controllers/spud/admin/MenuItemsController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package spud.admin | ||
import spud.cms.* | ||
import spud.core.* | ||
|
||
@SpudApp(name="Menus", thumbnail="spud/admin/menus_thumb.png") | ||
@SpudSecure(['MENUS']) | ||
class MenuItemsController { | ||
static namespace = "spud_admin" | ||
|
||
def index() { | ||
def menu = loadMenu() | ||
if(!menu) { | ||
return | ||
} | ||
def menuItems = SpudMenuItem.findAllByMenu(menu) | ||
render view: '/spud/admin/menu_items/index', model:[menuItems: menuItems] | ||
} | ||
|
||
def create() { | ||
def menu = new SpudMenu() | ||
render view: '/spud/admin/menus/create', model:[menu: menu] | ||
} | ||
|
||
def save() { | ||
if(!params.menu) { | ||
flash.error = "Menu submission not specified" | ||
redirect resource: 'menus', action: 'index', namespace: 'spud_admin' | ||
return | ||
} | ||
|
||
def menu = new SpudMenu(params.menu) | ||
|
||
|
||
|
||
if(menu.save(flush:true)) { | ||
redirect resource: 'menus', action: 'index', namespace: 'spud_admin' | ||
} else { | ||
flash.error = "Error Saving Menu" | ||
render view: '/spud/admin/menus/create', model:[menu:menu] | ||
} | ||
} | ||
|
||
def edit = { | ||
def menu = loadMenu() | ||
if(!menu) { | ||
return | ||
} | ||
render view: '/spud/admin/menus/edit', model: [menu: menu] | ||
|
||
} | ||
|
||
def update() { | ||
def menu = loadMenu() | ||
if(!menu) { | ||
return | ||
} | ||
menu.properties += params.menu | ||
|
||
if(menu.save(flush:true)) { | ||
redirect resource: 'menus', action: 'index', namespace: 'spud_admin' | ||
} else { | ||
render view: '/spud/admin/menus/edit', model: [menu: menu] | ||
} | ||
} | ||
|
||
def delete() { | ||
def menu = loadMenu() | ||
if(!menu) { | ||
return | ||
} | ||
menu.delete() | ||
flash.notice = "Menu Removed Successfully!" | ||
redirect resource: 'menus', action: 'index', namespace: 'spud_admin' | ||
} | ||
|
||
private loadMenu() { | ||
if(!params.menusId) { | ||
flash.error = "Menu Id Not Specified For Listing Menu Items" | ||
redirect controller: 'menus', action: 'index', namespace: 'spud_admin' | ||
return null | ||
} | ||
|
||
def menu = SpudMenu.get(params.menusId) | ||
if(!menu) { | ||
flash.error = "Menu not found for listing Menu Items!" | ||
redirect controller: 'menus', action: 'index', namespace: 'spud_admin' | ||
return null | ||
} | ||
return menu | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
SpudCms/grails-app/controllers/spud/admin/MenusController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package spud.admin | ||
import spud.cms.* | ||
import spud.core.* | ||
|
||
@SpudApp(name="Menus", thumbnail="spud/admin/menus_thumb.png") | ||
@SpudSecure(['MENUS']) | ||
class MenusController { | ||
static namespace = "spud_admin" | ||
|
||
def index() { | ||
def menus = SpudMenu.list([sort: 'name', max: 25] + params) | ||
render view: '/spud/admin/menus/index', model:[menus: menus, menuCount: SpudMenu.count()] | ||
} | ||
|
||
def create() { | ||
def menu = new SpudMenu() | ||
render view: '/spud/admin/menus/create', model:[menu: menu] | ||
} | ||
|
||
def save() { | ||
if(!params.menu) { | ||
flash.error = "Menu submission not specified" | ||
redirect resource: 'menus', action: 'index', namespace: 'spud_admin' | ||
return | ||
} | ||
|
||
def menu = new SpudMenu(params.menu) | ||
|
||
|
||
|
||
if(menu.save(flush:true)) { | ||
redirect resource: 'menus', action: 'index', namespace: 'spud_admin' | ||
} else { | ||
flash.error = "Error Saving Menu" | ||
render view: '/spud/admin/menus/create', model:[menu:menu] | ||
} | ||
} | ||
|
||
def edit = { | ||
def menu = loadMenu() | ||
if(!menu) { | ||
return | ||
} | ||
render view: '/spud/admin/menus/edit', model: [menu: menu] | ||
|
||
} | ||
|
||
def update() { | ||
def menu = loadMenu() | ||
if(!menu) { | ||
return | ||
} | ||
menu.properties += params.menu | ||
|
||
if(menu.save(flush:true)) { | ||
redirect resource: 'menus', action: 'index', namespace: 'spud_admin' | ||
} else { | ||
render view: '/spud/admin/menus/edit', model: [menu: menu] | ||
} | ||
} | ||
|
||
def delete() { | ||
def menu = loadMenu() | ||
if(!menu) { | ||
return | ||
} | ||
menu.delete() | ||
flash.notice = "Menu Removed Successfully!" | ||
redirect resource: 'menus', action: 'index', namespace: 'spud_admin' | ||
} | ||
|
||
private loadMenu() { | ||
if(!params.id) { | ||
flash.error = "Menu Id Not Specified" | ||
redirect controller: 'menus', action: 'index', namespace: 'spud_admin' | ||
return null | ||
} | ||
|
||
def menu = SpudMenu.get(params.id) | ||
if(!menu) { | ||
flash.error = "Menu not found!" | ||
redirect controller: 'menus', action: 'index', namespace: 'spud_admin' | ||
return null | ||
} | ||
return menu | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package spud.cms | ||
|
||
class SpudMenu { | ||
Integer siteId = 0 | ||
String name | ||
String description | ||
|
||
|
||
Date dateCreated | ||
Date lastUpdated | ||
|
||
static mapping = { | ||
table 'spud_menus' | ||
autoTimestamp true | ||
description type:'text' | ||
|
||
dateCreated column: 'created_at' | ||
lastUpdated column: 'updated_at' | ||
} | ||
static constraints = { | ||
name blank:false, unique: 'siteId' | ||
description nullable:true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package spud.cms | ||
|
||
class SpudMenuItem { | ||
String name | ||
String parentType | ||
Long parentId | ||
|
||
Integer menuOrder = 0 | ||
String url | ||
SpudPage page | ||
|
||
SpudMenu menu | ||
|
||
|
||
Date dateCreated | ||
Date lastUpdated | ||
|
||
static mapping = { | ||
table 'spud_menu_items' | ||
autoTimestamp true | ||
|
||
menu column: 'spud_menu_id' | ||
page column: 'spud_page_id' | ||
|
||
dateCreated column: 'created_at' | ||
lastUpdated column: 'updated_at' | ||
|
||
// parentType index: 'idx_menu_item_parent' | ||
// parentId index: 'idx_menu_item_parent' | ||
// TODO Add Multi column index for parent in right order | ||
} | ||
static constraints = { | ||
name blank:false | ||
menu nullable: false | ||
parentType blank: false | ||
parentId blank: false | ||
url nullable: true | ||
page nullable: true | ||
menuOrder nullable: true | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<fieldset> | ||
<div class="control-group"> | ||
<label for="menu.name" class="control-label">Name</label> | ||
<div class="controls"> | ||
<g:textField name="menu.name" value="${menu?.name}"/> | ||
</div> | ||
|
||
</div> | ||
</fieldset> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<g:applyLayout name="spud/admin/detail" > | ||
|
||
<content tag="detail"> | ||
<g:form name="new_menu" url="[action: 'save', method:'POST', resource: 'menus',namespace: 'spud_admin']" method="POST" class="form-horizontal"> | ||
<g:render template="/spud/admin/menus/form" model="[menu: menu]" /> | ||
<div class="form-actions"> | ||
<g:submitButton name="_submit" value="Create Menu" class="btn btn-primary"/> or <spAdmin:link action="index" resource="menus" class="btn">cancel</spAdmin:link> | ||
</div> | ||
</g:form> | ||
</content> | ||
</g:applyLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<g:applyLayout name="spud/admin/detail" > | ||
|
||
<content tag="detail"> | ||
<g:form name="edit_menu" url="[action: 'update', method:'PUT', resource: 'menus', id: menu.id ,namespace: 'spud_admin']" method="PUT" class="form-horizontal"> | ||
<g:render template="/spud/admin/menus/form" model="[menu: menu]" /> | ||
<div class="form-actions"> | ||
<g:submitButton name="_submit" value="Save Menu" class="btn btn-primary"/> or <spAdmin:link action="index" resource="menus" class="btn">cancel</spAdmin:link> | ||
</div> | ||
</g:form> | ||
</content> | ||
</g:applyLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<g:applyLayout name="spud/admin/detail" > | ||
<content tag="data_controls"> | ||
<spAdmin:link resource="menus" action="create" class="btn btn-primary" title="New Menu">New Menu</spAdmin:link> | ||
</content> | ||
|
||
|
||
<content tag="detail"> | ||
<div class="page_list"> | ||
<g:each var="menu" in="${menus}"> | ||
<div class="page_row"> | ||
|
||
<span class="row_meta"><spAdmin:link controller="menuItems" action="index" params="[menusId: menu.id]">${menu.name}</spAdmin:link> | ||
|
||
<span class="edit_controls"> | ||
<spAdmin:link action="edit" id="${menu.id}" title="Edit ${menu.name}" class="btn">Edit</spAdmin:link> | ||
|
||
<spAdmin:link resource="menus" action="delete" data-method="DELETE" id="${menu.id}" data-confirm="Are you sure you want to remove this menu and all items associated with it?" class="btn btn-danger">Remove</spAdmin:link> | ||
</span> | ||
<br style="clear:both;"/> | ||
</div> | ||
</g:each> | ||
<g:paginate resource="menus" action="index" namespace="spud_admin" total="${menuCount}" max="25" /> | ||
</div> | ||
|
||
|
||
|
||
</content> | ||
</g:applyLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters