2

There is a modal dialog displaying mantle.ledger.transaction.AcctgTransEntry of the selected invoice. A button in the dialog calls a service which posts a GL transaction:

function postTransactionToGl() {
                            var invoiceId = $("input[id='showGlTransactions_Header_invoiceId_id']").val();

                            $.ajax(
                                {
                                    type:"POST",
                                    url:"${sri.buildUrl('postInvoiceToGl').url}",
                                    data:
                                        {
                                            moquiSessionToken: "${(ec.getWeb().sessionToken)!}",
                                            invoiceId: invoiceId
                                        },
                                    dataType:"json"
                                }
                            );
                        };

Then there is a JS function that displays the content of a table in the dialog. It calls a service which returns JSON data with entries included. I would like to fire both functions one after another, first post the transactions, then redraw the table. How shall I do that? Is there a way I can run the service, wait for the transaction to commit and then run the refresh?

mrovnanik
  • 123
  • 9

1 Answers1

1

This is more of a jQuery question than a Moqui question. The answer is simple: use the 'success' option in jQuery.ajax() to specify a function to call a method to do something. See:

http://api.jquery.com/jquery.ajax/

What you are describing is something that is much easier with an MVVM or MVC tool that runs in the browser. There are many of these out there and currently there is a proof of concept effort to use Vue JS in Moqui. With data binding the callback from the AJAX request would be easy, just update the data in the model and the view will automatically be updated. See the 'vuejs' branch in the moqui-framework and moqui-runtime repositories.

David E. Jones
  • 1,721
  • 1
  • 9
  • 8