#workReportEditAddModal.modal(tabindex='-1', role='dialog', aria-labelledby='workReportEditAddModalLabel') //-form(method='GET',id='holidayForm' action='/employee/holidays_byperson/') style(type="text/css"). .aaa:active, .aaa.active { background: red !important; box-shadow: none !important; } .modal-dialog(role='document', style='width:1000px;') .modal-content .modal-header#workReportEditAddHeader.bg-primary(style="background: Primary") h4 #{workTitle} .modal-body(style='background-color:#5f6b79') form#kabelform3 #form-group input#wn1(name='wn1',style='display:none') input#userid(name='userid',style='display:none', value=user._id) input#id(name='id',style='display:none') input#modify(name='modify',style='display:none') .row .col-sm-12 label(for="workFlow1",style='color: white') Munka leírása: input.form-control(id='workFlow1', name='workFlow1', required, minlength="6",type=text, autofocus, readonly=false,style='') br .row .col-sm-12 #buttons3(style="margin: 10px;") h4#arc br //button#submit.btn.btn-primary(type='submit' ) Rendben .modal-footer(style="background-color: #2C3446") button#sendData1.btn.btn-primary(type='button',data-dismiss='modal') Mentés button#fmodalClose.btn.btn-primary(type='button', data-dismiss='modal') Mégsem script(src='/bower_components/jquery/dist/jquery.min.js') //-script(src='/bower_components/bootstrap-validator/dist/validator.min.js') script. var cid=0; var workers=[] var usedWorkers=[] const form1 = document.getElementById('kabelform3'); function handleClick(identifier) { const state=$(identifier).hasClass('active'); //const d=JSON.parse(decodeURIComponent($(identifier).data('item'))) const d=$(identifier).data('id') const name=$(identifier).data('name') const company=$(identifier).data('company') if (!state) { workers.push({employeeId:d, name:name,company:company}); } else { workers=workers.filter(obj=>obj.employeeId!==d); } if (workers.length) { document.getElementById("sendData1").disabled=false } else { document.getElementById("sendData1").disabled=true } $('#arc').text(JSON.stringify(workers)) } function textChanged1(){ var length=document.getElementById("workFlow1").value.length if (length>3) { let divElement = document.getElementById("buttons3"); $.each(divElement.children,function(i,item){ if (workers.some(item3 => item3.employeeId === item.id)){ item.classList.add("active") } if (usedWorkers.some(item2 => item2.employeeId === item.id)===false){ item.disabled=false } }) if (workers.length) { document.getElementById("sendData1").disabled=false } }else{ let divElement = document.getElementById("buttons3"); $.each(divElement.children,function(i,item){ item.disabled=true item.classList.remove("active") }) workers=[] document.getElementById("sendData1").disabled=true } } $(document).ready(function () { var wid = document.getElementById ('wn').textContent; var uid = document.getElementById ('uid').textContent; var workFlowId="" const title=document.getElementById ('wn').textContent; document.getElementById("workFlow1").onkeydown = function() { textChanged1(); }; $('#workFlow1').change(function(event) { //do stuff with the "event" object as the object that called the method textChanged1(); } ); document.getElementById('sendData1').addEventListener('click', function(a) { const workFlowTitle = document.getElementById('workFlow1').value; var dummy=document.getElementById('dummy').textContent var t=JSON.parse(dummy); //let result = t.workFlow.find(obj => obj._id === workFlowId); /*var foundIndex = t.workFlow.findIndex(x => x._id == workFlowId); const workFlowItem= { Title : workFlowTitle, employeeList: workers } t.workFlow[foundIndex].Title=workFlowTitle; t.workFlow[foundIndex].employeeList=workers;*/ const workFlowItem= { cid: Date.now(), Title : workFlowTitle, employeeList: workers } t.workFlow.push(workFlowItem) document.getElementById('dummy').textContent=JSON.stringify(t) updateEditTable() }) // Modal megjelenítése esemény $(document).on('show.bs.modal','#workReportEditAddModal', function (event) { form1.reset(); document.getElementById("sendData1").disabled=true var dummy=document.getElementById('dummy').textContent var button = $(event.relatedTarget); // button the triggered modal workFlowId = button.data("rid"); //data-id of button which is equal to id (primary key) of person var t=JSON.parse(dummy); //let result = t.workFlow.find(obj => obj._id === workFlowId); //document.getElementById("workFlow").value=result.Title workers=[] usedWorkers=[]; //workers=result.employeeList; $.each(t.workFlow,function(i,item){ //if(item._id!=result._id) // { var arr=usedWorkers usedWorkers=[...arr,...item.employeeList]//.push(item.employeeList) // } }) let divElement = document.getElementById("buttons3"); while (divElement.firstChild) { divElement.removeChild(divElement.firstChild); } // const title=document.getElementById ('headertitle').textContent; //var foo = document.getElementById("buttons"); //Append the element in page (in span). //Fetch workReport fetch('/workreportUserList', { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer YOUR_ACCESS_TOKEN' } }) .then(response => response.json()) .then(data => { console.log(data) /* $.each(data.users,function(i,item){ var data_str = encodeURIComponent(JSON.stringify(item)); $('').appendTo('#buttons3'); })*/ $.each(data.users,function(i,item){ $('

'+item._id.company+'

').appendTo('#buttons3'); $.each(item.employees,function(l,user){ var data_str = encodeURIComponent(JSON.stringify(user)); $('').appendTo('#buttons3'); }) }) textChanged1() }) .catch(error => console.error('Error:', error)); }) });