var sessID
function copyToClipboard(d) {
navigator.clipboard.writeText(d);
showTip("Copied to clipboard");
}
sessID = getSessionID();
function ajaxError(response) {
//debugger
r = response.responseText
p = r.indexOf("Exception Value:")
p1 = r.indexOf("Traceback:")
p2 = r.indexOf("Request information:")
p3 = r.indexOf("Exception Type:")
v = r.substr(p, p2 - p)
r = r.substr(p1, p3 - p1)
r = r.replaceAll("\n", "
")
p = r.lastIndexOf("
", r.length - 10)
d = r.substr(p + 13)
showAlert("Error reported back from system:
" + d + v + "
" + r);
console.log("ERROR", response.responseText)
}
function getSessionID() {
$.ajax({
type: "GET",
url: "/getSessionID",
complete: function (data, status, settings) {
//console.log(data)
sessID = data.responseJSON["sessID"]
return sessID
},
error: ajaxError,
});
}
function getProgress(progFld) {
//alert("H")
$.ajax({
type: "GET",
url: "/getProgress",
complete: function (data, status, settings) {
pctComplete = data.responseJSON["pctComplete"]
if (pctComplete !== null) {
//console.log(pctComplete)
$("#" + progFld).text("Progress: " + (pctComplete * 100).toFixed(1) + '%')
}
},
error: ajaxError,
});
}
$(function () {
$("#showAlert").dialog({
autoOpen: false,
resizable: false,
modal: true,
width: 'auto',
minWidth: 200,
maxHeight: $(window).height() - 70,
create: function (event, ui) {
$(this).css("maxWidth", 800);
$(this).css("maxHeight", 500);
},
open: function () {
$(this).dialog('option', 'maxHeight', $(window).height() - 70);
}
});
$("#showConfirm").dialog({
autoOpen: false,
resizable: false,
modal: true,
buttons: {
"Confirm": function () {
eval($("#xx_vAction").val())
$(this).dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
},
minWidth: 150,
//width: 'auto',
maxHeight: $(window).height() - 70,
create: function (event, ui) {
$(this).css("maxWidth", 800);
$(this).css("maxHeight", 500);
},
open: function () {
$(this).dialog('option', 'maxHeight', $(window).height() - 70);
}
});
});
function showAlert(txt) {
$("#showAlert").html(txt)
$("#showAlert").dialog("open");
$(".ui-dialog-title").css("color","red")
$(".ui-dialog-title").css("font-weight", 900)
$(".ui-dialog-titlebar-close").addClass("ui-icon ui-icon-closethick")
}
function showConfirm(txt, lbl) {
$("#showConfirm").html(txt)
$("#showConfirm").dialog("open");
$(".ui-dialog-title").css("color", "red")
$(".ui-dialog-title").css("font-weight", 900)
$(".ui-dialog-titlebar-close").addClass("ui-icon ui-icon-closethick")
}
function test() {
alert("TEST")
}
function jsSpaceOut(s) {
s = s.replace(/([A-Z])/g, ' $1').trim();
s = s.replace(" I D", " ID");
s = s.replace(" U R L", " URL");
s = s.replace(" Y N", "?");
return s
}
function ismt(str) {
str = String(str)
return str == null || str == "null" || str === null || str.match(/^\s*$/) !== null || str=="0";
}
$(".control-label").each(function () {
this.innerText = jsSpaceOut(this.innerText);
});
$(".datepicker").datepicker({
container: "#modalRecord",
changeMonth: true,
changeYear: true,
showButtonPanel: true,
yearRange: "-100:+0",
});
function formatMoney() {
$(".money").each(function () {
$(this).text('$' + parseFloat($(this).text(), 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString());
});
}
function generateFields(dataVals, inputs, displayOnly) {
for (i = 0; i < inputs.length; i++) {
var fldNm = inputs[i].title
if (document.getElementById("div" + fldNm)) {
var o = document.getElementById("div" + fldNm);
if (displayOnly == "DISPLAYONLY") {
if (fldNm.slice(-2) == "YN") {
var el = document.createElement("INPUT");
el.setAttribute("type", "checkbox")
el.checked = (dataVals[0][fldNm] != "'False'");
} else if (fldNm.slice(-3) == "URL") {
var el = document.createElement("a");
el.innerHTML = fldNm;
el.setAttribute("href", dataVals[0][fldNm]);
el.setAttribute("target", "_new");
} else {
var el = document.createElement("span");
el.innerHTML = dataVals[0][fldNm];
el.style.textAlign = "left";
}
} else {
v = inputs[i].type
p = v.indexOf("-")
if (p > 0) v = v.substr(0, p)
if (v == "list") {
var el = document.createElement("select");
el.setAttribute("class", "form-control");
options = inputs[i].options;
for (const opt of options) {
var option = document.createElement("option");
option.value = opt.value;
if (option.value == dataVals[0][fldNm]) option.selected = true;
option.text = opt.display;
el.appendChild(option);
}
} else {
var el = document.createElement("INPUT");
typ = inputs[i].type;
typ = typ.replace("-confirm", "");
if (typ == "readonly") {
el.setAttribute("type", "text");
el.setAttribute("readOnly", true);
} else if (typ == "datepicker") {
el.setAttribute("type", "date");
el.setAttribute("class", "datepicker form-control");
} else if (typ == "textarea") {
var el = document.createElement("textarea");
el.setAttribute("id", fldNm);
el.setAttribute("class", "form-control");
el.setAttribute("placeholder", "Enter " + fldNm);
el.setAttribute("type", typ);
el.setAttribute("cols", 60);
el.setAttribute("rows", 3);
} else {
el.setAttribute("type", typ);
}
if (dataVals[0][fldNm] != "") {
if (inputs[i].type == "textarea-confirm") {
el.innerHTML = dataVals[0][fldNm]
} else {
el.setAttribute("value", dataVals[0][fldNm]);
}
} else {
if (inputs[i].default != null) {
x = inputs[i].default
if (x == "((0))") v = false
if (x == "((1))") v = true
if (x == "(getdate())") v = new Date().toLocaleString().split(/\D/).slice(0, 3).map(num => num.padStart(2, "0")).join("/")
el.setAttribute("value", v);
}
}
if (inputs[i].maxNbrLength != "") {
el.setAttribute("max-width", inputs[i].maxNbrLength);
}
if (inputs[i].maxCharLength != "") {
el.setAttribute("max-width", inputs[i].maxCharLength);
}
}
if (inputs[i].isRequired == "True") {
el.required = true;
}
if ('undefined' !== typeof inputs[i].onChange) {
x = inputs[i].onChange
while (x.indexOf("^") != -1) {
x = x.replace("^", "'")
}
eval("el.addEventListener('change', function () { " + x + "});")
}
}
el.id = fldNm;
el.name = fldNm;
if (displayOnly != "DISPLAYONLY") {
el.setAttribute("class", "form-control");
el.setAttribute("placeholder", "Enter " + fldNm);
}
o.appendChild(el);
if (inputs[i].fullRow == "True") {
$("#" + fldNm).css("max-width", "unset")
$("#" + fldNm).css("width", "90%")
$("#" + fldNm).css("height", "200px")
$("#" + fldNm).css("margin-left", "20px")
$("#lbl" + fldNm).css("text-align", "left")
oDiv = $("#div" + fldNm)
oDiv.parent().attr("class", "col-lg-16")
}
}
}
}
function dateMMDDYY(dt) {
var dt = new Date();
var dd = dt.getDate();
var mm = dt.getMonth() + 1;
var yyyy = dt.getFullYear();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
return mm + '/' + dd + '/' + yyyy;
}
function fixJSON(s) {
s = s.toString()
s = s.replace(/'/g, '"')
s = s.replaceAll(': None,', ': "",')
return s
}
String.prototype.toProperCase = function () {
return this.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
};