Changeset 254


Ignore:
Timestamp:
Dec 30, 2009, 4:33:42 AM (15 years ago)
Author:
gav
Message:

Add ajax feature to show persons in the group when creating and editing assignedGroup.
Remove the list and show detailed views since they are no longer used.

Location:
trunk/grails-app
Files:
1 added
2 deleted
5 edited

Legend:

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

    r248 r254  
    1212    // the delete, save and update actions only accept POST requests
    1313    static allowedMethods = [delete:'POST', save:'POST', update:'POST']
    14 
    15     def list = {
    16             def result = assignedGroupService.list(params)
    17             if(!result.error) {
    18                 return [ assignedGroupInstanceList: result.assignedGroupInstanceList,
    19                                 assignedGroupInstanceTotal: result.assignedGroupInstanceTotal ]
    20             }
    21 
    22             flash.message = g.message(code: result.error.code, args: result.error.args)
    23             redirect( controller: "appCore", action: "start" )
    24     }
    25 
    26     def show = {
    27         def result = assignedGroupService.show(params)
    28 
    29         if(!result.error)
    30             return [ assignedGroupInstance: result.assignedGroupInstance ]
    31 
    32         flash.message = g.message(code: result.error.code, args: result.error.args)
    33 
    34         if(params.task?.id)
    35             redirect(controller:"taskDetailed", action:"show", id: params.task.id)
    36 
    37         redirect(controller:"taskDetailed", action:"search")
    38     }
    3914
    4015    def delete = {
     
    6035        def result = assignedGroupService.edit(params)
    6136
    62         if(!result.error)
    63             return [ assignedGroupInstance : result.assignedGroupInstance ]
     37        if(!result.error) {
     38            return [assignedGroupInstance: result.assignedGroupInstance,
     39                            personGroup: result.personGroup,
     40                            personsInGroup: result.personsInGroup]
     41        }
    6442
    6543        flash.message = g.message(code: result.error.code, args: result.error.args)
     
    7452        if(!result.error) {
    7553            flash.message = g.message(code: "default.update.success", args: ["AssignedGroup", params.id])
    76             redirect(action:show, id: params.id)
     54            redirect(controller:"taskDetailed", action:"show", id: result.assignedGroupInstance.task.id)
    7755            return
    7856        }
     
    8462        }
    8563
    86         render(view:'edit', model:[assignedGroupInstance: result.assignedGroupInstance.attach()])
     64        if(result.error.code == "personGroup.not.found") {
     65            flash.message = g.message(code: result.error.code, args: result.error.args)
     66            redirect(action:"edit", id: params.id)
     67            return
     68        }
     69
     70        render(view:'edit', model:[assignedGroupInstance: result.assignedGroupInstance.attach(),
     71                                                personGroup: result.personGroup.attach(),
     72                                                personsInGroup: result.personsInGroup])
    8773    }
    8874
     
    9076        def result = assignedGroupService.create(params)
    9177
    92         if(!result.error)
    93             return [assignedGroupInstance: result.assignedGroupInstance]
     78        if(!result.error) {
     79            return [assignedGroupInstance: result.assignedGroupInstance,
     80                            personGroup: result.personGroup,
     81                            personsInGroup: result.personsInGroup]
     82        }
    9483
    9584        if(result.error.code == "assignedGroup.task.not.found") {
     
    112101        }
    113102
    114         render(view:'edit', model:[assignedGroupInstance: result.assignedGroupInstance])
     103        if(result.error.code == "personGroup.not.found") {
     104            flash.message = g.message(code: result.error.code, args: result.error.args)
     105            redirect(action:"create", params:["task.id": params.task?.id])
     106            return
     107        }
     108
     109        render(view:'create', model:[assignedGroupInstance: result.assignedGroupInstance,
     110                                                personGroup: result.personGroup.attach(),
     111                                                personsInGroup: result.personsInGroup])
     112    }
     113
     114    def personsInGroup = {
     115        def result = assignedGroupService.personsInGroup(params)
     116
     117        if(!result.error) {
     118            render ( template:"personsInGroup",
     119                            model: [personGroup: result.personGroup, personsInGroup: result.personsInGroup] )
     120            return
     121        }
     122
     123        render {
     124            div(id:"personsInGroup", g.message(code: result.error.code, args: result.error.args) )
     125        }
     126
    115127    }
    116128
  • trunk/grails-app/i18n/messages.properties

    r249 r254  
    5252
    5353taskRecurringSchedule.notFound=Could not complete operation, recurring schedule not found.
     54personGroup.not.found=Person Group not found, it may have been deleted.
    5455
    5556task.assignedGroups=Assigned Groups
  • trunk/grails-app/services/AssignedGroupService.groovy

    r251 r254  
    44
    55    def personService
    6 
    7     def list(params) {
    8         def result = [:]
    9         def fail = { Map m ->
    10             result.error = [ code: m.code, args: ["AssignedGroup"] ]
    11             return result
    12         }
    13 
    14         params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
    15         result.assignedGroupInstanceList = AssignedGroup.list(params)
    16         result.assignedGroupInstanceTotal = AssignedGroup.count()
    17 
    18         if(!result.assignedGroupInstanceList || !result.assignedGroupInstanceTotal)
    19             return fail(code:"default.list.failure")
    20 
    21         // Success.
    22         return result
    23     }
    24 
    25     def show(params) {
    26         def result = [:]
    27         def fail = { Map m ->
    28             result.error = [ code: m.code, args: ["AssignedGroup", params.id] ]
    29             return result
    30         }
    31 
    32         result.assignedGroupInstance = AssignedGroup.get(params.id)
    33 
    34         if(!result.assignedGroupInstance)
    35             return fail(code:"default.not.found")
    36 
    37         // Success.
    38         return result
    39     }
    406
    417    def delete(params) {
     
    8652            return fail(code:"default.not.found")
    8753
     54        result.personGroup = result.assignedGroupInstance.personGroup
     55        result.personsInGroup = result.personGroup.persons
     56
    8857        // Success.
    8958        return result
     
    10170                return result
    10271            }
     72
     73            result.personGroup = PersonGroup.get(params.personGroup.id)
     74
     75            // Prevent a null property reference.
     76            if(!result.personGroup)
     77                return fail(code:"personGroup.not.found")
     78
     79            result.personsInGroup = result.personGroup.persons
    10380
    10481            result.assignedGroupInstance = AssignedGroup.get(params.id)
     
    144121        result.assignedGroupInstance.properties = params
    145122
     123        result.personGroup = PersonGroup.list().sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name)}[0] // Get the first result.
     124        result.personsInGroup = result.personGroup.persons
     125
    146126        // success
    147127        return result
     
    153133
    154134            def fail = { Map m ->
     135                status.setRollbackOnly()
    155136                if(result.assignedGroupInstance && m.field)
    156137                    result.assignedGroupInstance.errors.rejectValue(m.field, m.code)
     
    159140            }
    160141
    161             result.assignedGroupInstance = new AssignedGroup(params)
     142            result.personGroup = PersonGroup.get(params.personGroup.id)
     143
     144            // Prevent a null property reference.
     145            if(!result.personGroup)
     146                return fail(code:"personGroup.not.found")
     147
     148            result.personsInGroup = result.personGroup.persons
     149
     150            result.assignedGroupInstance = new AssignedGroup()
     151            result.assignedGroupInstance.properties = params
    162152
    163153            if(result.assignedGroupInstance.hasErrors() || !result.assignedGroupInstance.save())
    164154                return fail(code:"default.create.failure")
    165155
    166             // Record a taskModification for every one except "system".
     156            // Record a taskModification for everyone except "system".
    167157            if(personService.currentUser.id != 1) {
    168158                def taskModification = new TaskModification(person: personService.currentUser,
     
    174164            }
    175165
    176             // success
     166            // Success.
    177167            return result
    178168
     
    180170    } // end save()
    181171
     172    def personsInGroup(params) {
     173        def result = [:]
     174
     175        def fail = { Map m ->
     176            result.error = [ code: m.code, args: ["PersonGroup", params.personGroup?.id] ]
     177            return result
     178        }
     179
     180        result.personGroup = PersonGroup.get(params.personGroup?.id)
     181
     182        if(!result.personGroup)
     183            return fail(code:"default.not.found")
     184
     185        result.personsInGroup = result.personGroup.persons
     186
     187        // Success.
     188        return result
     189    }
     190
    182191} // end class
  • trunk/grails-app/views/assignedGroupDetailed/create.gsp

    r247 r254  
    66        <meta name="layout" content="main" />
    77        <title>Create Assigned Group</title>
     8        <g:javascript src="overlayPane.js" />
    89    </head>
    910    <body>
     
    4243                                </td>
    4344                                <td valign="top" class="value ${hasErrors(bean:assignedGroupInstance,field:'personGroup','errors')}">
    44                                     <g:select optionKey="id" from="${PersonGroup.list()}" name="personGroup.id" value="${assignedGroupInstance?.personGroup?.id}" ></g:select>
     45                                    <g:select optionKey="id"
     46                                                        from="${PersonGroup.list().sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }}"
     47                                                        name="personGroup.id"
     48                                                        value="${assignedGroupInstance?.personGroup?.id}"
     49                                                        onchange="${remoteFunction(action:'personsInGroup', update:'personsInGroup', params: '\'personGroup.id=\' + this.value' )}">
     50                                    </g:select>
    4551                                </td>
    4652                            </tr>
     
    6672                    </table>
    6773                </div>
     74
    6875                <div class="buttons">
    6976                    <span class="button"><input class="save" type="submit" value="Create" /></span>
    7077                </div>
    7178            </g:form>
     79
     80            <br />
     81
     82            <div id="personsInGroup" class="dialog">
     83                <g:render template="personsInGroup" />
     84            </div>
     85
    7286        </div>
    7387    </body>
  • trunk/grails-app/views/assignedGroupDetailed/edit.gsp

    r247 r254  
    4444                                </td>
    4545                                <td valign="top" class="value ${hasErrors(bean:assignedGroupInstance,field:'personGroup','errors')}">
    46                                     <g:select optionKey="id" from="${PersonGroup.list()}" name="personGroup.id" value="${assignedGroupInstance?.personGroup?.id}" ></g:select>
     46                                    <g:select optionKey="id"
     47                                                        from="${PersonGroup.list().sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) }}"
     48                                                        name="personGroup.id"
     49                                                        value="${assignedGroupInstance?.personGroup?.id}"
     50                                                        onchange="${remoteFunction(action:'personsInGroup', update:'personsInGroup', params: '\'personGroup.id=\' + this.value' )}">
     51                                    </g:select>
    4752                                </td>
    4853                            </tr>
     
    7277                </div>
    7378            </g:form>
     79
     80            <br />
     81
     82            <div id="personsInGroup" class="dialog">
     83                <g:render template="personsInGroup" />
     84            </div>
     85
    7486        </div>
    7587    </body>
Note: See TracChangeset for help on using the changeset viewer.