Advertisement
Guest User

Table.ftl

a guest
Dec 15th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 17.39 KB | None | 0 0
  1. <#assign controlId = fieldHtmlId + "-cntrl">
  2. <#assign colCount = field.columns!1>
  3. <#assign colNames = field.columnNames!'["Uživatel"]' >
  4. <#assign colNamesNoDia = field.columnNamesNoDia!'["cislo_objektu", "Sadzba DPH", "mj", "mnozstvo" , "jednotkova_cena"]' >
  5. <#assign colTypes = field.colTypes!'["text"]' >
  6. <#assign delimiter = field.delim!', '>
  7.  
  8.  
  9. <script type="text/javascript">//<![CDATA[
  10.     var summaryParser_rowCount = 0;
  11.     var summaryParser_colNames = ${colNames};
  12.     var summaryParser_colNamesNoDia = ${colNamesNoDia};
  13.     var summaryParser_colTypes = ${colTypes};
  14.     var summaryParser_rowArray = [];
  15.     var summaryParser_MJOptions = "";
  16.    
  17.     var summaryParser_getTableId = function(rowId, num){
  18.         return '${fieldHtmlId}-table-' + rowId + '-' + num;
  19.     }
  20.     var summaryParser_addRow = function(rowId, values){
  21.        for(var i = 0; i < values.length; i++) {
  22.             if(typeof values[i] === 'undefined') {
  23.                 return "";
  24.             }
  25.         }
  26.        summaryParser_rowArray.push(rowId);
  27.         summaryParser_rowCount++;
  28.         var table = '<tr id="${fieldHtmlId}-th'+rowId+'" class="yui-dt-rec yui-dt-first yui-dt-even" style="">';
  29.         for(var i = 0; i < values.length; i++){
  30.            
  31.             <#if form.mode != "view" && form.mode !="edit">
  32.                
  33.                
  34.                 table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id" >';
  35.                 if(${colTypes}[i] === "number")
  36.                 {
  37.                     table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><input style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '" type="number" min="0" value="' + numberWithCommas(values[i]) + '"></div>';
  38.                 }
  39.                else if(${colTypes}[i] === "customNumber")
  40.                {
  41.                    table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><input style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '" value="' + values[i] + '"></div>';
  42.                }
  43.                 else if(${colTypes}[i] === "text")
  44.                 {
  45.                     table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><input style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '" type="text"></div>';
  46.                 }
  47.                
  48.                 else if (${colTypes}[i] === "selectDPH")
  49.                 {
  50.                     table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><select style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '"  value="' + values[i] + '"><option value=" " > </option><option value="0" >0</option><option value="10">10</option><option value="20">20</option></select></div>';
  51.                 }
  52.                 else if (${colTypes}[i] === "selectMJ")
  53.                 {
  54.                     table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><select style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '"  value="' + values[i] + '">' +  summaryParser_MJOptions + '</select></div>';
  55.                 }
  56.                 table += '</td>'
  57.  
  58.             <#else>
  59.                 table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id" >';
  60.                if(${colTypes}[i] === "customNumber"){
  61.                  table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '">' + numberWithCommas(values[i]) + '</div>';
  62.                  } else {
  63.                  table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '">' + values[i] + '</div>';
  64.                 }
  65.                
  66.                 table += '</td>'
  67.             </#if>
  68.         }
  69.        
  70.         <#if form.mode != "view">
  71.             <#if form.mode == "edit">
  72.                 table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id">'
  73.                 +'<div class="yui-button yui-submit-button alf-primary-button yui-button-hover yui-submit-button-hover" style="display:inline-flex;"><button  id="${fieldHtmlId}-buton-'+rowId+'" type="button" value="uprav" onClick="summaryParser_showDialog('+rowId+')" >Upraviť</button><button  id="${fieldHtmlId}-buton2-'+rowId+'" type="button" value="zmaz" onClick="summaryParser_myDeleteRow('+rowId+')" >Smazat</button></div></td></tr>';
  74.                
  75.             <#else>
  76.                 table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id">'
  77.                 +'<div class="yui-button yui-submit-button alf-primary-button yui-button-hover yui-submit-button-hover" style="display:flex; justify-content:center;"><button  id="${fieldHtmlId}-buton-'+rowId+'" type="button" value="ulozNovy" onClick="summaryParser_showDialog('+rowId+')" >Uložit</button><button  class="hideButton" id="${fieldHtmlId}-buton2-'+rowId+'" type="button" value="zmaz" onClick="summaryParser_myDeleteRow('+rowId+')" >Smazat</button></div></td></tr>';
  78.            </#if>
  79.        </#if>
  80.        return table;
  81.     };
  82.    
  83.     var summaryParser_addRow_editMode = function(rowId, values){
  84.        for(var i = 0; i < values.length; i++) {
  85.             if(typeof values[i] === 'undefined') {
  86.                 return "";
  87.             }
  88.         }
  89.  
  90.        summaryParser_rowArray.push(rowId);
  91.         summaryParser_rowCount++;
  92.        
  93.         var table = '<tr id="${fieldHtmlId}-th'+rowId+'" class="yui-dt-rec yui-dt-first yui-dt-even" style="">';
  94.        
  95.         for(var i = 0; i < values.length; i++){
  96.            
  97.             table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id" >';
  98.             if(${colTypes}[i] === "number")
  99.             {
  100.                 table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><input style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '" type="number" min="0" value="' + numberWithCommas(values[i]) + '"></div>';
  101.             }
  102.            else if(${colTypes}[i] === "customNumber")
  103.            {
  104.                table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><input style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '" value="' + values[i] + '"></div>';
  105.            }
  106.             else if(${colTypes}[i] === "text")
  107.             {
  108.                 table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><input style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '" type="text" value="' + values[i] + '"></div>';
  109.             }
  110.             else if (${colTypes}[i] === "selectDPH")
  111.             {
  112.                 table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><select style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '"  value="' + values[i] + '"><option value=" " > </option><option value="0" >0</option><option value="10">10</option><option value="20">20</option></select></div>';
  113.             }
  114.             else if (${colTypes}[i] === "selectMJ")
  115.             {
  116.                 table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><select  style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '"  value="' + values[i] + '">' +  summaryParser_MJOptions + '</select></div>';
  117.             }
  118.             table += '</td>'
  119.         }
  120.             table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id">'
  121.              +'<div class="yui-button yui-submit-button alf-primary-button yui-button-hover yui-submit-button-hover" style="display:flex; justify-content:center;"><button  id="${fieldHtmlId}-buton-'+rowId+'" type="button" value="ulozNovy" onClick="summaryParser_showDialog('+rowId+')" >Uložit</button><button  class="hideButton" id="${fieldHtmlId}-buton2-'+rowId+'" type="button" value="zmaz" onClick="summaryParser_myDeleteRow('+rowId+')" >Smazat</button></div></td></tr>'; //AK upravujeme fakturu
  122.  
  123.        return table;
  124.     };
  125.    
  126.     (function()
  127.     {    
  128.         var delim = "${delimiter}";
  129.        
  130.         // After html input element is generated
  131.         YAHOO.util.Event.onAvailable("${fieldHtmlId}-table", function() {
  132.             <#compress>
  133.             var deductions = "${field.value}";
  134.             </#compress>
  135.             if(deductions !== ""){
  136.                 deductions = deductions.split(delim)
  137.             } else {
  138.                 deductions = [];
  139.             }
  140.            
  141.             var table = '<div id="${fieldHtmlId}-table-div" class="deductions"><div style="overflow-x:auto;" class="form-element-background-color yui-dt"><div class="yui-dt-mask" style="display: none;"></div><table summary="" class="dynamicTable"><colgroup><col><col><col><col><col></colgroup>'+
  142.             '<thead><tr class="yui-dt-first yui-dt-last">';
  143.             for (var i = 0; i < ${colCount}; i++){
  144.                 var last = "";
  145.                 if (i + 1 === ${colCount}){
  146.                     last = "yui-dt-last";
  147.                 }
  148.                 table += '<th rowspan="1" colspan="1" class="row yui-dt9-col-id yui-dt-col-id ' + last + '">'+
  149.                 '<div class="yui-dt-liner"> <span class="yui-dt-label">' + summaryParser_colNames[i] + '</span></div></th>';
  150.             }
  151.             <#if form.mode != "view">
  152.                 table += '<th rowspan="1" colspan="1" class="yui-dt-last"><div class="yui-dt-liner"> <span class="yui-dt-label">Operace</span></div></th>';
  153.             </#if>
  154.             table += '</tr></thead><tbody tabindex="0" class="yui-dt-data" style="">';
  155.        
  156.             for (var i = 0; i < deductions.length; i+=${colCount}) {
  157.                 var addArr = [];
  158.                 for(var j = 0; j < ${colCount}; j++){
  159.                     addArr.push(deductions[i + j]);
  160.                 }
  161.                 table += summaryParser_addRow(i/${colCount}, addArr);
  162.             }
  163.             var addArr = [];
  164.            for(var j = 0; j < ${colCount}; j++){
  165.                addArr.push("");
  166.            }
  167.            <#if form.mode != "view" && form.mode != "edit">table += summaryParser_addRow(summaryParser_rowCount, addArr);</#if>
  168.             <#if form.mode == "edit"> table += summaryParser_addRow_editMode(summaryParser_rowCount, addArr);</#if>
  169.  
  170.             table += '</tbody></table></div></div>';
  171.            
  172.             document.getElementById("${fieldHtmlId}-table").innerHTML = table;  
  173.            
  174.         });  
  175.        
  176.     })();
  177.    
  178.     var summaryParser_updateTableValue = function(id, value){
  179.         Dom.get(id).innerHTML = value;
  180.     };
  181.    
  182.     var summaryParser_addLastRow = function(){
  183.         var addArr = [];
  184.        for(var j = 0; j < ${colCount}; j++){
  185.            addArr.push("");
  186.        }
  187.         var addTable
  188.         <#if form.mode == "edit">
  189.             addTable = summaryParser_addRow_editMode(summaryParser_rowCount, addArr);
  190.         <#else>
  191.             addTable = summaryParser_addRow(summaryParser_rowCount, addArr);
  192.         </#if>
  193.         addTable += '</tbody></table></div></div>';
  194.        
  195.         var newTable = document.getElementById("${fieldHtmlId}-table").innerHTML.replace('</tbody></table></div></div>','');   
  196.         document.getElementById("${fieldHtmlId}-table").innerHTML = newTable + addTable;  
  197.     };
  198.    
  199.  
  200.     var summaryParser_myDeleteRow = function (rowId){
  201.         var deductionsArray = Dom.get("${controlId}").value.replace(/["']/g, "");
  202.         var delim = "${delimiter}";
  203.  
  204.         if(deductionsArray !== ""){
  205.             deductionsArray = deductionsArray.split(delim)
  206.        } else {
  207.             deductionsArray = [];
  208.        }
  209.  
  210.         var index;
  211.         var row;
  212.        
  213.         for(var i = 0; i<summaryParser_rowArray.length; i++){
  214.             if(summaryParser_rowArray[i] === rowId)
  215.             {
  216.                 index = i;
  217.                 row = document.getElementById("${fieldHtmlId}-th"+rowId);
  218.                 summaryParser_rowArray.splice(i,1);
  219.             }  
  220.         }
  221.        
  222.         for(var i = index*5; i < deductionsArray.length-5; i++){
  223.             if(typeof deductionsArray[ i] === 'undefined'){
  224.                 deductionsArray[i] = "";
  225.             } else {
  226.                 deductionsArray[i] = deductionsArray[i+5];
  227.             }
  228.         }
  229.  
  230.         for(i=0; i<${colCount}; i++){
  231.             deductionsArray.pop();
  232.         }
  233.        
  234.         Dom.get("${controlId}").value = deductionsArray.join(delim).replace(/["']/g, "");
  235.         row.innerHTML="";
  236.     };
  237.    
  238.     var summaryParser_showDialog = function (rowId){
  239.  
  240.         var delim = "${delimiter}";
  241.         var deductionsArray = Dom.get("${controlId}").value.replace(/["']/g, "");
  242.  
  243.         if(deductionsArray !== ""){
  244.             deductionsArray = deductionsArray.split(delim)
  245.        } else {
  246.             deductionsArray = [];
  247.        }
  248.  
  249.        
  250.         if((document.getElementById("${fieldHtmlId}-buton-"+rowId).value === 'ulozNovy') || (document.getElementById("${fieldHtmlId}-buton-"+rowId).value === 'ulozStary'))    
  251.         {
  252.            
  253.             if(document.getElementById("${fieldHtmlId}-buton-"+rowId).value === 'ulozNovy')
  254.             {
  255.                 indexInputu = "'${fieldHtmlId}-input-'+ (i + 1)";
  256.             }
  257.             else indexInputu = "${fieldHtmlId}-input-"+rowId+"-"+ (i + 1);
  258.            
  259.             var valueArray = [];
  260.             for(var i = 0; i < ${colCount}; i++){
  261.                 if(typeof deductionsArray[rowId*${colCount} + i] === 'undefined'){
  262.                     valueArray.push("");
  263.                 } else {
  264.                     valueArray.push(deductionsArray[rowId*${colCount} + i]);
  265.                 }
  266.             }
  267.            
  268.             for(var i = 0; i < ${colCount}; i++)
  269.             {
  270.                 if(document.getElementById("${fieldHtmlId}-buton-"+rowId).value === 'ulozNovy')
  271.                 {
  272.                     valueArray[i] = document.getElementById("${fieldHtmlId}-input-"+ (i + 1)).value;   
  273.                 }
  274.                 else valueArray[i] = document.getElementById("${fieldHtmlId}-input-"+rowId+"-"+ (i + 1)).value;
  275.                 if(${colTypes}[i] === "customNumber"){
  276.                     summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), numberWithCommas(valueArray[i]));
  277.                 } else {
  278.                        summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), valueArray[i]);
  279.                 }
  280.                
  281.                
  282.             }
  283.                
  284.             if(rowId == (summaryParser_rowCount - 1))
  285.             {
  286.                 for(var i = 0; i < ${colCount}; i++)
  287.                 {
  288.                     deductionsArray.push(valueArray[i]);
  289.                 }
  290.                 summaryParser_addLastRow();
  291.             }
  292.             else
  293.             {
  294.                 for(var i = 0; i < ${colCount}; i++)
  295.                 {
  296.                     deductionsArray[rowId*${colCount} + i] = valueArray[i];
  297.                 }
  298.             }
  299.             Dom.get("${controlId}").value = deductionsArray.join(delim).replace(/["']/g, "");
  300.                
  301.             document.getElementById("${fieldHtmlId}-buton-"+rowId).innerHTML = "Upravit";
  302.             document.getElementById("${fieldHtmlId}-buton-"+rowId).setAttribute( "value", "uprav" );
  303.             document.getElementById("${fieldHtmlId}-buton2-"+rowId).classList.remove("hideButton");
  304.         }
  305.         else if (document.getElementById("${fieldHtmlId}-buton-"+rowId).value === 'uprav')
  306.         {
  307.            
  308.             for(var i = 0; i < ${colCount}; i++)
  309.             {
  310.                 if(${colTypes}[i] === "number")
  311.                 {
  312.                     summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), '<input style="width:95%;" id="${fieldHtmlId}-input-'+rowId+'-'+ (i + 1) + '" type="number" min="0" value="' + deductionsArray[i+( ${colCount}*rowId)] + '"></input>');
  313.                 }
  314.                else if(${colTypes}[i] === "customNumber")
  315.                {
  316.                    summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), '<input style="width:95%;" id="${fieldHtmlId}-input-'+rowId+'-'+ (i + 1) + '"  value="' + deductionsArray[i+( ${colCount}*rowId)] + '"></input>');
  317.                }
  318.                 else if(${colTypes}[i] === "text")
  319.                 {
  320.                     summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), '<input style="width:95%;" id="${fieldHtmlId}-input-'+rowId+'-'+ (i + 1) + '" type="text" " value="' + deductionsArray[i+( ${colCount}*rowId)] + '"></input>');
  321.                 }
  322.                 else if (${colTypes}[i] === "selectDPH")
  323.                 {
  324.                     var index;
  325.                        
  326.                     if (deductionsArray[i+( ${colCount}*rowId)] === " ") index = 0;
  327.                     else if (deductionsArray[i+( ${colCount}*rowId)] === "0") index = 1;
  328.                     else if (deductionsArray[i+( ${colCount}*rowId)] === "10") index = 2;
  329.                     else if (deductionsArray[i+( ${colCount}*rowId)] === "20") index = 3;
  330.                    
  331.                     summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), '<select style="width:95%;" id="${fieldHtmlId}-input-'+rowId+'-'+ (i + 1)+ '"  value="' + deductionsArray[i+( ${colCount}*rowId)] + '"><option value=" "> </option><option value="0">0</option><option value="10">10</option><option value="20">20</option></select>');
  332.                        
  333.                     document.getElementById("${fieldHtmlId}-input-"+rowId+'-'+ (i + 1)).selectedIndex = index;
  334.                        
  335.                 }
  336.                 else if (${colTypes}[i] === "selectMJ")
  337.                 {
  338.                     var index;
  339.                        
  340.                     if (deductionsArray[i+( ${colCount}*rowId)] === "ks") index = 0;
  341.                     else if (deductionsArray[i+( ${colCount}*rowId)] === "kg") index = 1;
  342.                     else if (deductionsArray[i+( ${colCount}*rowId)] === "balenie") index = 2;
  343.                        
  344.                     summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), '<select style="width:95%;" id="${fieldHtmlId}-input-'+rowId+'-'+ (i + 1)+'"  value="' + deductionsArray[i+( ${colCount}*rowId)] + '">' +  summaryParser_MJOptions + '</select>');
  345.                        
  346.                     document.getElementById("${fieldHtmlId}-input-"+rowId+'-'+ (i + 1)).selectedIndex = index;
  347.                        
  348.                 }
  349.             }
  350.  
  351.                 document.getElementById("${fieldHtmlId}-buton-"+rowId).innerHTML = "Uložit";
  352.                 document.getElementById("${fieldHtmlId}-buton-"+rowId).setAttribute( "value", "ulozStary" );
  353.         }
  354.        
  355.        
  356.  
  357.     };
  358. //]]></script>
  359.  
  360. <style type="text/css">
  361.    
  362.     .preconfValue {
  363.         width: 12%;
  364.     }
  365.    
  366.     .dynamicTable {
  367.         width: 100%;
  368.         table-layout: flex;
  369.     }
  370.  
  371.     td {
  372.         `width:25%;
  373.     }
  374.    
  375.  
  376.     .bd {
  377.         margin-left: 8px;
  378.     }
  379.    
  380.     .comment {
  381.         width: 37%;
  382.     }
  383.    
  384.     .row {
  385.         width: 24%;
  386.     }
  387.    
  388.     .centered {
  389.         margin-left: 49px;
  390.     }
  391.  
  392.     button
  393.     {
  394.         width:100%; /* toto sa mi nep84i*/
  395.         margin-top:2px !important;
  396.         margin-bottom:2px !important;
  397.         margin-right: 2px !important;
  398.         margin-left:2px !important;
  399.  
  400.     }
  401.    
  402.     .hideButton {display:none !important;}
  403. </style>
  404.  
  405. <div class="form-field">
  406.    <#if form.mode == "view">
  407.       <div class="viewmode-field">
  408.          <div id="${fieldHtmlId}">
  409.             <div id="${fieldHtmlId}-table"></div>
  410.            
  411.           </div>
  412.       </div>
  413.       </div>
  414.    <#else>
  415.      <div id="${fieldHtmlId}">
  416.         <div id="${fieldHtmlId}-table"></div>
  417.         <input type="hidden" id="${controlId}" name="${field.name}" value="${field.value?html}" />
  418.         <div id="${fieldHtmlId}-dialog">
  419.         </div>
  420.        
  421.       </div>
  422.    </#if>
  423. </div>
  424.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement