This is step 3 in the Property Editor tutorial. In this part, we will integrate one of the built-in Umbraco Services. For this sample, we will use the notificationsService
to show a dialog with a custom view when you click in a textbox. The dialog will appear if the content is longer than 35 characters.
First up, we need to get access to the service. This is done in the suggestion.controller.js
, where we add it as a parameter:
To hook the service with the textbox, we will use the add
method of the notificationsService. This will be used to render our own view by setting the view property. We will also pass an args
object which contains the Property Value and a callback function that we are going to call from our notification.
The callback is used to return data to the editor.
Now that we have access to the editor events, we will trim the text to a length of 35.
Now let's edit the getSuggestion
method to call showNotification
on clicking Get Suggestions
button.
At this point your controller should look like this:
suggestion.html
package.manifest
We will add 2 files to the /App_Plugins/Suggestions/
folder:
notification.html
notification.controller.js
In the notification.html
, we'll add:
In the notification.controller.js
we will add:
Restart the application and either enter a suggestion longer than 35 characters or click on the Get Suggestions
button. When you do so and click in the textarea, you will be presented with a notification like this:
The notification object contains the args
object that we passed to the view in our suggestion.controller.js
. When we click the Yes
button in the notification, we use the callback function from the Suggestions controller. This function is executed in the scope of our Suggestions Property Editor.
Over the 3 previous steps, we have:
Created a plugin.
Defined an editor.
Registered the Data Type in Umbraco.
Added a $scope
object to pass information from the controller to the view.
Added configuration to the Property Editor.
Connected the editor with the Notification Service.
Looked at the notification dialog in action.