Changeset 667 for trunk


Ignore:
Timestamp:
Oct 1, 2010, 3:21:28 PM (14 years ago)
Author:
gav
Message:

New custom tag, jasperButtons .

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/taglib/CustomTagLib.groovy

    r582 r667  
    195195    } // sortableColumnWithImg
    196196
     197    /**
     198    * Customised version of jasperButton as found in jaser plugin.
     199     * custom:jasperButtons is intended to be wrapped by g:jasperForm
     200     */
     201    def jasperButtons = {attrs ->
     202        if(!attrs['format']){throw new Exception(message(code:"jasper.taglib.missingAttribute", args:'format'))}
     203        if(!attrs['formName']){throw new Exception(message(code:"jasper.taglib.missingAttribute", args:'formName'))}
     204        String formName = attrs['formName']
     205        String buttonClass = attrs['class'] ?:  "jasperButton"
     206        String format = attrs['format'].toUpperCase()
     207        String text = attrs['text']
     208        String heightAttr = attrs['height'] ? ' height="' + attrs['height'] + '"' : '' // leading space on purpose
     209        String imgSrc = ''
     210        String delimiter = attrs['delimiter'] ?: "|"
     211        String delimiterBefore = attrs['delimiterBefore'] ?: delimiter
     212        String delimiterAfter = attrs['delimiterAfter'] ?: delimiter
     213
     214        out << '''
     215                    <script type="text/javascript">
     216                        function submit_jasperForm(name, fmt) {
     217                            var jasperForm = document.getElementsByName(name).item(0)
     218                            jasperForm._format.value = fmt;
     219                            jasperForm.submit();
     220                            return false;
     221                        }
     222                    </script>
     223                    '''
     224
     225        out << delimiterBefore
     226
     227        attrs['format'].toUpperCase().split(",").eachWithIndex { it, i ->
     228            if (i > 0) out << delimiter
     229            imgSrc = g.resource(plugin:"jasper", dir:'images/icons', file:"${it.trim()}.gif")
     230            def fmt = it.trim()
     231            out << """
     232                        <a href="#" class="${buttonClass}" title="${it.trim()}" onClick="return submit_jasperForm('${formName}', '${fmt}')">
     233                        <img border="0" src="${imgSrc}"${heightAttr} /></a>
     234                        """
     235        }
     236
     237        out << delimiterAfter
     238    } // jasperButtons
     239
    197240} // end class
Note: See TracChangeset for help on using the changeset viewer.