var parts = []; let latest; let earliest; window.parent.postMessage({ action: 'getUrl' }, '*'); window.addEventListener('message', function(event) { if (event.data && event.data.action === 'sendUrl') { const parentUrl = event.data.url; // Split the remaining path by "/" parts = parentUrl.split("/"); } }); gantt.ajax.get({ url: `${base_url}activity/${ganttId}/${proyekId}/get`, headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}` } }).then(function (xhr) { let data = {}; let response = xhr.responseText; let obj = JSON.parse(response); data['data'] = obj.data.data; data['links'] = obj.data.links; // check if baseline has been set if (data.data && data.data.length > 0) { if (data.data[0].planned_start !== null && data.data[0].planned_end !== null) { isBaselineSet = true; } else { isBaselineSet = false; } } if(!parts[7]){ gantt.silent(function () { gantt.parse(data); earliest = getEarliestTaskDate(); latest = getLatestTaskDate(); }); } }); function refresData(id){ gantt.ajax.get({ url: `${base_url}activity/${ganttId}/${proyekId}/get`, headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}` } }).then(function (xhr) { gantt.clearAll(); let data = {}; let response = xhr.responseText; let obj = JSON.parse(response); data['data'] = obj.data.data; data['links'] = obj.data.links; if(!parts[7]){ gantt.silent(function () { gantt.parse(data); earliest = getEarliestTaskDate(); latest = getLatestTaskDate(); }); } if(id){ if(gantt.isTaskExists(id)){ expandTask(); } } }); } // entity - "task"|"link" // action - "create"|"update"|"delete" // data - an object with task or link data // id – the id of a processed object (task or link) var dp = gantt.createDataProcessor(function(entity, action, data, id) { switch(action) { case "create": if(entity=="task"){ data['proyek_id'] = proyekId; data['start_date'] = `${data.start_date}+07`; data['end_date'] = `${data.start_date}`; // data['start_date'] = moment(data.start_date).format("DD-MM-YYYY HH:mm:ss+07"); // data['end_date'] = moment(data.end_date).format("DD-MM-YYYY HH:mm:ss+07"); if(data && data.parent){ data['parent_id'] = data.parent; } } data['version_gantt_id'] = ganttId; return gantt.ajax.post({ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}` }, url: base_url + entity, data:JSON.stringify(data) }).then(function(response){ let res = response.responseText res = JSON.parse(res) if(entity=="link"){ gantt.changeLinkId(id, res.tid); }else if(entity=="task"){ gantt.changeTaskId(id, res.tid); } }); break; case "update": if(entity=="task"){ data['start_date'] = moment(data.start_date).format("YYYY-MM-DD HH:mm:ss+07"); data['end_date'] = moment(data.end_date).format("YYYY-MM-DD HH:mm:ss+07"); if(data && data.parent){ data['parent_id'] = data.parent; } Object.keys(data).forEach(function(key) { if(data[key]==""){ data[key]=null; } }); } return gantt.ajax.put({ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}` }, url: base_url + entity + "/" + id, data:JSON.stringify(data) }).then(function(response){ if(entity=="task"){ let parent = data.parent; let responseText = JSON.parse(response.responseText) let resData = responseText let updateBobot = resData.update_bobot || false if(updateBobot){ refresData(id); }else{ if(parent && parent > 0){ updateActivity(parent); } } } }); break; case "delete": return gantt.ajax.del({ headers: { "Authorization": `Bearer ${token}` }, url: base_url + entity + "/" + id }).then(function(response){ if(entity=="task"){ let parent = data.parent; if(parent && parent > 0){ let children = gantt.getChildren(parent); updateActivity(parent); if(children && children.length > 0){ }else{ if(gantt.isTaskExists(parent)){ gantt.getTask(parent).type = "task"; gantt.updateTask(parent); } } } } }); break; } });