I am currently hooking into the content service to grab a property run it though embed.ly and then save the code back into a property, it's working pretty well, however, I've two issues I need a little help with:
I am binding only the save event, however when a Umbraco users Saves and Publishes, the in memory cache is not being updated with the new values (right clicking then publish entire site sorts it out). I am wondering if this is because my call to the .Save has raiseEvents false, but I can't have a save event triggering a save event as it will never end....?
In order to get the UI to refresh with the new value, I am having to use the ClientTools.ChangeContentFrameUrl method however this causes the old double reload and also if the user was on a specific tab, they are taken back to the beginning, is there a better way?
Hi Andrew, not really as that would then publish the content even if the user had only saved. I have just realised that the solution to point 1 was to use the .Saving event instead of .Saved as that is equivalent to the v4 BeforeSave event.
Yeah, it would be nice to at least go back to the right tab. I think I can probably find which tab the property is on from the ContentTypeComposition but I can't see any method on clientTools to setActiveTab or similar....?
#1 Why not use the Saving event ? If its just a property value you want to update then you can just "inject" that before the Content is Saved or Saved and Published. Would save you from double saving as far as I can tell. The in memory cache should be updated regardless of which and how many saves you are doing. As soon as you hit "update" through the repositories (the level below the ContentService) the in memory cache is updated.
#2 I don't think there is a much better way to do it. The issue is unfortunately because of the legacy code used in the Backoffice, which loads a Document OnInit. This Document is used by the ContentControl, which renders out all the fields and the values within them. The Document has an internal version of the new IContent object, which is updated based on the changes made through the editor and then passed on to the ContentService for saving. When you are updating the Content through events these updates are not really fed back into the ContentControl because its using a Document (with the IContent object behind the scenes) that is already loaded. So yea the only way to have the content editor (frame) updated with changes made through events would be to reload the content frame. Only other alternative would be to override the editContent.aspx and ensure that the loaded ContentControl is fed the newly updated IContent object. That would be a bit more hacky then what you are currently doing.
Altough....there is another thing that might be worth a shot. The legacy Document.Before save event might actually be a better fit. If you update the property through the document.GenericProperties collection then I believe you would be updating the instance of the object that is loaded in editContent and the ContentControl, so that the updated value would be shown. But im not 100% certain, but worth a try.
Yeah, realised that one this morning, and it's working perfectly :-)
Hmm, interesting something you can do in the v4 Api you can't do in the v6 Api! It would be really useful if there was a clientTools.SetActiveTab method or similar though, c'est la vie :-) I'll wait for v7....
On second thought I'm not really sure that is the case. As Mr.Kipusoep mentioned its most likely because the browser remembers the values - until you do a "hard" refresh.
Yes, the reload "hack" I posted is the only method for v6.1.x. I haven't looked to see how this works in v7 yet but hopefully there might be something nicer....
ContentService help please
Hi All,
I am currently hooking into the content service to grab a property run it though embed.ly and then save the code back into a property, it's working pretty well, however, I've two issues I need a little help with:
My code:
Any suggestions greatly appreciated!
Thanks!
Jeavon
hi Jeavon, it sounds like you want to use the SaveAndPublish() method on the content service rather than just Save()?
Hi Andrew, not really as that would then publish the content even if the user had only saved. I have just realised that the solution to point 1 was to use the .Saving event instead of .Saved as that is equivalent to the v4 BeforeSave event.
Still stumped on point 2 though...?
Thanks!
I can't think of a better way for point 2. It's because the browser remembers the form values entered before.
Yeah, it would be nice to at least go back to the right tab. I think I can probably find which tab the property is on from the ContentTypeComposition but I can't see any method on clientTools to setActiveTab or similar....?
Hi Jeavon,
#1 Why not use the Saving event ? If its just a property value you want to update then you can just "inject" that before the Content is Saved or Saved and Published. Would save you from double saving as far as I can tell.
The in memory cache should be updated regardless of which and how many saves you are doing. As soon as you hit "update" through the repositories (the level below the ContentService) the in memory cache is updated.
#2 I don't think there is a much better way to do it. The issue is unfortunately because of the legacy code used in the Backoffice, which loads a Document OnInit. This Document is used by the ContentControl, which renders out all the fields and the values within them. The Document has an internal version of the new IContent object, which is updated based on the changes made through the editor and then passed on to the ContentService for saving. When you are updating the Content through events these updates are not really fed back into the ContentControl because its using a Document (with the IContent object behind the scenes) that is already loaded.
So yea the only way to have the content editor (frame) updated with changes made through events would be to reload the content frame. Only other alternative would be to override the editContent.aspx and ensure that the loaded ContentControl is fed the newly updated IContent object. That would be a bit more hacky then what you are currently doing.
Altough....there is another thing that might be worth a shot. The legacy Document.Before save event might actually be a better fit. If you update the property through the document.GenericProperties collection then I believe you would be updating the instance of the object that is loaded in editContent and the ContentControl, so that the updated value would be shown. But im not 100% certain, but worth a try.
Hope this helps,
Morten Christensen
Thanks Morten!
Jeavon
On second thought I'm not really sure that is the case. As Mr.Kipusoep mentioned its most likely because the browser remembers the values - until you do a "hard" refresh.
- Morten
Just wondering what you ended up doing? I am using ContentService.Saving but the value isn't refreshed as you experienced..
Is there a way to force a refresh?
Thanks,
Tom
Hi Tom,
I ended up using the reload "hack", obviously the users ends up on the first tab
Hope that helps you.
Jeavon
Thanks Jeavon,
that worked perfectly.
Cheers,
Tom
Can someone please post and let me know if this (Tom's hack above) is still the best way to handle this in v6.1 ??
Hi Scott,
Yes, the reload "hack" I posted is the only method for v6.1.x. I haven't looked to see how this works in v7 yet but hopefully there might be something nicer....
Jeavon
is working on a reply...