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.

199 lines
6.4 KiB

1 year ago
gantt.attachEvent("onTaskDblClick", function (id, e) {
3 years ago
return false;
});
1 year ago
gantt.attachEvent("onAfterTaskAdd", function (id, item) {
if (item.parent && gantt.hasChild()) {
3 years ago
let parentId = item.parent;
1 year ago
if (gantt.getTask(parentId).parent_id != null) {
gantt.getTask(parentId).type = "project";
gantt.updateTask(parentId);
}
}
1 year ago
updateRange();
3 years ago
});
1 year ago
gantt.attachEvent("onTaskRowClick", function (id, row) {
activityId = id;
var activity = gantt.getTaskBy("id", id);
activityName = activity[0]?.name;
1 year ago
activityEarlyStart = new Date(activity[0]?.start_date);
activityEarlyFinish = new Date(activity[0]?.end_date);
});
3 years ago
1 year ago
gantt.ext.inlineEditors.attachEvent("onBeforeEditStart", function (state) {
3 years ago
let id = parseInt(state.id)
let ganttData = gantt.getTask(id);
1 year ago
if (ganttData?.type_activity == "header") {
3 years ago
return false
}
let column = state.columnName
1 year ago
if (column == "progress" || column == "rencana_biaya") {
3 years ago
let hasChild = gantt.hasChild(id);
1 year ago
if (hasChild) {
3 years ago
return false
}
}
1 year ago
if (column == "cost_actual") {
3 years ago
let progress = ganttData.progress ? ganttData.progress : 0
1 year ago
if (progress <= 0) {
3 years ago
return false
}
}
return true
1 year ago
});
1 year ago
function updateRange(){
var range = gantt.getSubtaskDates();
var chart = gantt.getState();
if(range.start_date.valueOf() <= chart.min_date.valueOf() || range.end_date.valueOf() >= chart.max_date.valueOf()){
gantt.config.start_date = gantt.date.add(range.start_date, -1, "day");
gantt.config.end_date = gantt.date.add(range.end_date, 2, "day");
gantt.render();
}
}
gantt.attachEvent("onAfterTaskUpdate", updateRange);
1 year ago
gantt.attachEvent("onBeforeTaskUpdate", function (id, new_item) {
3 years ago
// format progress
let progress = new_item.progress;
1 year ago
if (progress > 100) {
3 years ago
progress = 100;
1 year ago
} else if (progress <= 0) {
3 years ago
progress = 0;
1 year ago
} else if (progress <= 1 && progress > 0) {
progress = progress * 100
3 years ago
}
1 year ago
progress = progress / 100;
1 year ago
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);
}
1 year ago
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) {
1 year ago
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
}
1 year ago
}
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;
}
3 years ago
});
1 year ago
gantt.attachEvent("onAfterTaskDrag", function (id, mode, e) {
var task = gantt.getTask(id);
task.end_date = gantt.calculateEndDate(task);
gantt.updateTask(id);
});
3 years ago
1 year ago
gantt.attachEvent("onBeforeLinkAdd", function (id, link) {
3 years ago
//any custom logic here
let source = link.source;
let target = link.target;
let parents = gantt.getParent(source);
let parentt = gantt.getParent(target);
1 year ago
let childt = gantt.hasChild(target);
if (childt) {
3 years ago
return false;
}
1 year ago
if (parents == target) {
3 years ago
return false;
}
1 year ago
if (parentt == source) {
3 years ago
return false
}
return true;
});
1 year ago
gantt.attachEvent("onGanttReady", function () {
3 years ago
});
1 year ago
gantt.attachEvent("onGanttRender", function () {
if (readOnly && parseInt(readOnly) == 1) {
3 years ago
gantt.config.readonly = true;
1 year ago
} else if (readOnly && parseInt(readOnly) == 0) {
3 years ago
gantt.config.readonly = false;
1 year ago
} else {
3 years ago
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)
let taskCount = gantt.getTaskCount();
if (taskCount > 0) {
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 (earliest && +left_date <= +min_allowed_date && +left_date >= +earliest){
gantt.config.start_date = gantt.date.add(gantt.config.start_date, -1, "day");
repaint = true;
}
if (latest && +right_date >= +max_allowed_date && +right_date <= +latest){
gantt.config.end_date = gantt.date.add(gantt.config.end_date, 1, "day");
repaint = true;
}
if (repaint) {
setTimeout(function(){
gantt.render()
},20)
}
}
1 year ago
});