Ignore:
Timestamp:
Mar 16, 2010, 11:33:22 AM (14 years ago)
Author:
gav
Message:

Add Person import feature.
Commit has a small amount of cross over code to the commits will follow.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/PersonController.groovy

    r403 r440  
    11import org.codehaus.groovy.grails.plugins.springsecurity.Secured
     2import org.codehaus.groovy.grails.commons.ConfigurationHolder
    23
    34@Secured(['ROLE_Manager','ROLE_AppAdmin'])
    45class PersonController extends BaseAppAdminController {
    56
     7    def filterService
     8    def personCsvService
    69    def authenticateService
    7     def filterService
    810
    911    // the delete, save and update actions only accept POST requests
     
    1214    def index = {
    1315        redirect action: list, params: params
     16    }
     17
     18    /**
     19    * Disaply the import view.
     20    */
     21    def importPersons = {
     22    }
     23
     24    /**
     25    * Handle the import save.
     26    */
     27    def importPersonsSave = {
     28        def result = personCsvService.importPersons(request)
     29
     30        if(!result.error) {
     31            response.contentType = ConfigurationHolder.config.grails.mime.types["text"]
     32            response.setHeader("Content-disposition", "attachment; filename=LoginNamesAndPasswords.txt")
     33            render result.loginNamesAndPasswords
     34            return
     35        }
     36
     37        flash.errorMessage = g.message(code: result.error.code, args: result.error.args)
     38        redirect(action: importPersons)
     39    }
     40
     41    /**
     42    * Export a csv template.
     43    * NOTE: IE has a 'validating' bug in dev mode that causes the export to take a long time!
     44    * This does not appear to be a problem once deployed to Tomcat.
     45    */
     46    def exportPersonsTemplate = {
     47        response.contentType = ConfigurationHolder.config.grails.mime.types["csv"]
     48        response.setHeader("Content-disposition", "attachment; filename=personsTemplate.csv")
     49        def s = personCsvService.buildPersonsTemplate()
     50        render s
    1451    }
    1552
Note: See TracChangeset for help on using the changeset viewer.