aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2018-11-24 22:29:02 -0600
committerluxagraf <sng@luxagraf.net>2018-11-24 22:29:02 -0600
commit0c2a092e8d8ad33a1c306ee9efca0da96eb56415 (patch)
tree0aaf48f20771c97ec30e005ef818ef6ce4856097 /scripts
parent7a284139f6b97bb06548e69d47eef188bc99099d (diff)
way to much for a single commit
Diffstat (limited to 'scripts')
-rw-r--r--scripts/util.js76
1 files changed, 70 insertions, 6 deletions
diff --git a/scripts/util.js b/scripts/util.js
index d70c012..99a5ef3 100644
--- a/scripts/util.js
+++ b/scripts/util.js
@@ -1,14 +1,56 @@
+function edit_note(btn, title, qcontainer, quill, url){
+ console.log(editing);
+ var formElement = document.querySelector("form");
+ if (editing === false) {
+ title.setAttribute("contenteditable", true);
+ title.classList.add('highlight')
+ qcontainer.classList.remove('inactive')
+ quill.enable(true);
+ btn.innerHTML = "Save"
+ editing = true;
+ } else {
+ if (window.quillchange === true) {
+ var form_note_title = document.getElementById('id_title');
+ var note_html = document.getElementById('id_body_html');
+ var note_qjson = document.getElementById('id_body_qjson');
+ form_note_title.value = title.innerHTML;
+ note_html.innerHTML = quill.root.innerHTML;
+ note_qjson.innerHTML = JSON.stringify(quill.getContents());
+ 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"
+ 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) {
- var data =
- for(var i in data) {
- var u = data[i]['fields']['part_number'] + ' - ' + data[i]['fields']['part_name']
- choices.push({ value: String(data[i].pk), label: u, });
- }
- populateParts(choices);
} else {
console.log("server error");
}
@@ -18,3 +60,25 @@ function get_login_form() {
};
request.send();
}
+
+//Global init for Quill
+function initQuill(el) {
+ window.quill = new Quill(el, {
+ modules: {
+ syntax: true, // Include syntax module
+ toolbar: [
+ [{ header: [1, 2, 3, 4, false] }],
+ ['bold', 'italic', 'underline', 'blockquote'],
+ [{ 'list': 'bullet'}, { 'list': 'ordered'},{ 'list': 'check'} ],
+ ['link', 'code-block', 'image', 'video', 'formula',],
+ [{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
+ [{ 'font': [] }],
+ ]
+ },
+ theme: 'snow',
+ enable: false
+ });
+ window.quill.on('text-change', function() {
+ window.quillchange = true;
+ });
+}