Add entry in related field
- Single Page
Posted 15 July 2012 - 07:32 AM
I am trying to build an app so that I can keep a record of various papers/articles. Articles have a n-n relationship with authors and a 1-n relationship with journals.
Presently if I wish to add an article from a new author or from a new journal, I have to add the author and journal first and then go to add paper view and then add the paper.
What I would like is that somehow I can directly go to the add paper view and from there jump to add author view (as a pop up or in new tab or within the same tab as long as I don't lose any data already filled) if I don't find the author. Similarly for the journal.
One way I know to achieve this is to make the CRUD myself and have all things the way I need but I do not want to spend so much time doing that.
Could you suggest an alternative way to do this?
PS: This can be a suggestion for future features in Grocery (if not already present).
Posted 15 July 2012 - 18:23 PM
On crud before render:
$crud->callback_add_field('somefield',array($this,'add_field_callback_1'));
Then the function:
function add_field_callback_1()
{
return '<input type="text" maxlength="50" value="" name="somefield" style="width:462px"> - <a href="LINK_TO_ADD_AUTHOR CRUD" target="_blank">Add Author</a>';
}
Check the docs for the callback_add_field http://www.grocerycrud.com/documentation/options_functions/callback_add_field and callback_edit_field http://www.grocerycrud.com/documentation/options_functions/callback_edit_field
You could have it so it opens on a pop up (using a window.open javascript function or a lightbox iframe style jquery plugin to make it fancy) and even set it to refresh the parent page once you close it, this way you will be able to see the newly added author on the relation list.
I hope I was clear
Cheers.
Posted 15 July 2012 - 18:29 PM
Check out the iframe demo:
http://fancybox.net/
If you call the other crud on the iframe and refresh the parent frame (your current crud) on a onClosed event. I think it could work well.
Let me know how it works out for you. I'm thinking about not only using this but perhaps add it as a plugin for GC as I find it very usefull.
Cheers.
Posted 16 July 2012 - 04:14 AM
For now I have used the iframe method and it worked like a charm!
I am sure it would be a good idea to add this in as a plugin. Let me know when you create the said plugin
Thanks again and cheers!
--
Just one more thing here: Author and Paper have a n-n relation. By following your method now I have to keep looking up the name and enter the corresponding ID or query and display a table of id-name relationship on this page. The original n-n relation input system was much better at this. Can I somehow add this 'add author' button along with the original input mechanism rather than the 'text input'.
Posted 16 July 2012 - 11:45 AM
I guess it's possible, but it should be a little tricky to do.
Another option I thought about was to have an iframe on the callback function with the desired grid and sent to that iframe the primary key so I can filter the data.
Posted 16 July 2012 - 16:04 PM
Iframes is a good idea. It might bring down the amount of coding. It would be something new for me to pass data between the parent and the child iframes.
It will solve the purpose but we surely need a plugin to do this job.
Posted 16 July 2012 - 16:49 PM