Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/richdocuments.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2018-09-18 20:10:06 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2018-12-20 09:38:43 +0300
commitc680b535c970a46a29d0d4ccd670014b54b98f65 (patch)
tree40e77746faf5304ef146698a28476184f497276b /js/admin.js
parentec9a21184695b99033ad70bceca892c1d1518560 (diff)
Add template js handler and comments
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'js/admin.js')
-rw-r--r--js/admin.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/js/admin.js b/js/admin.js
index fb50ad98..531575d6 100644
--- a/js/admin.js
+++ b/js/admin.js
@@ -262,6 +262,24 @@ var documentsSettings = {
}
};
+/**
+ * Append a new template to the dom
+ *
+ * @param {Object} data the template data from the template controller response
+ */
+function appendTemplateFromData(data) {
+ var template = document.querySelector('.template-model');
+ template.className = '';
+ template.querySelector('img').src = data.preview;
+ template.querySelector('figcaption').textContent = data.name;
+ template.querySelector('.delete-template').href = data.delete;
+
+ document.querySelector('#richdocuments-templates > ul').appendChild(template)
+}
+
+/**
+ * Init the upload manager and the delete template handler
+ */
function initTemplateManager() {
var inputElmt = document.querySelector('#add-template');
var buttonElmt = document.querySelector('.icon-add');
@@ -270,6 +288,8 @@ function initTemplateManager() {
deleteElmts.forEach(function(elmt) {
elmt.addEventListener('click', function(event) {
event.preventDefault();
+
+ // ensure no request is in progress
if (event.target.className.indexOf('loading') === -1 && elmt.textContent === '') {
var remote = event.target.href;
elmt.classList.add('icon-loading');
@@ -281,10 +301,11 @@ function initTemplateManager() {
type: 'DELETE',
})
.done(function() {
- // Remove template
+ // remove template
elmt.parentElement.remove();
})
.fail(function(e) {
+ // failure, show warning
elmt.textContent = t('richdocuments', 'Error');
elmt.classList.remove('icon-loading');
setTimeout(function() {
@@ -296,7 +317,7 @@ function initTemplateManager() {
})
})
-
+ // fileupload plugin
$('#richdocuments-templates').fileupload({
dataType: 'json',
url: OC.generateUrl(OC.linkTo('richdocuments', 'template')),
@@ -318,9 +339,12 @@ function initTemplateManager() {
success: function(e, data) {
inputElmt.disabled = false;
buttonElmt.className = 'icon-add';
+ // add template to dom
+ appendTemplateFromData(e.data)
},
fail: function(e, data) {
+ // failure, show warning
buttonElmt.className = 'icon-add';
buttonElmt.textContent = t('richdocuments', 'An error occured');
// TODO: add error message from server