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

Adding operations

mlist edited this page Apr 12, 2013 · 2 revisions

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.

Show view of a gene in OLF

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".

Clone this wiki locally