You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.5 KiB

2 years ago
function resetFormHoliday(){
$("#form_holiday").hide();
$('#form_holiday').trigger("reset");
$("#add-holiday").show();
$("#hide-holiday").hide();
$('#btn_add_holiday').html('Add Holiday');
$('#btn_add_holiday').prop("disabled",false);
}
$(document).ready(function () {
var tableHoliday = $("#table_holiday").DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": `${base_url}holiday/datatables`,
"data": function ( d ) {
d.proyek_id = proyekId;
d.gantt_id = ganttId;
}
},
"columns": [
{data: 'date', name: 'date'},
{data: 'duration', name: 'duration'},
{data: 'description', name: 'description'},
]
});
$('#modal_gantt_setting').on('hide.bs.modal', function (event) {
gantt.render();
});
$("#modal_gantt_setting").on("click", "#add-holiday", function(){
$(this).hide();
$("#hide-holiday").show();
$("#form_holiday").show();
});
$("#modal_gantt_setting").on("click", "#hide-holiday", function(){
$(this).hide();
resetFormHoliday()
$("#add-holiday").show();
});
$("#form_holiday").on('submit', function (e) {
e.preventDefault();
let payload = {
date: $("#date_holiday").val(),
duration: $("#duration_holiday").val(),
description: $("#desc_holiday").val(),
version_gantt_id:ganttId,
proyek_id:proyekId,
}
$.ajax({
data: JSON.stringify(payload),
url: `${base_url}holiday/add`,
type: "POST",
processData: false,
contentType: false,
success: function (data) {
resetFormHoliday();
tableHoliday.draw();
gantt.alert("Add Holiday Success!");
initHolidays();
},
error: function (data) {
resetFormHoliday();
gantt.alert("Add Holiday Failed, try again later!");
}
});
});
function unsetHolidays(data){
var a = moment(data.date);
2 years ago
var b = moment(a).add(data.duration, 'days');
2 years ago
for (var m = moment(a); m.isBefore(b); m.add(1, 'days')) {
let holiday = new Date(m.format('YYYY-MM-DD'));
gantt.unsetWorkTime({
2 years ago
date: holiday,
2 years ago
hours:false
});
}
initHolidays();
}
function deleteHoliday(id)
{
$.ajax({
url: `${base_url}holiday/delete/${id}`,
type:"DELETE",
success: function (data) {
gantt.alert("Delete Holiday Success!");
tableHoliday.draw();
if(data.data){
unsetHolidays(data.data);
}
},
error: function (data) {
gantt.alert("Delete Holiday Failed, try again later!");
}
});
}
$("#table_holiday").on("click", ".btn-holiday-delete", function() {
let id = $(this).data('id');
gantt.confirm({
text: "Holiday will be deleted from gantt, continue?",
2 years ago
ok:"Delete",
2 years ago
cancel:"Cancel",
callback: function(result){
if(result){
deleteHoliday(id);
}
}
});
});
2 years ago
});