Changeset 195


Ignore:
Timestamp:
Feb 12, 2010, 1:11:52 PM (14 years ago)
Author:
duh
Message:
  • seperated template page from study page
  • seperated study logic from flow
  • added initial templates and flow logic for events, samples, protocols and assays
Location:
trunk/grails-app
Files:
6 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/studycapturing/WizardController.groovy

    r192 r195  
    4747                        flow.page = 0
    4848                        flow.pages = [
     49                                [title: 'Templates'],   // templates
    4950                                [title: 'Study'],               // study
    5051                                [title: 'Subjects'],    // subjects
    5152                                [title: 'Groups'],              // groups
    52                                 [title: 'Form elements demo page']
     53                                [title: 'Events'],              // events
     54                                [title: 'Samples'],             // samples
     55                                [title: 'Protocols'],   // protocols
     56                                [title: 'Assays'],              // assays
     57                                [title: 'Done']                 // finish page
    5358                        ]
    5459
     
    6469                                flow.page = 1
    6570                        }
    66                         on("next").to "study"
    67                 }
    68 
    69                 // render and handle the study page
    70                 study {
    71                         render(view: "_study")
     71                        on("next").to "templates"
     72                }
     73
     74                // select the templates to use for this study
     75                templates {
     76                        render(view: "_templates")
    7277                        onRender {
    7378                                flow.page = 1
    7479                        }
    7580                        on("next") {
    76                                 // create date instance from date string?
    77                                 // @see WizardTagLibrary::dateElement{...}
    78                                 if (params.get('startDate')) {
    79                                         params.startDate = new Date().parse("d/M/yyyy", params.get('startDate').toString())
    80                                 }
    81 
    82                                 // if a template is selected, get template instance
    83                                 if (params.get('template')) {
    84                                         params.template = Template.findByName(params.get('template'))
    85                                 }
    86 
    87                                 // create a study instance
    88                                 flow.study = new Study(params)
     81                                // if we don't have a study, instantiate a study with dummy values
     82                                if (!flow.study) {
     83                                        flow.study = new Study(
     84                                                title: "my study",
     85                                                code: "",
     86                                                ecCode: "",
     87                                                researchQuestion: "",
     88                                                description: "",
     89                                                startDate: new Date().format("d/M/yyyy")
     90                                        )
     91                                }
     92/*
     93flow.study.getProperties().constraints.each() { key, value ->
     94        println key
     95        value.getProperties().each() {
     96                println it
     97        }
     98}
     99*/
     100                                // assign template to study
     101                                flow.study.template = Template.findByName(params.get('template'));
    89102
    90103                                // validate study
     
    97110                                        error()
    98111                                }
     112                        }.to "study"
     113                }
     114
     115                // render and handle the study page
     116                study {
     117                        render(view: "_study")
     118                        onRender {
     119                                flow.page = 2
     120                        }
     121                        on("previous") {
     122                                flash.errors = new LinkedHashMap()
     123
     124                                if (this.handleStudy(flow, flash, params)) {
     125                                        success()
     126                                } else {
     127                                        error()
     128                                }
     129                        }.to "templates"
     130                        on("next") {
     131                                flash.errors = new LinkedHashMap()
     132
     133                                if (this.handleStudy(flow, flash, params)) {
     134                                        success()
     135                                } else {
     136                                        error()
     137                                }
    99138                        }.to "subjects"
    100139                }
     
    104143                        render(view: "_subjects")
    105144                        onRender {
    106                                 flow.page = 2
     145                                flow.page = 3
    107146
    108147                                if (!flow.subjects) {
     
    155194                        render(view: "_groups")
    156195                        onRender {
    157                                 flow.page = 3
     196                                flow.page = 4
    158197
    159198                                if (!flow.groups) {
     
    174213
    175214                // render page three
    176                 demo {
    177                         render(view: "_three")
    178                         onRender {
    179                                 flow.page = 4
    180                         }
    181                         on("previous") {
    182                                 // TODO
    183                         }.to "groups"
     215                events {
     216                        render(view: "_events")
     217                        onRender {
     218                                flow.page = 5
     219                        }
     220                        on("previous") {
     221                                // TODO
     222                        }.to "subjects"
     223                        on("next") {
     224                                // TODO
     225                        }.to "samples"
     226                }
     227
     228                // render page three
     229                samples {
     230                        render(view: "_samples")
     231                        onRender {
     232                                flow.page = 6
     233                        }
     234                        on("previous") {
     235                                // TODO
     236                        }.to "events"
     237                        on("next") {
     238                                // TODO
     239                        }.to "protocols"
     240                }
     241
     242                // render page three
     243                protocols {
     244                        render(view: "_protocols")
     245                        onRender {
     246                                flow.page = 7
     247                        }
     248                        on("previous") {
     249                                // TODO
     250                        }.to "samples"
     251                        on("next") {
     252                                // TODO
     253                        }.to "assays"
     254                }
     255
     256                // render page three
     257                assays {
     258                        render(view: "_assays")
     259                        onRender {
     260                                flow.page = 8
     261                        }
     262                        on("previous") {
     263                                // TODO
     264                        }.to "protocols"
     265                        on("next") {
     266                                // TODO
     267                        }.to "done"
     268                }
     269
     270                // render page three
     271                done {
     272                        render(view: "_done")
     273                        onRender {
     274                                flow.page = 9
     275                        }
     276                        on("previous") {
     277                                // TODO
     278                        }.to "assays"
     279                }
     280        }
     281
     282        /**
     283         * re-usable code for handling study form data in a web flow
     284         * @param Map LocalAttributeMap (the flow scope)
     285         * @param Map localAttributeMap (the flash scope)
     286         * @param Map GrailsParameterMap (the flow parameters = form data)
     287         * @returns boolean
     288         */
     289        def handleStudy(flow, flash, params) {
     290                // create study instance if we have none
     291                if (!flow.study) flow.study = new Study();
     292
     293                // create date instance from date string?
     294                // @see WizardTagLibrary::dateElement{...}
     295                if (params.get('startDate')) {
     296                        params.startDate = new Date().parse("d/M/yyyy", params.get('startDate').toString())
     297                }
     298
     299                // if a template is selected, get template instance
     300                if (params.get('template')) {
     301                        params.template = Template.findByName(params.get('template'))
     302                }
     303
     304                // update study instance with parameters
     305                params.each() {key, value ->
     306                        if (flow.study.hasProperty(key)) {
     307                                flow.study.setProperty(key, value);
     308                        }
     309                }
     310
     311                // validate study
     312                if (flow.study.validate()) {
     313                        return true
     314                } else {
     315                        // validation failed, feedback errors
     316                        flash.errors = new LinkedHashMap()
     317                        this.appendErrors(flow.study, flash.errors)
     318                        return false
    184319                }
    185320        }
  • trunk/grails-app/views/wizard/pages/_study.gsp

    r163 r195  
    3434                The start date of the study     
    3535        </wizard:dateElement>
    36         <wizard:templateElement name="template" description="Template" value="${study?.template}">
    37                 The meta data template to use for this study
    38         </wizard:templateElement>
    3936</wizard:pageContent>
Note: See TracChangeset for help on using the changeset viewer.