|
|
|
gantt.attachEvent("onTaskDblClick", function (id, e) {
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
gantt.attachEvent("onAfterTaskAdd", function (id, item) {
|
|
|
|
if (item.parent && gantt.hasChild()) {
|
|
|
|
let parentId = item.parent;
|
|
|
|
if (gantt.getTask(parentId).parent_id != null) {
|
|
|
|
gantt.getTask(parentId).type = "project";
|
|
|
|
gantt.updateTask(parentId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
gantt.attachEvent("onTaskRowClick", function (id, row) {
|
|
|
|
activityId = id;
|
|
|
|
var activity = gantt.getTaskBy("id", id);
|
|
|
|
activityName = activity[0]?.name;
|
|
|
|
});
|
|
|
|
|
|
|
|
gantt.ext.inlineEditors.attachEvent("onBeforeEditStart", function (state) {
|
|
|
|
let id = parseInt(state.id)
|
|
|
|
let ganttData = gantt.getTask(id);
|
|
|
|
if (ganttData?.type_activity == "header") {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
let column = state.columnName
|
|
|
|
if (column == "progress" || column == "rencana_biaya") {
|
|
|
|
let hasChild = gantt.hasChild(id);
|
|
|
|
if (hasChild) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (column == "cost_actual") {
|
|
|
|
let progress = ganttData.progress ? ganttData.progress : 0
|
|
|
|
if (progress <= 0) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
});
|
|
|
|
|
|
|
|
gantt.attachEvent("onBeforeTaskUpdate", function (id, new_item) {
|
|
|
|
// format progress
|
|
|
|
let progress = new_item.progress;
|
|
|
|
if (progress > 100) {
|
|
|
|
progress = 100;
|
|
|
|
} else if (progress <= 0) {
|
|
|
|
progress = 0;
|
|
|
|
} else if (progress <= 1 && progress > 0) {
|
|
|
|
progress = progress * 100
|
|
|
|
}
|
|
|
|
progress = progress / 100;
|
|
|
|
let task = gantt.getTask(id);
|
|
|
|
let link = task.$target;
|
|
|
|
// link.length > 0 -> successor
|
|
|
|
new_item['progress'] = progress;
|
|
|
|
if (editEndDateDurationTriggered) {
|
|
|
|
if(link.length == 0){
|
|
|
|
new_item['start_date'].setHours(0,0,0);
|
|
|
|
}
|
|
|
|
new_item['duration'] = new_item['duration'] + (link.length == 0 ? 0 : 1);
|
|
|
|
new_item['end_date'] = gantt.calculateEndDate({
|
|
|
|
start_date: new_item['start_date'],
|
|
|
|
duration: new_item['duration']
|
|
|
|
})
|
|
|
|
new_item['end_date'].setHours(23, 59, 59);
|
|
|
|
if (forceDurationUpdateTriggered) {
|
|
|
|
let tempDuration = new_item['duration'] - 1;
|
|
|
|
new_item['end_date'] = gantt.calculateEndDate({
|
|
|
|
start_date: new_item['start_date'],
|
|
|
|
duration: tempDuration
|
|
|
|
})
|
|
|
|
new_item['end_date'].setHours(23, 59, 59);
|
|
|
|
}
|
|
|
|
|
|
|
|
const dateToCheck = new Date(new_item['end_date']);
|
|
|
|
if (gantt.isWorkTime({ date: dateToCheck, hours: false })) {
|
|
|
|
} else {
|
|
|
|
if (link.length == 0) {
|
|
|
|
let duration = gantt.calculateDuration({
|
|
|
|
start_date: new_item['start_date'],
|
|
|
|
end_date: new_item['end_date']
|
|
|
|
})
|
|
|
|
let endDate = gantt.calculateEndDate({
|
|
|
|
start_date: new_item['start_date'],
|
|
|
|
duration: duration + 1
|
|
|
|
})
|
|
|
|
endDate.setDate(endDate.getDate() - 1)
|
|
|
|
endDate.setHours(23,59,59);
|
|
|
|
new_item['end_date'] = endDate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let newStart = new Date(new_item['start_date']);
|
|
|
|
let newEnd = new Date(new_item['end_date']);
|
|
|
|
if (new_item['start_date'] && new_item['end_date']) {
|
|
|
|
new_item['duration'] = gantt.calculateDuration({
|
|
|
|
start_date: newStart,
|
|
|
|
end_date: newEnd
|
|
|
|
});
|
|
|
|
}
|
|
|
|
forceDurationUpdateTriggered = false;
|
|
|
|
editEndDateDurationTriggered = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
gantt.attachEvent("onAfterTaskDrag", function (id, mode, e) {
|
|
|
|
var task = gantt.getTask(id);
|
|
|
|
task.end_date = gantt.calculateEndDate(task);
|
|
|
|
gantt.updateTask(id);
|
|
|
|
});
|
|
|
|
|
|
|
|
gantt.attachEvent("onBeforeLinkAdd", function (id, link) {
|
|
|
|
//any custom logic here
|
|
|
|
let source = link.source;
|
|
|
|
let target = link.target;
|
|
|
|
let parents = gantt.getParent(source);
|
|
|
|
let parentt = gantt.getParent(target);
|
|
|
|
let childt = gantt.hasChild(target);
|
|
|
|
if (childt) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parents == target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parentt == source) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
gantt.attachEvent("onGanttReady", function () {
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
gantt.attachEvent("onGanttRender", function () {
|
|
|
|
if (readOnly && parseInt(readOnly) == 1) {
|
|
|
|
gantt.config.readonly = true;
|
|
|
|
} else if (readOnly && parseInt(readOnly) == 0) {
|
|
|
|
gantt.config.readonly = false;
|
|
|
|
} else {
|
|
|
|
gantt.config.readonly = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
gantt.attachEvent("onTaskOpened", function (id) {
|
|
|
|
setGanttOpen()
|
|
|
|
});
|
|
|
|
|
|
|
|
gantt.attachEvent("onTaskClosed", function (id) {
|
|
|
|
setGanttOpen()
|
|
|
|
});
|
|
|
|
|
|
|
|
gantt.attachEvent("onGanttScroll", function (left, top){
|
|
|
|
var left_date = gantt.dateFromPos(left)
|
|
|
|
var right_date = gantt.dateFromPos(left + gantt.$task.offsetWidth)
|
|
|
|
|
|
|
|
gantt.config.start_date = gantt.config.start_date || gantt.getState().min_date;
|
|
|
|
gantt.config.end_date = gantt.config.end_date || gantt.getState().max_date;
|
|
|
|
|
|
|
|
var min_allowed_date = gantt.date.add(gantt.config.start_date, 1, "day");
|
|
|
|
var max_allowed_date = gantt.date.add(gantt.config.end_date, -1, "day");
|
|
|
|
|
|
|
|
var repaint = false;
|
|
|
|
if (+left_date <= +min_allowed_date){
|
|
|
|
gantt.config.start_date = gantt.date.add(gantt.config.start_date, -1, "day");
|
|
|
|
repaint = true;
|
|
|
|
}
|
|
|
|
if (+right_date >= +max_allowed_date){
|
|
|
|
gantt.config.end_date = gantt.date.add(gantt.config.end_date, 1, "day");
|
|
|
|
repaint = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (repaint) {
|
|
|
|
setTimeout(function(){
|
|
|
|
gantt.render()
|
|
|
|
},20)
|
|
|
|
}
|
|
|
|
});
|