// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts

// grails.config.locations = [ "classpath:${appName}-config.properties",
//                             "classpath:${appName}-config.groovy",
//                             "file:${userHome}/.grails/${appName}-config.properties",
//                             "file:${userHome}/.grails/${appName}-config.groovy"]

// if(System.properties["${appName}.config.location"]) {
//    grails.config.locations << "file:" + System.properties["${appName}.config.location"]
// }

// Set false due to acegi security issue.
// See: http://jira.grails.org/browse/GPACEGI-41
// See: http://www.gnumims.org/trac/ticket/98
grails.mime.file.extensions = false // enables the parsing of file extensions from URLs into the request format

grails.mime.types = [ html: ['text/html','application/xhtml+xml'],
                      xml: ['text/xml', 'application/xml'],
                      text: 'text-plain',
                      js: 'text/javascript',
                      rss: 'application/rss+xml',
                      atom: 'application/atom+xml',
                      css: 'text/css',
                      csv: 'text/csv',
                      pdf: 'application/pdf',
                      rtf: 'application/rtf',
                      excel: 'application/vnd.ms-excel',
                      ods: 'application/vnd.oasis.opendocument.spreadsheet',
                      all: '*/*',
                      json: ['application/json','text/json'],
                      form: 'application/x-www-form-urlencoded',
                      multipartForm: 'multipart/form-data'
                    ]
// The default codec used to encode data with ${}
grails.views.default.codec="none" // none, html, base64
grails.views.gsp.encoding="UTF-8"
grails.converters.encoding="UTF-8"

// enable Sitemesh preprocessing of GSP pages
grails.views.gsp.sitemesh.preprocess = true
// scaffolding templates configuration
grails.scaffolding.templates.domainSuffix = 'Instance'

// Set to false to use the new Grails 1.2 JSONBuilder in the render method
grails.json.legacy.builder=false

// enabled native2ascii conversion of i18n properties files
grails.enable.native2ascii = true

// whether to install the java.util.logging bridge for sl4j. Disable fo AppEngine!
grails.logging.jul.usebridge = true
// packages to include in Spring bean scanning
grails.spring.bean.packages = []

/**
* Internal searchable index config.
*/
// Is set true by createDataService.startSearchableIndex() once bootstrap completes.
appSearchable.cascadeOnUpdate = false

/**
* Directory configuration.
* Pickup the Tomcat/Catalina directory else use the target or current dir.
*/
def fs = File.separator // Local variable.
globalDirs.targetDir = new File("target${fs}").isDirectory() ? "target${fs}" : ''
globalDirs.catalinaBase = System.properties.getProperty('catalina.base')
globalDirs.logDirectory = globalDirs.catalinaBase ? "${globalDirs.catalinaBase}${fs}logs${fs}" : globalDirs.targetDir
globalDirs.workDirectory = globalDirs.catalinaBase ? "${globalDirs.catalinaBase}${fs}work${fs}" : globalDirs.targetDir
globalDirs.tempDirectory = globalDirs.catalinaBase ? "${globalDirs.catalinaBase}${fs}temp${fs}${appName}${fs}" : globalDirs.targetDir
globalDirs.searchableIndexDirectory = "${globalDirs.workDirectory}SearchableIndex${fs}${appName}${fs}"
globalDirs.tempInventoryItemPicturesDirectory = "${globalDirs.tempDirectory}InventoryItemPictures${fs}"

/**
 * Log4j configuration.
 * Causing this file to reload (e.g. edit+save) may break the appLog destination
 * and further logs will be written to files or directories like "[:]".
 * For more info see http://logging.apache.org/log4j/1.2/manual.html
 * For log levels see http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html
 * Basic log levels are ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < OFF
 */

