I have a requirement to provide read-only access to member data and I have almost achieved this apart from one key property, the email address!
I have achieved most of what I need so far by using interceptors to replace the view urls with my own which reference my own controllers which extend the core ones rather than duplicating them. A simplified example as follows:
angular.module('umbraco.services').config([
'$httpProvider',
function($httpProvider) {
$httpProvider.interceptors.push([
'$q', '$injector', 'notificationsService', function($q, $injector, notificationsService) {
return {
'request': function(request) {
// Redirect any requests to built in property editor and instead redirect to our own
if (request.url.indexOf("views/propertyeditors/textbox/textbox.html") === 0) {
request.url = '/App_Plugins/MyPlugin/PropertyEditors/securetextbox.html';
}
return request || $q.when(request);
}
};
}
]);
}
]);
This is an achievement in itself for me as I am no Angular expert! However, I am now at a roadblock with the email property as it using directive and unlike the other views which allow me to reference my own controller, I don't seem to have that luxury with a directive.
Can anyone offer some advice or potential solutions on how to tackle this, please?
Wow, thanks Dave - How did I not know about this before now!? Looks exactly the sort of thing I need so will have a play with it and mark your answer as the solution if successful.
I have one additional question relating to this implementation of making the fields read-only. Is it also possible to disable the save button in this scenario? In my case I have a few custom property editors on the member and so making the fields read-only means the value displayed to users in some cases makes no sense as it just raw data. As such I am converting the value before rendering the read-only version however if the user clicks save in the read-only view they end up saving the converted data and losing the original value(s).
Edit: I know I could cancel the save event but I would prefer not to even present the option in the first place.
Intercepting a Core Directive in Angular
I have a requirement to provide read-only access to member data and I have almost achieved this apart from one key property, the email address!
I have achieved most of what I need so far by using interceptors to replace the view urls with my own which reference my own controllers which extend the core ones rather than duplicating them. A simplified example as follows:
Any my custom controller as follows:
This is an achievement in itself for me as I am no Angular expert! However, I am now at a roadblock with the email property as it using directive and unlike the other views which allow me to reference my own controller, I don't seem to have that luxury with a directive.
Can anyone offer some advice or potential solutions on how to tackle this, please?
Hi Simon,
I thinks this can be done easier without any angular hacking (I know i am partially responsible for this because of my skrift article :-D )
Have a look at the editor model events : https://our.umbraco.com/documentation/Reference/Events/EditorModel-Events/
They can be used for members as well.
Have a look here on how I make properties ready for content items : https://github.com/dawoe/umbraco-journey-into-the-unknown/blob/master/App_Code/EditorModelEvents.cs#L87
In this example a field is only editable for admins. All other users will see it as readonly
The same can be done for members.
Dave
Wow, thanks Dave - How did I not know about this before now!? Looks exactly the sort of thing I need so will have a play with it and mark your answer as the solution if successful.
I owe you a beer or two for sure by now :)
This works perfectly thanks. I'm so glad you have drawn my attention to this as I can see it being immensely useful in so many other projects!
I have one additional question relating to this implementation of making the fields read-only. Is it also possible to disable the save button in this scenario? In my case I have a few custom property editors on the member and so making the fields read-only means the value displayed to users in some cases makes no sense as it just raw data. As such I am converting the value before rendering the read-only version however if the user clicks save in the read-only view they end up saving the converted data and losing the original value(s).
Edit: I know I could cancel the save event but I would prefer not to even present the option in the first place.
Will try see if it is possible. Feel free to send me a reminder if I forget.
Dave
is working on a reply...