Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
825
saveResult error-handling when using (non-transactional) restSettings
posted

I have an editable igGrid set up to save pending transactions using RESTful services. Excerpt:

    $("#ar_invoices").igGrid({
        aggregateTransactions : true,
        columns : [ blah blah ],
        features : [
        {
            name : 'Updating',
            editMode: "row",
            showDoneCancelButtons : true,
            columnSettings : [ blah blah ]
        } ],
        restSettings: {
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            contentSerializer: iggridUrlEncode,
            create: {
                url: env_constants.DATASERVICES_URL + "/ar_invoices/"
            },
            update: {
                url: env_constants.DATASERVICES_URL + "/ar_invoices/"
            },
            remove: {
                url: env_constants.DATASERVICES_URL + "/ar_invoices/"
            }
        }
    });

The issue I'm currently wrestling with is error handling when a batch of changes are submitted. Here is my JavaScript function for saving pending changes:

function ar_invoice_changes_save() {
    $("#saveResult").text("");
    $("#ar_invoices").igGrid("saveChanges",
        function (data) {
            $("#user_prompt").text("Changes were saved successfully").fadeIn(3000).fadeOut(5000);
        },
        function (jqXHR, textStatus, errorThrown) {
            alert(jqXHR.responseText);
        });
}

My question is how to handle errors if the user adds multiple rows and saves them. The grid seems to keep all pendingTransactions around, which makes sense if they are saved in a transaction, but RESTful transactions are submitted independently. For example, consider the following scenario:

  1. User adds two rows.
  2. User clicks save, the first row is POSTed succesfully but the second returns an error.
  3. The user fixes the bad row, clicks Save again. All transactions are resubmitted, including ones that were already saved.
  4. The first row therefore gets POSTed twice, and (assuming there aren't any data constraints preventing it) a duplicate will be created.

This is not a problem for PUT, which is idempotent, and possibly not for DELETE, but POST-ing new rows is explicitly not idempotent.

At a high level, my options seem to be:

  1. Find a way to identify transactions that were successfully POSTed and avoid posting them again
  2. Bypass the grid's Add New Row operation in favor of my own form that forces the user to add one new row at a time
  3. Rewrite the POST operation to accept a list of new rows, then submit all new rows as a single POST from the grid somehow, as an atomic transaction

Does the grid have any support for #1? For example, knowing which pending transactions succeeded, if any? (Note: I am using "aggregateTransactions : true" so as I understand it, each edited row is effectively one transaction.)

Other suggestions also welcome. Thanks,

Parents Reply Children
No Data