Ignore:
Timestamp:
Jun 10, 2010, 4:45:53 PM (12 years ago)
Author:
roberth
Message:

Improved the TemplateEditor? again: templates can be created and removed and some checks were built in to ensure that the same fields in different templates point to the same TemplateField? object.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateField.groovy

    r550 r556  
    5353                return name.toLowerCase().replaceAll("([^a-z0-9])", "_")
    5454        }
     55
     56        /**
     57         * overloading the findAllByEntity method to make it function as expected
     58         * @param Class entity (for example: dbnp.studycapturing.Subject)
     59         * @return ArrayList
     60         */
     61        public static findAllByEntity(java.lang.Class entity) {
     62                def results = []
     63                // 'this' should not work in static context, so taking Template instead of this
     64                TemplateField.findAll().each() {
     65                        if (entity.equals(it.entity)) {
     66                                results[results.size()] = it
     67                        }
     68                }
     69
     70                return results
     71        }
     72
     73        /**
     74         * Checks whether this template field is used in a template
     75         *
     76         * @returns             true iff this template field is used in a template (even if the template is never used), false otherwise
     77         */
     78        def inUse() {
     79                return numUses() > 0;
     80        }
     81
     82        /**
     83         * The number of templates that use this template
     84         *
     85         * @returns             the number of templates that use this template.
     86         */
     87        def numUses() {
     88                def templates = Template.findAll();
     89                def elements;
     90                if( templates && templates.size() > 0 ) {
     91                        elements = templates.findAll { template -> template.fields.contains( this ) };
     92                } else {
     93                        return 0;
     94                }
     95
     96                return elements.size();
     97        }
     98
     99
    55100}
Note: See TracChangeset for help on using the changeset viewer.