Hi
I found a skrift article by Dave W that has been really useful so far. I've been able to intercept the preview button in the back office but I'm now have a question which I hope someone can help with as my angular knowledge is rubbish.
I need to only interept the preview button if I'm using a specific document type and if that matches,I want to make a get request to a controller that I have which creates a pdf on the fly.
Just now if I call the pdf via a URL, it works so all I need is for the preview button to also load that pdf.
The issue I have is, on the front end, the only way you can generate a PDF is by going through a number of steps, which creates a JSON object and that is then parsed in to the PDF.
When in the backoffice, these steps haven't been carried out and so the JSON object is empty. What I've done is if /umbraco/surface/pdfgenerator/prewiewpdf is hit, then I put my own json in and the PDF works fine.
The other issue is, the PDF is made up of content from the CMS and content that is within a view. It's hard to explain but basically, I find a node in the backoffice by xpath and I take all the content from that node and pass it to a seperate view. That seperate view now has the CMS'd and non CMS'd content in it but when pressing preview, it doesn't go through that journey as it's only trying to display the node I'm on.
So when I hit /umbraco/surface/pdfgenerator/prewiewpdf that journey is executed.
Not sure what the preview url looks like but shouldn't it contain the ID of the page? With that you could fetch the whole info about it and check the document type. Then call your controller or switch the url.
I'm actually rebuilding this in U8 so can try a couple of options. Yes the URL does have the id of the page, my issue is lack of knowledge on how to do any of this in angular.
By the sounds of it, it is possible, which is good but if anyone can guide me on how to progress this, I'd really appreciate it.
As I said, I've been having some success by using the skrift article i.e I can get the URL from the preview button but that's about it so far.
I think the issue is I don't want to preview anything in the backoffice within the usual preview screen. I want to actually hit my PDF generator controller when I click the Preview button. This will then actually generate the PDF and download for the user. To do this, unless Im mistaken, I need to use angular to highjack the preview button
Custom action on preview button
Hi I found a skrift article by Dave W that has been really useful so far. I've been able to intercept the preview button in the back office but I'm now have a question which I hope someone can help with as my angular knowledge is rubbish.
Firstly the article is: https://skrift.io/articles/archive/changing-backoffice-functionality-without-changing-core-code/
I need to only interept the preview button if I'm using a specific document type and if that matches,I want to make a get request to a controller that I have which creates a pdf on the fly.
Just now if I call the pdf via a URL, it works so all I need is for the preview button to also load that pdf.
Can anyone help?
Thanks
Hi there,
Why not use the documents templates CSHTML file, and have that respond with a PDF stream?
The issue I have is, on the front end, the only way you can generate a PDF is by going through a number of steps, which creates a JSON object and that is then parsed in to the PDF. When in the backoffice, these steps haven't been carried out and so the JSON object is empty. What I've done is if
/umbraco/surface/pdfgenerator/prewiewpdf
is hit, then I put my own json in and the PDF works fine.The other issue is, the PDF is made up of content from the CMS and content that is within a view. It's hard to explain but basically, I find a node in the backoffice by xpath and I take all the content from that node and pass it to a seperate view. That seperate view now has the CMS'd and non CMS'd content in it but when pressing preview, it doesn't go through that journey as it's only trying to display the node I'm on.
So when I hit
/umbraco/surface/pdfgenerator/prewiewpdf
that journey is executed.Does that make sense?
Hi Owain,
Yes it kind of does.
You can do all the same logic from your view file or a render controller, that is done in your current surface controller.
You can also call your surface method by creating a new instance of the controller inside your view og render controller.
What I do in these cases, is creating a new class which does all the business logic. Controllers should have no business logic.
Construct the new class with dependency injcection for umbraco 8. And using a normal construct for umbraco 7.
But if you are not up for the refractor. I would recommend you simply redirect from view to surface controller.
That should work without issues.
Then the normal preview function should be fine.
Hi Owain,
Not sure what the preview url looks like but shouldn't it contain the ID of the page? With that you could fetch the whole info about it and check the document type. Then call your controller or switch the url.
I'm actually rebuilding this in U8 so can try a couple of options. Yes the URL does have the id of the page, my issue is lack of knowledge on how to do any of this in angular.
By the sounds of it, it is possible, which is good but if anyone can guide me on how to progress this, I'd really appreciate it.
As I said, I've been having some success by using the skrift article i.e I can get the URL from the preview button but that's about it so far.
Hi Owain, I'm confused why you want to do it with angular?
I would recommend doing it using C#
I think the issue is I don't want to preview anything in the backoffice within the usual preview screen. I want to actually hit my PDF generator controller when I click the Preview button. This will then actually generate the PDF and download for the user. To do this, unless Im mistaken, I need to use angular to highjack the preview button
That makes sense, in that case I would use a httpmodule, to hijack the request, and then return your custom PDF stream response.
Our use your current angular and just link to your controller on click?
If I can make some time today I will try if I can come up with something; if nobody else is faster ;)
That would be a massive help David, thank you
Hi Owain,
I had a look and I'm not sure if it is possible to do it in angular. The preview button opens a new windows and then set's the url.
Maybe it is easier to do a HttpModule or so to listen to the url.
I'll see if I can get another chance to have a look at this. Been a bit busy on another project for the past week :)
Hi Owain,
Did you managed to get a solution for this?
Hi Mathew Wow, this was a file ago, I can't even remember what I was trying to do. I think we gave up in the end. Sorry that's not very useful.
O.
Hi Owain,
Thanks for your response :)
I have been looking to give a custom url for preview. Do you think I have to stop here and look for any other work-around? :'(
is working on a reply...