Skip to content

Commit cd51e67

Browse files
author
Sorita Heng
committed
Update option and api examples
1 parent 55674d4 commit cd51e67

File tree

6 files changed

+61
-43
lines changed

6 files changed

+61
-43
lines changed

modules/ROOT/pages/suggestededits.adoc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,14 @@ For example:
8282

8383
[source,js]
8484
----
85-
const suggestededits_model = `<YOUR_DOCUMENT_MODEL>` // model provided by suggestededits plugin API
85+
const suggestededits_model = `<YOUR_DOCUMENT_MODEL>` // model provided by the getModel API
8686
8787
tinymce.init({
8888
selector: 'textarea#suggestededits', // change this value according to your HTML
8989
plugins: 'suggestededits',
9090
toolbar: 'suggestededits',
91-
suggestededits_model, // model provided by suggestededits plugin API
91+
suggestededits_model,
9292
});
93-
94-
<textarea id="suggestededits"><p>Your initial content here </p></textarea>
9593
----
9694

9795
== Options
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
include::partial$configuration/userlookup_userid.adoc[]
2-
include::partial$configuration/userlookup_fetch.adoc[]
1+
include::partial$configuration/userlookup_user_id.adoc[]
2+
include::partial$configuration/userlookup_fetch_users.adoc[]
33
include::partial$configuration/suggestededits_model.adoc[]
44
include::partial$configuration/suggestededits_content.adoc[]
55
include::partial$configuration/suggestededits_access.adoc[]

modules/ROOT/partials/configuration/suggestededits_access.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ tinymce.init({
3838
selector: 'textarea', // Change this value according to your HTML
3939
plugins: 'suggestededits',
4040
toolbar: 'suggestededits',
41-
suggestededits_uid: 'unique-identifier', // replace this with a unique string to identify the user
42-
suggestededits_access: 'full' //change this value to set permission to the Suggested Edits view
41+
user_id: 'unique-identifier', // replace this with a unique string to identify the user
42+
fetch_users, // Function to fetch users for the user lookup API
43+
suggestededits_access: 'full', //change this value to set the user's permission to the Suggested Edits view
4344
readonly: false //set to true to restrict a user's editing permission
4445
});
4546
----

modules/ROOT/partials/configuration/suggestededits_content.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ In either case, if a model is not provided, the plugin will generate a new model
1616

1717
=== Example: using `{plugincode}_content`
1818

19-
// Add a working and tested configuration.
2019
[source,js]
2120
----
2221
tinymce.init({
2322
selector: 'textarea', // Change this value according to your HTML
2423
plugins: 'suggestededits',
2524
toolbar: 'suggestededits',
26-
suggestededits_uid: 'unique-identifier', // replace this with a unique string to identify the user
27-
suggestededits_model,
28-
suggestededits_content: 'model' // change this value to set the content source
25+
user_id: 'unique-identifier', // Replace this with a unique string to identify the user
26+
fetch_users, // Function to fetch users for the user lookup API
27+
suggestededits_model, // Load the saved model into the editor
28+
suggestededits_content: 'model' // Only set this if you want to load the initial content from the model
2929
});
3030
----

modules/ROOT/partials/configuration/suggestededits_model.adoc

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,27 @@
44
The `{plugincode}_model` option sets the initial model of the document to begin tracking changes. It takes as input an object representing the document, containing all edits made to the document up to that point. This model should be saved externally alongside the document, and loaded into the editor each time the document is opened. This will ensure that both the document and the model are in sync, and that the plugin can track edits correctly.
55

66
If the model is not provided in the editor configuration, the plugin will create a new model from the current content of the editor. This model can be retrieved from the editor at any time using the xref:#get_model[`getModel` API].
7-
//*Type:* xref:#trackeddocument[TrackedDocument] `+Object+`
7+
8+
*Type:* `+Object+`
89

910
=== Example: using `{plugincode}_model`
1011

