Merge branch 'master' into section_complete_boolean
This commit is contained in:
		
						commit
						38e29903fe
					
				
					 2 changed files with 43 additions and 44 deletions
				
			
		|  | @ -186,13 +186,10 @@ def section(request, report_pk, section_pk): | ||||||
| 
 | 
 | ||||||
|         if update.field_type == "boolean": |         if update.field_type == "boolean": | ||||||
|             # flight check |             # flight check | ||||||
|             if request.data[key] == "on": |             if request.data[key] == "true": | ||||||
|                 update.data_bool = True |                 update.data_bool = True | ||||||
|             elif request.data[key] == "off": |             elif request.data[key] == "false": | ||||||
|                 update.data_bool = False |                 update.data_bool = False | ||||||
|             # everything else |  | ||||||
|             else: |  | ||||||
|                 update.data_bool = request.data[key] |  | ||||||
| 
 | 
 | ||||||
|         if update.field_type == "decimal": |         if update.field_type == "decimal": | ||||||
|             # initialize to 0 |             # initialize to 0 | ||||||
|  |  | ||||||
|  | @ -56,40 +56,44 @@ function makeAjaxRequest(method, url, callback, type, payload) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Wraps a Bootstrap form group around a field
 | // Wraps a Bootstrap form group around a field
 | ||||||
