First of all thanks very much to the providers of these aef modules - a very exciting package of modules.
... and apologies if I'm being stupid ...
I'm loving the thickbox-style modal but I cannot find a setting for 'refresh parent page', or 'force reload', or similar functionality after the save button has been pressed. I've had a look through the code, and had a search through the forums but to no avail. Is there a standard way to do get a page refresh for these kind of 'modals'? Am I missing something obvious?
The problem in detail:
I've got a simple view of news items on a page, and each news item has an 'edit' link to aef_embedded_edit. When I click the link the thickbox-style modal comes up, I enter the data and then hit save. The thickbox-style modal then closes and I return to the parent page. The view is unchanged. If I hit refresh then the updated values are displayed and it all looks great.
Is there anyone who could point me in the direction of a solution? Any help would be greatly appreciated.
Comments
Comment #1
ndeschildre commentedHello!
A not so clean way to do that:
On the code of aef_embedded_edit.js:
Drupal.Ajax.plugins.embedded_edit = function(hook, args) {
var tb_init_original;
//If a node just got saved, load its infos saved on a cookie, and put it on a noderef
if (hook === 'complete') {
//HERE is the code called when the form is submitted and is about to dissapear.
Here you could call some javascript to force the refresh of your page.
Cheers,
Nicolas
Comment #2
just_fixed_it commentedNicolas,
thanks very much for your reply ...
... I had come to the conclusion that I may have to hack the code in the complete hook of the ajax form, but I was hoping there would be a cleaner way to do it - one does try to be good.
For the benefit of others trying to solve the same problem here is the line I added that refreshes the parent page after the embedded edit 'modal' has been saved.
Where: aef_embedded_edit.js, line 40 (ish)
Code before hack:
Code after hack:
This line of code should be the last thing called inside the conditional if (hook === 'complete' ) code block.
I haven't tested this in loads of browsers, and there may be a more elegant way to do it. Any suggestions/improvements will be very welcome.
Once again, thanks Nicolas.
Aaron
Comment #3
ndeschildre commentedMaybe if you implement the complete ajax hook, and make sure it is called after ours...
Comment #4
just_fixed_it commentedHello again Nicolas,
there's a little problem with the hack that I did and I was wondering if you could take a moment to suggest a better solution. If I can get it working I would be happy to post the code changes (or pass them on to you for your consideration).
When I refresh the parent page from javascript as above, in the instance when I use aef_embedded_edit for uberimage nodereference creation it stops the ajax data update.
I would like to pass in an optional flag to refresh the parent page. I've not used the ajax forms before, and don't know how hard it would be to pass the argument all the way through, or if it would break anything else in the way the aef modules use this code. Your opinion would be greatly appreciated.
So ...
in the js function
Drupal.Ajax.plugins.embedded_edit = function(hook, args)
we have 'args' passed in. Presumably this is how I could get the flag.
'node/%node/edit/aef_embedded_edit'
is the path, so I could add '/refresh' to the end (?) to pass the flag in.
Does this sound like the right way to go?
Can you envisage this approach causing any other problems (e.g. expected arguments)?
Would this be a useful addition to the module functionality?
Thanks in advance for your time and patience.
Comment #5
ndeschildre commentedOh.
So in fact you are editing a image node in the embedded edit, and you want the change to be reflected in the uberimage field?
If so, a trigger('change'); to the uberimage nodereference input will trigger the reload of the field (as if there was a new value inserted), and everything will be reloaded.
Cheers,
Nicolas
Comment #6
just_fixed_it commentedHello Nicolas!
Thanks for your reply. I don't think I was clear enough in describing my problem. Let me try again ....
I'm attempting to use aef_embedded_edit in 2 ways:
1)
I have a 'newsitem' content type with an uberimage cck field of type nodereference. On editing, I click 'create new' on the empty uberimage field and the 'modal' pops up allowing me to create a new 'photo' type (which contains an uberimage upload field). On creation of the 'photo' the modal closes and the nodereference field of the 'newsitem' is populated.
2)
I have a page with a view of news items, each with an 'edit story' link to
'node/%node/edit/aef_embedded_edit'
When clicked the node form modal is shown. On save of the node form the modal is hidden, the data is saved to the database, and the parent (page with view) is shown. The new data should be displayed in the page's view.
The provided source files work correctly for usage 1. To get usage 2 to work I added the above js hack to refresh the parent after child window close. This breaks usage 1. My proposed solution is to add a flag argument to optionally refresh the parent after child close (defaulting to NO_REFRESH).
Your thoughts?
Comment #7
just_fixed_it commentedI would really like to use aef_embedded_edit for usage 2 as well, but maybe it would be simpler to go for a different solution ...
Comment #8
ndeschildre commentedHmm, I think it goes beyond my knowledge.
This part of the module was made by a member of the team which has since then left, I can't ask him.
In:
Drupal.Ajax.plugins.embedded_edit = function(hook, args)
I see args at the end, so there must be a way to give a flag to the AJAX module on form submit.
So it looks definitely possible. I have unfortunately not the time to search for it right now. Maybe later.
If you plan to look for it, good luck!
Comment #9
just_fixed_it commentedOnce again thanks for your time and sharing your knowledge. I'll get stuck in.
Cheers,
Aaron
Comment #10
just_fixed_it commentedI've decided to go a different route.
It's all working nicely.
Thanks again.