log4j = {
    appenders {
        // Use if we want to prevent creation of a stacktrace.log file.
        'null' name:'stacktrace'

        // Use this if we want to modify the default appender called 'stdout'.
        console name:'stdout', layout:pattern(conversionPattern: '[%t] %-5p %c{2} %x - %m%n')

        // Custom log file.
        rollingFile name:"appLog",
                        file:"${globalDirs.logDirectory}${appName}.log".toString(),
                        maxFileSize:'300kB',
                        maxBackupIndex:1,
                        layout:pattern(conversionPattern: '%d{[EEE, dd-MMM-yyyy @ HH:mm:ss.SSS]} [%t] %-5p %c %x - %m%n')
    }

    // This is for the built-in stuff and from the default Grails-1.2.1 config.
    error 'org.codehaus.groovy.grails.web.servlet',  //  controllers
            'org.codehaus.groovy.grails.web.pages', //  GSP
            'org.codehaus.groovy.grails.web.sitemesh', //  layouts
            'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
            'org.codehaus.groovy.grails.web.mapping', // URL mapping
            'org.codehaus.groovy.grails.commons', // core / classloading
            'org.codehaus.groovy.grails.plugins', // plugins
            'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
            'org.springframework',
            'org.hibernate',
            'net.sf.ehcache.hibernate'

    warn   'org.mortbay.log' // Jetty

    error 'grails.app' // Set the default log level for our app code.
    info 'grails.app.bootstrap' // Set the log level per type and per type.class
    error 'grails.app.service.AuthService'
    error 'grails.app.service.NavigationService'
    error 'grails.app.service.com.zeddware.grails.plugins.filterpane.FilterService'
    info 'org.codehaus.groovy.grails.plugins.searchable'
    //info 'org.compass'
    error 'grails.app.task' // Quartz jobs.
    info 'grails.app.task.InventoryIndexJob'

    // Move anything that should behave differently into this section.
    switch(environment) {
        case 'development':
            // Configure the root logger to output to stdout and appLog appenders.
            root {
                error 'stdout','appLog'
                additivity = true
            }
            //debug "org.hibernate.SQL"
            debug 'grails.app.service'
            debug 'grails.app.controller'
            break
        case 'test':
            // Configure the root logger to only output to appLog appender.
            root {
                error 'stdout','appLog'
                additivity = true
            }
            debug 'grails.app.service'
            debug 'grails.app.controller'
            break
        case 'production':
            // Configure the root logger to only output to appLog appender.
            root {
                error 'appLog'
                additivity = true
            }
            warn 'grails.app.service'
            warn 'grails.app.controller'
            debug 'grails.app.service.AssetCsvService'
            debug 'grails.app.service.PersonCsvService'
            debug 'grails.app.service.InventoryCsvService'
            info 'grails.app.service.InventoryItemService'
            debug 'grails.app.service.AssetTreeService' /// @todo: remove after testing.
            break
    }
}

/**
 * Environment specific configuration.
 */
environments {

    production {
        grails.serverURL = "http://www.changeme.com" // Set serverURL stem for creating absolute links.
    }

    development {
        grails.serverURL = "http://localhost:8080/${appName}" // Set serverURL stem for creating absolute links.
    }

    test {
        grails.serverURL = "http://localhost:8080/${appName}" // Set serverURL stem for creating absolute links.
    }

} // end environments

/**
 * Navigation plugin menu.
 * The top level titles are taken from i18n message bundles.
 * Subitems i18n message bundles are not currently resolving with this plugin.
 */
