Skip to content

Commit 55b35e4

Browse files
Merge pull request #3755 from syncfusion-content/904164-cmtEvent-CM
904164: Added Comment Event in Core and MVC
2 parents 97cad30 + 31e0563 commit 55b35e4

File tree

6 files changed

+103
-4
lines changed

6 files changed

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

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ Document editor provides an option to protect and unprotect document using `enfo
153153
{% include code-snippet/document-editor-container/comment-only-protect/tagHelper %}
154154
{% endhighlight %}
155155
{% highlight c# tabtitle="Comment-only.cs" %}
156-
{% endhighlight %}{% endtabs %}
156+
{% include code-snippet/document-editor-container/comment-only-protect/document-editor.cs %}
157+
{% endhighlight %}
158+
{% endtabs %}
157159

158160
{% elsif page.publishingplatform == "aspnet-mvc" %}
159161

@@ -162,7 +164,9 @@ Document editor provides an option to protect and unprotect document using `enfo
162164
{% include code-snippet/document-editor-container/comment-only-protect/razor %}
163165
{% endhighlight %}
164166
{% highlight c# tabtitle="Comment-only.cs" %}
165-
{% endhighlight %}{% endtabs %}
167+
{% include code-snippet/document-editor-container/comment-only-protect/document-editor.cs %}
168+
{% endhighlight %}
169+
{% endtabs %}
166170
{% endif %}
167171

168172

@@ -185,7 +189,9 @@ The following example illustrates how to enable mention support in Document Edit
185189
{% include code-snippet/document-editor-container/comments-mention/tagHelper %}
186190
{% endhighlight %}
187191
{% highlight c# tabtitle="comments-mention.cs" %}
188-
{% endhighlight %}{% endtabs %}
192+
{% include code-snippet/document-editor-container/comments-mention/document-editor.cs %}
193+
{% endhighlight %}
194+
{% endtabs %}
189195

190196
{% elsif page.publishingplatform == "aspnet-mvc" %}
191197

@@ -194,5 +200,36 @@ The following example illustrates how to enable mention support in Document Edit
194200
{% include code-snippet/document-editor-container/comments-mention/razor %}
195201
{% endhighlight %}
196202
{% highlight c# tabtitle="comments-mention.cs" %}
197-
{% endhighlight %}{% endtabs %}
203+
{% include code-snippet/document-editor-container/comments-mention/document-editor.cs %}
204+
{% endhighlight %}
205+
{% endtabs %}
206+
{% endif %}
207+
208+
## Events
209+
210+
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.
211+
212+
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:
213+
214+
{% if page.publishingplatform == "aspnet-core" %}
215+
216+
{% tabs %}
217+
{% highlight cshtml tabtitle="CSHTML" %}
218+
{% include code-snippet/document-editor-container/comments-event/tagHelper %}
219+
{% endhighlight %}
220+
{% highlight c# tabtitle="comments-event.cs" %}
221+
{% include code-snippet/document-editor-container/comments-event/document-editor.cs %}
222+
{% endhighlight %}
223+
{% endtabs %}
224+
225+
{% elsif page.publishingplatform == "aspnet-mvc" %}
226+
227+
{% tabs %}
228+
{% highlight razor tabtitle="CSHTML" %}
229+
{% include code-snippet/document-editor-container/comments-event/razor %}
230+
{% endhighlight %}
231+
{% highlight c# tabtitle="comments-event.cs" %}
232+
{% include code-snippet/document-editor-container/comments-event/document-editor.cs %}
233+
{% endhighlight %}
234+
{% endtabs %}
198235
{% endif %}

0 commit comments

Comments
 (0)