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.

133 lines
4.5 KiB

3 years ago
var milestoneModal = $('#modal-add-milestone > .modal-dialog > .modal-content');
function addMilestone(id){
if(id && id > 0){
$("#milestone_parent").val(id);
}
$("#modal-add-milestone").modal("show");
}
function resetFormMilestone(){
$('#select-milestone').val(null).trigger("change");
$('#select-milestone').find('option').remove();
$('#select-milestone').val("");
$("#milestone_parent").val("");
$("#name_milestone").val("");
$('#form-milestone').trigger("reset");
$('#submit-milestone').html('Add');
$('#submit-milestone').prop("disabled",false);
$("#modal-add-milestone").modal("hide");
}
$(document).ready(function () {
$('#select-milestone').select2({
dropdownParent: milestoneModal,
selectOnBlur: true,
placeholder: 'Pilih / masukan milestone',
allowClear:true,
ajax: {
url: `${base_url}project-milestone/select`,
dataType: 'json',
data: function (params) {
var query = {
search: params.term,
type: 'public',
idProject:proyekId,
idGantt:ganttId
}
return query;
},
processResults: function (result) {
return {
results: $.map(result, function (item) {
return {
due_date:item.due_date,
deadline:item.deadline,
text: item.status,
id: item.id
}
})
};
},
cache: false
},
tags: true,
createTag: function (params) {
return {
id: params.term,
text: params.term,
newOption: true
}
}
});
$('#select-milestone').on('select2:select', function (e) {
var data = e.params.data;
$("#due_milestone").val(data.due_date);
$("#deadline_milestone").val(data.deadline);
$("#name_milestone").val(data.text);
});
$('#due_milestone').datepicker({
format: 'dd-mm-yyyy', // Set the desired format
autoclose: true // Close the datepicker when a date is selected
});
3 years ago
$('#deadline_milestone').datepicker({
format: 'dd-mm-yyyy', // Set the desired format
autoclose: true // Close the datepicker when a date is selected
});
3 years ago
$('#modal-material').on('show.bs.modal', function (event) {
});
$('#modal-material').on('hide.bs.modal', function (event) {
resetFormMilestone();
});
// form-milestone
$("#form-milestone").on('submit', function (e) {
e.preventDefault();
$('#submit-milestone').html('Add..');
$('#submit-milestone').prop("disabled",true);
var data = Object.fromEntries(new FormData(this));
let parent = data.milestone_parent;
var taskId = 0;
var start = moment(data.due_date, "DD-MM-YYYY");
var end = moment(data.deadline, "DD-MM-YYYY");
3 years ago
let duration = moment.duration(start.diff(end)).asDays();
let nameMilestone = data.status!="" ? data.status : data.id_milestone
if(parent && parseInt(parent) > 0){
taskId = gantt.addTask({
id: Math.floor(Math.random() * 1000) + 5000,
text: nameMilestone,
start_date: start.format("YYYY-MM-DD"),
end_date: end.format("YYYY-MM-DD"),
3 years ago
duration: Math.abs(duration),
type: "milestone",
type_activity:"milestone"
}, parent);
}else{
taskId = gantt.addTask({
id: Math.floor(Math.random() * 1000) + 5000,
text: nameMilestone,
start_date: start.format("YYYY-MM-DD"),
end_date: end.format("YYYY-MM-DD"),
3 years ago
duration: Math.abs(duration),
type: "milestone",
type_activity:"milestone"
});
}
if(taskId && taskId > 0){
resetFormMilestone();
gantt.alert("Add Milestone Success!");
}else{
$('#submit-milestone').html('Add');
$('#submit-milestone').prop("disabled",false);
gantt.alert("Add Milestone Failed!");
}
});
});