Changeset 180


Ignore:
Timestamp:
Feb 9, 2010, 3:22:46 PM (14 years ago)
Author:
duh
Message:
  • wizard subject page now mainains state and stores form data in flow scope
Location:
trunk
Files:
5 edited

Legend:

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

    r178 r180  
    9494                                        // validation failed, feedback errors
    9595                                        flash.errors = new LinkedHashMap()
    96                                         this.appendErrors(flow.study,flash.errors)
     96                                        this.appendErrors(flow.study, flash.errors)
    9797                                        error()
    9898                                }
     
    110110                                }
    111111                        }
    112                         on ("add") {
     112                        on("add") {
    113113                                // fetch species by name (as posted by the form)
    114114                                def speciesTerm = Term.findByName(params.addSpecies)
    115                                
     115
    116116                                // add x subject of species y
    117117                                (params.addNumber as int).times {
    118118                                        def increment = flow.subjects.size()
    119                                         flow.subjects[ increment ] = new Subject(
    120                                                 name: 'Subject ' + (increment+1),
    121                                                 species: speciesTerm
     119                                        flow.subjects[increment] = new Subject(
     120                                                name: 'Subject ' + (increment + 1),
     121                                                species: speciesTerm,
     122                                                template: flow.study.template
    122123                                        )
    123124                                }
    124125                        }.to "subjects"
    125126                        on("next") {
     127                                def errors = false
     128                                flash.errors = new LinkedHashMap()
     129
    126130                                // got one or more subjects?
    127131                                if (flow.subjects.size() < 1) {
     132                                        errors = true;
     133                                } else {
     134                                        // handle form data
     135                                        def id = 0;
     136                                        flow.subjects.each() {
     137                                                // store subject properties
     138                                                it.name = params.get('subject_' + id + '_name')
     139                                                it.species = Term.findByName(params.get('subject_' + id + '_species'))
     140
     141                                                // clear lists
     142                                                def stringList = new LinkedHashMap();
     143                                                def intList = new LinkedHashMap();
     144
     145                                                // get all template fields
     146                                                flow.study.template.subjectFields.each() {
     147                                                        // get value
     148                                                        def value = params.get('subject_' + id + '_' + it.name);
     149                                                        if (value) {
     150                                                                // add to template parameters
     151                                                                switch (it.type) {
     152                                                                        case 'STRINGLIST':
     153                                                                                stringList[it.name] = value
     154                                                                                break;
     155                                                                        case 'INTEGER':
     156                                                                                intList[ it.name ] = value
     157                                                                                break;
     158                                                                        default:
     159                                                                                // unsupported type?
     160                                                                                println "ERROR: unsupported type: "+it.type
     161                                                                                break;
     162                                                                }
     163                                                        }
     164                                                }
     165
     166                                                // set field data
     167                                                it.templateStringFields         = stringList
     168                                                it.templateIntegerFields        = intList
     169
     170                                                // validate subject
     171                                                if (!it.validate()) {
     172                                                        errors = true
     173                                                        //println id + ' :: ' + it.errors.getAllErrors()
     174                                                        this.appendErrors(it, flash.errors)
     175                                                }
     176
     177                                                id++;
     178                                        }
     179                                }
     180
     181                                // got errors?
     182                                if (errors) {
     183                                        println flash.errors
    128184                                        error()
    129                                 }
    130                                 println params
     185                                } else {
     186                                        success()
     187                                }
    131188                        }.to "groups"
    132189                        on("previous") {
     
    146203                        on("add") {
    147204                                def increment = flow.groups.size()
    148                                 flow.groups[ increment ] = new SubjectGroup(params)
     205                                flow.groups[increment] = new SubjectGroup(params)
    149206
    150207                                println flow.groups
  • trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy

    r162 r180  
    352352         */
    353353        def templateColumns = { attrs, body ->
    354                 def subjectId = attrs.remove('id')
    355                 def template = attrs.remove('template')
     354                def subject                     = attrs.remove('subject')
     355                def subjectId           = attrs.remove('id')
     356                def template            = attrs.remove('template')
     357                def intFields           = subject.templateIntegerFields
     358                def stringFields        = subject.templateStringFields
    356359
    357360                // output columns for these subjectFields
    358361                template.subjectFields.each() {
     362                        // output div
    359363                        out << '<div class="' + attrs.get('class') + '">'
    360364
     
    364368                                        if (!it.listEntries.isEmpty()) {
    365369                                                out << select(
    366                                                         name: it.name,
    367                                                         from: it.listEntries
     370                                                        name: attrs.name + '_' + it.name,
     371                                                        from: it.listEntries,
     372                                                        value: (stringFields) ? stringFields.get(it.name) : ''
    368373                                                )
    369374                                        } else {
     
    374379                                        // render integer subjectfield
    375380                                        out << textField(
    376                                                 name: it.name
     381                                                name: attrs.name + '_' + it.name,
     382                                                value: (intFields) ? intFields.get(it.name) : ''
    377383                                        )
    378384                                        break;
  • trunk/grails-app/views/wizard/pages/_groups.gsp

    r178 r180  
    3232                                <div class="label">${group.name}</div>
    3333                                <div class="subjects">
     34                                        <div class="subject">test subject 1</div>
     35                                        <div class="subject">test subject 2</div>
     36                                        <div class="subject">test subject 3</div>
    3437                                </div>
    3538                        </div>
  • trunk/grails-app/views/wizard/pages/_subjects.gsp

    r172 r180  
    3535                        <wizard:speciesSelect value="${subject.species}" name="subject_${i}_species" />
    3636                </div>
    37                 <wizard:templateColumns id="${i}" template="${study.template}" class="column" />
     37                <wizard:templateColumns id="${i}" template="${study.template}" name="subject_${i}" class="column" subject="${subject}" />
    3838        </div>
    3939</g:each>
  • trunk/web-app/js/grouping.js

    r178 r180  
    1414function Grouping() {
    1515}
     16/*
    1617Grouping.prototype = {
    1718    itemsIdentifier:    null,
    18     itemIdentifier:    null,
     19    itemIdentifier:     null,
    1920    groupsIdentifier:   null,
    20     groupIdentifier:   null,
     21    groupIdentifier:    null,
     22
     23    init: function(itemsIdentifier, itemIdentifier, groupsIdentifier, groupIdentifier) {
     24        var that = this;
     25
     26        this.itemsIdentifier    = itemsIdentifier;
     27        this.itemIdentifier     = itemIdentifier;
     28        this.groupsIdentifier   = groupsIdentifier;
     29        this.groupIdentifier    = groupIdentifier;
     30
     31        this.initItems();
     32    },
     33
     34    initItems: function() {
     35        $(this.itemsIdentifier).
     36    }
     37}
     38*/
     39
     40Grouping.prototype = {
     41    itemsIdentifier:    null,
     42    itemIdentifier:     null,
     43    groupsIdentifier:   null,
     44    groupIdentifier:    null,
    2145
    2246    init: function(itemsIdentifier, itemIdentifier, groupsIdentifier, groupIdentifier) {
     
    3660
    3761        // make all items selectable
     62        console.log($(this.itemsIdentifier))
    3863        $(this.itemsIdentifier).selectable({
    3964            filter: that.itemIdentifier,
     
    6287                    $('.ui-selected', $(that.itemsIdentifier)).each(function() {
    6388                        var E = $(this);
    64                        
     89
    6590                        // add to list
    6691                        E.appendTo(list);
     
    132157}
    133158
    134 
Note: See TracChangeset for help on using the changeset viewer.