Changeset 216


Ignore:
Timestamp:
Feb 26, 2010, 3:23:03 PM (13 years ago)
Author:
duh
Message:
  • event grouping data is now handled properly
  • added image support to ajaxButton which now renders to an "input type='image'" instead of the default "input type='button'"
  • changed some in grouping to famfamfam icons
  • evenGroup deletions
  • eventGroup names are now uniquely generated
  • improved CSS
  • improved javascript
Location:
trunk
Files:
7 edited

Legend:

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

    r213 r216  
    5252                                [title: 'Event Descriptions'],  // event descriptions
    5353                                [title: 'Events'],                              // events
    54                                 [title: 'Confirmation'],        // confirmation page
     54                                [title: 'Confirmation'],                // confirmation page
    5555                                [title: 'Done']                                 // finish page
    5656                        ]
     
    271271
    272272                                // get eventDescription instance by name
    273                                 params.eventDescription = this.getObjectByName(params.get('eventDescription'),flow.eventDescriptions)
     273                                params.eventDescription = this.getObjectByName(params.get('eventDescription'), flow.eventDescriptions)
    274274
    275275                                // instantiate Event with parameters
    276276                                def event = new Event(params)
     277
     278                                // handle event groupings
     279                                this.handleEventGrouping(flow, flash, params)
    277280
    278281                                // validate event
     
    287290                                        this.appendErrors(event, flash.errors)
    288291
    289                                         flash.startTime                 = params.startTime
    290                                         flash.endTime                   = params.endTime
    291                                         flash.eventDescription  = params.eventDescription
    292                                        
     292                                        flash.startTime = params.startTime
     293                                        flash.endTime = params.endTime
     294                                        flash.eventDescription = params.eventDescription
     295
    293296                                        error()
    294297                                }
     
    296299                        on("addEventGroup") {
    297300                                def increment = flow.eventGroups.size()
    298                                 flow.eventGroups[ increment ] = new EventGroup(name: "Group "+(increment+1))
     301                                def groupName = "Group " + (increment + 1)
     302
     303                                // check if group name exists
     304                                def nameExists = true
     305                                def u = 0
     306
     307                                // make sure a unique name is generated
     308                                while (nameExists) {
     309                                        u++
     310                                        def count = 0
     311                                       
     312                                        flow.eventGroups.each() {
     313                                                if (it.name == groupName) {
     314                                                        groupName = "Group " + (increment + 1) + "," + u
     315                                                } else {
     316                                                        count++
     317                                                }
     318                                        }
     319
     320                                        nameExists = !(count == flow.eventGroups.size())
     321                                }
     322
     323                                flow.eventGroups[increment] = new EventGroup(name: groupName)
     324                        }.to "events"
     325                        on("deleteEventGroup") {
     326                                def delete = params.get('do') as int;
     327
     328                                // handle event groupings
     329                                this.handleEventGrouping(flow, flash, params)
     330
     331                                // remove the group with this specific id
     332                                if (flow.eventGroups[delete] && flow.eventGroups[delete] instanceof EventGroup) {
     333                                        // remove this eventGroup
     334                                        flow.eventGroups.remove(delete)
     335                                }
    299336                        }.to "events"
    300337                        on("previous") {
    301                                 // TODO
     338                                // handle event groupings
     339                                this.handleEventGrouping(flow, flash, params)
    302340                        }.to "eventDescriptions"
    303341                        on("next") {
    304342                                flash.errors = new LinkedHashMap()
     343
     344                                // handle event groupings
     345                                this.handleEventGrouping(flow, flash, params)
    305346
    306347                                // check if we have at least one subject
     
    312353                                        error()
    313354                                }
    314                         }.to "confirm"
     355                        }.to "events"
    315356                }
    316357
     
    338379                                // TODO
    339380                        }.to "confirm"
     381                }
     382        }
     383
     384        /**
     385         * re-usable code for handling event grouping in a web flow
     386         * @param Map LocalAttributeMap (the flow scope)
     387         * @param Map localAttributeMap (the flash scope)
     388         * @param Map GrailsParameterMap (the flow parameters = form data)
     389         * @returns boolean
     390         */
     391        def handleEventGrouping(flow, flash, params) {
     392                // walk through eventGroups
     393                def g = 0
     394                flow.eventGroups.each() {
     395                        def e = 0
     396                        def eventGroup = it
     397
     398                        // reset events
     399                        eventGroup.events = new HashSet()
     400
     401                        // walk through events
     402                        flow.events.each() {
     403                                if (params.get('event_' + e + '_group_' + g) == 'on') {
     404                                        eventGroup.addToEvents(it)
     405                                        //} else {
     406                                        //      eventGroup.events.minus(it)
     407                                }
     408                                e++
     409                        }
     410                        g++
    340411                }
    341412        }
     
    396467
    397468                flow.eventDescriptions.each() {
    398                         it.name                         = params.get('eventDescription_' + id + '_name')
    399                         it.description          = params.get('eventDescription_' + id + '_description')
    400                         it.classification       = Term.findByName(params.get('eventDescription_' + id + '_classification'))
    401                         it.isSamplingEvent      = (params.containsKey('eventDescription_' + id + '_isSamplingEvent'))
     469                        it.name = params.get('eventDescription_' + id + '_name')
     470                        it.description = params.get('eventDescription_' + id + '_description')
     471                        it.classification = Term.findByName(params.get('eventDescription_' + id + '_classification'))
     472                        it.isSamplingEvent = (params.containsKey('eventDescription_' + id + '_isSamplingEvent'))
    402473
    403474                        // validate eventDescription
     
    443514                                        // yeah, also mention the first
    444515                                        // occurrence in the error message
    445                                         this.appendErrorMap(name: 'The subject name needs to be unique!', flash.errors, 'subject_'+names[it.name]['firstId']+'_')
     516                                        this.appendErrorMap(name: 'The subject name needs to be unique!', flash.errors, 'subject_' + names[it.name]['firstId'] + '_')
    446517                                }
    447518
    448519                                // add to error map
    449                                 this.appendErrorMap([name: 'The subject name needs to be unique!'], flash.errors, 'subject_'+id+'_')
     520                                this.appendErrorMap([name: 'The subject name needs to be unique!'], flash.errors, 'subject_' + id + '_')
    450521                                errors = true
    451522                        }
     
    502573        }
    503574
    504 
    505575        /**
    506576         * return the object from a map of objects by searching for a name
    507          * @param String        name
    508          * @param Map           map of objects
     577         * @param String name
     578         * @param Map map of objects
    509579         * @return Object
    510580         */
     
    545615                this.appendErrorMap(this.getHumanReadableErrors(object), map)
    546616        }
     617
    547618        def appendErrors(object, map, prepend) {
    548619                this.appendErrorMap(this.getHumanReadableErrors(object), map, prepend)
     
    560631                }
    561632        }
     633
    562634        def appendErrorMap(map, mapToExtend, prepend) {
    563635                map.each() {key, value ->
  • trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy

    r213 r216  
    5555                // javascript function to call after success
    5656                def afterSuccess = attrs['afterSuccess']
     57
     58                // src parameter?
     59                def src = attrs['src']
     60                def alt = attrs['alt']
    5761
    5862                // generate a normal submitToRemote button
     
    8993                if (afterSuccess) {
    9094                        button = button.replaceFirst(/\.html\(data\)\;/, '.html(data);' + afterSuccess + ';')
     95                }
     96
     97                // got an src parameter?
     98                if (src) {
     99                        def replace = 'type="image" src="' + src + '"'
     100
     101                        if (alt) replace = replace + ' alt="' + alt + '"'
     102
     103                        button = button.replaceFirst(/type="button"/, replace)
    91104                }
    92105
  • trunk/grails-app/views/wizard/common/_wizard.gsp

    r145 r216  
    1818        <h1>Create a new study</h1>
    1919        <g:form action="pages" name="wizardForm" id="wizardForm">
     20        <g:hiddenField name="do" value="" />
    2021                <div id="wizardPage">
    2122                        <wizard:ajaxFlowRedirect form="form#wizardForm" name="next" url="[controller:'wizard',action:'pages']" update="[success:'wizardPage',failure:'wizardError']" afterSuccess="onWizardPage()" />
  • trunk/grails-app/views/wizard/pages/_events.gsp

    r213 r216  
    4545                        <div class="column">duration</div>
    4646                        <g:if test="${eventGroups}"><g:each var="eventGroup" status="i" in="${eventGroups}">
    47                         <div class="column"><g:textField name="eventGroup_${i}_name" value="${eventGroup.name}" /></div>
     47                        <div class="column">
     48                                <g:textField name="eventGroup_${i}_name" value="${eventGroup.name}" />
     49                                <wizard:ajaxButton name="deleteEventGroup" src="../images/icons/famfamfam/delete.png" alt="delete this eventgroup" class="famfamfam" value="-" url="[controller:'wizard',action:'pages']" update="[success:'wizardPage',failure:'wizardError']" before="\$(\'input[name=do]\').val(${i});" afterSuccess="onWizardPage()" />
     50                        </div>
    4851                        </g:each></g:if>
    49                         <div class="column"><wizard:ajaxButton name="addEventGroup" value="+" url="[controller:'wizard',action:'pages']" update="[success:'wizardPage',failure:'wizardError']" afterSuccess="onWizardPage()" /></div>
     52                        <div class="column">
     53                                <wizard:ajaxButton name="addEventGroup" src="../images/icons/famfamfam/add.png" alt="add a new eventgroup" class="famfamfam" value="+" url="[controller:'wizard',action:'pages']" update="[success:'wizardPage',failure:'wizardError']" afterSuccess="onWizardPage()" />
     54                        </div>
    5055                </div>
    5156        <g:each var="event" status="i" in="${events}">
     
    5762                        <div class="column">${event.getShortDuration()}</div>
    5863                        <g:if test="${eventGroups}"><g:each var="eventGroup" status="j" in="${eventGroups}">
    59                         <div class="column"><input type="checkbox" name="event_${i}_group_${j}"/></div>
     64                        <div class="column">
     65                                <g:if test="${eventGroup.events.find{ it == event} }">
     66                                        <input type="checkbox" name="event_${i}_group_${j}" checked="checked" />
     67                                </g:if><g:else>
     68                                        <input type="checkbox" name="event_${i}_group_${j}"/>
     69                                </g:else>
     70                        </div>
    6071                        </g:each></g:if>
    6172                        <div class="column"></div>
     
    6374        </g:each>
    6475        </div>
     76        <div class="sliderContainer">
     77                <div class="slider"/>
     78        </div>
    6579</g:if>
    6680</wizard:pageContent>
  • trunk/web-app/css/default_style.css

    r162 r216  
    3030        margin: 20px 0 10px;
    3131}
     32
    3233/** END :: header **/
    3334/** START :: topnav **/
  • trunk/web-app/css/wizard.css

    r213 r216  
    2121    padding-left: 20px;
    2222    background: url(../images/icons/famfamfam/information.png) no-repeat center left;
     23}
     24
     25.wizard .famfamfam {
     26    width: 16px;
     27    height: 16px;
     28    margin-top: 5px;
    2329}
    2430
     
    212218}
    213219
    214 .wizard .table input, .wizard .table select {
     220.wizard .table input[type=text], .wizard .table select {
    215221    border: 1px solid #8e908f;
    216222    margin: 2px 0;
     
    219225    width: 100px;
    220226}
    221 .wizard .table .header input, .wizard .table .header select, .wizard .table .header button {
     227.wizard .table .header input[type=text], .wizard .table .header select, .wizard .table .header button {
    222228    border: 1px solid #8e908f;
    223229    margin: 2px 0;
    224230    padding: 2px 4px;
    225231    background-color: #fff;
    226     width: 100px;
     232    width: 75px;
    227233}
    228234
     
    238244
    239245/* END :: TABLE */
    240 
    241 /* START :: GROUPING */
    242 .wizard .grouping {
    243     border: 1px solid black;
    244     display: inline-block;
    245     height: auto;
    246     width: 100%;
    247 }
    248 
    249 .wizard .grouping .ui-selected {
    250     background-color: red;
    251 }
    252 .wizard .grouping .ui-selecting {
    253     background-color: orange;
    254 }
    255 
    256 .wizard .grouping .subjects {
    257     display: block;
    258     float: left;
    259 }
    260 .wizard .grouping .subjects .subject {
    261     margin: 1px;
    262     padding: 0.2em;
    263     font-size: .8em;
    264     height: 14px;
    265 }
    266 .wizard .grouping .middle {
    267     display: inline-block;
    268     float: left;
    269 }
    270 .wizard .grouping .add {
    271     background: url(../images/wizard/add.png) no-repeat left top;
    272     width: 149px;
    273     height: 29px;
    274     margin-top: 10px;
    275     margin-left: 14px;
    276 }
    277 .wizard .grouping .add-hover {
    278     background: url(../images/wizard/add-hover.png) no-repeat left top;
    279 }
    280 .wizard .grouping .remove {
    281     background: url(../images/wizard/remove.png) no-repeat left top;
    282     width: 149px;
    283     height: 29px;
    284     margin-top: 10px;
    285 }
    286 .wizard .grouping .remove-hover {
    287     background: url(../images/wizard/remove-hover.png) no-repeat left top;   
    288 }
    289 .wizard .grouping .right {
    290     display: inline-block;
    291     float: right;
    292 }
    293 .wizard .grouping .right .form {
    294     border: 1px solid black;
    295 }
    296 .wizard .grouping .group {
    297     margin: 5px 0px 5px 0px;
    298     border: 1px solid black;
    299     height: auto;
    300 }
    301 .wizard .grouping .ui-selected {
    302     border: 4px solid red;
    303 }
    304 .wizard .grouping .group .label {
    305     display: block;
    306     background-color: #006DBA;
    307     color: #fff;
    308     font-weight: bold;
    309     width: auto;
    310     height: 32px;
    311     line-height: 32px;
    312     text-align: center;
    313 }
    314 .wizard .grouping .group .subjects {
    315     display: inline-block;
    316     height: auto;
    317 }
    318 .wizard .grouping .group .subject {
    319     display: inline-block;
    320     width: 100%;
    321     font-size: 10px;
    322 }
    323 
    324 /* END :: GROUPING */
  • trunk/web-app/js/table-editor.js

    r213 r216  
    9191                        var columnNumber = count;
    9292                        $(input).bind('click', function() {
    93                             console.log(columnNumber+': update checkboxes with value '+input)
    9493                            that.updateSingleInputElements(input, columnNumber, 'input');
    9594                        });
Note: See TracChangeset for help on using the changeset viewer.