⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Standard CRUD List Mode with Custom Add/Edit Mode?



Pablo Weinx
  • profile picture
  • Member

Posted 10 April 2013 - 18:06 PM

Hi, my friends. In first instance, i'm spechless since i work with your library. It's the best!!! Congratulations and thanks.

My question is very simple.

I have to allow users import data from another remote database, and save the results of importation (date, number of registers, etc), in a table from my local database. I've solved, in a standard form of codeigniter the remote import to the remote database and all works perfect, with a spinner that indicates the progress of the import proccess, etc.

I was wondering how can integrate it into the GC philosofy, i mean, in list mode must appear the standard flexigrid, but when clicking Edit or Add new, the form must be the mine, with the hidden fields that will be filled by ajax when the import proccess finish (because there are many parameters the user would fill for execute the process, but the fields that will be stored in the table would be the same as the seen in list mode), and what actions or JSON results must have the Accept / Accept and back to list / Cancel for send to GC for make appears the Success or Error Div and continue inserting or backing to the list.

Thanks for your help!


davidoster
  • profile picture
  • Member

Posted 10 April 2013 - 22:10 PM

Thank you and welcome to the forum!

 

Depending on the theme you use, if you go under assets/grocery_crud/themes/your_theme/views you will see add.php and edit.php

This is standard CodeIgniter views that you can customize at will.

 

For the fields specifically, you can use the add_fields, edit_fields in order to specify any fields you want to be available during add/edit.

Then you need to call the callback_before_insert and callback_before_update in order to customize the addition and edit of the fields before soring to the database.

This way you need not to worry about JSON and AJAX.

 

I hope this answers your question!

 

P.S. Just study GC's API here.


Pablo Weinx
  • profile picture
  • Member

Posted 11 April 2013 - 10:53 AM

Thanks davidoster for your reply!

 

So, if you can continue helping me, imagine the next scenario:

 

1. I want to store the fields: import_id, import_date (timestamp), import_num_regs

2. These are the fields i want to show in the list mode

3. In the add/edit mode, i also want to store only this fields, but these are calculated when the import process finished

4. So, in the add/edit form, i want to add some fields like: import_from_category, import_to_category, import_from_date_import_to_date, and a button with a label "Start importing" (without abandoning the screen). I can do easily with the add_fields and edit_fields.

5. Only when the proccess has been finished, y can press one of the three GC buttons (Save / Save and Back to list / Cancel) to save the import results in a row of the simple table with these 3 fields. Is in the callback_before_insert and callback_before_update when i guess assign the values to the post vars.

 

Is the correct way? The fields that i add with both functions add_fields and edit_fields doesn't want to belongs to the post array and doesn't try to be inserted in the physical table, really?

 

Thanks again!

 

P.D.: I wish also include the funcionality of saving a previous register in the import table, marked as incomplete or interrupted, if the user breaks the proccess, maybe before starting if, but it's secondary issue.


davidoster
  • profile picture
  • Member

Posted 11 April 2013 - 22:30 PM

Since you have the import process implemented you must know when this is finished.

While it is working you can have a <div></div> with all the fields and buttons hidden.

When the import process is finished you unhide the fields you need to have displayed along with the buttons.

Of course for this you will need to have some jQuery(or javascript in general running in order to make it happen).

 

The fields of the post_array need to exist within the table. But they don't need to be displayed (to the user) in order to be saved in the database.

 

So basically you call the fields or add_fields or edit_fields with the fields you want to.

Then you change the fields that you don't want to be displayed (and filled by the user to invisible) and then

you make the callback_before_add/insert and you customize the final post_array JUST BEFORE it is sent to the database.

 

For the interrupted process you mention, it reminds me something that phplist does with the users' import. There when something has gone wrong (incomplete), it gives you the option to reset the process and start all over again. This might be a good solution. But in any way you need to keep a strict log of all the changes that have being made and be able to backtrack them from the database! This is not an easy task if yo ask me.