Skip to content
This repository was archived by the owner on Jun 7, 2024. It is now read-only.

Extending the menu

mlist edited this page Apr 12, 2013 · 1 revision

OLF's menu can be manipulated by a content module class implementing the interface MenuModule. Like all content modules it should be placed into the folder grails-app/modules/ of an arbitrary OLF module. It is important that the name of the class ends in MenuModule for grails to recognize the class as corresponding artefact.

A typical example looks like this

package org.openlab.module.menu

import org.openlab.module.*
import groovy.xml.MarkupBuilder

class geneMenuModule implements MenuModule{

	def getPriority()
	{
		10
	}
	
	def getMenu()
	{
		def writer = new StringWriter()
		def xml = new MarkupBuilder(writer)
		def controller = "gene"
		
		xml.root
		{
			submenu(label: 'Gene')
			{
				menuitem(controller: controller, action: 'create', label: 'Create Gene')
				menuitem(controller: controller, action: 'list', label: 'List Genes')
				menuitem(controller: "recombinant", action: 'list', label: 'List Vector Combinations')
                menuitem(controller: controller, action: 'stats', label: 'Show Stats')
			}
		}
		
		return writer.toString()
	}
}

As you can see there are two methods. getPriority() can be used to manipulate the order of the menu. Menu entries with a higher priority will be closer to the left side. getMenu() should create an XML markup for the menu by adding "menuitems". A menuitems takes a controller, action, and label to create a new link. Menuitems can be grouped in a submenu by adding a corresponding level to the XML hierarchy. Submenu items only require a label.

Clone this wiki locally