-
Notifications
You must be signed in to change notification settings - Fork 6
Adding operations
Operations are content modules that will be rendered in a separate box in the "view" part of a domain object. It is found on the right side of the main panel directly under the object's history.

This kind of content module is slightly more complicated than a menu module, because it is more flexible. Operations can be rendered for all or only for specific domain objects. Furthermore, different templates can be defined for different domain objects. Like all content modules the class has to be placed under grails-app/modules. Operations, as well as Tab content modules need to implement the interface Module and the class name needs to end in Module.
Let's look at an example:
package org.openlab.module.operations
import org.openlab.module.*;
import org.openlab.genetracker.*;
class GeneOperationsModule implements Module{
//returns the name of the grails-plug-in, e.g. the name of your OLF module.
//this information is used to locate the templates to be rendered later on.
def getPluginName()
{
"gene-tracker"
}
//returns the name of the template for a given domainClass name
//allows in this way to render different templates where necessary
def getTemplateForDomainClass(def domainClass)
{
if(domainClass == "gene") return "geneOperations"
}
//returns a template to render for mobile view.
@Override
def getMobileTemplateForDomainClass(Object domainClass) {
return null
}
//returns a boolean if the module offers a template for a given domain class and type (either "tab" or "operations"
def isInterestedIn(def domainClass, def type)
{
if((type == "operations") && (domainClass == "gene")) return true
return false
}
//it is possible to create a model for rendering the templates.
def getModelForDomainClass(def domainClass, def id)
{
if(domainClass == "gene")
{
def gene = Gene.get(id)
[geneInstance: gene]
}
}
//should return true only if a mobile template is available.
@Override
def isMobile()
{
return false
}
}However, this is only half of the story. It is equally important to provide the view templates. Their implementation follows the same rules as normal GSP views. Consider however, that the size of the box is relatively small. View templates for operations have to be placed under a dedicated folder "grails-app/views/operations". Note that grails view templates are indicated by an underscore in the name, e.g. "_geneOperations.gsp".