source: trunk/grails-app/taglib/dbnp/importer/ImporterTagLib.groovy @ 200

Last change on this file since 200 was 200, checked in by tabma, 9 years ago
  • properties template
  • Property svn:keywords set to Date Author Rev
File size: 2.6 KB
Line 
1/**
2 * Importer tag library
3 *
4 * The importer tag library gives support for automating several 'components'
5 *
6 * @package     importer
7 * @author      t.w.abma@umcutrecht.nl
8 * @since       20100202
9 *
10 * Revision information:
11 * $Rev: 200 $
12 * $Author: tabma $
13 * $Date: 2010-02-15 20:38:24 +0000 (ma, 15 feb 2010) $
14 */
15
16package dbnp.importer
17
18class ImporterTagLib {
19    static namespace = 'importer'
20    def entities = [[value:0, name:"Study"], [value:1, name:"Subject"], [value:2, name:"Event"],
21                        [value:3, name:"Protocol"], [value:4, name:"Sample"]]
22
23    def celltypes = [[value:0, name:"Numeric"], [value:1, name:"String"], [value:2, name:"Formula"],
24                         [value:3, name:"Blank"], [value:4, name:"Boolean"], [value:5, name:"Error"]]
25
26    /**
27    * @param header string array containing header
28    * @param datamatrix two dimensional array containing actual data
29    * @return preview of the data with the ability to adjust the datatypes
30    */
31    def preview = { attrs ->
32       
33        def header = attrs['header']
34        def datamatrix = attrs['datamatrix']
35
36        out << render (template:"common/preview", model:[header:header, datamatrix:datamatrix])
37    }
38
39    def entity = { attrs ->
40        out << entities[attrs['index']].name
41    }
42
43    /**
44     * @param entities array of entity:columnindex values
45     */
46    def properties = { attrs ->
47        def ent = []
48
49        attrs['entities'].each { e ->
50            def temp = e.split(":")         
51            def entity = [type:temp[0],columnindex:temp[1]]
52            ent.add(entity)
53        }
54
55        out << render (template:"common/properties", model:[entities:ent])
56    }
57
58    def createSelect(int selected, String name, ArrayList options, String customvalue) {
59        def res = "<select style=\"font-size:10px\" name=\"${name}\">"
60
61        options.each { e ->
62            res += "<option value=\"${e.value}:${customvalue}\""
63            res += (e.value == selected) ? " selected" : ""
64            res += ">${e.name}</option>"
65        }
66
67        res += "</select>"
68        return res
69    }
70
71   
72
73    /**
74     * @param selected selected entity
75     * @param name name of the HTML select object
76     **/
77    def entitySelect = { attrs ->       
78        def selected = (attrs['selected']==null) ? -1 : attrs['selected']
79        def customvalue = (attrs['customvalue']==null) ? "" : attrs['customvalue']
80        out << createSelect(selected, attrs['name'], entities, customvalue)
81    }
82
83    /**
84    * @param selected selected celltype
85    * @param name name of the HTML select object
86    * @see org.apache.poi.ss.usermodel.Cell for the possible cell types
87    * @return HTML select object
88    */
89    def celltypeSelect = { attrs ->
90        def selected = (attrs['selected']==null) ? -1 : attrs['selected']
91        def customvalue = (attrs['customvalue']==null) ? "" : attrs['customvalue']
92        out << createSelect(selected, attrs['name'], celltypes, customvalue)
93    }
94}
Note: See TracBrowser for help on using the repository browser.