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.

186 lines
5.7 KiB

1 year ago
gantt.attachEvent("onTaskDblClick", function (id, e) {
2 years ago
return false;
});
1 year ago
gantt.attachEvent("onAfterTaskAdd", function (id, item) {
if (item.parent && gantt.hasChild()) {
2 years ago
let parentId = item.parent;
1 year ago
if (gantt.getTask(parentId).parent_id != null) {
gantt.getTask(parentId).type = "project";
gantt.updateTask(parentId);
}
}
2 years ago
});
1 year ago
gantt.attachEvent("onTaskRowClick", function (id, row) {
activityId = id;
var activity = gantt.getTaskBy("id", id);
activityName = activity[0]?.name;
});
2 years ago
1 year ago
gantt.ext.inlineEditors.attachEvent("onBeforeEditStart", function (state) {
2 years ago
let id = parseInt(state.id)
let ganttData = gantt.getTask(id);
1 year ago
if (ganttData?.type_activity == "header") {
2 years ago
return false
}
let column = state.columnName
1 year ago
if (column == "progress" || column == "rencana_biaya") {
2 years ago
let hasChild = gantt.hasChild(id);
1 year ago
if (hasChild) {
2 years ago
return false
}
}
1 year ago
if (column == "cost_actual") {
2 years ago
let progress = ganttData.progress ? ganttData.progress : 0
1 year ago
if (progress <= 0) {
2 years ago
return false
}
}
return true
1 year ago
});
2 years ago
1 year ago
gantt.attachEvent("onBeforeTaskUpdate", function (id, new_item) {
2 years ago
// format progress
let progress = new_item.progress;
1 year ago
if (progress > 100) {
2 years ago
progress = 100;
1 year ago
} else if (progress <= 0) {
2 years ago
progress = 0;
1 year ago
} else if (progress <= 1 && progress > 0) {
progress = progress * 100
2 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;
}
2 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);
});
2 years ago
1 year ago
gantt.attachEvent("onBeforeLinkAdd", function (id, link) {
2 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) {
2 years ago
return false;
}
1 year ago
if (parents == target) {
2 years ago
return false;
}
1 year ago
if (parentt == source) {
2 years ago
return false
}
return true;
});
1 year ago
gantt.attachEvent("onGanttReady", function () {
2 years ago
});
1 year ago
gantt.attachEvent("onGanttRender", function () {
if (readOnly && parseInt(readOnly) == 1) {
2 years ago
gantt.config.readonly = true;
1 year ago
} else if (readOnly && parseInt(readOnly) == 0) {
2 years ago
gantt.config.readonly = false;
1 year ago
} else {
2 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 (+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)
}
}
});