Ignore:
Timestamp:
Feb 2, 2011, 8:38:20 PM (13 years ago)
Author:
gav
Message:

Domain change, improved draft of creating taskProcedure dynamic form.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/features/taskProcedureRework/grails-app/views/taskProcedureDetailed/_maintenanceActions.gsp

    r762 r770  
    11<script type="text/javascript">
    22    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";
    38
    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();
    1229        childCount++;
    1330    }
     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
    1462</script>
    1563
    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>
Note: See TracChangeset for help on using the changeset viewer.