Skip to content

Commit 08112c2

Browse files
committed
DOC-3309_2: Update full-feature demo to include initial comments, and include tinycomments_can_resolve callback.
1 parent ace4f11 commit 08112c2

File tree

3 files changed

+58
-33
lines changed

3 files changed

+58
-33
lines changed

modules/ROOT/examples/live-demos/full-featured/example.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const collaborator_id = 'mia-andersson';
99
const now = new Date();
1010
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString();
1111
const anhourago = new Date(now.getTime() - 60 * 60 * 1000).toISOString();
12+
const oneminuteago = new Date(now.getTime() - 1 * 60 * 1000).toISOString();
13+
const amomentago = new Date(now.getTime() - 30 * 1000).toISOString();
1214
const fakeDelay = 200;
1315

1416
const randomString = () => {
@@ -23,29 +25,29 @@ const conversationDb = {
2325
author: user_id,
2426
authorName: 'James Wilson',
2527
authorAvatar: 'https://sneak-preview.tiny.cloud/demouserdirectory/images/employee_james-wilson_128_52f19412.jpg',
26-
content: `What do you think about this? @${collaborator_id}?`,
27-
createdAt: yesterday,
28-
modifiedAt: yesterday
28+
content: 'Do we want to say "rich text editor" or "WYSIWYG editor" here?',
29+
createdAt: oneminuteago,
30+
modifiedAt: oneminuteago
2931
}, {
3032
uid: 'mce-conversation_19679600221621399703917',
3133
author: collaborator_id,
3234
authorName: 'Mia Andersson',
3335
authorAvatar: 'https://sneak-preview.tiny.cloud/demouserdirectory/images/employee_mia-andersson_128_e6f9424b.jpg',
34-
content: `I think this is a great idea @${user_id}!`,
35-
createdAt: anhourago,
36-
modifiedAt: anhourago,
36+
content: 'I think "rich text editor" works ok.',
37+
createdAt: amomentago,
38+
modifiedAt: amomentago,
3739
}]
3840
},
3941
'mce-conversation_420304606321716900864126': {
4042
uid: 'mce-conversation_420304606321716900864126',
4143
comments: [{
4244
uid: 'mce-conversation_420304606321716900864126',
43-
author: collaborator_id,
44-
authorName: 'Mia Andersson',
45-
authorAvatar: 'https://sneak-preview.tiny.cloud/demouserdirectory/images/employee_mia-andersson_128_e6f9424b.jpg',
46-
content: `@${user_id} Please revise this sentence, exclamation points are unprofessional!`,
47-
createdAt: yesterday,
48-
modifiedAt: anhourago
45+
author: user_id,
46+
authorName: 'James Wilson',
47+
authorAvatar: 'https://sneak-preview.tiny.cloud/demouserdirectory/images/employee_james-wilson_128_52f19412.jpg',
48+
content: 'Let\'s mention Export to PDF here as well.',
49+
createdAt: oneminuteago,
50+
modifiedAt: oneminuteago
4951
}]
5052
}
5153
};
@@ -140,11 +142,12 @@ const tinycomments_reply = (req, done) => {
140142
};
141143

142144
const tinycomments_delete = (req, done) => {
143-
if (user_id === collaborator_id) { // Replace wth your own logic, e.g. check if user created the conversation
145+
const conversation = conversationDb[req.conversationUid];
146+
if (user_id === conversation.comments[0].author) { // Replace wth your own logic, e.g. check if user created the conversation
144147
delete conversationDb[req.conversationUid];
145148
setTimeout(() => done({ canDelete: true }), fakeDelay);
146149
} else {
147-
setTimeout(() => done({ canDelete: false, reason: 'Must be admin user' }), fakeDelay);
150+
setTimeout(() => done({ canDelete: false, reason: 'Must be conversation author' }), fakeDelay);
148151
}
149152
};
150153

@@ -158,6 +161,15 @@ const tinycomments_resolve = (req, done) => {
158161
}
159162
};
160163

