Changeset 247


Ignore:
Timestamp:
Dec 27, 2009, 8:13:08 PM (15 years ago)
Author:
gav
Message:

Refactor AssignedGroup to use a serviced controller.

Location:
trunk/grails-app
Files:
1 added
7 edited

Legend:

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

    r242 r247  
    33class AssignedGroupDetailedController extends BaseController {
    44
    5     def index = { redirect(action:list,params:params) }
     5    def assignedGroupService
     6
     7    def index = {
     8        flash.message = g.message(code: "assignedGroup.task.not.found")
     9        redirect(controller:"taskDetailed", action:"search")
     10    }
    611
    712    // the delete, save and update actions only accept POST requests
     
    914
    1015    def list = {
    11         params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
    12         [ assignedGroupInstanceList: AssignedGroup.list( params ), assignedGroupInstanceTotal: AssignedGroup.count() ]
     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( url: resource(dir:'') )
    1324    }
    1425
    1526    def show = {
    16         def assignedGroupInstance = AssignedGroup.get( params.id )
     27        def result = assignedGroupService.show(params)
    1728
    18         if(!assignedGroupInstance) {
    19             flash.message = "AssignedGroup not found with id ${params.id}"
    20             redirect(action:list)
    21         }
    22         else { return [ assignedGroupInstance : assignedGroupInstance ] }
     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")
    2338    }
    2439
    2540    def delete = {
    26         def assignedGroupInstance = AssignedGroup.get( params.id )
    27         if(assignedGroupInstance) {
    28             try {
    29                 def taskId = assignedGroupInstance.task.id
    30                 assignedGroupInstance.delete()
    31                 flash.message = "AssignedGroup ${params.id} deleted"
    32                 redirect(controller:"taskDetailed", action:"show", id: taskId)
    33             }
    34             catch(org.springframework.dao.DataIntegrityViolationException e) {
    35                 flash.message = "AssignedGroup ${params.id} could not be deleted"
    36                 redirect(action:show,id:params.id)
    37             }
     41        def result = assignedGroupService.delete(params)
     42
     43        if(!result.error) {
     44            flash.message = g.message(code: "default.delete.success", args: ["AssignedGroup", params.id])
     45            redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
     46            return
    3847        }
    39         else {
    40             flash.message = "AssignedGroup not found with id ${params.id}"
    41             redirect(action:list)
     48
     49        flash.message = g.message(code: result.error.code, args: result.error.args)
     50
     51        if(result.error.code == "default.not.found") {
     52            redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
     53            return
    4254        }
     55
     56        redirect(action:show, id: params.id)
    4357    }
    4458
    4559    def edit = {
    46         def assignedGroupInstance = AssignedGroup.get( params.id )
     60        def result = assignedGroupService.edit(params)
    4761
    48         if(!assignedGroupInstance) {
    49             flash.message = "AssignedGroup not found with id ${params.id}"
    50             redirect(action:list)
    51         }
    52         else {
    53             return [ assignedGroupInstance : assignedGroupInstance ]
    54         }
     62        if(!result.error)
     63            return [ assignedGroupInstance : result.assignedGroupInstance ]
     64
     65        flash.message = g.message(code: result.error.code, args: result.error.args)
     66
     67        redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
     68
    5569    }
    5670
    5771    def update = {
    58         def assignedGroupInstance = AssignedGroup.get( params.id )
    59         if(assignedGroupInstance) {
    60             if(params.version) {
    61                 def version = params.version.toLong()
    62                 if(assignedGroupInstance.version > version) {
     72        def result = assignedGroupService.update(params)
    6373
    64                     assignedGroupInstance.errors.rejectValue("version", "assignedGroup.optimistic.locking.failure", "Another user has updated this AssignedGroup while you were editing.")
    65                     render(view:'edit',model:[assignedGroupInstance:assignedGroupInstance])
    66                     return
    67                 }
    68             }
    69             assignedGroupInstance.properties = params
    70             if(!assignedGroupInstance.hasErrors() && assignedGroupInstance.save(flush: true)) {
    71                 flash.message = "AssignedGroup ${params.id} updated"
    72                 redirect(action:show,id:assignedGroupInstance.id)
    73             }
    74             else {
    75                 render(view:'edit',model:[assignedGroupInstance:assignedGroupInstance])
    76             }
     74        if(!result.error) {
     75            flash.message = g.message(code: "default.update.success", args: ["AssignedGroup", params.id])
     76            redirect(action:show, id: params.id)
     77            return
    7778        }
    78         else {
    79             flash.message = "AssignedGroup not found with id ${params.id}"
    80             redirect(action:edit,id:params.id)
     79
     80        if(result.error.code == "default.not.found") {
     81            flash.message = g.message(code: result.error.code, args: result.error.args)
     82            redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
     83            return
    8184        }
     85
     86        render(view:'edit', model:[assignedGroupInstance: result.assignedGroupInstance.attach()])
    8287    }
    8388
    8489    def create = {
    85         if(!params.task?.id) {
    86             flash.message = "Please select a task and then 'Add Assigned Group'"
     90        def result = assignedGroupService.create(params)
     91
     92        if(!result.error)
     93            return [assignedGroupInstance: result.assignedGroupInstance]
     94
     95        if(result.error.code == "assignedGroup.task.not.found") {
     96            flash.message = g.message(code: result.error.code, args: result.error.args)
    8797            redirect(controller: "taskDetailed", action: "search")
     98            return
    8899        }
    89         else {
    90             def assignedGroupInstance = new AssignedGroup()
    91             assignedGroupInstance.properties = params
    92             return ['assignedGroupInstance':assignedGroupInstance]
    93         }
     100
     101        flash.message = g.message(code: result.error.code, args: result.error.args)
     102        redirect(controller:"taskDetailed", action:"show", id: params.task?.id)
    94103    }
    95104
    96105    def save = {
    97         def assignedGroupInstance = new AssignedGroup(params)
     106        def result = assignedGroupService.save(params)
    98107
    99         if(!assignedGroupInstance.hasErrors() && assignedGroupInstance.save(flush: true)) {
    100             flash.message = "AssignedGroup ${assignedGroupInstance.id} created"
    101             redirect(controller:"taskDetailed", action:"show", id: params.task.id)
     108        if(!result.error) {
     109            flash.message = g.message(code: "default.create.success", args: ["AssignedGroup", result.assignedGroupInstance.id])
     110            redirect(controller:"taskDetailed", action:"show", id: result.assignedGroupInstance.task.id)
     111            return
    102112        }
    103         else {
    104             render(view:'create',model:[assignedGroupInstance:assignedGroupInstance])
    105         }
     113
     114        render(view:'edit', model:[assignedGroupInstance: result.assignedGroupInstance])
    106115    }
     116
    107117}
  • trunk/grails-app/i18n/messages.properties

    r243 r247  
    9494inventoryMovement.inventoryItem.notFound=Inventory Item not found.
    9595
     96assignedGroup.task.not.found=Please select a task and then ''Add Assigned Group''.
     97
     98default.list.failure=Could not generate list for class {0}.
     99default.not.found={0} {1} not found, it may have been deleted.
     100default.delete.success={0} {1} deleted.
     101default.delete.failure={0} {1} could not be deleted.
     102default.update.success={0} {1} updated.
     103default.update.failure={0} {1} could not be updated.
     104default.create.success={0} {1} created.
     105default.create.failure={0} {1} could not be created.
     106default.optimistic.locking.failure=Another user has updated this item while you were editing, please check the updated values.
     107
    96108default.doesnt.match.message=Property [{0}] of class [{1}] with value [{2}] does not match the required pattern [{3}]
    97109default.invalid.url.message=Property [{0}] of class [{1}] with value [{2}] is not a valid URL
     
    113125default.paginate.prev=Previous
    114126default.paginate.next=Next
    115 default.optimistic.locking.failure=Another user has updated this item while you were editing, please check the updated values.
    116127
    117128# Rich UI plugin - Calendar
  • trunk/grails-app/views/assignedGroupDetailed/create.gsp

    r242 r247  
    2121            </g:hasErrors>
    2222            <g:form action="save" method="post" >
    23                 <input type="hidden" name="task.id" value="${assignedGroupInstance?.task?.id}" />
     23                <g:hiddenField name="task.id" value="${assignedGroupInstance?.task?.id}" />
    2424                <div class="dialog">
    2525                    <table>
  • trunk/grails-app/views/assignedGroupDetailed/edit.gsp

    r242 r247  
    2121            </g:hasErrors>
    2222            <g:form method="post" >
    23                 <input type="hidden" name="id" value="${assignedGroupInstance?.id}" />
    24                 <input type="hidden" name="version" value="${assignedGroupInstance?.version}" />
     23                <g:hiddenField name="id" value="${assignedGroupInstance?.id}" />
     24                <g:hiddenField name="task.id" value="${assignedGroupInstance?.task?.id}" />
     25                <g:hiddenField name="version" value="${assignedGroupInstance?.version}" />
    2526                <div class="dialog">
    2627                    <table>
  • trunk/grails-app/views/assignedGroupDetailed/show.gsp

    r242 r247  
    5151            <div class="buttons">
    5252                <g:form>
    53                     <input type="hidden" name="id" value="${assignedGroupInstance?.id}" />
     53                    <g:hiddenField name="id" value="${assignedGroupInstance?.id}" />
     54                    <g:hiddenField name="task.id" value="${assignedGroupInstance?.task?.id}" />
    5455                    <span class="button"><g:actionSubmit class="edit" value="Edit" /></span>
    5556                    <span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete" /></span>
  • trunk/grails-app/views/taskDetailed/edit.gsp

    r246 r247  
    55        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    66        <meta name="layout" content="main" />
    7         <title>Edit Task #${taskInstance.id}</title>
     7        <title>Edit Task #${taskInstance?.id}</title>
    88        <nav:resources override="true"/>
    99        <resource:dateChooser />
     
    3636                            </tr>
    3737
    38                             <g:if test="${taskInstance.parentTask}">
     38                            <g:if test="${taskInstance?.parentTask}">
    3939                                <tr class="prop">
    4040                                    <td valign="top" class="name">Parent Task:</td>
     
    166166                                <ul>
    167167                                <g:each var="a" in="${taskInstance?.assignedGroups?}">
    168                                     <li><g:link controller="assignedGroupDetailed" action="edit" id="${a.id}">${a?.encodeAsHTML()}</g:link></li>
     168                                    <li><g:link controller="assignedGroupDetailed" action="edit" id="${a.id}" params="['task.id':taskInstance?.id]">${a?.encodeAsHTML()}</g:link></li>
    169169                                </g:each>
    170170                                </ul>
     
    181181                                <ul>
    182182                                <g:each var="a" in="${taskInstance?.assignedPersons?}">
    183                                     <li><g:link controller="assignedPersonDetailed" action="edit" id="${a.id}">${a?.encodeAsHTML()}</g:link></li>
     183                                    <li><g:link controller="assignedPersonDetailed" action="edit" id="${a.id}" params="['task.id':taskInstance?.id]">${a?.encodeAsHTML()}</g:link></li>
    184184                                </g:each>
    185185                                </ul>
  • trunk/grails-app/views/taskDetailed/show.gsp

    r246 r247  
    189189                                            <ul>
    190190                                            <g:each var="a" in="${taskInstance.assignedGroups}">
    191                                                 <li><g:link controller="assignedGroupDetailed" action="edit" id="${a.id}">${a?.encodeAsHTML()}</g:link></li>
     191                                                <li><g:link controller="assignedGroupDetailed" action="edit" id="${a.id}" params="['task.id':taskInstance.id]">${a?.encodeAsHTML()}</g:link></li>
    192192                                            </g:each>
    193193                                            </ul>
    194                                             <g:link controller="assignedGroupDetailed" params="['task.id':taskInstance?.id]" action="create">Add Assigned Group</g:link>
     194                                            <g:link controller="assignedGroupDetailed" action="create" params="['task.id':taskInstance.id]">Add Assigned Group</g:link>
    195195                                        </td>
    196196
     
    462462                                <div class="buttons">
    463463                                    <span class="button">
    464                                         <g:actionSubmit value="Create" action="create"  class="add"/>
     464                                        <g:actionSubmit value="Add" action="create"  class="add"/>
    465465                                    </span>
    466466                                </div>
     
    664664                                    </g:else>
    665665                                    <span class="button"><g:actionSubmit action="listSubTasks" class="table" value="List" /></span>
    666                                     <span class="button"><g:actionSubmit action="createSubTask" class="add" value="Create" /></span>
     666                                    <span class="button"><g:actionSubmit action="createSubTask" class="save" value="Create" /></span>
    667667                                </g:form>
    668668                            </div>
     
    678678                                <g:form>
    679679                                    <g:hiddenField name="id" value="${taskInstance?.id}" />
    680                                     <span class="button"><g:actionSubmit action="createSubTask" class="add" value="Create" /></span>
     680                                    <span class="button"><g:actionSubmit action="createSubTask" class="save" value="Create" /></span>
    681681                                </g:form>
    682682                            </div>
Note: See TracChangeset for help on using the changeset viewer.