source: trunk/grails-app/domain/Asset.groovy @ 906

Last change on this file since 906 was 723, checked in by gav, 14 years ago

No domain change, avoid possible bug by using toLong() instead of toInteger() in setFromCheckBoxList().

File size: 1.8 KB
RevLine 
[622]1import org.codehaus.groovy.grails.commons.ConfigurationHolder
2
[116]3class Asset {
[122]4
[268]5    Section section
[122]6
[116]7    String name
8    String description = ""
[329]9    String comment = ""
[116]10    boolean isActive = true
11
[268]12    static hasMany = [assetSubItems: AssetSubItem,
13                                    maintenanceActions: MaintenanceAction,
[131]14                                    assetExtendedAttributes: AssetExtendedAttribute]
[121]15
[268]16    static belongsTo = [Section]
[121]17
[124]18    static constraints = {
[268]19        name(maxSize:50, unique:true, blank:false)
[329]20        description(maxSize:75)
21        comment(maxSize:500)
[268]22        isActive()
23        section()
[124]24    }
[116]25
[456]26    static mapping = {
27        assetSubItems(batchSize:1000)
28    }
29
[116]30    String toString() {
31        "${this.name}"
32    }
[286]33
[562]34    static searchable = {
35        root false // only index as a component of InventoryItem.
36        only = ['name', 'description', 'comment']
37    }
38
[622]39    def afterUpdate = {
40        // Update the Inventory searchable index, since cascading in searchable-0.5.5 is broken.
41        if(ConfigurationHolder.config.appSearchable.cascadeOnUpdate) {
42            try {
43                InventoryIndexJob.triggerNow(['calledBy':'Asset afterUpdate{}'])
44            }
45            catch(e) {log.error e}
46        } // if
47    } // afterUpdate
48
[343]49    //  This additional setter is used to convert the checkBoxList string or string array
[286]50    //  of ids selected to the corresponding domain objects.
51    public void setAssetSubItemsFromCheckBoxList(ids) {
52        def idList = []
[343]53        if(ids instanceof String) {
54                if(ids.isInteger())
[723]55                    idList << ids.toLong()
[286]56        }
[343]57        else {
58            ids.each() {
59                if(it.isInteger())
[723]60                    idList << it.toLong()
[343]61            }
62        }
[286]63        this.assetSubItems = idList.collect { AssetSubItem.get( it ) }
64    }
65
[116]66}
67
Note: See TracBrowser for help on using the repository browser.