source: branches/features/taskProcedureRework/grails-app/views/taskProcedureDetailed/_maintenanceActions.gsp @ 776

Last change on this file since 776 was 776, checked in by gav, 13 years ago

TaskProcedure? improvements, filter assemblies, pre populate a maintenanceAction for each assembly at creation.

File size: 3.3 KB
RevLine 
[760]1<script type="text/javascript">
2    var childCount = ${taskProcedureInstance?.maintenanceActions.size()} + 0;
[770]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";
[760]8
[770]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();
[760]29        childCount++;
30    }
[770]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
[760]62</script>
63
[770]64
65
66    <div>
67        <table>
68            <thead>
69                <tr>
70
71                    <th>Step</th>
[776]72                    <th>Assembly</th>
[770]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">
[776]81                            <g:render template="maintenanceAction" model="['tp':taskProcedureInstance,
82                                                                                                                'ma': ma,
83                                                                                                                'i':i,
84                                                                                                                'assemblies': assemblies]" />
[770]85                    </g:each>
86                    </tr>
87            </tbody>
88        </table>
89    </div>
90
91    <br />
92
93    <div style="text-align:right;">
94        <span class="buttons add-ma">
95            <input type="button" class="add" value="Add MaintenanceAction" />
96        </span>
97    </div>
Note: See TracBrowser for help on using the repository browser.