aboutsummaryrefslogtreecommitdiff
path: root/scripts/src/util.js
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2019-01-09 13:29:17 -0600
committerluxagraf <sng@luxagraf.net>2019-01-09 13:29:17 -0600
commitbe0bb4e123240ac3ce02431b974c82f8f05d843b (patch)
treee2da7ac44be955ad5cbf32c0a35dc507ba63e844 /scripts/src/util.js
parentd5f430d3e1e2b274d8d8f744251e8b6b4b72ebd9 (diff)
latest changes
Diffstat (limited to 'scripts/src/util.js')
-rw-r--r--scripts/src/util.js49
1 files changed, 36 insertions, 13 deletions
diff --git a/scripts/src/util.js b/scripts/src/util.js
index 144deae..6d3769f 100644
--- a/scripts/src/util.js
+++ b/scripts/src/util.js
@@ -6,21 +6,26 @@ function buildComponent(tag, id, html){
return el;
};
-function getJSON(method, url, callback) {
+function getJSONFromDjango(method, url, callback, data) {
+ var data = data || null
var request = new XMLHttpRequest();
- request.addEventListener('load', callback);
+ var csrftoken = getCookie('csrftoken');
+ request.addEventListener('load', callback.bind(null, request));
request.open(method, url, true);
- request.onload = function() {
- if (request.status >= 200 && request.status < 400) {
- //console.log(request.responseText);
- } else {
- console.log('server error');
- }
- };
+ request.setRequestHeader('X-CSRFToken', csrftoken);
request.onerror = function() {
console.log('error on request');
};
- request.send();
+ //create a modal to let the user know we're saving
+ var saveModal = document.createElement('div');
+ var loader = document.createElement('div');
+ loader.classList.add('loader');
+ saveModal.appendChild(loader);
+ saveModal.close = false; //no close button
+ saveModal.modalHed = "Saving changes"; //modal text content
+ saveModal.wrapperClass = 'loading'; //add a wrapper class to the modal for styling
+ var modal = modalBox(saveModal);
+ request.send(data);
}
// hijack a form and submit with ajax
@@ -132,13 +137,16 @@ function modalBox(content, btn){
headline.className = 'hed';
content.classList.remove('hide');
var content = buildComponent('div', 'content-wrapper', options.content);
+ var hed_wrapper = buildComponent('div', 'hed-wrapper');
+ hed_wrapper.appendChild(headline);
+ console.log("close var is: ",options.content.close);
var actions = buildComponent('div', 'close-btn');
var cancel = buildComponent('button', 'modalCancel', options.cancelText);
cancel.classList.add('btn', 'btn-hollow', 'btn-light');
actions.appendChild(cancel);
- var hed_wrapper = buildComponent('div', 'hed-wrapper');
- hed_wrapper.appendChild(headline);
- hed_wrapper.appendChild(actions); //actions includes action buttons
+ if (options.content.close !== false) {
+ hed_wrapper.appendChild(actions); //actions includes action buttons
+ }
innermodal.appendChild(hed_wrapper);
innermodal.appendChild(content);
overlay.appendChild(outermodal);
@@ -182,3 +190,18 @@ function isEmpty(quill) {
const re = /^<p>(<br>|<br\/>|<br\s\/>|\s+|\r)<\/p>$/gm;
return re.test(commentText);
};
+
+function addNotebookModal(notebookAddForm, btn) {
+ initColorPicker(notebookAddForm);
+ ajaxHijack(notebookAddForm, notebookCreate)
+ btn.content = notebookAddForm.parentNode;
+ addHandler(btn);
+ function addHandler(el){
+ el.addEventListener('click', function(e){
+ e.preventDefault();
+ var modalContent = e.target.content;
+ modalContent.wrapperClass = 'overlay'; //add a wrapper class to the modal for styling
+ var modal = modalBox(modalContent, el);
+ });
+ }
+}