fix merge conflict

This commit is contained in:
Rupika 2019-02-13 17:45:39 -08:00
commit 75932daef1
2 changed files with 34 additions and 5 deletions

View file

@ -177,6 +177,9 @@ def section(request, report_pk, section_pk):
update_field.data_integer = v["value"] update_field.data_integer = v["value"]
update_field.save() update_field.save()
data = {
return JsonResponse({"message": "Updated report {0}, section {1}.".format(report_pk, section_pk)}) "message": "Updated report {0}, section {1}.".format(report_pk, section_pk),
"request.data": request.data
}
return JsonResponse(data)

View file

@ -9,6 +9,10 @@ function getEndpointDomain() {
return "https://" + window.location.hostname + ":8444/"; return "https://" + window.location.hostname + ":8444/";
} }
function alertCallback(parsedData) {
alert(JSON.stringify(parsedData));
}
function makeAjaxRequest(method, url, callback, type, payload) { function makeAjaxRequest(method, url, callback, type, payload) {
const token = localStorage.getItem("token"); const token = localStorage.getItem("token");
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
@ -17,7 +21,17 @@ function makeAjaxRequest(method, url, callback, type, payload) {
xhr.open(method, url, true); xhr.open(method, url, true);
xhr.setRequestHeader("Authorization", "Bearer " + token); xhr.setRequestHeader("Authorization", "Bearer " + token);
method === "POST" ? xhr.setRequestHeader("Content-Type", "application/json") : payload = null;
switch (method) {
case "PUT":
break;
case "POST":
xhr.setRequestHeader("Content-Type", "application/json");
break;
default:
payload = null;
break;
}
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (this.readyState === 4) { if (this.readyState === 4) {
@ -217,8 +231,10 @@ function createReportForm(parsedData, type) {
// Create a new form with the section key index as id // Create a new form with the section key index as id
let form = document.createElement("form"); let form = document.createElement("form");
form.classList.add("form"); form.classList.add("form", "section-form");
form.id = "form" + key; form.id = "form" + key;
form.setAttribute("data-rid", parsedData.report_pk);
form.setAttribute("data-sid", section.id);
// Traverse the fields of this section // Traverse the fields of this section
let fields = section.fields; let fields = section.fields;
@ -238,7 +254,7 @@ function createReportForm(parsedData, type) {
let saveButton = document.createElement("button"); let saveButton = document.createElement("button");
saveButton.innerHTML = "Save"; saveButton.innerHTML = "Save";
saveButton.type = "submit"; saveButton.type = "submit";
saveButton.classList.add("btn", "btn-primary"); // TODO: add eventListener saveButton.classList.add("btn", "btn-primary", "save-section"); // TODO: add eventListener
form.appendChild(saveButton); form.appendChild(saveButton);
// Create collapsible card body, append form to it, append card to accordion // Create collapsible card body, append form to it, append card to accordion
@ -411,3 +427,13 @@ if (newReportForm) {
this.reset(); this.reset();
}); });
} }
document.addEventListener("submit", function(event) {
if (event.target.classList.contains("section-form")) {
event.preventDefault();
console.log(event.target);
const formData = new FormData(event.target);
const url = getEndpointDomain() + "api/v1/report/" + event.target.dataset.rid + "/section/" + event.target.dataset.sid;
makeAjaxRequest("PUT", url, alertCallback, null, formData);
}
});