| function createFormGroup(field) { | function createFormGroup(sectionIdStr, field) { | ||||||
|  |     const inputId = sectionIdStr + field.field_name; | ||||||
|     const formGroup = document.createElement("div") |     const formGroup = document.createElement("div") | ||||||
|     formGroup.classList.add("form-group", "row"); |     formGroup.classList.add("form-group", "row"); | ||||||
| 
 | 
 | ||||||
|     const label = document.createElement("label"); |     const label = document.createElement("label"); | ||||||
|     label.classList.add("col-sm-4", "col-form"); |     label.classList.add("col-sm-4", "col-form"); | ||||||
|     label.innerHTML = field.label + ": "; |     label.innerHTML = field.label + ": "; | ||||||
|     label.setAttribute("for", field.field_name); |     label.setAttribute("for", inputId); | ||||||
| 
 | 
 | ||||||
|     const div = document.createElement("div"); |     const div = document.createElement("div"); | ||||||
|     div.classList.add("col-sm-6"); |     div.classList.add("col-sm-6"); | ||||||
| 
 | 
 | ||||||
|     const input = document.createElement("input"); |     const input = document.createElement("input"); | ||||||
|     input.name = field.field_name; |     input.name = field.field_name; | ||||||
|     input.id = field.field_name; |     input.id = inputId; | ||||||
| 
 | 
 | ||||||
|     switch(field.field_type) { |     switch(field.field_type) { | ||||||
|         case "boolean": |         case "boolean": | ||||||
|             input.type = "checkbox"; |             const select = document.createElement("select"); | ||||||
|             if (field.value === true) |             select.name = field.field_name; | ||||||
|                 input.setAttribute("checked", "checked"); |             select.id = inputId; | ||||||
|             input.classList.add("form-check-input"); |             select.classList.add("form-control"); | ||||||
|             label.className = ""; |             const yesOption = document.createElement("option"); | ||||||
|             label.classList.add("form-check-label"); |             yesOption.innerHTML = "Yes"; | ||||||
|             label.innerHTML = field.label; |             yesOption.value = "true"; | ||||||
|             outerLabel = document.createElement("div"); |             const noOption = document.createElement("option"); | ||||||
|             outerLabel.classList.add("col-sm-4"); |             noOption.innerHTML = "No"; | ||||||
|             outerLabel.innerHTML = "Flight type: "; |             noOption.value = "false"; | ||||||
|             formCheck = document.createElement("div"); |             if (field.value === true) { | ||||||
|             formCheck.classList.add("form-check"); |                 yesOption.setAttribute("selected", "selected"); | ||||||
|             formCheck.appendChild(input); |             } else { | ||||||
|             formCheck.appendChild(label); |                 noOption.setAttribute("selected", "selected"); | ||||||
|             div.appendChild(formCheck); |             } | ||||||
|             formGroup.appendChild(outerLabel); |             select.appendChild(yesOption); | ||||||
|  |             select.appendChild(noOption); | ||||||
|  |             formGroup.appendChild(label); | ||||||
|  |             div.appendChild(select) | ||||||
|             formGroup.appendChild(div); |             formGroup.appendChild(div); | ||||||
|             break; |             break; | ||||||
|         case "date": |         case "date": | ||||||
|  | @ -138,7 +142,7 @@ function createFormGroup(field) { | ||||||
|     return formGroup; |     return formGroup; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function createCollapsibleCard(key, sectionTitle) { | function createCollapsibleCard(sectionIdStr, sectionTitle) { | ||||||
|     // Create card and header
 |     // Create card and header
 | ||||||
|     const card = document.createElement("div"); |     const card = document.createElement("div"); | ||||||
|     card.classList.add("card"); |     card.classList.add("card"); | ||||||
|  | @ -151,7 +155,7 @@ function createCollapsibleCard(key, sectionTitle) { | ||||||
|     button.classList.add("btn", "btn-link"); |     button.classList.add("btn", "btn-link"); | ||||||
|     button.type = "button"; |     button.type = "button"; | ||||||
|     button.setAttribute("data-toggle", "collapse"); |     button.setAttribute("data-toggle", "collapse"); | ||||||
|     button.setAttribute("data-target", "#collapse" + key); |     button.setAttribute("data-target", "#" + sectionIdStr + "collapse"); | ||||||
|     button.innerHTML = sectionTitle; |     button.innerHTML = sectionTitle; | ||||||
|     h2.appendChild(button); |     h2.appendChild(button); | ||||||
|     cardHeader.appendChild(h2); |     cardHeader.appendChild(h2); | ||||||
|  | @ -160,10 +164,10 @@ function createCollapsibleCard(key, sectionTitle) { | ||||||
|     return card; |     return card; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function createCollapsibleCardBody(key, form, type, sectionDescription, sectionCompleted) { | function createCollapsibleCardBody(form, type, sectionIdStr, sectionDescription, sectionCompleted) { | ||||||
|     // Create wrapper div
 |     // Create wrapper div
 | ||||||
|     const div = document.createElement("div"); |     const div = document.createElement("div"); | ||||||
|     div.id = "collapse" + key; |     div.id = sectionIdStr + "collapse"; | ||||||
|     const sectionAlert = document.createElement("div"); |     const sectionAlert = document.createElement("div"); | ||||||
|     const cardBody = document.createElement("div"); |     const cardBody = document.createElement("div"); | ||||||
|     cardBody.classList.add("card-body"); |     cardBody.classList.add("card-body"); | ||||||
|  | @ -195,7 +199,7 @@ function createCollapsibleCardBody(key, form, type, sectionDescription, sectionC | ||||||
| 
 | 
 | ||||||
| function createReportForm(parsedData, type) { | function createReportForm(parsedData, type) { | ||||||
|     let modalBody; |     let modalBody; | ||||||
|     let modalLabl; |     let modalLabel; | ||||||
|     const accordion = document.createElement("div"); |     const accordion = document.createElement("div"); | ||||||
|     accordion.classList.add("accordion"); |     accordion.classList.add("accordion"); | ||||||
| 
 | 
 | ||||||
|  | @ -225,40 +229,38 @@ function createReportForm(parsedData, type) { | ||||||
| 
 | 
 | ||||||
|     // Traverse the report's sections array
 |     // Traverse the report's sections array
 | ||||||
|     const sections = parsedData.sections; |     const sections = parsedData.sections; | ||||||
|     for (let key in sections) { |     for (let i = 0; i < sections.length; i++) { | ||||||
|         let section = sections[key]; |         let sectionIdStr = "section-" + sections[i].id + "-"; | ||||||
|         let collapsibleCard = createCollapsibleCard(key, section.title) |         let collapsibleCard = createCollapsibleCard(sectionIdStr, sections[i].title) | ||||||
| 
 | 
 | ||||||
|         // 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", "section-form"); |         form.classList.add("form", "section-form"); | ||||||
|         form.id = "form" + key; |         form.id = sectionIdStr + "form"; | ||||||
|         form.setAttribute("data-rid", parsedData.report_pk); |         form.setAttribute("data-rid", parsedData.report_pk); | ||||||
|         form.setAttribute("data-sid", section.id); |         form.setAttribute("data-sid", sections[i].id); | ||||||
| 
 | 
 | ||||||
|         // Traverse the fields of this section
 |         // Traverse the fields of this section
 | ||||||
|         let fields = section.fields; |         let fields = sections[i].fields; | ||||||
|         for (let key in fields) { |         for (let j = 0; j < fields.length; j++) { | ||||||
|             let field = fields[key]; |  | ||||||
| 
 | 
 | ||||||
|             console.log("Field label: " + field.label); |             console.log("Field label: " + fields[j].label); | ||||||
|             console.log("Field type: " + field.field_type); |             console.log("Field type: " + fields[j].field_type); | ||||||
|             console.log("Field value: " + field.value); |             console.log("Field value: " + fields[j].value); | ||||||
| 
 | 
 | ||||||
|             // Create a form group for each field and add it to the form
 |             // Create a form group for each field and add it to the form
 | ||||||
|             let formGroup = createFormGroup(field); |             form.appendChild(createFormGroup(sectionIdStr, fields[j])); | ||||||
|             form.appendChild(formGroup); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // Add save button to the current form
 |         // Add save button to the current form
 | ||||||
|         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", "save-section"); // TODO: add eventListener
 |         saveButton.classList.add("btn", "btn-primary", "save-section"); | ||||||
|         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
 | ||||||
|         let cardBody = createCollapsibleCardBody(key, form, type, section.html_description, section.completed); |         let cardBody = createCollapsibleCardBody(form, type, sectionIdStr, sections[i].html_description, sections[i].completed); | ||||||
|         collapsibleCard.appendChild(cardBody); |         collapsibleCard.appendChild(cardBody); | ||||||
|         accordion.appendChild(collapsibleCard); |         accordion.appendChild(collapsibleCard); | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Rupika
						Rupika