Commit 8f42e223 by Jorem Magcawas

save form update on next and previous amd change of schema

parent 049513e5
......@@ -3,23 +3,16 @@ var File_Path;
var gfsFileName;
async function accessFile() {
var button = 0;
var size = 0;
let file_url = [];
const elStatus = document.getElementById('status');
function status(text) {
elStatus.innerHTML = text;
}
const progressBar = document.getElementById('progressBar');
const elProgress = document.getElementById('progress');
function progress({ loaded, total }) {
// elProgress.innerHTML = Math.round(loaded * .000001) + " mb of " + Math.round(total * .000001);
progressBar.value = Math.round(loaded / total * 100);
}
const indexedDB =
window.indexedDB ||
window.mozIndexedDB ||
......
......@@ -34,8 +34,7 @@ const displayFields = async (parentID) => {
createSection('Section', div)
Object.keys(schema).forEach(function(key) {
console.log(key + ": " + schema[key]); //doctypes in schema
/* Object.keys(schema).forEach(function(key) {
let doctypes = schema[key];
const { valid, error } = validateSchema(key)
if(!valid){
......@@ -51,11 +50,9 @@ const displayFields = async (parentID) => {
}
}
});
});*/
/* const { ACCOUNTING_DOCUMENTS } = schema
const { ACCOUNTING_DOCUMENTS } = schema
//getDocType = DOC_TYPE1 ;
......@@ -72,9 +69,8 @@ const displayFields = async (parentID) => {
const { HR_FILES } = schema
const { SECTION3 } = HR_FILES
div = deconstruct(SECTION3, div, 'SECTION3')*/
div = deconstruct(SECTION3, div, 'SECTION3')
const submit = document.createElement('input')
submit.type = 'submit'
......@@ -240,6 +236,7 @@ const inputString = (key, validation) => {
let input = document.createElement('input')
input.setAttribute('id', `${key}`)
input.setAttribute('name', `${key}`)
input.setAttribute('type', 'text')
input.setAttribute('autocomplete', 'off')
input.addEventListener('focusout', handleInput)
......@@ -302,6 +299,7 @@ const inputNumeric = (key, validation) => {
const input = document.createElement('input')
input.setAttribute('id', `${key}`)
input.setAttribute('name', `${key}`)
input.setAttribute('type', 'text')
input.setAttribute('autocomplete', 'off')
input.setAttribute('pattern', '[0-9/-]+')
......@@ -332,6 +330,7 @@ const inputDate = (key, validation) => {
const input = document.createElement('input')
input.setAttribute('id', `${key}`)
input.setAttribute('name', `${key}`)
input.setAttribute('type', 'date')
input.addEventListener('focusout', handleInput)
......@@ -358,6 +357,7 @@ const inputDropdown = (key, validation) => {
const { mandatory, options } = validation
const input = document.createElement('select')
input.setAttribute('id', `${key}`)
input.setAttribute('name', `${key}`)
input.classList.add('dropdown-input')
input.addEventListener('focusout', handleInput)
......@@ -626,22 +626,23 @@ const createSection = (fieldLabel, div) => {
}
function saveForm(index){
const form = document.querySelector("#fields");
const inputs = form.querySelectorAll("input,textarea");
const values = {};
inputs.forEach(input => {
if(input.value != ''){
values[input.name] = input.value;
}
});
let formValues = {
name : document.getElementById("Name").value,
subject : document.getElementById("Subject").value,
docNo : document.getElementById("Document_No").value,
date : document.getElementById("Date").value,
accountNo : document.getElementById("Account_No").value,
empNo : document.getElementById("Employee_No").value,
}
index--;
var formArray = JSON.parse(sessionStorage.getItem('formArray'));
//formArray.push(formValues);
if(typeof formArray[index] !== 'undefined') {
formArray.splice(index, 1, formValues)
formArray.splice(index, 1, values)
} else {
formArray.splice(index, 0, formValues)
formArray.splice(index, 0, values)
}
sessionStorage.setItem('formArray', JSON.stringify(formArray));
......@@ -656,36 +657,13 @@ function populateForm(index){
var formArray = JSON.parse(sessionStorage.getItem('formArray'));
var name = document.getElementById("Name");
var subject = document.getElementById("Subject");
var docNo = document.getElementById("Document_No");
var date = document.getElementById("Date");
var accountNo = document.getElementById("Account_No");
var empNo = document.getElementById("Employee_No");
if (formArray[index].name != null) {
name.value = formArray[index].name;
}
if (formArray[index].subject != null) {
subject.value = formArray[index].subject;
}
if (formArray[index].docNo != null) {
docNo.value = formArray[index].docNo;
}
if (formArray[index].date != null) {
date.value = formArray[index].date;
}
if (formArray[index].accountNo != null) {
accountNo.value = formArray[index].accountNo;
}
if (formArray[index].empNo != null) {
empNo.value = formArray[index].empNo;
if (formArray[index] != null) {
var currForm = formArray[index];
for (let field in currForm) {
document.getElementById(field).value = currForm[field];
}
}
}
\ No newline at end of file
......@@ -182,8 +182,6 @@ function initHighlight() {
//waits until TIFF image is loaded, since its size is based on the displayed TIFF image
const observer = new MutationObserver(function (mutations, mutationInstance) {
console.log(sessionStorage.getItem("TiffViewer_current"));
var TIFFimg = document.getElementById(sessionStorage.getItem("TiffViewer_current"));
if (TIFFimg != null) {
//waits until width and height has been assigned
......
const validateSchema = (doctype) => {
const validate = schema[doctype]
const validateSchema = () => {
const { ACCOUNTING_DOCUMENTS } = schema
if(!validate) return { valid: false, error: 'SECTION is missing!' }
if(!ACCOUNTING_DOCUMENTS) return { valid: false, error: 'SECTION is missing!' }
return { valid: true }
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment