- Timestamp:
- Feb 2, 2011, 8:38:20 PM (14 years ago)
- Location:
- branches/features/taskProcedureRework/grails-app
- Files:
-
- 2 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/features/taskProcedureRework/grails-app/controllers/TaskProcedureDetailedController.groovy
r762 r770 40 40 41 41 if(!taskProcedureInstance) { 42 flash.message = "TaskProcedure not found with id ${params.id}" 43 redirect(action:list) 44 } 45 else { return [ taskProcedureInstance : taskProcedureInstance ] } 42 flash.errorMessage = "TaskProcedure not found with id ${params.id}" 43 redirect(controller:'taskDetailed', action:'search') 44 return 45 } 46 47 redirect(controller:'taskDetailed', 48 action:'show', 49 id:taskProcedureInstance.linkedTask?.id, 50 params:[showTab:"showProcedureTab"]) 46 51 } 47 52 … … 49 54 def taskProcedureInstance = TaskProcedure.get( params.id ) 50 55 if(taskProcedureInstance) { 56 def taskInstance = taskProcedureInstance.linkedTask 51 57 try { 52 58 taskProcedureInstance.tasks.each { … … 55 61 taskProcedureInstance.delete(flush:true) 56 62 flash.message = "TaskProcedure ${params.id} deleted" 57 redirect(action:list) 63 redirect(controller:'taskDetailed', 64 action:'show', 65 id:taskInstance.id, 66 params:[showTab:"showProcedureTab"]) 58 67 } 59 68 catch(org.springframework.dao.DataIntegrityViolationException e) { 60 69 flash.message = "TaskProcedure ${params.id} could not be deleted" 61 redirect(action:show,id:params.id) 70 redirect(controller:'taskDetailed', 71 action:'show', 72 id:taskInstance.id, 73 params:[showTab:"showProcedureTab"]) 62 74 } 63 75 } … … 99 111 taskProcedureInstance.properties = params 100 112 101 def toBeDeleted = taskProcedureInstance.maintenanceActions.findAll {it.deleted} 102 if(toBeDeleted) { 113 // Gaps in the html index's can be created by adding 2 items and removing the first one. 114 // This creates a gap at the missing index where LazyList will return a null. 115 def nullMaintenanceActions = taskProcedureInstance.maintenanceActions.findAll {!it} 116 if (nullMaintenanceActions) { 117 taskProcedureInstance.maintenanceActions.removeAll(nullMaintenanceActions) 118 } 119 120 // Save for restoration if validation fails. 121 def savedMaintenanceActions = new ArrayList(taskProcedureInstance.maintenanceActions) 122 123 // Remove toBeDeleted before validation. 124 def toBeDeleted = taskProcedureInstance.maintenanceActions.findAll {it.toBeDeleted} 125 if (toBeDeleted) { 103 126 taskProcedureInstance.maintenanceActions.removeAll(toBeDeleted) 104 127 } … … 106 129 if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { 107 130 flash.message = "TaskProcedure ${params.id} updated" 108 redirect(action:show,id:taskProcedureInstance.id) 131 redirect(controller:'taskDetailed', 132 action:'show', 133 id:taskProcedureInstance.linkedTask.id, 134 params:[showTab:"showProcedureTab"]) 109 135 } 110 136 else { 137 // Restore the saved items, some of which contain toBeDeleted flags but 138 // have not been deleted yet since validation failed. 139 // The toBeDeleted items are hidden in the view. 140 taskProcedureInstance.maintenanceActions = savedMaintenanceActions 141 // Populate maintenanceAction errors for display. 142 taskProcedureInstance.maintenanceActions.each { it.validate() } 111 143 render(view:'edit',model:[taskProcedureInstance:taskProcedureInstance]) 112 144 } … … 119 151 120 152 def create = { 121 if(params.taskInstance?.id) { 122 def taskInstance = Task.get(params.taskInstance.id) 123 124 def taskProcedureInstance = new TaskProcedure() 125 taskProcedureInstance.properties = params 126 return ['taskProcedureInstance':taskProcedureInstance, 127 taskInstance: taskInstance] 128 } else { 129 flash.message = "Please select or create a task, then go to the Procedure tab." 153 154 if(!params.taskInstance?.id) { 155 flash.errorMessage = "Please select or create a task, then go to the Procedure tab." 130 156 redirect(controller:"taskDetailed", action:"search") 131 } 157 return 158 } 159 160 params.linkedTask = Task.get(params.taskInstance.id) 161 162 if(!params.linkedTask?.primaryAsset) { 163 flash.errorMessage = "Please set a Primary Asset first, then go to the Procedure tab." 164 redirect(controller:"taskDetailed", action:"show", id:params.linkedTask?.id) 165 return 166 } 167 168 def taskProcedureInstance = new TaskProcedure() 169 taskProcedureInstance.properties = params 170 return ['taskProcedureInstance':taskProcedureInstance] 132 171 } 133 172 … … 136 175 def taskInstance = Task.get(params.linkedTask.id) 137 176 177 // Gaps in the html index's can be created by adding 2 items and removing the first one. 178 // This creates a gap at the missing index where LazyList will return a null. 179 def nullMaintenanceActions = taskProcedureInstance.maintenanceActions.findAll {!it} 180 if (nullMaintenanceActions) { 181 taskProcedureInstance.maintenanceActions.removeAll(nullMaintenanceActions) 182 } 183 138 184 if(!taskProcedureInstance.hasErrors() && taskProcedureInstance.save(flush: true)) { 139 taskProcedureInstance.addToTasks(taskInstance) // also sets: taskInstance.taskProcedure = taskProcedureInstance 185 // Also sets: taskInstance.taskProcedure = taskProcedureInstance 186 taskProcedureInstance.addToTasks(taskInstance) 140 187 flash.message = "TaskProcedure ${taskProcedureInstance.id} created." 141 redirect(action:show,id:taskProcedureInstance.id) 142 } 143 else { 144 render(view:'create',model:[taskProcedureInstance:taskProcedureInstance, taskInstance: taskInstance]) 145 } 146 } 188 redirect(controller:'taskDetailed', 189 action:'show', 190 id:taskProcedureInstance.linkedTask.id, 191 params:[showTab:"showProcedureTab"]) 192 } 193 else { 194 // Populate maintenanceAction errors for display. 195 taskProcedureInstance.maintenanceActions.each { it.validate() } 196 render(view:'create',model:[taskProcedureInstance:taskProcedureInstance]) 197 } 198 } 199 147 200 } -
branches/features/taskProcedureRework/grails-app/domain/MaintenanceAction.groovy
r769 r770 11 11 Integer procedureStepNumber 12 12 13 Boolean deleted 14 static transients = [ 'deleted' ] 13 Boolean toBeDeleted 14 Boolean isNew 15 static transients = [ 'toBeDeleted', 'isNew' ] 15 16 16 17 // static hasMany = [] -
branches/features/taskProcedureRework/grails-app/views/taskDetailed/show.gsp
r762 r770 513 513 <tr class="prop"> 514 514 <td valign="top" class="name">Procedure Id:</td> 515 516 <td valign="top" class="value">${fieldValue(bean:taskProcedureInstance, field:'id')}</td> 517 518 </tr> 519 520 <tr class="prop"> 521 <td valign="top" class="name">Linked Task:</td> 522 <td valign="top" class="value"> 523 <g:link controller="taskDetailed" action="show" id="${taskProcedureInstance.linkedTask.id}"> 524 ${taskProcedureInstance.linkedTask.encodeAsHTML()} 525 </g:link> 526 </td> 527 </tr> 515 <td valign="top" class="value"> 516 ${fieldValue(bean:taskProcedureInstance, field:'id')} 517 </td> 518 </tr> 519 520 <tr class="prop"> 521 <td valign="top" class="name">Linked Task:</td> 522 <td valign="top" class="value"> 523 <g:link controller="taskDetailed" 524 action="show" 525 id="${taskProcedureInstance.linkedTask.id}"> 526 ${taskProcedureInstance.linkedTask.encodeAsHTML()} 527 </g:link> 528 </td> 529 </tr> 530 531 <tr class="prop"> 532 <td valign="top" class="name">Linked Asset:</td> 533 <td valign="top" class="value"> 534 ${fieldValue(bean:taskProcedureInstance, field:'linkedTask.primaryAsset')} 535 </td> 536 </tr> 537 538 <tr class="prop"> 539 <td valign="top" class="name">Version:</td> 540 <td valign="top" class="value"> 541 ${fieldValue(bean:taskProcedureInstance, field:'version')} 542 </td> 543 </tr> 528 544 529 545 </tbody> … … 542 558 <tr> 543 559 <th>Step</th> 560 <th>Sub Item</th> 544 561 <th>Description</th> 545 562 <th>Reasoning</th> 546 <th>Sub Item</th>547 563 </tr> 548 564 </thead> … … 556 572 557 573 <td valign="top" style="text-align:left;" class="value"> 574 ${fieldValue(bean:maintenanceAction, field:'assetSubItem')} 575 </td> 576 577 <td valign="top" style="text-align:left;" class="value"> 558 578 ${fieldValue(bean:maintenanceAction, field:'description')} 559 579 </td> … … 561 581 <td valign="top" style="text-align:left;" class="value"> 562 582 ${fieldValue(bean:maintenanceAction, field:'reasoning')} 563 </td>564 565 <td valign="top" style="text-align:left;" class="value">566 ${fieldValue(bean:maintenanceAction, field:'assetSubItem')}567 583 </td> 568 584 -
branches/features/taskProcedureRework/grails-app/views/taskProcedureDetailed/_maintenanceActions.gsp
r762 r770 1 1 <script type="text/javascript"> 2 2 var childCount = ${taskProcedureInstance?.maintenanceActions.size()} + 0; 3 var ma_wrapperId = "ma_wrapper"; 4 var ma_cloneId = "maintenanceActionLazyList_clone"; 5 var ma_lazyList = "maintenanceActionLazyList"; 6 var ma_fields = ["toBeDeleted", "isNew", "description", "reasoning", "assetSubItem.id", "procedureStepNumber"]; 7 var ma_focusField = "procedureStepNumber"; 3 8 4 function addChild() { 5 var htmlId = "maintenanceAction" + childCount; 6 var deleteIcon = "${resource(dir:'images/skin', file:'database_delete.png')}"; 7 var templateHtml = "<div id='" + htmlId + "' name='" + htmlId + "'>\n"; 8 templateHtml += "<input type='text' id='maintenanceActionLazyList[" + childCount + "].description' name='maintenanceActionLazyList[" + childCount + "].description' />\n"; 9 templateHtml += "<span onClick='jQuery(\"#" + htmlId + "\").remove();'><img src='" + deleteIcon + "' /></span>\n"; 10 templateHtml += "</div>\n"; 11 jQuery("#childList").append(templateHtml); 9 10 function addChild(wrapperId, cloneId, lazyList, fields, focusField){ 11 12 var clone = jQuery("#"+cloneId).clone(); 13 clone.attr('id', lazyList+childCount); 14 var htmlId = lazyList+'['+childCount+'].'; 15 16 var fieldsMap = {}; 17 jQuery.each(fields, function(index, field) { 18 fieldsMap[field] = clone.find('[id$="'+field+'"]'); 19 fieldsMap[field].attr('id',htmlId + field) 20 .attr('name',htmlId + field); 21 if(field == 'isNew') { 22 fieldsMap[field].attr('value', 'true'); 23 } 24 }); 25 26 jQuery("#"+wrapperId).append(clone); 27 clone.show(); 28 fieldsMap[focusField].focus(); 12 29 childCount++; 13 30 } 31 32 // Click event on add button. 33 jQuery('.add-ma').live('click', function() { 34 addChild(ma_wrapperId, ma_cloneId, ma_lazyList, ma_fields, ma_focusField); 35 }); 36 37 // Click event on delete buttons. 38 jQuery('.del-ma').live('click', function() { 39 //find the parent div 40 var prnt = jQuery(this).parents(".ma-div"); 41 //find the deleted hidden input 42 var delInput = prnt.find("input[id$=toBeDeleted]"); 43 //check if this is still not persisted 44 var newValue = prnt.find("input[id$=isNew]").attr('value'); 45 //if it is new then i can safely remove from dom 46 if(newValue == 'true'){ 47 prnt.remove(); 48 }else{ 49 //set the deletedFlag to true 50 delInput.attr('value','true'); 51 //hide the div 52 prnt.hide(); 53 } 54 }); 55 56 jQuery(window).load(function() { 57 if(childCount == 0) { 58 addChild(ma_wrapperId, ma_cloneId, ma_lazyList, ma_fields, ma_focusField); 59 } 60 }); 61 14 62 </script> 15 63 16 <div id="childList"> 17 <g:each var="ma" in="${taskProcedureInstance.maintenanceActions}" status="i"> 18 <div id="maintenanceAction${i}"> 19 <g:hiddenField name='maintenanceActionLazyList[${i}].id' value='${ma.id}'/> 20 <g:textField name='maintenanceActionLazyList[${i}].description' value='${ma.description}'/> 21 <input type="hidden" name='maintenanceActionLazyList[${i}].deleted' id='maintenanceActionLazyList[${i}].deleted' value='false'/> 22 <span onClick="jQuery('#maintenanceActionLazyList\\[${i}\\]\\.deleted').val('true'); jQuery('#maintenanceAction${i}').hide()"> 23 <img src="${resource(dir:'images/skin', file:'database_delete.png')}" /> 24 </span> 25 </div> 26 </g:each> 27 </div> 28 <input type="button" value="Add MaintenanceAction" onclick="addChild();" /> 64 65 66 <div> 67 <table> 68 <thead> 69 <tr> 70 71 <th>Step</th> 72 <th>Sub Item</th> 73 <th>Description</th> 74 <th>Reasoning</th> 75 <th></th> 76 77 </tr> 78 </thead> 79 <tbody id="ma_wrapper"> 80 <g:each var="ma" in="${taskProcedureInstance.maintenanceActions}" status="i"> 81 <g:render template="maintenanceAction" model="['tp':taskProcedureInstance, 'ma': ma, 'i':i]" /> 82 </g:each> 83 </tr> 84 </tbody> 85 </table> 86 </div> 87 88 <br /> 89 90 <div style="text-align:right;"> 91 <span class="buttons add-ma"> 92 <input type="button" class="add" value="Add MaintenanceAction" /> 93 </span> 94 </div> -
branches/features/taskProcedureRework/grails-app/views/taskProcedureDetailed/create.gsp
r762 r770 13 13 </div> 14 14 <div class="body"> 15 <g:if test="${flash.message}"> 16 <div class="message">${flash.message}</div> 17 </g:if> 15 <g:render template="/shared/messages" /> 16 18 17 <g:hasErrors bean="${taskProcedureInstance}"> 19 <div class="errors">20 <g:renderErrors bean="${taskProcedureInstance}" as="list" />21 </div>18 <div class="errors"> 19 <g:renderErrors bean="${taskProcedureInstance}" as="list" /> 20 </div> 22 21 </g:hasErrors> 23 22 24 23 <g:form action="save" method="post" > 25 <input type="hidden" name="linkedTask.id" value="${taskInstance.id}" />24 <input type="hidden" name="linkedTask.id" value="${taskProcedureInstance.linkedTask.id}" /> 26 25 27 <div class="dialog"> 28 <table> 29 <tbody> 26 <g:render template="taskProcedure" model="['taskProcedureInstance': taskProcedureInstance]" /> 30 27 31 <tr class="prop">32 <td valign="top" class="name">33 <label for="taskInstance">Parent Task:</label>34 </td>35 <td valign="top" name="taskInstance" class="value">36 <g:link controller="taskDetailed" action="show" id="${taskInstance.id}">37 ${taskInstance.encodeAsHTML()}38 </g:link>39 </td>40 </tr>41 42 <tr class="prop">43 <td valign="top" class="name">44 <label for="maintenanceActions">Maintenance Actions:</label>45 </td>46 <td valign="top" class="value ${hasErrors(bean:taskProcedureInstance,field:'maintenanceActions','errors')}">47 <g:render template="maintenanceActions" model="['taskProcedureInstance': taskProcedureInstance]" />48 </td>49 </tr>50 51 </tbody>52 </table>53 </div>54 28 <div class="buttons"> 55 29 <span class="button"><input class="save" type="submit" value="Create" /></span> … … 57 31 </g:form> 58 32 </div> 33 <table style="display:none;"> 34 <g:render template="maintenanceAction" model="['tp': null, 'ma': null, 'i': '_clone']" /> 35 </table> 59 36 </body> 60 37 </html> -
branches/features/taskProcedureRework/grails-app/views/taskProcedureDetailed/edit.gsp
r762 r770 13 13 </div> 14 14 <div class="body"> 15 <g:if test="${flash.message}"> 16 <div class="message">${flash.message}</div> 17 </g:if> 15 <g:render template="/shared/messages" /> 16 18 17 <g:hasErrors bean="${taskProcedureInstance}"> 19 <div class="errors">20 <g:renderErrors bean="${taskProcedureInstance}" as="list" />21 </div>18 <div class="errors"> 19 <g:renderErrors bean="${taskProcedureInstance}" as="list" /> 20 </div> 22 21 </g:hasErrors> 22 23 23 <g:form method="post" > 24 24 <input type="hidden" name="id" value="${taskProcedureInstance?.id}" /> 25 25 <input type="hidden" name="version" value="${taskProcedureInstance?.version}" /> 26 <div class="dialog">27 <table>28 <tbody>29 26 30 <tr class="prop"> 31 <td valign="top" class="name">Id:</td> 32 <td valign="top" class="value">${fieldValue(bean:taskProcedureInstance, field:'id')}</td> 33 </tr> 27 <g:render template="taskProcedure" model="['taskProcedureInstance': taskProcedureInstance]" /> 34 28 35 <tr class="prop">36 <td valign="top" class="name">37 <label for="taskInstance">Linked Task:</label>38 </td>39 <td valign="top" name="taskInstance" class="value">40 <g:link controller="taskDetailed" action="show" id="${taskProcedureInstance.linkedTask.id}">41 ${taskProcedureInstance.linkedTask.encodeAsHTML()}42 </g:link>43 </td>44 </tr>45 46 <tr class="prop">47 <td valign="top" class="name">48 <label for="maintenanceActions">Maintenance Actions:</label>49 </td>50 51 <td valign="top" class="value ${hasErrors(bean:taskProcedureInstance,field:'maintenanceActions','errors')}">52 <g:render template="maintenanceActions" model="['taskProcedureInstance': taskProcedureInstance]" />53 </td>54 </tr>55 56 </tbody>57 </table>58 </div>59 29 <div class="buttons"> 60 30 <span class="button"><g:actionSubmit class="save" value="Update" /></span> … … 63 33 </g:form> 64 34 </div> 35 <table style="display:none;"> 36 <g:render template="maintenanceAction" model="['tp': null, 'ma': null, 'i': '_clone']" /> 37 </table> 65 38 </body> 66 39 </html>
Note: See TracChangeset
for help on using the changeset viewer.