Cancel from custom dialog for new task with data processor

I am new to using DHMTLX Gantt but I am very pleased with it.

For the requirements I have I need to implement a custom dialog so I have attached to the “onBeforeLightbox” event and provided the code for displaying my custom dialog and always returning false. I am using the dataProcessor for my server calls.

// specifying the date format 
gantt.config.xml_date = "%Y-%m-%d %H:%i";

gantt.init("ganttTest");

// enabling data loading.
 gantt.load("../api/gantt/data");

// initializing dataProcessor
var dp = new gantt.dataProcessor("../api/gantt/");
// and attaching it to gantt
dp.init(gantt);
// setting the REST mode for dataProcessor
dp.setTransactionMode("REST");

When I click the cancel button on my dialog for adding a new task I call the gantt.deleteTask(id) method as a number of demos show in order to remove the “new task” from the gantt chart, but I have noticed this calls the DELETE method on the server. If I use the default provided Lightbox dialog in this scenario and click its cancel button I notice that the dataProcessor does not end up calling the DELETE method on the server. After debugging through some code I found that this was accomplished by using a “private” method of gantt._deleteTask(id, silent). So for testing purposes I updated my code for the cancel button click of my custom dialog to be:

if (task.$new) {
    gantt._deleteTask(id, true);
}
taskEditWindow.hide();
gantt.refreshData();

This behaves as I would desire by not calling the server when removing a task that has not really been added on the server yet.

So my real question … Is there another more “proper” way of accomplishing this rather than calling the “Private” method?

Thanks!

Hi,

Yes, you should use ‘gann._deleteTask’ method according to the result you want to achieve.
When you cancel the lightbox, this method is used to delete new task without calling DELETE method on the server.
github.com/DHTMLX/gantt/blob/ma … t.js#L7965

But possibly it is not very good idea to hide default lightbox and create new custom popup.
As a rule, I advice use built-in lightbox. You can customize it in different ways. And also it will work correctly with Gantt chart API.

Thank you for the quick reply and great info! :smiley:

So, apparently with the 5.0 version this has changed. It looks like the code to “delete” a task without calling the back end is now:

if (gantt.isTaskExists(task.id) && task.$new) {
    gantt.silent(function silentRemoveOfTask() {
        gantt.$data.tasksStore.removeItem(task.id);
        gantt._update_flags(task.id, null);
    });
}

gantt.refreshData();

If I am missing something or am incorrect, please let me know. Thanks!