PDA

View Full Version : Optimal Design for saving grid with form?



wilfogn
3 Aug 2015, 1:20 PM
Hello,

I have a working application that feels clunky. I would like to use Extjs more optimally.

Currently I have a form and a grid sharing a panel that is used to create new "Doctors" in my example. The grid is populated with "Patients" assigned to that Doctor. Upon Submit I do the following things in order:

1. Submit my form POSTing the Doctors information to my Database
2. Return Success and the new Doctor's ID number generated by my DB
3. Assign the Doctor's ID number to each of the patients in my grid.
4. Call store.sync() on my grid's store POSTing the patients to the DB.

Is there a more optimal design for this process? I'm not sure adding hasMany/Belongsto assists me here. Ideally I would like to reduce this to one POST. Thank you.

scottmartin
4 Aug 2015, 10:51 AM
Why not just send the request to the server, have the server updated all that is needed return the new snapshot with store.load()
This would eliminate all of the back and forth.

wilfogn
5 Aug 2015, 6:36 AM
Why not just send the request to the server, have the server updated all that is needed return the new snapshot with store.load()
This would eliminate all of the back and forth.

Thank you for the input. If I understand clearly, you are suggesting that I encode the patient grid and send it with the submit POST, then handle everything on the PHP side?

scottmartin
5 Aug 2015, 7:17 AM
Perhaps I am not understanding the full scope process.
Seems like you are having a lot of conversations with the client/server to perform updates your data.

- Create new doctor on client, send to server.
- Assign the patients to the doctor
- return the updated data to store/grid.

Why go through the process of coming back to the client and perform patient updates to the store, then back to the server again?

wilfogn
6 Aug 2015, 8:50 AM
Scott, Thank you for your time.

This form can also be used for editing doctors/patients, but when it it used to add a new Doctor the doctor_id is not generated/known until the doctor is created in the database. I cannot save any patients until I have a doctor_id to use as their foreign key.

The actual process I am using is :
- Create new doctor on client, send to server. Return doctor_id
- Now that I have a doctor_id Assign it to the patient store/grid
- send store/grid to server to be saved

I could send the patient grid in my post with the Doctor information, then handle the doctor_id assignment and saving of patients on the server side. Using store.sync seems more elegant/readable but generates more posts. As a student and new developer I am trying to learn to use my tools correctly.

scottmartin
6 Aug 2015, 9:05 AM
I would recommend letting the server do the work and let the client show the results.