~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/macros.vm

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#*
 
3
Displays a table which lists a set of objects and it's common operations: Filter, 
 
4
add, update, translate, remove and show details. The macro produces code against 
 
5
some specific conventions for the scripts and actions to call. Call it this way:
 
6
 
 
7
#objectList( [name of object, e.g. DataElement], [list of such objects, e.g. $dataElements] )
 
8
 
 
9
@param objectName The litteral name of the type of object to display, e.g. DataElement
 
10
@param objects A Velocity list of the objects to be formatted, typically prepared by an action.
 
11
*#
 
12
#macro( objectList $objectName $objects )
 
13
    <table class="objectListTable">
 
14
        <col>
 
15
        <col width="80">
 
16
        <tr>
 
17
            <td class="filter"><label for="filter">$i18n.getString( "filter_by_name" )</label>: <form action="none" onsubmit="filterValues(this.firstChild.firstChild.value);return false"><div><input id="filter" type="text"><input type="submit" value="Filter"></div></form></td>
 
18
            <td style="text-align:right"><input type="button" value="$i18n.getString( "add_new" )" onclick="window.location.href='showAdd${objectName}Form.action'"></td>
 
19
        </tr>
 
20
        <tr>
 
21
            <th>$i18n.getString( "name" )</th>
 
22
            <th>$i18n.getString( "operations" )</th>
 
23
        </tr>
 
24
        <tbody id="list">
 
25
        #set( $mark = false )
 
26
        #set( $info = false )
 
27
        #foreach( $object in $objects )
 
28
        <tr #if( $mark ) class="odd" #end>
 
29
            <td>$encoder.htmlEncode( $object.name )</td>
 
30
            <td>
 
31
              <a href="showUpdate${objectName}Form.action?id=${object.id}" title="$i18n.getString( "edit" )"><img src="../images/edit.png" alt="$i18n.getString( "edit" )"></a>
 
32
              <a href="$i18n.getString( "translation_translate" )" title="$i18n.getString( "translation_translate" )" onclick="this.href='javascript:location.href= \'../dhis-web-commons/i18n.action?className=${objectName}&amp;$objectId=${object.id}&amp;returnUrl=\' + location.href'"><img src="../images/i18n.png" alt="$i18n.getString( "translation_translate" )"></a>
 
33
              <a href="javascript:remove${objectName}( $object.id, '$encoder.jsEncode( $object.name )' )" title="$i18n.getString( "remove" )"><img src="../images/delete.png" alt="$i18n.getString( "remove" )"></a>
 
34
              <a href="javascript:show${objectName}Details( $object.id )" title="$i18n.getString( "show_details" )"><img src="../images/information.png" alt="$i18n.getString( "show_details" )"></a>
 
35
            </td>
 
36
        </tr>
 
37
            #if( $mark )
 
38
                #set( $mark = false )
 
39
            #else
 
40
                #set( $mark = true )
 
41
            #end
 
42
        #end
 
43
        </tbody>
 
44
    </table>
 
45
#end
 
46
 
 
47
#*
 
48
Supportive method for displaying rows with alternating colors in a table.
 
49
 
 
50
@param mark boolean alternating the color.
 
51
*#
 
52
#macro( alternate $mark )
 
53
    #if ( $mark ) class="listAlternateRow"#else class="listRow"#end
 
54
#end
 
55
 
 
56
#*
 
57
Formats a boolean into a readable value
 
58
 
 
59
@param bool the boolean to format.
 
60
*#
 
61
#macro( formatBool $bool )
 
62
        #if ( $bool )
 
63
                $i18n.getString( "yes" )
 
64
        #else
 
65
           $i18n.getString( "no" )
 
66
    #end
 
67
#end
 
68
 
 
69
#macro( formatAggregationOperator $operator )
 
70
        #if ( $operator == "average" )
 
71
                $i18n.getString( "average" )
 
72
    #elseif ( $operator == "count" )
 
73
        $i18n.getString( "count" )
 
74
    #elseif ( $operator == "sum" )
 
75
        $i18n.getString( "sum" )
 
76
    #else
 
77
        $i18n.getString( "unknown" )
 
78
    #end
 
79
#end
 
80
 
 
81
#macro( formatType $type )
 
82
        #if ( $type == "string" )
 
83
                $i18n.getString( "text" )
 
84
    #elseif ( $type == "bool" )
 
85
        $i18n.getString( "yes_no" )
 
86
    #elseif ( $type == "int" )
 
87
        $i18n.getString( "number" )
 
88
        #else      
 
89
        $i18n.getString( "unknown" )
 
90
    #end
 
91
#end