diff options
Diffstat (limited to 'scripts/src/util.js')
-rw-r--r-- | scripts/src/util.js | 79 |
1 files changed, 8 insertions, 71 deletions
diff --git a/scripts/src/util.js b/scripts/src/util.js index 3a4efc4..dfaeeea 100644 --- a/scripts/src/util.js +++ b/scripts/src/util.js @@ -1,87 +1,24 @@ -function getJSON(url, callback) { +function getJSON(method, url, callback) { var request = new XMLHttpRequest(); - request.addEventListener("load", callback); - request.open('GET', url, true); + request.addEventListener('load', callback); + request.open(method, url, true); request.onload = function() { if (request.status >= 200 && request.status < 400) { //console.log(request.responseText); } else { - console.log("server error"); + console.log('server error'); } }; request.onerror = function() { - console.log("error on request"); + console.log('error on request'); }; request.send(); } -function edit_note(btn, title, qcontainer, quill, url){ - var formElement = document.getElementById("note-edit-form"); - if (window.editing === false) { - title.setAttribute("contenteditable", true); - title.classList.add('highlight') - qcontainer.classList.remove('inactive') - quill.enable(true); - btn.innerHTML = "Save" - btn.classList.add("save"); - window.editing = true; - window.titlecontents = title.innerHTML - } else { - if (window.quillchange === true || window.titlecontents != title.innerHTML) { - var form_note_title = document.getElementById('id_title'); - var note_html = document.getElementById('id_body_html'); - var note_text = document.getElementById('id_body_text'); - var note_qjson = document.getElementById('id_body_qjson'); - var new_title = document.getElementById('id_title'); - new_title.value = title.innerHTML; - note_html.innerHTML = quill.root.innerHTML; - note_text.innerHTML = quill.getText(); - note_qjson.innerHTML = JSON.stringify(quill.getContents()); - console.log(note_text); - var request = new XMLHttpRequest(); - request.open("PATCH", url); - var csrftoken = Cookies.get('csrftoken'); - request.setRequestHeader("X-CSRFToken", csrftoken) - request.onload = function() { - if (request.status >= 200 && request.status < 400) { - console.log(request); - window.quillchange = false; - } else { - console.log(request); - console.log("server error"); - } - }; - request.onerror = function() { - console.log("error on request"); - }; - request.send(new FormData(formElement)); - } - title.setAttribute("contenteditable", false); - title.classList.remove('highlight') - qcontainer.classList.add('inactive'); - quill.enable(false); - btn.innerHTML = "Edit" - btn.classList.remove("save"); - document.body.focus(); - editing = false; - } - return false; -} - - function get_login_form() { - var request = new XMLHttpRequest(); - request.open('GET', '/login/', true); - request.onload = function() { - if (request.status >= 200 && request.status < 400) { - } else { - console.log("server error"); - } - }; - request.onerror = function() { - console.log("error on request"); - }; - request.send(); + getJSON('GET', '/login/', function(e){ + console.log(e); + }); } //Global init for Quill |