Is there any way to attach to the click event of the 'save and publish' button on the client side. Reason being I need to call off to an external API and do a check before I actually allow the article to be published. I don't want to do this on the server side (through attached to publish event) as I want to show a custom message to the user informing them of why they cannot publish.
You could hook into the rendering process of the edit page using the baseclass for all backend pages. Basiclly you override the reneder method, find the elements that you would like to modify and then adds/chages/removes attributes as needed.
// make sure we stop the content var when either save button is clicked
$('iframe#right').contents().find('input#body_TabView1_tab01layer_save').click(function(){ DO STUFF HERE WHEN 'SAVE' BUTTON CLICKED TO CANCEL 'SAVE' REQUEST, JUST 'RETURN FALSE'; }); $('iframe#right').contents().find('input#body_TabView1_tab01layer_publish').click(function(){ JS CALLS FOR SAVE & PUBLISH CLICK EVENT });
Drew, I was going to take this approach however I realised that I can do the check on the server side in the data type, and if the publish shouldn't go ahead I add a failed custom validator which cancels the publish - plus I get to show a custom error back to the user so met my needs.
I'm going to mark your answer as correct as I need to do some other stuff that has to happen on the client side and this seems to be the only way to do it. I do feel it's a little brittle as if the id's of the elements change in a future version of Umbraco then the data type breaks without warning.
I know its fairly fragile - I tried quite a few different methods to try and make it as flexible as possible, but because the content editing area is inside an iFrame - you need to ue specific ID's :-/
Ideally, its always best to manage events on the server side rather than client side :)
(The JS I've posted is purely for a simple "has anything changed on the form?" feature, which can't rely on server-side controls that require a post-back, as users would have to already have remembered to click 'save' or another button before navigating away :) )
Attaching to 'save and publish' button click
Is there any way to attach to the click event of the 'save and publish' button on the client side. Reason being I need to call off to an external API and do a check before I actually allow the article to be published. I don't want to do this on the server side (through attached to publish event) as I want to show a custom message to the user informing them of why they cannot publish.
You could hook into the rendering process of the edit page using the baseclass for all backend pages. Basiclly you override the reneder method, find the elements that you would like to modify and then adds/chages/removes attributes as needed.
Per Ploug shows this in this Umbraco TV-edpisod
http://umbraco.com/help-and-support/video-tutorials/developing-with-umbraco/events/modify-backend-ui-with-page-events/TVPlayer
Oddly enough, I posted some code that does just what you want a couple of hours before you posted:
http://our.umbraco.org/forum/developers/extending-umbraco/26646-BETA-Prompt-User-To-Save-Content-Changes
Specifically:
// make sure we stop the content var when either save button is clicked
Drew, I was going to take this approach however I realised that I can do the check on the server side in the data type, and if the publish shouldn't go ahead I add a failed custom validator which cancels the publish - plus I get to show a custom error back to the user so met my needs.
I'm going to mark your answer as correct as I need to do some other stuff that has to happen on the client side and this seems to be the only way to do it. I do feel it's a little brittle as if the id's of the elements change in a future version of Umbraco then the data type breaks without warning.
I know its fairly fragile - I tried quite a few different methods to try and make it as flexible as possible, but because the content editing area is inside an iFrame - you need to ue specific ID's :-/
Ideally, its always best to manage events on the server side rather than client side :)
(The JS I've posted is purely for a simple "has anything changed on the form?" feature, which can't rely on server-side controls that require a post-back, as users would have to already have remembered to click 'save' or another button before navigating away :) )
Cheers,
Drew
is working on a reply...