11-
// Add a working and tested configuration.
1212
[source,js]
1313
----
14-
tinymce.init({
15-
selector: 'textarea', // Change this value according to your HTML
16-
plugins: 'suggestededits',
17-
toolbar: 'suggestededits',
18-
suggestededits_uid: 'unique-identifier', // replace this with a unique string to identify the user
19-
suggestededits_model // Model representing the document with up to date edits
14+
async function fetchSavedModel(documentId) {
15+
// Replace this URL and logic with your actual backend API
16+
const response = await fetch(`/api/models/${documentId}`);
17+
return await response.json();
18+
}
19+
20+
fetchSavedModel('your-document-id').then((savedModel) => {
21+
tinymce.init({
22+
selector: 'textarea', // Change this value according to your HTML
23+
plugins: 'suggestededits',
24+
toolbar: 'suggestededits',
25+
user_id: 'unique-identifier', // Replace with a unique string to identify the user
26+
fetch_users, // Function to fetch users for the user lookup API
27+
suggestededits_model: savedModel // Load the saved model into the editor
28+
});
2029
});
2130
----

modules/ROOT/partials/plugin-apis/suggestededits-apis.adoc

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
|===
33
|Name |Arguments |Description
44

5-
|getModel |N/A |Return an object representing the document model used to store data of the tracked changes.
6-
|setModel |xref:#trackeddocument[TrackedDocument] `+Object+` | Set the current model of the document.
5+
|getModel |N/A |Return an object representing the document model used to store data of the suggested edits.
6+
|setModel | `+Object+` | Set the current model of the document.
77
//|resetModel |N/A |Reset the document to its original state.
8-
|hasChanges |N/A |Return a boolean value indicating whether the document contains changes to be reviewed.
8+
|hasChanges |N/A |Return a boolean value indicating whether the document contains edits to be reviewed.
99
|===
1010

1111
.Examples
@@ -25,7 +25,7 @@ tinymce.activeEditor.plugins.suggestededits.hasChanges();
2525
.`getModel` Example
2626
[source,js]
2727
----
28-
const documentId = '<YOUR_DOCUMENT_ID>'; // Replace with the actual document ID
28+
const documentId = '<YOUR_DOCUMENT_ID>'; // Replace with your document ID
2929
3030
tinymce.init({
3131
selector: 'textarea#suggestededits', // change this value according to your HTML
@@ -75,30 +75,40 @@ tinymce.init({
7575
.`setModel` Example
7676
[source,js]
7777
----
78-
const documentId = '<YOUR_DOCUMENT_ID>'; // Replace with the actual document ID
78+
const documentIds = ['doc1', 'doc2', 'doc3']; // Example document IDs
7979
8080
tinymce.init({
8181
selector: 'textarea#suggestededits', // change this value according to your HTML
8282
plugins: 'suggestededits',
8383
toolbar: 'suggestededits',
84-
// No model provided in the editor configuration, it will be fetched from the server
85-
init_instance_callback: (editor) => {
86-
// Fetch the document from the server
87-
fetch(`/api/documents/${documentId}`)
88-
.then((response) => {
89-
// Set the content in the editor
90-
editor.setContent(response);
91-
})
92-
.catch((error) => console.error(`Error fetching document ${documentId}:`, error));
93-
94-
// Fetch the document model from the server
95-
fetch(`/api/models/${documentId}`)
96-
.then((response) => response.json())
97-
.then((model) => {
98-
// Set the model in the editor
99-
editor.plugins.suggestededits.setModel(model);
100-
})
101-
.catch((error) => console.error(`Error fetching document ${documentId} model:`, error));
84+
setup: (editor) => {
85+
// Function to load a document and its model
86+
function loadDocument(documentId) {
87+
// Fetch and set the document content
88+
fetch(`/api/documents/${documentId}`)
89+
.then((response) => response.text())
90+
.then((content) => {
91+
editor.setContent(content);
92+
})
93+
.catch((error) => console.error(`Error fetching document ${documentId}:`, error));
94+
95+
// Fetch and set the suggested edits model
96+
fetch(`/api/models/${documentId}`)
97+
.then((response) => response.json())
98+
.then((model) => {
99+
editor.plugins.suggestededits.setModel(model);
100+
})
101+
.catch((error) => console.error(`Error fetching model for ${documentId}:`, error));
102+
}
103+
104+
// Example: Attach to a button click event
105+
document.getElementById('loadDocBtn').addEventListener('click', () => {
106+
const selectedId = document.getElementById('docSelect').value;
107+
loadDocument(selectedId);
108+
});
109+
110+
// Optionally, load the first document on init
111+
loadDocument(documentIds[0]);
102112
}
103113
});
104114
----

0 commit comments

Comments
 (0)