164+
const tinycomments_can_resolve = (req, done, fail) => {
165+
const conversation = conversationDb[req.conversationUid];
166+
if (user_id === conversation.comments[0].author) { // Replace wth your own logic, e.g. check if user has admin priveleges
167+
setTimeout(() => done({ canResolve: true }), fakeDelay);
168+
} else {
169+
setTimeout(() => done({ canResolve: false, reason: 'Must be conversation author' }), fakeDelay);
170+
}
171+
};
172+
161173
const tinycomments_delete_comment = (req, done) => {
162174
const oldcomments = conversationDb[req.conversationUid].comments;
163175
let reason = 'Comment not found';
@@ -616,7 +628,7 @@ tinymce.init({
616628
],
617629
importcss_append: true,
618630
height: 600,
619-
quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quicktable',
631+
quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quicktable | addcomment showcomments',
620632
noneditable_class: 'mceNonEditable',
621633
toolbar_mode: 'sliding',
622634
spellchecker_ignore_list: ['Ephox', 'Moxiecode', 'tinymce', 'TinyMCE'],
@@ -633,6 +645,7 @@ tinymce.init({
633645
tinycomments_reply,
634646
tinycomments_delete,
635647
tinycomments_resolve,
648+
tinycomments_can_resolve,
636649
tinycomments_delete_all,
637650
tinycomments_lookup,
638651
tinycomments_delete_comment,

modules/ROOT/examples/live-demos/full-featured/index.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<textarea id="full-featured">
2-
<p>&nbsp;</p>
32
<h1 style="text-align: left;">Welcome to the TinyMCE editor demo!</h1>
4-
<p>Meet <strong>TinyMCE, </strong>the Internet's most&nbsp;<span style="background-color: #eccafa;">battle-tested rich text editor</span> with over 60 features including: <em>Advanced formatting, </em><span style="color: #ba372a;"><strong><em>Export to and from Word and PDF, </em></strong></span><span style="font-family: 'times new roman', times, serif; font-size: 14pt;">Accessibility and spelling checkers</span>,&nbsp;Mentions and comments, and <strong><span style="color: #169179;">an AI assistant</span></strong>.</p>
3+
<p>Meet <strong>TinyMCE, </strong>the Internet's most&nbsp;<span style="background-color: #eccafa;">battle-tested <span class="mce-annotation tox-comment" data-mce-annotation-uid="mce-conversation_19679600221621399703915" data-mce-annotation="tinycomments">rich text editor</span></span> with over 60 features including: <em>Advanced formatting, </em><span style="color: #ba372a;"><strong><em>Export to and from Word and PDF, </em></strong></span><span style="font-family: 'times new roman', times, serif; font-size: 14pt;">Accessibility and spelling checkers</span>,&nbsp;Mentions and comments, and <strong><span style="color: #169179;">an AI assistant</span></strong>.</p>
54
<p><span style="font-family: terminal, monaco, monospace;">TinyMCE is easy to implement and configure</span>. <a href="https://www.tiny.cloud/auth/signup/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">Try it out yourself today</a>.</p>
65
<h2>⭐️ Popular features</h2>
76
<ul>
87
<li>Collaborate with <a href="https://www.tiny.cloud/docs/tinymce/latest/mentions/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">@Mentions</a>, <a href="https://www.tiny.cloud/docs/tinymce/latest/introduction-to-tiny-comments/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">discuss using Comments</a> and review changes using <a href="https://www.tiny.cloud/docs/tinymce/latest/suggestededits/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">Suggested Edits</a> and keep an audit trail with <a href="https://www.tiny.cloud/docs/tinymce/latest/revisionhistory/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">Revision history</a>.</li>
9-
<li><a href="https://www.tiny.cloud/docs/tinymce/latest/introduction-to-powerpaste/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">Paste from MS Word</a> and retain formatting. You can even <a href="https://www.tiny.cloud/docs/tinymce/latest/importword/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">import Word documents</a>!&nbsp;</li>
8+
<li><span class="mce-annotation tox-comment" data-mce-annotation-uid="mce-conversation_420304606321716900864126" data-mce-annotation="tinycomments"><a href="https://www.tiny.cloud/docs/tinymce/latest/introduction-to-powerpaste/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">Paste from MS Word</a> and retain formatting. You can even <a href="https://www.tiny.cloud/docs/tinymce/latest/importword/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">import Word documents</a>!</span>&nbsp;</li>
109
<li>Power your email editor with <a href="https://www.tiny.cloud/docs/tinymce/latest/mergetags/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">Merge tags</a> and <a href="https://www.tiny.cloud/docs/tinymce/latest/inline-css/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">Inline CSS output</a>.</li>
1110
<li>Hit the highest standards with <a href="https://www.tiny.cloud/docs/tinymce/latest/introduction-to-tiny-spellchecker/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">Spell Checker</a>, <a href="https://www.tiny.cloud/docs/tinymce/latest/a11ychecker/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">Accessibility Checker</a>, <a href="https://www.tiny.cloud/docs/tinymce/latest/advanced-typography/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">Advanced Typography</a> and <a href="https://www.tiny.cloud/docs/tinymce/latest/linkchecker/?utm_campaign=tiny_docs&amp;utm_source=site&amp;keyword=docs">Link Checker</a>.</li>
1211
</ul>

modules/ROOT/examples/live-demos/full-featured/index.js

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const collaborator_id = 'mia-andersson';
99
const now = new Date();
1010
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString();
1111
const anhourago = new Date(now.getTime() - 60 * 60 * 1000).toISOString();
12+
const oneminuteago = new Date(now.getTime() - 1 * 60 * 1000).toISOString();
13+
const amomentago = new Date(now.getTime() - 30 * 1000).toISOString();
1214
const fakeDelay = 200;
1315

1416
const randomString = () => {
@@ -23,29 +25,29 @@ const conversationDb = {
2325
author: user_id,
2426
authorName: 'James Wilson',
2527
authorAvatar: 'https://sneak-preview.tiny.cloud/demouserdirectory/images/employee_james-wilson_128_52f19412.jpg',
26-
content: `What do you think about this? @${collaborator_id}?`,
27-
createdAt: yesterday,
28-
modifiedAt: yesterday
28+
content: 'Do we want to say "rich text editor" or "WYSIWYG editor" here?',
29+
createdAt: oneminuteago,
30+
modifiedAt: oneminuteago
2931
}, {
3032
uid: 'mce-conversation_19679600221621399703917',
3133
author: collaborator_id,
3234
authorName: 'Mia Andersson',
3335
authorAvatar: 'https://sneak-preview.tiny.cloud/demouserdirectory/images/employee_mia-andersson_128_e6f9424b.jpg',
34-
content: `I think this is a great idea @${user_id}!`,
35-
createdAt: anhourago,
36-
modifiedAt: anhourago,
36+
content: 'I think "rich text editor" works ok.',
37+
createdAt: amomentago,
38+
modifiedAt: amomentago,
3739
}]
3840
},
3941
'mce-conversation_420304606321716900864126': {
4042
uid: 'mce-conversation_420304606321716900864126',
4143
comments: [{
4244
uid: 'mce-conversation_420304606321716900864126',
43-
author: collaborator_id,
44-
authorName: 'Mia Andersson',
45-
authorAvatar: 'https://sneak-preview.tiny.cloud/demouserdirectory/images/employee_mia-andersson_128_e6f9424b.jpg',
46-
content: `@${user_id} Please revise this sentence, exclamation points are unprofessional!`,
47-
createdAt: yesterday,
48-
modifiedAt: anhourago
45+
author: user_id,
46+
authorName: 'James Wilson',
47+
authorAvatar: 'https://sneak-preview.tiny.cloud/demouserdirectory/images/employee_james-wilson_128_52f19412.jpg',
48+
content: 'Let\'s mention Export to PDF here as well.',
49+
createdAt: oneminuteago,
50+
modifiedAt: oneminuteago
4951
}]
5052
}
5153
};
@@ -140,11 +142,12 @@ const tinycomments_reply = (req, done) => {
140142
};
141143

142144
const tinycomments_delete = (req, done) => {
143-
if (user_id === collaborator_id) { // Replace wth your own logic, e.g. check if user created the conversation
145+
const conversation = conversationDb[req.conversationUid];
146+
if (user_id === conversation.comments[0].author) { // Replace wth your own logic, e.g. check if user created the conversation
144147
delete conversationDb[req.conversationUid];
145148
setTimeout(() => done({ canDelete: true }), fakeDelay);
146149
} else {
147-
setTimeout(() => done({ canDelete: false, reason: 'Must be admin user' }), fakeDelay);
150+
setTimeout(() => done({ canDelete: false, reason: 'Must be conversation author' }), fakeDelay);
148151
}
149152
};
150153

@@ -158,6 +161,15 @@ const tinycomments_resolve = (req, done) => {
158161
}
159162
};
160163

164+
const tinycomments_can_resolve = (req, done, fail) => {
165+
const conversation = conversationDb[req.conversationUid];
166+
if (user_id === conversation.comments[0].author) { // Replace wth your own logic, e.g. check if user has admin priveleges
167+
setTimeout(() => done({ canResolve: true }), fakeDelay);
168+
} else {
169+
setTimeout(() => done({ canResolve: false, reason: 'Must be conversation author' }), fakeDelay);
170+
}
171+
};
172+
161173
const tinycomments_delete_comment = (req, done) => {
162174
const oldcomments = conversationDb[req.conversationUid].comments;
163175
let reason = 'Comment not found';
@@ -601,7 +613,7 @@ tinymce.init({
601613
],
602614
importcss_append: true,
603615
height: 600,
604-
quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quicktable',
616+
quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quicktable | addcomment showcomments',
605617
noneditable_class: 'mceNonEditable',
606618
toolbar_mode: 'sliding',
607619
spellchecker_ignore_list: ['Ephox', 'Moxiecode', 'tinymce', 'TinyMCE'],
@@ -618,6 +630,7 @@ tinymce.init({
618630
tinycomments_reply,
619631
tinycomments_delete,
620632
tinycomments_resolve,
633+
tinycomments_can_resolve,
621634
tinycomments_delete_all,
622635
tinycomments_lookup,
623636
tinycomments_delete_comment,

0 commit comments

Comments
 (0)