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