1 | <script type="text/javascript"> |
---|
2 | var ma_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, childCount){ |
---|
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 | }); |
---|
22 | |
---|
23 | jQuery("#"+wrapperId).append(clone); |
---|
24 | clone.show(); |
---|
25 | fieldsMap[focusField].focus(); |
---|
26 | } |
---|
27 | |
---|
28 | // Click event on add button. |
---|
29 | jQuery('.add-ma').live('click', function() { |
---|
30 | addChild(ma_wrapperId, ma_cloneId, ma_lazyList, ma_fields, ma_focusField, ma_childCount); |
---|
31 | ma_childCount++; |
---|
32 | }); |
---|
33 | |
---|
34 | // Click event on delete buttons. |
---|
35 | jQuery('.del-ma').live('click', function() { |
---|
36 | //find the parent div |
---|
37 | var prnt = jQuery(this).parents(".ma-div"); |
---|
38 | //find the deleted hidden input |
---|
39 | var delInput = prnt.find("input[id$=toBeDeleted]"); |
---|
40 | //check if this is still not persisted |
---|
41 | var newValue = prnt.find("input[id$=isNew]").attr('value'); |
---|
42 | //if it is new then i can safely remove from dom |
---|
43 | if(newValue == 'true'){ |
---|
44 | prnt.remove(); |
---|
45 | }else{ |
---|
46 | //set the deletedFlag to true |
---|
47 | delInput.attr('value','true'); |
---|
48 | //hide the div |
---|
49 | prnt.hide(); |
---|
50 | } |
---|
51 | }); |
---|
52 | |
---|
53 | jQuery(window).load(function() { |
---|
54 | if(ma_childCount == 0) { |
---|
55 | addChild(ma_wrapperId, ma_cloneId, ma_lazyList, ma_fields, ma_focusField, ma_childCount); |
---|
56 | ma_childCount++; |
---|
57 | } |
---|
58 | }); |
---|
59 | |
---|
60 | </script> |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | <div> |
---|
65 | <table> |
---|
66 | <thead> |
---|
67 | <tr> |
---|
68 | |
---|
69 | <th>Step</th> |
---|
70 | <th>Assembly</th> |
---|
71 | <th>Description</th> |
---|
72 | <th>Reasoning</th> |
---|
73 | <th></th> |
---|
74 | |
---|
75 | </tr> |
---|
76 | </thead> |
---|
77 | <tbody id="ma_wrapper"> |
---|
78 | <g:each var="ma" in="${taskProcedureInstance.maintenanceActions}" status="i"> |
---|
79 | <g:render template="maintenanceAction" model="['tp':taskProcedureInstance, |
---|
80 | 'ma': ma, |
---|
81 | 'i':i, |
---|
82 | 'assemblies': assemblies]" /> |
---|
83 | </g:each> |
---|
84 | </tr> |
---|
85 | </tbody> |
---|
86 | </table> |
---|
87 | </div> |
---|
88 | |
---|
89 | <br /> |
---|
90 | |
---|
91 | <div style="text-align:right;"> |
---|
92 | <span class="buttons add-ma"> |
---|
93 | <input type="button" class="add" value="Add MaintenanceAction" /> |
---|
94 | </span> |
---|
95 | </div> |
---|