Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#assign controlId = fieldHtmlId + "-cntrl">
- <#assign colCount = field.columns!1>
- <#assign colNames = field.columnNames!'["Uživatel"]' >
- <#assign colNamesNoDia = field.columnNamesNoDia!'["cislo_objektu", "Sadzba DPH", "mj", "mnozstvo" , "jednotkova_cena"]' >
- <#assign colTypes = field.colTypes!'["text"]' >
- <#assign delimiter = field.delim!', '>
- <script type="text/javascript">//<![CDATA[
- var summaryParser_rowCount = 0;
- var summaryParser_colNames = ${colNames};
- var summaryParser_colNamesNoDia = ${colNamesNoDia};
- var summaryParser_colTypes = ${colTypes};
- var summaryParser_rowArray = [];
- var summaryParser_MJOptions = "";
- var summaryParser_getTableId = function(rowId, num){
- return '${fieldHtmlId}-table-' + rowId + '-' + num;
- }
- var summaryParser_addRow = function(rowId, values){
- for(var i = 0; i < values.length; i++) {
- if(typeof values[i] === 'undefined') {
- return "";
- }
- }
- summaryParser_rowArray.push(rowId);
- summaryParser_rowCount++;
- var table = '<tr id="${fieldHtmlId}-th'+rowId+'" class="yui-dt-rec yui-dt-first yui-dt-even" style="">';
- for(var i = 0; i < values.length; i++){
- <#if form.mode != "view" && form.mode !="edit">
- table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id" >';
- if(${colTypes}[i] === "number")
- {
- 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>';
- }
- else if(${colTypes}[i] === "customNumber")
- {
- table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><input style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '" value="' + values[i] + '"></div>';
- }
- else if(${colTypes}[i] === "text")
- {
- table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><input style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '" type="text"></div>';
- }
- else if (${colTypes}[i] === "selectDPH")
- {
- 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>';
- }
- else if (${colTypes}[i] === "selectMJ")
- {
- 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>';
- }
- table += '</td>'
- <#else>
- table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id" >';
- if(${colTypes}[i] === "customNumber"){
- table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '">' + numberWithCommas(values[i]) + '</div>';
- } else {
- table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '">' + values[i] + '</div>';
- }
- table += '</td>'
- </#if>
- }
- <#if form.mode != "view">
- <#if form.mode == "edit">
- table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id">'
- +'<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>';
- <#else>
- table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id">'
- +'<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>';
- </#if>
- </#if>
- return table;
- };
- var summaryParser_addRow_editMode = function(rowId, values){
- for(var i = 0; i < values.length; i++) {
- if(typeof values[i] === 'undefined') {
- return "";
- }
- }
- summaryParser_rowArray.push(rowId);
- summaryParser_rowCount++;
- var table = '<tr id="${fieldHtmlId}-th'+rowId+'" class="yui-dt-rec yui-dt-first yui-dt-even" style="">';
- for(var i = 0; i < values.length; i++){
- table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id" >';
- if(${colTypes}[i] === "number")
- {
- 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>';
- }
- else if(${colTypes}[i] === "customNumber")
- {
- table += '<div class="yui-dt-liner" id="' + summaryParser_getTableId(rowId, i) + '"><input style="width:95%;" id="${fieldHtmlId}-input-'+ (i + 1) + '" value="' + values[i] + '"></div>';
- }
- else if(${colTypes}[i] === "text")
- {
- 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>';
- }
- else if (${colTypes}[i] === "selectDPH")
- {
- 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>';
- }
- else if (${colTypes}[i] === "selectMJ")
- {
- 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>';
- }
- table += '</td>'
- }
- table += '<td headers="yui-dt9-th-name" class="row yui-dt9-col-id yui-dt-col-id">'
- +'<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
- return table;
- };
- (function()
- {
- var delim = "${delimiter}";
- // After html input element is generated
- YAHOO.util.Event.onAvailable("${fieldHtmlId}-table", function() {
- <#compress>
- var deductions = "${field.value}";
- </#compress>
- if(deductions !== ""){
- deductions = deductions.split(delim)
- } else {
- deductions = [];
- }
- 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>'+
- '<thead><tr class="yui-dt-first yui-dt-last">';
- for (var i = 0; i < ${colCount}; i++){
- var last = "";
- if (i + 1 === ${colCount}){
- last = "yui-dt-last";
- }
- table += '<th rowspan="1" colspan="1" class="row yui-dt9-col-id yui-dt-col-id ' + last + '">'+
- '<div class="yui-dt-liner"> <span class="yui-dt-label">' + summaryParser_colNames[i] + '</span></div></th>';
- }
- <#if form.mode != "view">
- table += '<th rowspan="1" colspan="1" class="yui-dt-last"><div class="yui-dt-liner"> <span class="yui-dt-label">Operace</span></div></th>';
- </#if>
- table += '</tr></thead><tbody tabindex="0" class="yui-dt-data" style="">';
- for (var i = 0; i < deductions.length; i+=${colCount}) {
- var addArr = [];
- for(var j = 0; j < ${colCount}; j++){
- addArr.push(deductions[i + j]);
- }
- table += summaryParser_addRow(i/${colCount}, addArr);
- }
- var addArr = [];
- for(var j = 0; j < ${colCount}; j++){
- addArr.push("");
- }
- <#if form.mode != "view" && form.mode != "edit">table += summaryParser_addRow(summaryParser_rowCount, addArr);</#if>
- <#if form.mode == "edit"> table += summaryParser_addRow_editMode(summaryParser_rowCount, addArr);</#if>
- table += '</tbody></table></div></div>';
- document.getElementById("${fieldHtmlId}-table").innerHTML = table;
- });
- })();
- var summaryParser_updateTableValue = function(id, value){
- Dom.get(id).innerHTML = value;
- };
- var summaryParser_addLastRow = function(){
- var addArr = [];
- for(var j = 0; j < ${colCount}; j++){
- addArr.push("");
- }
- var addTable
- <#if form.mode == "edit">
- addTable = summaryParser_addRow_editMode(summaryParser_rowCount, addArr);
- <#else>
- addTable = summaryParser_addRow(summaryParser_rowCount, addArr);
- </#if>
- addTable += '</tbody></table></div></div>';
- var newTable = document.getElementById("${fieldHtmlId}-table").innerHTML.replace('</tbody></table></div></div>','');
- document.getElementById("${fieldHtmlId}-table").innerHTML = newTable + addTable;
- };
- var summaryParser_myDeleteRow = function (rowId){
- var deductionsArray = Dom.get("${controlId}").value.replace(/["']/g, "");
- var delim = "${delimiter}";
- if(deductionsArray !== ""){
- deductionsArray = deductionsArray.split(delim)
- } else {
- deductionsArray = [];
- }
- var index;
- var row;
- for(var i = 0; i<summaryParser_rowArray.length; i++){
- if(summaryParser_rowArray[i] === rowId)
- {
- index = i;
- row = document.getElementById("${fieldHtmlId}-th"+rowId);
- summaryParser_rowArray.splice(i,1);
- }
- }
- for(var i = index*5; i < deductionsArray.length-5; i++){
- if(typeof deductionsArray[ i] === 'undefined'){
- deductionsArray[i] = "";
- } else {
- deductionsArray[i] = deductionsArray[i+5];
- }
- }
- for(i=0; i<${colCount}; i++){
- deductionsArray.pop();
- }
- Dom.get("${controlId}").value = deductionsArray.join(delim).replace(/["']/g, "");
- row.innerHTML="";
- };
- var summaryParser_showDialog = function (rowId){
- var delim = "${delimiter}";
- var deductionsArray = Dom.get("${controlId}").value.replace(/["']/g, "");
- if(deductionsArray !== ""){
- deductionsArray = deductionsArray.split(delim)
- } else {
- deductionsArray = [];
- }
- if((document.getElementById("${fieldHtmlId}-buton-"+rowId).value === 'ulozNovy') || (document.getElementById("${fieldHtmlId}-buton-"+rowId).value === 'ulozStary'))
- {
- if(document.getElementById("${fieldHtmlId}-buton-"+rowId).value === 'ulozNovy')
- {
- indexInputu = "'${fieldHtmlId}-input-'+ (i + 1)";
- }
- else indexInputu = "${fieldHtmlId}-input-"+rowId+"-"+ (i + 1);
- var valueArray = [];
- for(var i = 0; i < ${colCount}; i++){
- if(typeof deductionsArray[rowId*${colCount} + i] === 'undefined'){
- valueArray.push("");
- } else {
- valueArray.push(deductionsArray[rowId*${colCount} + i]);
- }
- }
- for(var i = 0; i < ${colCount}; i++)
- {
- if(document.getElementById("${fieldHtmlId}-buton-"+rowId).value === 'ulozNovy')
- {
- valueArray[i] = document.getElementById("${fieldHtmlId}-input-"+ (i + 1)).value;
- }
- else valueArray[i] = document.getElementById("${fieldHtmlId}-input-"+rowId+"-"+ (i + 1)).value;
- if(${colTypes}[i] === "customNumber"){
- summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), numberWithCommas(valueArray[i]));
- } else {
- summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), valueArray[i]);
- }
- }
- if(rowId == (summaryParser_rowCount - 1))
- {
- for(var i = 0; i < ${colCount}; i++)
- {
- deductionsArray.push(valueArray[i]);
- }
- summaryParser_addLastRow();
- }
- else
- {
- for(var i = 0; i < ${colCount}; i++)
- {
- deductionsArray[rowId*${colCount} + i] = valueArray[i];
- }
- }
- Dom.get("${controlId}").value = deductionsArray.join(delim).replace(/["']/g, "");
- document.getElementById("${fieldHtmlId}-buton-"+rowId).innerHTML = "Upravit";
- document.getElementById("${fieldHtmlId}-buton-"+rowId).setAttribute( "value", "uprav" );
- document.getElementById("${fieldHtmlId}-buton2-"+rowId).classList.remove("hideButton");
- }
- else if (document.getElementById("${fieldHtmlId}-buton-"+rowId).value === 'uprav')
- {
- for(var i = 0; i < ${colCount}; i++)
- {
- if(${colTypes}[i] === "number")
- {
- 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>');
- }
- else if(${colTypes}[i] === "customNumber")
- {
- summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), '<input style="width:95%;" id="${fieldHtmlId}-input-'+rowId+'-'+ (i + 1) + '" value="' + deductionsArray[i+( ${colCount}*rowId)] + '"></input>');
- }
- else if(${colTypes}[i] === "text")
- {
- summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), '<input style="width:95%;" id="${fieldHtmlId}-input-'+rowId+'-'+ (i + 1) + '" type="text" " value="' + deductionsArray[i+( ${colCount}*rowId)] + '"></input>');
- }
- else if (${colTypes}[i] === "selectDPH")
- {
- var index;
- if (deductionsArray[i+( ${colCount}*rowId)] === " ") index = 0;
- else if (deductionsArray[i+( ${colCount}*rowId)] === "0") index = 1;
- else if (deductionsArray[i+( ${colCount}*rowId)] === "10") index = 2;
- else if (deductionsArray[i+( ${colCount}*rowId)] === "20") index = 3;
- 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>');
- document.getElementById("${fieldHtmlId}-input-"+rowId+'-'+ (i + 1)).selectedIndex = index;
- }
- else if (${colTypes}[i] === "selectMJ")
- {
- var index;
- if (deductionsArray[i+( ${colCount}*rowId)] === "ks") index = 0;
- else if (deductionsArray[i+( ${colCount}*rowId)] === "kg") index = 1;
- else if (deductionsArray[i+( ${colCount}*rowId)] === "balenie") index = 2;
- summaryParser_updateTableValue(summaryParser_getTableId(rowId, i), '<select style="width:95%;" id="${fieldHtmlId}-input-'+rowId+'-'+ (i + 1)+'" value="' + deductionsArray[i+( ${colCount}*rowId)] + '">' + summaryParser_MJOptions + '</select>');
- document.getElementById("${fieldHtmlId}-input-"+rowId+'-'+ (i + 1)).selectedIndex = index;
- }
- }
- document.getElementById("${fieldHtmlId}-buton-"+rowId).innerHTML = "Uložit";
- document.getElementById("${fieldHtmlId}-buton-"+rowId).setAttribute( "value", "ulozStary" );
- }
- };
- //]]></script>
- <style type="text/css">
- .preconfValue {
- width: 12%;
- }
- .dynamicTable {
- width: 100%;
- table-layout: flex;
- }
- td {
- `width:25%;
- }
- .bd {
- margin-left: 8px;
- }
- .comment {
- width: 37%;
- }
- .row {
- width: 24%;
- }
- .centered {
- margin-left: 49px;
- }
- button
- {
- width:100%; /* toto sa mi nep84i*/
- margin-top:2px !important;
- margin-bottom:2px !important;
- margin-right: 2px !important;
- margin-left:2px !important;
- }
- .hideButton {display:none !important;}
- </style>
- <div class="form-field">
- <#if form.mode == "view">
- <div class="viewmode-field">
- <div id="${fieldHtmlId}">
- <div id="${fieldHtmlId}-table"></div>
- </div>
- </div>
- </div>
- <#else>
- <div id="${fieldHtmlId}">
- <div id="${fieldHtmlId}-table"></div>
- <input type="hidden" id="${controlId}" name="${field.name}" value="${field.value?html}" />
- <div id="${fieldHtmlId}-dialog">
- </div>
- </div>
- </#if>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement