Commit 41a7e37b by Owen Ryan Ang

getElementId implem, fixed some bugs in return.

parent d8f95776
......@@ -11,7 +11,14 @@ import { returnForm } from "../Submit/submit.js";
export async function returnElementBPO(elementId) {
try {
// Get current timestamp
const currentTimeStamp = Date.now();
const currentDate = new Date(currentTimeStamp);
const humanReadableTime = currentDate.toLocaleString();
// Save to session storage
sessionStorage.setItem("timeEnd", humanReadableTime);
let response = await fetch(getUrlReturnElement(elementId), { method: "POST" });
if (response.ok) {
......
......@@ -18,4 +18,8 @@ export function fingerprintCapture(key){
export async function getLocation(){
await window.LocationHandlerInterface.setupLocation();
}
export async function getDeviceId(){
return await window.MobileGdeJavascriptInterface.getDeviceId();
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ import { showError } from "./showError.js";
import { submitForm } from "../Submit/submit.js";
import { BPO_OBJECT } from "../globalVariable.js";
import { fetchOptionsDB } from "./DBLookup/DBLookup.js";
import { fingerprintCapture, getLocation, imageCapture, videoCapture } from "./AndroidInterface/androidInterface.js";
import { fingerprintCapture, getDeviceId, getLocation, imageCapture, videoCapture } from "./AndroidInterface/androidInterface.js";
import { processCapture } from "./ImageCapture/captureImage.js";
import { processFingerprint } from "./FingerprintCapture/captureFingerprint.js";
import { processVideoCapture } from "./VideoCapture/captureVideo.js";
......@@ -1641,6 +1641,56 @@ const inputGeoTagStart = (key, validation) => {
* @returns
* created input field element
*/
const inputDeviceId = async (key, validation) => {
const {
mandatory,
fieldLength,
collection
} = validation
//Text box to store the longitude and lattitude (for easier submission of data)
const input1 = document.createElement('input')
input1.setAttribute('id', `${key}`)
input1.setAttribute('name', `${key}`)
input1.setAttribute('class', `${collection}`)
input1.setAttribute('type', 'text')
input1.setAttribute('readonly', 'true')
let deviceId
try {
// Get the device ID using async/await
deviceId = await getDeviceId();
} catch {
}
// Check if deviceId is null or an error
if (deviceId === null || deviceId instanceof Error || deviceId === undefined) {
// Handle the case where deviceId is null or an error
deviceId = ''; // Set a default value or handle it according to your logic
}
// Set the device ID as the value of the input element
input1.value = deviceId;
// Create a container div to hold both the input and the text node
const container = document.createElement('div');
// container.appendChild(input); // Append the input element to the container
container.appendChild(input1); // Append the text container to the container
return container; // Return the combined container
}
/**
*
* @param {*} key
* will serve as id of input field
* @param {*} validation
* validation of field from schema
* @returns
* created input field element
*/
const inputDropdown = (key, validation, readOnly) => {
try {
const { mandatory, options } = validation;
......@@ -1685,7 +1735,7 @@ const inputDropdown = (key, validation, readOnly) => {
} catch (err) {
throw err;
}
};
};
......@@ -1863,6 +1913,11 @@ const deconstruct = async (section, container, classAttribute) => {
hiddenInputGeoStart.setAttribute('class', classAttribute);
inputContainer.appendChild(hiddenInputGeoStart);
break;
case "deviceid":
const hiddenInputDeviceId = await inputDeviceId(key, validation);
hiddenInputDeviceId.setAttribute('class', classAttribute);
inputContainer.appendChild(hiddenInputDeviceId);
break;
default:
const hiddenInputDefault = inputHidden(key, validation);
hiddenInputDefault.setAttribute('class', classAttribute);
......@@ -1972,6 +2027,9 @@ const deconstruct = async (section, container, classAttribute) => {
case 'geotagstart':
input = inputGeoTagStart(key, validation)
break
case 'deviceid':
input = await inputDeviceId(key, validation, readOnly)
break
default:
input = noValidation()
break
......@@ -1979,7 +2037,7 @@ const deconstruct = async (section, container, classAttribute) => {
input.classList.add(classAttribute)
inputContainer.appendChild(input)
if (hidden && ["geotag", "geotagstart", "altitude", "direction"].includes(collection)){
if (hidden && ["geotag", "geotagstart", "altitude", "direction","deviceid"].includes(collection)){
newField.style.display = 'none'; // Hide the input
newField.classList.add('hidden'); // Add 'hidden' class
}
......
......@@ -39,7 +39,7 @@ export const submitForm = async (e) => {
const errorContainer = document.getElementById(`${id}_error`);
// Skip submit, buttons, and files
if (element.classList.contains('radioOther') || element.classList.contains('checkboxOther')) continue;
if (element.classList.contains('geotag') || element.classList.contains('geotagstart') || element.classList.contains('altitude') || element.classList.contains('direction')) {
if (element.classList.contains('geotag') || element.classList.contains('geotagstart') || element.classList.contains('altitude') || element.classList.contains('direction') || element.classList.contains('deviceid')) {
continue;
}
if (type === 'submit') continue
......@@ -200,7 +200,7 @@ export const returnForm = async (e) => {
const errorContainer = document.getElementById(`${id}_error`);
// Skip submit, buttons, and files
if (element.classList.contains('radioOther') || element.classList.contains('checkboxOther')) continue;
if (element.classList.contains('geotag') || element.classList.contains('geotagstart') || element.classList.contains('altitude') || element.classList.contains('direction')) {
if (element.classList.contains('geotag') || element.classList.contains('geotagstart') || element.classList.contains('altitude') || element.classList.contains('direction') || element.classList.contains('deviceid')) {
continue;
}
if (type === 'submit') continue
......
......@@ -117,6 +117,14 @@
"collection" : "geotagstart",
"mandatory" : false
}
},
"device_id" : {
"fieldLabel" : "Device ID",
"aka" : "field13",
"validation" : {
"collection" : "deviceid",
"mandatory" : false
}
}
}
}
......
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