custom Action

custom Action

rldean1rldean1 Posts: 141Questions: 66Answers: 1
edited June 2020 in Editor

In the Editor AJAX client-to-server data request, the default Actions are Create, Edit, and Remove.

Is there a built-in method or option to include additional custom actions? Bad example... but if I needed an Action named "Edit2"?

If not, I know that I can intercept the request object and modify it on my own, and then return a response in the expected/appropriate format. I just wanted to see if DT/DTE had a built-in way to do it

ajax: function (method, url, data, dte_success, error) {
     // reformat data
     JSONstring = app.dteFormatRequest(data);

     ...
}

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Does this thread answer your question?

    Kevin

  • rldean1rldean1 Posts: 141Questions: 66Answers: 1

    Sort of....

    I was looking for a way to change the Action during an Edit, like: Create, Edit, Delete, and AddWalkIn...

    My scenario is abnormal... I "massage" the data in the Editor AJAX function so that I can parse it on the SQL side, and I have to make the request in a special way... It's a long story I won't bore you with --- we have an overly-complicated custom framework with a complicated way to make a call.

    Anyway, I flatten the data.... This is the best thing I could come up with (pseudo-code below):

    ajax: function (method, url, data, dte_success, error) { 
    
        // data:  the raw Editor object containing the request that would be sent to SQL
        
        obj = {};  // obj will hold the new "flattened" request
    
    
        if (data.action === 'edit') {
    
            // example of how I restructure the {data} object
    
            $.each(data.data, function (i) {
                obj.ProcessingID = i;  // row source ID
                obj.Action = data.action;  // set Action to the Action that is being peformed
                $.each(data.data[i], function (key, val) {
                    obj[key] = val;
                });
            });
    
        }
    
        // here is how I am planning to set my own custom Action if an Edit is being performed
        else if (data.action === 'edit' && data.data[0].AddWalkIn === true) {
    
            obj.Action = 'AddWalkIn'  // set my own custom action
    
            // ... continue to build request object
    
        }
    
        else if (data.action === 'create') { ... }
    
    
        else if (data.action === 'delete') { ... }
    
    
    }
    
  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    Answer ✓

    The only thing that stands out is the else if in line 23 will probably never be executed because of the first if in line 8. Maybe move it after the if/else if block you have and make it a standalone if statement (assuming you are doing the same object build as lines 12-18.

    Kevin

This discussion has been closed.