Skip to content

Commit 5de6684

Browse files
904164: Added Comment Event in Core and MVC
1 parent 70e83a2 commit 5de6684

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@Html.EJS().DocumentEditorContainer("container").EnableToolbar(true).Height("590px").BeforeCommentAction("beforeComment").Render()
2+
<script>
3+
var documenteditor;
4+
var container;
5+
function onCreated() {
6+
var documenteditorElement = document.getElementById('container');
7+
container = documenteditorElement.ej2_instances[0];
8+
documenteditor = container.documentEditor;
9+
let mentionData = [
10+
{ "Name": "Mary Kate", "EmailId": "marry@company.com" },
11+
{ "Name": "Andrew James", "EmailId": "james@company.com" },
12+
{ "Name": "Andrew Fuller", "EmailId": "andrew@company.com" }
13+
];
14+
container.documentEditorSettings.mentionSettings = { dataSource: mentionData, fields: { text: 'Name' } };
15+
container.currentUser = "Guest User";
16+
}
17+
function beforeComment(args) {
18+
if (args.type === "Delete" && container.currentUser !== args.author) {
19+
args.cancel = true;
20+
}
21+
}
22+
</script>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<ejs-documenteditorcontainer id="container" serviceUrl="/api/DocumentEditor/" enableToolbar=true created="onCreated" beforeCommentAction="beforeComment" height="590px"></ejs-documenteditorcontainer>
2+
3+
<script>
4+
var documenteditor;
5+
var container;
6+
function onCreated() {
7+
var documenteditorElement = document.getElementById('container');
8+
container = documenteditorElement.ej2_instances[0];
9+
documenteditor = container.documentEditor;
10+
let mentionData = [
11+
{ "Name": "Mary Kate", "EmailId": "marry@company.com" },
12+
{ "Name": "Andrew James", "EmailId": "james@company.com" },
13+
{ "Name": "Andrew Fuller", "EmailId": "andrew@company.com"}
14+
];
15+
container.documentEditorSettings.mentionSettings = { dataSource: mentionData, fields: { text: 'Name' }};
16+
container.currentUser = "Guest User";
17+
}
18+
function beforeComment(args){
19+
if(args.type === "Delete" && container.currentUser !== args.author){
20+
args.cancel = true;
21+
}
22+
}
23+
</script>

ej2-asp-core-mvc/document-editor/comments.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,28 @@ The following example illustrates how to enable mention support in Document Edit
196196
{% highlight c# tabtitle="comments-mention.cs" %}
197197
{% endhighlight %}{% endtabs %}
198198
{% endif %}
199+
200+
## Events
201+
202+
DocumentEditor provides `beforeCommentAction` event, which is triggered on comment actions like Post, edit, reply, resolve and reopen. This event provides an opportunity to perform custom logic on comment actions like Post, edit, reply, resolve and reopen. The event handler receives the `CommentActionEventArgs` object as an argument, which allows access to information about the comment.
203+
204+
To demonstrate a specific use case, let’s consider an example where we want to restrict the delete functionality based on the author’s name. The following code snippet illustrates how to allow only the author of a comment to delete:
205+
206+
{% if page.publishingplatform == "aspnet-core" %}
207+
208+
{% tabs %}
209+
{% highlight cshtml tabtitle="CSHTML" %}
210+
{% include code-snippet/document-editor-container/comments-event/tagHelper %}
211+
{% endhighlight %}
212+
{% highlight c# tabtitle="comments-event.cs" %}
213+
{% endhighlight %}{% endtabs %}
214+
215+
{% elsif page.publishingplatform == "aspnet-mvc" %}
216+
217+
{% tabs %}
218+
{% highlight razor tabtitle="CSHTML" %}
219+
{% include code-snippet/document-editor-container/comments-event/razor %}
220+
{% endhighlight %}
221+
{% highlight c# tabtitle="comments-event.cs" %}
222+
{% endhighlight %}{% endtabs %}
223+
{% endif %}

0 commit comments

Comments
 (0)