From be0bb4e123240ac3ce02431b974c82f8f05d843b Mon Sep 17 00:00:00 2001 From: luxagraf Date: Wed, 9 Jan 2019 13:29:17 -0600 Subject: latest changes --- scripts/src/util.js | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'scripts/src/util.js') 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 = /^

(
|||\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); + }); + } +} -- cgit v1.2.3-70-g09d2