diff --git a/edit-mode/function/restActivityLink.js b/edit-mode/function/restActivityLink.js index 6574ce0..697e488 100644 --- a/edit-mode/function/restActivityLink.js +++ b/edit-mode/function/restActivityLink.js @@ -1,4 +1,5 @@ let geom = []; +$("body").addClass("loading"); gantt.ajax.get({ url: `${base_url}activity/${ganttId}/${proyekId}/get`, headers: { @@ -6,6 +7,7 @@ gantt.ajax.get({ "Authorization": `Bearer ${token}` } }).then(function (xhr) { + $("body").removeClass("loading"); let data = {}; let response = xhr.responseText; let obj = JSON.parse(response); @@ -30,8 +32,19 @@ gantt.ajax.get({ gantt.silent(function () { gantt.parse(data); getGanttOpen(); + gantt.parse(data); }); if (Date.now() < timestamp) { + expandTask(); + var allTasks = []; + var taskCount = gantt.getTaskCount(); + + for (var i = 0; i < taskCount; i++) { + var task = gantt.getTaskByIndex(i); + allTasks.push(task); + } + + $("body").addClass("loading"); gantt.ajax.post({ headers: { "Content-Type": "application/json", @@ -41,13 +54,28 @@ gantt.ajax.get({ dataType: "json", data: JSON.stringify(allTasks) }).then(function (response) { + $("body").removeClass("loading"); let res = response.responseText res = JSON.parse(res) if (res) { refresData(); } + }).catch(function (error) { + $("body").removeClass("loading"); + gantt.alert({ + title: "Peringatan", + type: "alert-error", + text: "Update import gagal" + }); }); } +}).catch(function (error) { + $("body").removeClass("loading"); + gantt.alert({ + title: "Peringatan", + type: "alert-error", + text: "Get activity gagal" + }); }); function refresData(id) { @@ -127,6 +155,7 @@ var dp = gantt.createDataProcessor(function (entity, action, data, id) { } } data['version_gantt_id'] = ganttId; + $("body").addClass("loading"); return gantt.ajax.post({ headers: { "Content-Type": "application/json", @@ -135,6 +164,7 @@ var dp = gantt.createDataProcessor(function (entity, action, data, id) { url: base_url + entity, data: JSON.stringify(data) }).then(function (response) { + $("body").removeClass("loading"); let res = response.responseText res = JSON.parse(res) if (entity == "link") { @@ -142,6 +172,13 @@ var dp = gantt.createDataProcessor(function (entity, action, data, id) { } else if (entity == "task") { gantt.changeTaskId(id, res.tid); } + }).catch(function (error) { + $("body").removeClass("loading"); + gantt.alert({ + title: "Peringatan", + type: "alert-error", + text: "Add activity gagal" + }); }); break; case "update": @@ -223,12 +260,14 @@ var dp = gantt.createDataProcessor(function (entity, action, data, id) { break; case "delete": + $("body").addClass("loading"); return gantt.ajax.del({ headers: { "Authorization": `Bearer ${token}` }, url: base_url + entity + "/" + id }).then(function (response) { + $("body").removeClass("loading"); if (entity == "task") { let parent = data.parent; if (parent && parent > 0) { @@ -244,6 +283,13 @@ var dp = gantt.createDataProcessor(function (entity, action, data, id) { } } } + }).catch(function (error) { + $("body").removeClass("loading"); + gantt.alert({ + title: "Peringatan", + type: "alert-error", + text: "Update activity gagal" + }); }); break; }