navigation.nav = [
    [order:10, controller:'appCore', title:'home', action:'start',
        subItems: [
            [order:10, controller:'appCore', title:'Start', action:'start', isVisible: { true }],
            [order:20, controller:'appCore', title:'Manager', action:'manager', isVisible: {
                    authenticateService.ifAnyGranted('ROLE_AppAdmin,ROLE_Manager,ROLE_TaskManager,ROLE_InventoryManager,ROLE_AssetManager,ROLE_ProductionManager')
                }
            ],
            [order:30, controller:'appCore', title:'Admin', action:'appAdmin', isVisible: { authenticateService.ifAllGranted('ROLE_AppAdmin') }],
            [order:90, controller:'appCore', title:'Timeout', action:'changeSessionTimeout', isVisible: { params.action == 'changeSessionTimeout' }],
            [order:91, controller:'appCore', title:'Password', action:'changePassword', isVisible: { params.action == 'changePassword' }],
        ]
    ],
    [order:20, controller:'taskDetailed', title:'tasks', action:'search',
        subItems: [
            [order:10, controller:'taskDetailed', title:'Search', action:'search', isVisible: { true }],
            [order:11, controller:'taskDetailed', title:'Calendar', action:'searchCalendar', isVisible: { true }],
            [order:20, controller:'taskDetailed', title:'+Scheduled', action:'create', isVisible: { true }],
            [order:30, controller:'taskDetailed', title:'+Unsheduled', action:'createUnscheduled', isVisible: { true }],
            [order:40, controller:'taskDetailed', title:'+Callout', action:'createImmediateCallout', isVisible: { true }],
            [order:90, controller:'taskDetailed', title:'Show', action:'show', id:'nav', isVisible: { params.action == 'show' }],
            [order:91, controller:'taskDetailed', title:'Edit', action:'edit', id:'nav', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:30, controller:'inventoryItemDetailed', title:'inventory', action:'search',
        subItems: [
            [order:10, controller:'inventoryItemDetailed', title:'Search', action:'search', isVisible: { true }],
            [order:20, controller:'inventoryItemDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'inventoryItemDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'inventoryItemDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }],
            [order:91, controller:'inventoryItemDetailed', title:'Reorder', action:'reorder', isVisible: { params.action == 'reorder' }]
        ]
    ],
    [order:40, controller:'assetDetailed', title:'assets', action:'search',
        subItems: [
            [order:10, controller:'assetDetailed', title:'Search', action:'search', isVisible: { true }],
            [order:20, controller:'assetDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'assetDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'assetDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }],
            [order:99, controller:'assetSubItemDetailed', title:'Sub Items', action:'search', isVisible: { true }]
        ]
    ]
]

/**
 * Navigation plugin alternate menu.
 * The alternate menu top level titles are not displayed anywhere.
 * Subitems i18n message bundles are not currently resolving with this plugin.
 */
navigation.navAlt = [
    [order:10, controller:'person', title:'person', action:'list',
        subItems: [
            [order:10, controller:'person', title:'Person List', action:'list', isVisible: { true }],
            [order:20, controller:'person', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'person', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'person', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:20, controller:'taskProcedureDetailed', title:'taskProcedure', action:'list',
        subItems: [
            [order:10, controller:'taskProcedureDetailed', title:'Task Procedure List', action:'list', isVisible: { true }],
            [order:20, controller:'taskProcedureDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'taskProcedureDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'taskProcedureDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:30, controller:'assetSubItemDetailed', title:'assetSubItem', action:'search',
        subItems: [
            [order:10, controller:'assetSubItemDetailed', title:'Sub Item Search', action:'search', isVisible: { true }],
            [order:20, controller:'assetSubItemDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'assetSubItemDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'assetSubItemDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:40, controller:'maintenancePolicyDetailed', title:'maintenancePolicy', action:'list',
        subItems: [
            [order:10, controller:'maintenancePolicyDetailed', title:'Maintenance Policy List', action:'list', isVisible: { true }],
            [order:20, controller:'maintenancePolicyDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'maintenancePolicyDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'maintenancePolicyDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:50, controller:'supplierDetailed', title:'supplier', action:'list',
        subItems: [
            [order:10, controller:'supplierDetailed', title:'Supplier List', action:'list', isVisible: { true }],
            [order:20, controller:'supplierDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'supplierDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'supplierDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:70, controller:'inventoryStoreDetailed', title:'inventoryStore', action:'list',
        subItems: [
            [order:10, controller:'inventoryStoreDetailed', title:'Inventory Store List', action:'list', isVisible: { true }],
            [order:20, controller:'inventoryStoreDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'inventoryStoreDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'inventoryStoreDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:80, controller:'inventoryLocationDetailed', title:'inventoryLocation', action:'list',
        subItems: [
            [order:10, controller:'inventoryLocationDetailed', title:'Inventory Location List', action:'list', isVisible: { true }],
            [order:20, controller:'inventoryLocationDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'inventoryLocationDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'inventoryLocationDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:90, controller:'inventoryGroupDetailed', title:'inventoryGroup', action:'list',
        subItems: [
            [order:10, controller:'inventoryGroupDetailed', title:'Inventory Group List', action:'list', isVisible: { true }],
            [order:20, controller:'inventoryGroupDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'inventoryGroupDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'inventoryGroupDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:110, controller:'supplierTypeDetailed', title:'supplierType', action:'list',
        subItems: [
            [order:10, controller:'supplierTypeDetailed', title:'Supplier Type List', action:'list', isVisible: { true }],
            [order:20, controller:'supplierTypeDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'supplierTypeDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'supplierTypeDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:120, controller:'siteDetailed', title:'site', action:'list',
        subItems: [
            [order:10, controller:'siteDetailed', title:'Site List', action:'list', isVisible: { true }],
            [order:20, controller:'siteDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'siteDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'siteDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:130, controller:'sectionDetailed', title:'section', action:'list',
        subItems: [
            [order:10, controller:'sectionDetailed', title:'Section List', action:'list', isVisible: { true }],
            [order:20, controller:'sectionDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'sectionDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'sectionDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:140, controller:'extendedAttributeTypeDetailed', title:'extendedAttributeType', action:'list',
        subItems: [
            [order:10, controller:'extendedAttributeTypeDetailed', title:'Attribute Type List', action:'list', isVisible: { true }],
            [order:20, controller:'extendedAttributeTypeDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'extendedAttributeTypeDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'extendedAttributeTypeDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:150, controller:'departmentDetailed', title:'department', action:'list',
        subItems: [
            [order:10, controller:'departmentDetailed', title:'Department List', action:'list', isVisible: { true }],
            [order:20, controller:'departmentDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'departmentDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'departmentDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:160, controller:'productionReferenceDetailed', title:'productionReference', action:'list',
        subItems: [
            [order:10, controller:'productionReferenceDetailed', title:'Production Reference List', action:'list', isVisible: { true }],
            [order:20, controller:'productionReferenceDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'productionReferenceDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'productionReferenceDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:170, controller:'costCodeDetailed', title:'costCode', action:'list',
        subItems: [
            [order:10, controller:'costCodeDetailed', title:'Cost Code List', action:'list', isVisible: { true }],
            [order:20, controller:'costCodeDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'costCodeDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'costCodeDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:180, controller:'personGroupDetailed', title:'personGroup', action:'list',
        subItems: [
            [order:10, controller:'personGroupDetailed', title:'Person Group List', action:'list', isVisible: { true }],
            [order:20, controller:'personGroupDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'personGroupDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'personGroupDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:190, controller:'personGroupTypeDetailed', title:'personGroupType', action:'list',
        subItems: [
            [order:10, controller:'personGroupTypeDetailed', title:'Person Group Type List', action:'list', isVisible: { true }],
            [order:20, controller:'personGroupTypeDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'personGroupTypeDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'personGroupTypeDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:200, controller:'taskGroupDetailed', title:'taskProcedure', action:'list',
        subItems: [
            [order:10, controller:'taskGroupDetailed', title:'Task Group List', action:'list', isVisible: { true }],
            [order:20, controller:'taskGroupDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'taskGroupDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'taskGroupDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:210, controller:'unitOfMeasureDetailed', title:'unitOfMeasure', action:'list',
        subItems: [
            [order:10, controller:'unitOfMeasureDetailed', title:'Unit Of Measure List', action:'list', isVisible: { true }],
            [order:20, controller:'unitOfMeasureDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'unitOfMeasureDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'unitOfMeasureDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:220, controller:'inventoryItemPurchaseDetailed', title:'inventoryItemPurchase', action:'search',
        subItems: [
            [order:10, controller:'inventoryItemPurchaseDetailed', title:'Purchase Search', action:'search', isVisible: { true }],
            [order:20, controller:'inventoryItemPurchaseDetailed', title:'Order', action:'create', isVisible: { true }],
            [order:90, controller:'inventoryItemPurchaseDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'inventoryItemPurchaseDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ],
    [order:230, controller:'purchasingGroupDetailed', title:'purchasingGroup', action:'list',
        subItems: [
            [order:10, controller:'purchasingGroupDetailed', title:'Purchasing Group List', action:'list', isVisible: { true }],
            [order:20, controller:'purchasingGroupDetailed', title:'Create', action:'create', isVisible: { true }],
            [order:90, controller:'purchasingGroupDetailed', title:'Show', action:'show', isVisible: { params.action == 'show' }],
            [order:91, controller:'purchasingGroupDetailed', title:'Edit', action:'edit', isVisible: { params.action == 'edit' }]
        ]
    ]
]

/**
 * Custom application global settings.
 * @todo: externalise these settings to a config file (along with the database settings) or have them configurable via the web interface+database.
 */
taskRecurringScheduleJob.repeatInterval=10
// It is recommended to limit the currencyList to the one that the site uses e.g: currencyList = ['AUD']
currencyList = ['EUR', 'XCD', 'USD', 'XOF', 'NOK', 'AUD', 'XAF', 'NZD', 'MAD', 'DKK', 'GBP', 'CHF', 'XPF', 'ILS', 'ROL', 'TRL']

