klnodekb/views/Modals/modal_workReportNew.pug

245 lines
12 KiB
Plaintext

#workReportNewModal.modal(tabindex='-1', role='dialog', aria-labelledby='workReportNewModalLabel')
//-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#workReportNewHeader.bg-primary(style="background: Primary")
h4 #{workTitle}
.modal-body(style='background-color:#5f6b79')
form#kabelform2
#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="workFlow",style='color: white') Munka leírása:
input.form-control(id='workFlow', name='workFlow', required, placeholder="Nevezze meg a munka folyamatot", minlength="6",type=text, autofocus, readonly=false,style='')
br
.row
.col-sm-12
#buttons(style="margin: 10px;")
h4#arc(style="display:none")
br
//button#submit.btn.btn-primary(type='submit' ) Rendben
.modal-footer(style="background-color: #2C3446")
button#sendData.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 workers=[]
var usedWorkers=[]
const form = document.getElementById('kabelform2');
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("sendData").disabled=false
}
else
{
document.getElementById("sendData").disabled=true
}
$('#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){
if (usedWorkers.some(item2 => item2.employeeId === item.id)===false){
item.disabled=false
}
})
if (workers.length)
{
document.getElementById("sendData").disabled=false
}
}else{
let divElement = document.getElementById("buttons");
$.each(divElement.children,function(i,item){
item.disabled=true
item.classList.remove("active")
})
workers=[]
document.getElementById("sendData").disabled=true
}
}
$(document).ready(function () {
var wid = document.getElementById ('wn').textContent;
var uid = document.getElementById ('uid').textContent;
var selectedDate="";
const title=document.getElementById ('wn').textContent;
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 workFlowTitle = document.getElementById('workFlow').value;
var dummy=document.getElementById('dummy').textContent
var t=JSON.parse(dummy);
const workFlowItem=
{
Title : workFlowTitle,
employeeList: workers
}
t.workFlow.push(workFlowItem)
document.getElementById('dummy').textContent=JSON.stringify(t)
/* {
// Napi jelentés
workId:1,
date: {type: Date},
foremanId: {type: String},
workTitle: {type: String},
workFlow: [{
Title: {type: String},
employeeList:[{
id:{type: mongoose.Schema.Types.ObjectId},
name: {type: String},
}]
}],
}*/
/* 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
});
}
$('#workReportNewModal').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)); */
})
// Modal megjelenítése esemény
$(document).on('show.bs.modal','#workReportNewModal', function () {
document.getElementById("sendData").disabled=true
var dummy=document.getElementById('dummy').textContent
var t=JSON.parse(dummy);
$.each(t.workFlow,function(i,item){
var arr=usedWorkers
usedWorkers=[...arr,...item.employeeList]//.push(item.employeeList)
})
form.reset();
let divElement = document.getElementById("buttons");
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){
$('<hr><h3>'+item._id.company+'</h3>').appendTo('#buttons');
$.each(item.employees,function(l,user){
var data_str = encodeURIComponent(JSON.stringify(user));
//$('<button class="btn btn-primary aaa" disabled onclick="handleClick(this)" id="'+item._id+'"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');
$('<button class="btn btn-primary aaa" disabled onclick="handleClick(this)" id="'+user.id+'"data-item="'+data_str+'" data-name="'+user.name+'" data-id="'+user.id+'" data-company="'+item._id.company+'"style="width:150px;margin: 3px" data-toggle="button" type="button">'+user.name+'</button>').appendTo('#buttons');
})
})
})
.catch(error => console.error('Error:', error));
})
});