Skip to content

Commit dfadc29

Browse files
committed
DOC-3246: Improve API examples
1 parent 129183b commit dfadc29

File tree

2 files changed

+49
-54
lines changed

2 files changed

+49
-54
lines changed

modules/ROOT/partials/index-pages/premium-plugins.adoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ a|
181181
[.lead]
182182
xref:suggestededits.adoc[Suggested Edits]
183183

184-
Review document changes by multiple users.
184+
Collaborate with multiple users on a document by drafting edits, providing feedback, and reviewing suggestions.
185185

186186
a|
187187
[.lead]
@@ -209,4 +209,3 @@ Cloud-based file and image management for {productname}.
209209
// when the number of cells in the table is even.
210210
a|
211211
|===
212-
Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[cols="1,1,4",options="header"]
22
|===
33
|Name |Arguments |Description
4-
5-
|getModel |N/A |Returns a JSON object representing the document model and all suggested edits.
6-
|setModel | `+Object+` | Sets the current model of the document.
7-
//|resetModel |N/A |Resets the document to its original state.
8-
|hasChanges |N/A |Returns a boolean value indicating whether the document contains any suggested edits.
4+
|getModel |N/A |Returns a JSON object representing the current model of the document.
5+
|setModel | `+Object+` | Sets the current model of the document.
6+
|resetModel |N/A |Generates a model from the current content and sets it as the current model, clearing all suggestions.
7+
|hasChanges |N/A |Returns a boolean value indicating whether the document contains any suggested edits.
98
|===
109

11-
.Examples
10+
== Examples
11+
1212
[source,js]
1313
----
1414
// Get the current model of the document
@@ -17,18 +17,20 @@ tinymce.activeEditor.plugins.suggestededits.getModel();
1717
// Set current model of the document
1818
tinymce.activeEditor.plugins.suggestededits.setModel(model);
1919
20+
// Reset the model to the current content, clearing all suggestions
21+
tinymce.activeEditor.plugins.suggestededits.resetModel();
22+
2023
// Check if document contains changes to be reviewed
2124
tinymce.activeEditor.plugins.suggestededits.hasChanges();
2225
----
2326

2427
[[get_model]]
25-
== `getModel`
28+
== `getModel` Example
29+
30+
This example demonstrates how to submit the current document and model to a server, to ensure they are saved synchronously. The current model is retrieved using the `getModel` API.
2631

27-
.Example
2832
[source,js]
2933
----
30-
const documentId = '<YOUR_DOCUMENT_ID>'; // Replace with your document ID
31-
3234
tinymce.init({
3335
selector: 'textarea#suggestededits', // change this value according to your HTML
3436
plugins: 'suggestededits',
@@ -49,7 +51,7 @@ tinymce.init({
4951
headers: {
5052
'Content-Type': 'application/json',
5153
},
52-
body: JSON.stringify({ content, model }),
54+
body: content,
5355
})
5456
.then((response) => response.json())
5557
.then((data) => console.log('Document saved:', data))
@@ -74,53 +76,64 @@ tinymce.init({
7476
----
7577

7678
[[set_model]]
77-
== `setModel`
79+
== `setModel` Example
80+
81+
This example demonstrates how to set the model and the document in the editor, after fetching them from a server. The `setModel` method sets the current model of the document and the editor content, as generated from that model.
7882

79-
.Example
8083
[source,js]
8184
----
82-
const documentIds = ['doc1', 'doc2', 'doc3']; // Example document IDs
83-
8485
tinymce.init({
8586
selector: 'textarea#suggestededits', // change this value according to your HTML
8687
plugins: 'suggestededits',
8788
toolbar: 'suggestededits',
8889
setup: (editor) => {
89-
// Function to load a document and its model
90-
function loadDocument(documentId) {
91-
// Fetch and set the document content
92-
fetch(`/api/documents/${documentId}`)
93-
.then((response) => response.text())
94-
.then((content) => {
95-
editor.setContent(content);
96-
})
97-
.catch((error) => console.error(`Error fetching document ${documentId}:`, error));
98-
90+
editor.on('init', () => {
9991
// Fetch and set the suggested edits model
10092
fetch(`/api/models/${documentId}`)
10193
.then((response) => response.json())
10294
.then((model) => {
10395
editor.plugins.suggestededits.setModel(model);
10496
})
10597
.catch((error) => console.error(`Error fetching model for ${documentId}:`, error));
106-
}
107-
108-
// Example: Attach to a button click event
109-
document.getElementById('loadDocBtn').addEventListener('click', () => {
110-
const selectedId = document.getElementById('docSelect').value;
111-
loadDocument(selectedId);
11298
});
99+
}
100+
});
101+
----
102+
103+
[[reset_model]]
104+
== `resetModel` Example
113105

114-
// Optionally, load the first document on init
115-
loadDocument(documentIds[0]);
106+
This example demonstrates how to reset the model to the current content of the editor, clearing all suggestions. The `resetModel` method generates a new model from the current content and sets it as the current model.
107+
108+
[source,js]
109+
----
110+
tinymce.init({
111+
selector: 'textarea#suggestededits', // change this value according to your HTML
112+
plugins: 'suggestededits',
113+
toolbar: 'suggestededits clearsuggestions',
114+
setup: (editor) => {
115+
editor.ui.registry.addButton('clearsuggestions', {
116+
text: 'Clear Suggestions',
117+
onAction: () => {
118+
// Reset the model to the current content, clearing all suggestions
119+
editor.plugins.suggestededits.resetModel();
120+
121+
editor.notificationManager.open({
122+
text: 'All suggestions have been cleared.',
123+
type: 'info',
124+
timeout: 5000,
125+
});
126+
}
127+
});
116128
}
117129
});
118130
----
119131

120132
[[has_changes]]
121-
==`hasChanges`
133+
== `hasChanges` Example
134+
135+
This example demonstrates how to check if there are any changes in the document that need to be reviewed before saving. The `hasChanges` method is used to determine if there are any unreviewed edits.
122136

123-
.Example
124137
[source,js]
125138
----
126139
tinymce.init({
@@ -148,20 +161,3 @@ tinymce.init({
148161
}
149162
});
150163
----
151-
////
152-
.Examples
153-
[source,js]
154-
----
155-
// Get the current model of the document
156-
tinymce.activeEditor.plugins.suggestededits.getModel();
157-
158-
// Set current model of the document
159-
tinymce.activeEditor.plugins.suggestededits.setModel(model);
160-
161-
// Reset the document model to its original state
162-
tinymce.activeEditor.plugins.suggestededits.resetModel();
163-
164-
// Check if document contains changes to be reviewed
165-
tinymce.activeEditor.plugins.suggestededits.hasChanges();
166-
----
167-
////

0 commit comments

Comments
 (0)