1 | <script type="text/javascript"> |
---|
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"; |
---|
8 | |
---|
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(); |
---|
29 | childCount++; |
---|
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 | |
---|
62 | </script> |
---|
63 | |
---|
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> |
---|