klnodekb/views/Modals/modal_workReport.pug

256 lines
12 KiB
Plaintext

#workReportModal.modal(tabindex='-1', role='dialog', aria-labelledby='workReportModalLabel')
//-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#workReportHeader.bg-primary(style="background: Primary")
h4#headertitle
.modal-body(style='background-color:#5f6b79')
form#kabelform
#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
input(id='datepicker',style='display:none', type=text)
.row
.table-responsive
table#workReportEdit.table.table-striped
col(width='15%')
col(width='auto')
thead
th(style='text-align:left') Résztvevők
th(style='text-align:left') Munkavégzés leírása
tbody
hr
.row
.col-sm-12
label(for="workFlow",style='color: white') Munka leírása:
input.form-control(id='workFlow', name='workFlow', required, minlength="6",type=text, autofocus, readonly=false,style='')
br
.row
.col-sm-12
#buttons(style="margin: 10px;")
h4#arc
br
//button#submit.btn.btn-primary(type='submit' ) Rendben
button#sendData.btn.btn-primary(type='button') Rendben
.modal-footer(style="background-color: #2C3446")
button#fmodalClose.btn.btn-primary(type='button', data-dismiss='modal') Bezár
script(src='/bower_components/jquery/dist/jquery.min.js')
//-script(src='/bower_components/bootstrap-validator/dist/validator.min.js')
script.
var workers=[]
function tableUpdate()
{
const workFlow = document.getElementById('workFlow').value;
// $.each(data.reports,function(i,item){
var newRow="<tr><td>"
//newRow+='<td>'
$.each(workers,function(i,employee){
newRow+=employee.name+'<br>'
});
newRow+='</td>'
newRow+="<td>"+workFlow+"</td>"
newRow+='</tr>';
$('#workReportEdit > tbody:last-child').append (newRow);
// })
}
const form = document.getElementById('kabelform');
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')
if (!state)
{
workers.push({employeeId:d, name:name,workFlow:""});
}
else
{
workers=workers.filter(obj=>obj._id!==d._id);
}
// alert("data-id:"+JSON.stringify(workers) );
tableUpdate()
$('#arc').text(JSON.stringify(workers))
}
function textChanged(){
var length=document.getElementById("workFlow").value.length
if (length>3)
{
let divElement = document.getElementById("buttons");
$.each(divElement.children,function(i,item){
item.disabled=false
})
}else{
let divElement = document.getElementById("buttons");
$.each(divElement.children,function(i,item){
item.disabled=true
item.classList.remove("active")
})
workers=[]
}
}
$(document).ready(function () {
var wid = document.getElementById ('wn').textContent;
var uid = document.getElementById ('user_id').textContent;
var selectedDate="";
const title=document.getElementById ('title').textContent;
var picker = new Lightpick({ field: document.getElementById('datepicker'),
singleDate: true,
inline: true,
numberOfColumns: 2,
numberOfMonths: 2,
format: 'YYYY.MM.DD',
disableWeekends: false,
maxDate: moment(),
onSelect: function(date){
selectedDate=date
}
});
document.getElementById("workFlow").onkeydown = function() {
textChanged();
};
$('#workFlow').change(function(event) {
//do stuff with the "event" object as the object that called the method
textChanged();
}
);
document.getElementById('sendData').addEventListener('click', function(a) {
const workFlow = document.getElementById('workFlow').value;
if(selectedDate.length)
{
Swal.fire('Error', '', 'error')
}
$.each(workers,function(i,w){
w.workFlow=workFlow
})
var dataa={
date: selectedDate,
workId:wid,
foremanId:uid,
workTitle:title,
employeeList:workers
}
const response = fetch('/workreport', {
method: 'POST',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(dataa)
})
.then(response => response.json())
.then(data => {
//console.log(data)
if (!data.response.ok)
{
Swal.fire('Error', '', 'error')
}
if (data.response="ok")
{
Swal.fire({
position: "top-end",
icon: "success",
title: data.message,
showConfirmButton: false,
timer: 1500,
backdrop: false
});
} else
{
Swal.fire({
position: "top-end",
icon: "error",
title: data.message,
showConfirmButton: false,
timer: 1500,
backdrop: false
});
}
$('#workReportModal').modal('hide');//.modal('toggle');
$('.modal').removeClass('in');
$('.modal').attr("aria-hidden","true");
$('.modal').css("display", "none");
$('.modal-backdrop').remove();
$('body').removeClass('modal-open');
$('.modal-backdrop').remove()
})
.catch(error => console.error('Error:', error));
})
/* if (!response.ok)
{
Swal.fire('Error', '', 'error')
}
if (resp.response="OK")
{
Swal.fire({
position: "top-end",
icon: "success",
title: resp.message,
showConfirmButton: false,
timer: 1500,
backdrop: false
});
} else
{
Swal.fire({
position: "top-end",
icon: "error",
title: resp.message,
showConfirmButton: false,
timer: 1500,
backdrop: false
});
} */
//});
$(document).on('show.bs.modal','#workReportModal', function () {
form.reset();
let divElement = document.getElementById("buttons");
while (divElement.firstChild) {
divElement.removeChild(divElement.firstChild);
}
selectedDate="";
//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));
$('<button class="btn btn-primary aaa" disabled onclick="handleClick(this)" data-item="'+data_str+'" data-name="'+item.name+'" data-id="'+item._id+'" style="width:150px;margin: 3px" data-toggle="button" type="button">'+item.name+'</button>').appendTo('#buttons');
})
})
.catch(error => console.error('Error:', error));
})
});