|
3 | 3 | |Name |Arguments |Description |
4 | 4 |
|
5 | 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. |
| 6 | +|setModel |xref:#trackeddocument[TrackedDocument] `+Object+` | Set the current model of the document. |
7 | 7 | //|resetModel |N/A |Reset the document to its original state. |
8 | 8 | |hasChanges |N/A |Return a boolean value indicating whether the document contains changes to be reviewed. |
9 | 9 | |=== |
|
14 | 14 | // Get the current model of the document |
15 | 15 | tinymce.activeEditor.plugins.suggestededits.getModel(); |
16 | 16 |
|
| 17 | +// Set current model of the document |
| 18 | +tinymce.activeEditor.plugins.suggestededits.setModel(model); |
| 19 | +
|
17 | 20 | // Check if document contains changes to be reviewed |
18 | 21 | tinymce.activeEditor.plugins.suggestededits.hasChanges(); |
19 | 22 | ---- |
20 | 23 |
|
| 24 | +[[get_model]] |
| 25 | +.`getModel` Example |
| 26 | +[source,js] |
| 27 | +---- |
| 28 | +const documentId = '<YOUR_DOCUMENT_ID>'; // Replace with the actual document ID |
| 29 | +
|
| 30 | +tinymce.init({ |
| 31 | + selector: 'textarea#suggestededits', // change this value according to your HTML |
| 32 | + plugins: 'suggestededits', |
| 33 | + toolbar: 'suggestededits save', |
| 34 | + suggestededits_model, |
| 35 | + setup: (editor) => { |
| 36 | + editor.ui.registry.addButton('save', { |
| 37 | + text: 'Save', |
| 38 | + onAction: () => { |
| 39 | + // Get the current content of the editor |
| 40 | + const content = editor.getContent(); |
| 41 | +
|
| 42 | + // Get the current model of the document |
| 43 | + const model = editor.plugins.suggestededits.getModel(); |
| 44 | + |
| 45 | + fetch(`/api/documents/${documentId}`, { |
| 46 | + method: 'POST', |
| 47 | + headers: { |
| 48 | + 'Content-Type': 'application/json', |
| 49 | + }, |
| 50 | + body: JSON.stringify({ content, model }), |
| 51 | + }) |
| 52 | + .then((response) => response.json()) |
| 53 | + .then((data) => console.log('Document saved:', data)) |
| 54 | + .catch((error) => console.error('Error saving document:', error)); |
| 55 | +
|
| 56 | + // Save the model to the server |
| 57 | + fetch(`/api/models/${documentId}`, { |
| 58 | + method: 'POST', |
| 59 | + headers: { |
| 60 | + 'Content-Type': 'application/json', |
| 61 | + }, |
| 62 | + body: JSON.stringify(model), |
| 63 | + }) |
| 64 | + .then((response) => response.json()) |
| 65 | + .then((data) => console.log('Model saved:', data)) |
| 66 | + .catch((error) => console.error('Error saving model:', error)); |
| 67 | + } |
| 68 | + }); |
| 69 | + } |
| 70 | +}); |
| 71 | +
|
| 72 | +---- |
| 73 | + |
| 74 | +[[set_model]] |
| 75 | +.`setModel` Example |
| 76 | +[source,js] |
| 77 | +---- |
| 78 | +const documentId = '<YOUR_DOCUMENT_ID>'; // Replace with the actual document ID |
| 79 | +
|
| 80 | +tinymce.init({ |
| 81 | + selector: 'textarea#suggestededits', // change this value according to your HTML |
| 82 | + plugins: 'suggestededits', |
| 83 | + 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)); |
| 102 | + } |
| 103 | +}); |
| 104 | +---- |
| 105 | + |
| 106 | +[[has_changes]] |
| 107 | +.`hasChanges` Example |
| 108 | +[source,js] |
| 109 | +---- |
| 110 | +tinymce.init({ |
| 111 | + selector: 'textarea#suggestededits', // change this value according to your HTML |
| 112 | + plugins: 'suggestededits', |
| 113 | + toolbar: 'suggestededits', |
| 114 | + setup: (editor) => { |
| 115 | + editor.ui.registry.addButton('save', { |
| 116 | + text: 'Save', |
| 117 | + onAction: () => { |
| 118 | + // Get the current model of the document |
| 119 | + const hasChanges = editor.plugins.suggestededits.hasChanges(); |
| 120 | + |
| 121 | + if (hasChanges) { |
| 122 | + editor.notificationManager.open({ |
| 123 | + text: 'There are changes to be reviewed.', |
| 124 | + type: 'warning', |
| 125 | + timeout: 5000, |
| 126 | + }); |
| 127 | + } else { |
| 128 | + // Insert save logic here |
| 129 | + } |
| 130 | + } |
| 131 | + }); |
| 132 | + } |
| 133 | +}); |
| 134 | +---- |
21 | 135 | //// |
22 | 136 | .Examples |
23 | 137 | [source,js] |
|
0 commit comments