For a package I'm developing I need to intercept the click on the unpublish button and display a custom notification to the user, letting them decide if they want to precede with the unpublish.
I have following code that works :
angular.module('umbraco').controller('Interceptor', function ($scope,notificationsService) {
// get scope of content editing form
var contentFormScope = angular.element('form[name=contentForm]').scope();
// function to store old unpublish handler
$scope.oldHanlder = function() {};
// custom unpublish handler to display custom notification
$scope.customUnpublish = function(oldHandler) {
notificationsService.success('intercepted unpublish');
$scope.oldHandler();
};
// function to intercept current unpublish action and replace it with our own
$scope.InterceptUnPublish = function() {
for(var i=0;i<contentFormScope.subButtons.length;i++)
{
console.log(contentFormScope.subButtons[i]);
if(contentFormScope.subButtons[i].labelKey=='content_unPublish') {
$scope.oldHandler = contentFormScope.subButtons[i].handler;
contentFormScope.subButtons[i].handler = $scope.customUnpublish;
}
}
};
// put a watch on the buttons, to trigger the intercepting
contentFormScope.$watch('subButtons', function() {
$scope.InterceptUnPublish();
},true);
});
This is triggered from a property editor.
But I'm looking to find a cleaner solution. Maybe do the interception at a another level. Is this possible ?
I think you can overrinde performAction method from edit.controller.js
You just need to keep reference to original performAction method e.g. like this
angular.module('umbraco').controller('Interceptor', function ($scope,notificationsService) {
// get scope of content editing form
var contentFormScope = angular.element('form[name=contentForm]').scope();
// function to store old unpublish handler
$scope.parentPerformAction = $scope.performAction;
// custom performAction to display custom notification
$scope.performAction= function(btn) {
if (btn.labelKey=='content_unPublish'){
notificationsService.success('intercepted unpublish');
}
$scope.parentPerformAction.call(this,btn);
};
});
I needed to modify your code a little bit to get it to work :
angular.module('umbraco').controller('Interceptor', function ($scope,notificationsService) {
// get scope of content editing form
var contentFormScope = angular.element('form[name=contentForm]').scope();
// function to store old unpublish handler
$scope.parentPerformAction = contentFormScope.performAction;
// custom performAction to display custom notification
contentFormScope.performAction= function(btn) {
if (btn.labelKey=='content_unPublish'){
notificationsService.success('intercepted unpublish');
}
$scope.parentPerformAction.call(this,btn);
};
});
This is a bit cleaner than my code. But what I'm looking for is to intercept it at a higher level. But I think this needs core modifications.
Now I have to create a property to a documenttype to get this to work. But I think it's the only way at the moment,
Intercepting unpublish button click
Hi,
For a package I'm developing I need to intercept the click on the unpublish button and display a custom notification to the user, letting them decide if they want to precede with the unpublish.
I have following code that works :
This is triggered from a property editor.
But I'm looking to find a cleaner solution. Maybe do the interception at a another level. Is this possible ?
Dave
Hi Dave,
I think you can overrinde performAction method from edit.controller.js
You just need to keep reference to original performAction method e.g. like this
Check out simple example I've prepared http://plnkr.co/edit/ekPeQkq2g3b9YnWbWoaZ?p=preview
Cheers
Pawel
Hi Pawel,
I needed to modify your code a little bit to get it to work :
This is a bit cleaner than my code. But what I'm looking for is to intercept it at a higher level. But I think this needs core modifications.
Now I have to create a property to a documenttype to get this to work. But I think it's the only way at the moment,
Dave
Dave, you are right, now it's correct.
I think it would be hard to intercept it on another level, but if you will find any way to do that please post it here :)
Maybe it is possible to override API method and return info that there is confirmation needed, but I'm not sure if it is something you are aiming for.
Cheers!
is working on a reply...