-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC-2513: fix store variable declaration issue, add missing semicolon…
…s and added advtemplate_get_template throw error.
- Loading branch information
1 parent
fe6b9fc
commit 5394480
Showing
2 changed files
with
180 additions
and
210 deletions.
There are no files selected for viewing
223 changes: 97 additions & 126 deletions
223
modules/ROOT/examples/live-demos/advtemplate-readonly-template/example.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,101 @@ | ||
const headers = { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
} | ||
|
||
const handleResponse = (message) => (response) => { | ||
if (!response.ok) { | ||
response.text().then((message) => console.error(message)) | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
const handleResponse = (message) => (response) => { | ||
if (!response.ok) { | ||
return response.text().then((error) => { | ||
console.error(error); | ||
throw new Error(message); | ||
} else { | ||
return response.json(); | ||
} | ||
} | ||
|
||
const advtemplate_list = () => fetch('/categories', { | ||
method: 'GET', | ||
headers, | ||
}) | ||
.then(handleResponse('Failed to get template list')) | ||
|
||
const advtemplate_get_template = (id) => fetch('/templates/' + id, { | ||
method: 'GET', | ||
headers, | ||
}) | ||
.then(handleResponse('Failed to get template')) | ||
|
||
const advtemplate_create_category = (title) => { | ||
return fetch('/categories', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
title | ||
}), | ||
headers, | ||
}) | ||
.then(handleResponse('Failed to create category')) | ||
} | ||
|
||
const advtemplate_create_template = (title, content, categoryId) => { | ||
return fetch('/templates', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
title, | ||
content, | ||
categoryId | ||
}), | ||
headers, | ||
}) | ||
.then(handleResponse('Failed to create template')) | ||
} | ||
|
||
const advtemplate_rename_category = (id, title) => { | ||
return fetch('/categories/' + id, { | ||
method: 'PUT', | ||
body: JSON.stringify({ | ||
title | ||
}), | ||
headers, | ||
}) | ||
.then(handleResponse('Failed to rename category')) | ||
}); | ||
} | ||
|
||
const advtemplate_rename_template = (id, title) => { | ||
return fetch('/templates/' + id, { | ||
method: 'PUT', | ||
body: JSON.stringify({ | ||
title | ||
}), | ||
headers, | ||
}) | ||
.then(handleResponse('Failed to rename template')) | ||
} | ||
|
||
const advtemplate_delete_template = (id) => { | ||
return fetch('/templates/' + id, { | ||
method: 'DELETE', | ||
headers, | ||
}) | ||
.then(handleResponse('Failed to delete template')) | ||
} | ||
|
||
const advtemplate_delete_category = (id) => { | ||
return fetch('/categories/' + id, { | ||
method: 'DELETE', | ||
headers, | ||
}) | ||
.then(handleResponse('Failed to delete category')) | ||
} | ||
const advtemplate_move_template = (id, categoryId) => { | ||
return fetch('/templates/' + id, { | ||
method: 'PATCH', | ||
body: JSON.stringify({ | ||
categoryId | ||
}), | ||
headers, | ||
}) | ||
.then(handleResponse('Failed to move template')) | ||
} | ||
|
||
const advtemplate_move_category_items = (id, categoryId) => { | ||
return fetch('/categories/' + id, { | ||
method: 'PATCH', | ||
body: JSON.stringify({ | ||
categoryId | ||
}), | ||
headers, | ||
}) | ||
.then(handleResponse('Failed to move all templates to new category')) | ||
} | ||
return response.json(); | ||
}; | ||
|
||
const advtemplate_list = () => | ||
fetch('/categories', { | ||
method: 'GET', | ||
headers, | ||
}).then(handleResponse('Failed to get template list')); | ||
|
||
const advtemplate_get_template = (id) => | ||
fetch(`/templates/${id}`, { | ||
method: 'GET', | ||
headers, | ||
}).then(handleResponse('Failed to get template')); | ||
|
||
const advtemplate_create_category = (title) => | ||
fetch('/categories', { | ||
method: 'POST', | ||
body: JSON.stringify({ title }), | ||
headers, | ||
}).then(handleResponse('Failed to create category')); | ||
|
||
const advtemplate_create_template = (title, content, categoryId) => | ||
fetch('/templates', { | ||
method: 'POST', | ||
body: JSON.stringify({ title, content, categoryId }), | ||
headers, | ||
}).then(handleResponse('Failed to create template')); | ||
|
||
const advtemplate_rename_category = (id, title) => | ||
fetch(`/categories/${id}`, { | ||
method: 'PUT', | ||
body: JSON.stringify({ title }), | ||
headers, | ||
}).then(handleResponse('Failed to rename category')); | ||
|
||
const advtemplate_rename_template = (id, title) => | ||
fetch(`/templates/${id}`, { | ||
method: 'PUT', | ||
body: JSON.stringify({ title }), | ||
headers, | ||
}).then(handleResponse('Failed to rename template')); | ||
|
||
const advtemplate_delete_template = (id) => | ||
fetch(`/templates/${id}`, { | ||
method: 'DELETE', | ||
headers, | ||
}).then(handleResponse('Failed to delete template')); | ||
|
||
const advtemplate_delete_category = (id) => | ||
fetch(`/categories/${id}`, { | ||
method: 'DELETE', | ||
headers, | ||
}).then(handleResponse('Failed to delete category')); | ||
|
||
const advtemplate_move_template = (id, categoryId) => | ||
fetch(`/templates/${id}`, { | ||
method: 'PATCH', | ||
body: JSON.stringify({ categoryId }), | ||
headers, | ||
}).then(handleResponse('Failed to move template')); | ||
|
||
const advtemplate_move_category_items = (id, categoryId) => | ||
fetch(`/categories/${id}`, { | ||
method: 'PATCH', | ||
body: JSON.stringify({ categoryId }), | ||
headers, | ||
}).then(handleResponse('Failed to move all templates to new category')); | ||
|
||
tinymce.init({ | ||
selector: "textarea#readonly-locked-template", | ||
plugins: [ | ||
"advlist", "anchor", "autolink", "charmap", "code", "fullscreen", | ||
"help", "image", "insertdatetime", "link", "lists", "media", | ||
"preview", "searchreplace", "table", "visualblocks", "advtemplate" | ||
], | ||
contextmenu: 'advtemplate', | ||
toolbar: "addtemplate inserttemplate | undo redo | styles | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image", | ||
advtemplate_list, | ||
advtemplate_get_template, | ||
advtemplate_create_category, | ||
advtemplate_create_template, | ||
advtemplate_rename_category, | ||
advtemplate_rename_template, | ||
advtemplate_delete_template, | ||
advtemplate_delete_category, | ||
advtemplate_move_template, | ||
advtemplate_move_category_items | ||
}); | ||
|
||
tinymce.init({ | ||
selector: "textarea#readonly-locked-template", | ||
plugins: [ | ||
"advlist", "anchor", "autolink", "charmap", "code", "fullscreen", | ||
"help", "image", "insertdatetime", "link", "lists", "media", | ||
"preview", "searchreplace", "table", "visualblocks", "advtemplate" | ||
], | ||
contextmenu: 'advtemplate', | ||
toolbar: "addtemplate inserttemplate | undo redo | styles | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image", | ||
advtemplate_list, | ||
advtemplate_get_template, | ||
advtemplate_create_category, | ||
advtemplate_create_template, | ||
advtemplate_rename_category, | ||
advtemplate_rename_template, | ||
advtemplate_delete_template, | ||
advtemplate_delete_category, | ||
advtemplate_move_template, | ||
advtemplate_move_category_items, | ||
}); |
Oops, something went wrong.