Page 1 of 1

Redirect to master data after insert in detail table

Posted: 2015-09-05 21:13
by tuxor
Hi, I have this 2 tables with parent/children enabled:
compras (parent)
detalles_compras (children).

Now I need to do this:

When insert a new register into detalles_compras, redirect to compras selected id,and no need to click in "back" button to go to compras details form.
The same thing when update and delete a register from detalles_compras.

Any idea? Thanks a lot.

Re: Redirect to master data after insert in detail table

Posted: 2015-09-20 10:05
by lucicd
Try this.

Create file 'detalles_compras-dv.js' in 'hooks' folder:

Code: Select all

document.observe('dom:loaded', function() { 
  var btn = $("insert") || $("update");
  if (btn) {
    btn.onclick = function() {
      var result = detalles_compras_validateData();
      if (result == true) {
        window.parent.jQuery(".modal").modal("hide");
      }
      return result;
    };
  }
  
  btn = $("delete");
  if (btn) {
    btn.onclick = function() {
      var result = confirm("Are you sure you want to delete this record?");
      if (result) {
        window.parent.jQuery(".modal").modal("hide");
      }
       return result;
    };
  }
});


Re: Redirect to master data after insert in detail table

Posted: 2015-09-21 21:46
by tuxor
Thank you!! I'll check if it woks.

Re: Redirect to master data after insert in detail table

Posted: 2015-09-23 16:03
by tuxor
Hi, thanks @lucid I'v tested the code, but don't works. Any idea?

Re: Redirect to master data after insert in detail table

Posted: 2015-09-23 16:46
by tuxor
The code only works for the button delete, do you have any idea why?

Re: Redirect to master data after insert in detail table

Posted: 2015-09-27 08:24
by lucicd
Hi,

The code that I gave you simply uses JavaScript functions that are normally called on the page generated by AppGini whenever user clicks, for example, "Save Changes" button. I figured out that details page calls tablename_validateData() function. If validation passes, then it should be safe to return back to the master form (i.e. simulate back button press).

You have to match the name of JavaScript function (i.e. table name). The key line in the code is:

Code: Select all

var result = detalles_compras_validateData();
If you use, for example, Chrome browser, try to inspect the Save Changes button an see the exact button ID and name of the function that is invoked on the details form.

In one of my projects, the "Save Changes" button looks like this:

Code: Select all

<button type="submit" class="btn btn-success btn-lg" id="update" name="update_x" value="1" onclick="return contacts_validateData();"><i class="glyphicon glyphicon-ok"></i> Save Changes</button>
"Back" button looks like this

Code: Select all

<button type="submit" class="btn btn-default" id="deselect" name="deselect_x" value="1" onclick="window.parent.jQuery('.modal').modal('hide'); return false;"><i class="glyphicon glyphicon-chevron-left"></i> Back</button>
Note:
  • ID of the "Save Changes" button is update
  • Function for the "Save Changes" button is onclick="return contacts_validateData();
  • Function for the "Back" button is onclick="window.parent.jQuery('.modal').modal('hide');
If you replace ID and function name from the example above with those that are specific for your project, it should be OK. If it still does not work, then I don't know the reason. Maybe browser incompatibility. Maybe some weird timing issue that I cannot replicate of my computer.

Re: Redirect to master data after insert in detail table

Posted: 2015-09-29 15:47
by tuxor
Thanks a lot!! it works. I just checked the fields and table names. Now, how can I do to refresh the master form (compras) to load the new values from detalles_compras? there is a function to execute after update/insert or delete in detalles_compras?

Thanks @lucid

Re: Redirect to master data after insert in detail table

Posted: 2015-09-30 06:48
by lucicd
Hm, separate refresh of the master form should not be necessary. The code

Code: Select all

window.parent.jQuery(".modal").modal("hide");
should take care of it automatically. This is what the "Back" button does. All works well in my project.

Re: Redirect to master data after insert in detail table

Posted: 2015-10-14 14:44
by tuxor
Hi @Lucid. I would like to know if you can tell me how to print in a javascript message window the values of some variables of the table detalles_compras when insert some value or delete a record? it's that possible?

Thanks

Re: Redirect to master data after insert in detail table

Posted: 2015-10-20 13:11
by lucicd
Hi,

I'm sorry for answering your question this late. After some consideration, I decided not to use AppGini any more because it is not suitable for the type of applications that I make.

Good luck!

Re: Redirect to master data after insert in detail table

Posted: 2015-10-20 15:04
by tuxor
Thanks for all. What tool do you recommend to use?

Re: Redirect to master data after insert in detail table

Posted: 2015-10-21 08:40
by lucicd
I will concentrate on Laravel.