Code Refactored

This commit is contained in:
2026-08-02 10:37:20 +05:30
parent 9b9557105c
commit 440c13cc49
10 changed files with 987 additions and 689 deletions

View File

@@ -20,10 +20,12 @@
<script language="javascript" src="/matrix/js/lib/jsfuncs.js" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/lib/notifications.js?ver=1" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/lib/payload-crypto.js?ver=1" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/lib/form-validation.js?ver=1" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/ui/msgdialog.js" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/ui/select.js" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/edp/initiation.js?ver=7" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/edp/application-save.js?ver=2" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/edp/punching/initiation.js?ver=7" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/edp/punching/initiation-validation.js?ver=1" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/edp/punching/application-save.js?ver=2" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/validator.js?ver=2" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/ajax.js" type="text/javascript"></script>
<script language="javascript" src="/matrix/js/ajax-dynamic-list.js?ver=1" type="text/javascript"></script>
@@ -115,7 +117,7 @@
Appl No.
</div>
<div class="inputcontainer">
<input type="text" id="applno" name="applno" maxlength="25" style="width:115px;text-transform:uppercase" value="" onblur="if(validate(this,'t','AlphaNumeric')){FindSameDet(this,'A','customername');}" />
<input type="text" id="applno" name="applno" maxlength="25" style="width:115px;text-transform:uppercase" value="" onblur="if(CygnusInitiationValidation.validateField(this)){FindSameDet(this,'A','customername');}" />
</div>
</div>
<div class="widget">
@@ -123,7 +125,7 @@
Bank Code
</div>
<div class="inputcontainer">
<input type="text" maxlength="25" id="bankcode" name="bankcode" style="width:70px;text-transform:uppercase" value="" onblur="validate(this,'f','AlphaNumeric');" />
<input type="text" maxlength="25" id="bankcode" name="bankcode" style="width:70px;text-transform:uppercase" value="" onblur="CygnusInitiationValidation.validateField(this);" />
</div>
</div>
<div class="widget">
@@ -132,7 +134,7 @@
</div>
<div class="inputcontainer">
<div class="divselect" id="divbranch" style="width:135px;">
<select id="bank_branch_id" name="bank_branch_id" style="width:153px" onblur="validate(this,'t','');">
<select id="bank_branch_id" name="bank_branch_id" style="width:153px" onblur="CygnusInitiationValidation.validateField(this);">
<option value="-1" selected >SELECT</option>
<c:choose>
<c:when test="${not empty model}">
@@ -152,7 +154,7 @@
</div>
<div class="inputcontainer">
<div class="divselect" id="divproduct" style="width:132px;">
<select id="product" name="product" style="width:150px" onblur="validate(this,'t','');">
<select id="product" name="product" style="width:150px" onblur="CygnusInitiationValidation.validateField(this);">
<option value="-1" selected >SELECT</option>
<c:choose>
<c:when test="${not empty model}"><c:forEach items="${model.options['product.']}" var="option"><option value="${option.value}"><c:out value="${option.label}" /></option></c:forEach></c:when>
@@ -167,7 +169,7 @@
Name
</div>
<div class="inputcontainer">
<input type="text" id="customername" name="customername" maxlength="100" style="width:200px" value="" onblur="validate(this,'t','AlphaSpace');" />
<input type="text" id="customername" name="customername" maxlength="100" style="width:200px" value="" onblur="CygnusInitiationValidation.validateField(this);" />
</div>
</div>
<div class="widget">
@@ -184,7 +186,7 @@
</div>
<div class="inputcontainer">
<div class="divselect" id="divapptype" style="width:135px;">
<select id="apptype" name="apptype" style="width:153px" onchange="ToggleChks((this.value.toUpperCase()!='APPLICANT' && this.value.toUpperCase()!='-1'),'sradd!C0L!soadd!C0L!spadd!C0L!','!C0L!')" onblur="validate(this,'t','');">
<select id="apptype" name="apptype" style="width:153px" onchange="ToggleChks((this.value.toUpperCase()!='APPLICANT' && this.value.toUpperCase()!='-1'),'sradd!C0L!soadd!C0L!spadd!C0L!','!C0L!')" onblur="CygnusInitiationValidation.validateField(this);">
<option value="-1" selected>SELECT</option>
<c:choose>
<c:when test="${not empty model}"><c:forEach items="${model.options['applicationType.']}" var="option"><option value="${option.value}"><c:out value="${option.label}" /></option></c:forEach></c:when>
@@ -264,10 +266,10 @@
<div class="title">
<img class="matrix-title-icon" src="/matrix/images/resdet.png" />
<span class="matrix-title-text">Residence Details</span>
<div class="divchk" id="ctrldiv">
<div class="divchk ctrldiv">
<input type="checkbox" id="rv" name="rv" onclick="HandleClick(this)" />RVR&nbsp;
<input type="checkbox" id="sradd" name="rv" onclick="return FindSameDet(this,'R','rphone')" /><span id="sradd">Same Resi</span>
<input type="checkbox" id="rtv" name="rv" onclick="HandleClick(this)" /><span id="rtv">RTV</span>
<input type="checkbox" id="sradd" name="sradd" onclick="return FindSameDet(this,'R','rphone')" /><span id="sradd-label">Same Resi</span>
<input type="checkbox" id="rtv" name="rtv" onclick="HandleClick(this)" /><span id="rtv-label">RTV</span>
</div>
</div>
<!-- -->
@@ -372,11 +374,11 @@
<div class="title">
<img class="matrix-title-icon" src="/matrix/images/optmale.png" />
<span class="matrix-title-text">Office Details</span>
<div class="divchk" id="ctrldiv">
<div class="divchk ctrldiv">
<input type="checkbox" id="ov" onclick="HandleClick(this)" />OVR&nbsp;
<input type="checkbox" id="rco" style="display:none" onclick="HandleClick(this)" /><span id="rco">RCO&nbsp;</span>
<input type="checkbox" id="soadd" onclick="return FindSameDet(this,'O','ophone')" /><span id="soadd">Same Office</span>
<input type="checkbox" id="otv" onclick="HandleClick(this)" /><span id="otv">OTV</span>
<input type="checkbox" id="rco" style="display:none" onclick="HandleClick(this)" /><span id="rco-label">RCO&nbsp;</span>
<input type="checkbox" id="soadd" onclick="return FindSameDet(this,'O','ophone')" /><span id="soadd-label">Same Office</span>
<input type="checkbox" id="otv" onclick="HandleClick(this)" /><span id="otv-label">OTV</span>
</div>
</div>
<!-- -->
@@ -473,7 +475,7 @@
</div>
<br >
<div class="inputcontainer" style="padding:1px">
<input type="text" id="department" name="designation" maxlength="50" style="width:100px" value="" onblur="validate(this,'f','SplInstruction')" />
<input type="text" id="department" name="department" maxlength="50" style="width:100px" value="" onblur="validate(this,'f','SplInstruction')" />
</div>
</div>
<div class="widget" style="margin-left:2px">
@@ -508,11 +510,11 @@
<div class="title">
<img class="matrix-title-icon" src="/matrix/images/resdet.png" />
<span class="matrix-title-text">Property Details</span>
<div class="divchk" id="ctrldiv">
<div class="divchk ctrldiv">
<input type="checkbox" id="pv" onclick="HandleClick(this)" />PVR&nbsp;
<input type="checkbox" id="rcp" style="display:none" onclick="HandleClick(this)" /><span id="rcp">RCP&nbsp;</span>
<input type="checkbox" id="ocp" style="display:none" onclick="HandleClick(this)" /><span id="ocp">OCP&nbsp;</span>
<input type="checkbox" id="spadd" onclick="return FindSameDet(this,'P','ppincode')" /><span id="spadd">Same Property</span>
<input type="checkbox" id="rcp" style="display:none" onclick="HandleClick(this)" /><span id="rcp-label">RCP&nbsp;</span>
<input type="checkbox" id="ocp" style="display:none" onclick="HandleClick(this)" /><span id="ocp-label">OCP&nbsp;</span>
<input type="checkbox" id="spadd" onclick="return FindSameDet(this,'P','ppincode')" /><span id="spadd-label">Same Property</span>
</div>
</div>
<!-- -->
@@ -527,7 +529,7 @@
</div>
<br >
<div class="inputcontainer" style="padding:1px">
<input type="text" id="paddr1" name="paddr1" readonly="readonly" maxlength="40" style="width:90px" value="" onblur="validate(this,document.getElementById('rv').checked ? 't':'f','SplInstruction')" />
<input type="text" id="paddr1" name="paddr1" readonly="readonly" maxlength="40" style="width:90px" value="" onblur="CygnusInitiationValidation.validateField(this);" />
</div>
</div>
<div class="widget" style="margin-left:2px">
@@ -582,7 +584,7 @@
</div>
<br >
<div class="inputcontainer" style="padding:1px">
<input type="text" id="ppincode" name="colp_pincode" readonly="readonly" maxlength="6" style="width:45px" value="" onblur="validate(this,document.getElementById('rv').checked ? 't':'f','Pincode')" />
<input type="text" id="ppincode" name="colp_pincode" readonly="readonly" maxlength="6" style="width:45px" value="" onblur="CygnusInitiationValidation.validateField(this);" />
</div>
</div>
<div class="widget" style="margin-left:2px">
@@ -608,7 +610,7 @@
<div class="title">
<img class="matrix-title-icon" src="/matrix/images/ref.png" />
<span class="matrix-title-text">Reference Details</span>
<div class="divchk" id="ctrldiv">
<div class="divchk ctrldiv">
<input type="checkbox" id="refv" name="refv" onclick="HandleClick(this)" />Ref Check&nbsp;
</div>
</div>
@@ -673,7 +675,7 @@
<div class="title">
<img class="matrix-title-icon" src="/matrix/images/documents.png" />
<span class="matrix-title-text">Document Details</span>
<div class="divchk" id="ctrldiv">
<div class="divchk ctrldiv">
<input type="checkbox" name="docv" id="docv" />Doc VR&nbsp;
</div>
</div>
@@ -696,10 +698,8 @@
<input type="hidden" id="branch_id" name="branch_id" value="${sessionScope.userSession.branchId}" />
<input type="hidden" id="status" name="status" value="" />
<!-- -->
<input type="hidden" id="invalidfields" value="0" />
<c:if test="${pageFormMode gt 0}">
<div style="position:fixed;text-align:right;bottom:0px;width:980px;" class="buttonbar">
<input type="hidden" id="invalidfields" value="0" />
<input type="button" class="button" name="btnfirst" style="margin-left:5px;margin-top:-2px;float:left;width:80px" value="" id="btnfirst" accesskey="F" onclick="findRecord(1)" />
<input type="button" class="button" name="btnprev" style="margin-top:-2px;float:left;width:80px" value="" id="btnprev" accesskey="P" onclick="findRecord(2)" />
<input type="button" class="button" name="btnnext" style="margin-top:-2px;float:left;width:80px" value="" id="btnnext" accesskey="N" onclick="findRecord(3)" />
@@ -723,6 +723,7 @@
<!-- Page Load Javascript -->
<script language="javascript" type="text/javascript">
(function () {
CygnusInitiationValidation.bind(document.getElementById("casedetails"));
var sectionFields = document.querySelectorAll(".model-visible-section");
if (sectionFields.length > 0) {
document.getElementById("visiblecontents").value = Array.prototype.map.call(
@@ -734,7 +735,10 @@
var code = document.getElementById("page-error-code");
var errorMessage = document.getElementById("page-error-message");
if (code && errorMessage) {
CallMessage(code.textContent + ":error:" + errorMessage.textContent, 3000, 200, 300);
CygnusNotifications.show({
type: "danger", code: code.textContent,
message: errorMessage.textContent, duration: 3000
});
}
}());
</script>

View File

@@ -75,7 +75,8 @@
right:8px;
cursor:pointer;
}
.title #ctrldiv
.title #ctrldiv,
.title .ctrldiv
{
border:none;
position:relative;

View File

@@ -41,7 +41,12 @@
const INTEGER_FIELDS = new Set(["applicationId", "portfolioId", "bankBranchId", "residenceColonyId",
"officeColonyId", "propertyColonyId", "formMode"]);
const element = (id) => document.getElementById(id);
const value = (id) => element(id)?.value?.trim() ?? "";
const value = (id) => {
const field = element(id);
if (!field) return "";
window.CygnusFormValidation.sanitizeElement(field);
return field.value?.trim() ?? "";
};
const integer = (id) => {
const parsed = Number.parseInt(value(id), 10);
return Number.isFinite(parsed) ? parsed : 0;
@@ -74,24 +79,14 @@
notify("danger", "APP-4221", "At least one verification type is required.");
return false;
}
window.invalidFields = 0;
window.validate(element("applno"), "t", "AlphaNumeric");
window.validate(element("bank_branch_id"), "t", "");
window.validate(element("product"), "t", "");
window.validate(element("customername"), "t", "AlphaSpace");
window.validate(element("apptype"), "t", "");
if (checked("rv")) window.CheckForm(element("rv"), "raddr1,raddr2,raddr3,rlandmark,colr,rcity,rpincode", "t,f,t,f,t,t,f", "SplInstruction,SplInstruction,SplInstruction,SplInstruction,SplInstruction,,Pincode");
if (checked("ov")) window.CheckForm(element("ov"), "companyname,oaddr1,oaddr2,oaddr3,olandmark,colo,ocity,opincode,department,designation", "f,t,f,t,f,t,t,f,f,f", "SplInstruction,SplInstruction,SplInstruction,SplInstruction,SplInstruction,SplInstruction,,Pincode,SplInstruction,SplInstruction");
if (checked("pv")) window.CheckForm(element("pv"), "paddr1,paddr2,paddr3,plandmark,colp,pcity,ppincode", "t,f,t,f,t,t,f", "SplInstruction,SplInstruction,SplInstruction,SplInstruction,SplInstruction,,Pincode");
if (checked("rtv")) window.CheckForm(element("rtv"), "rphone", "t", "Phone");
if (checked("otv")) window.CheckForm(element("otv"), "ophone", "t", "Phone");
if (checked("refv")) window.CheckForm(element("refv"), "refname1,refaddress1,refcontactno1", "t,f,t", "AlphaSpace,SplInstruction,Phone");
const validation = window.CygnusInitiationValidation.validateForm();
[["rv", "Rcolony", "colr"], ["ov", "Ocolony", "colo"], ["pv", "Pcolony", "colp"]]
.forEach(([flag, hidden, visible]) => {
if (checked(flag) && integer(hidden) === 0) window.highlightField(element(visible));
});
if (document.querySelector(".matrix-validation-error-icon")) {
if (!validation.valid || document.querySelector(".matrix-validation-error-icon")) {
notify("danger", "APP-4221", "Correct the highlighted fields and submit the application again.");
validation.invalid[0]?.focus();
return false;
}
return true;

View File

@@ -0,0 +1,75 @@
(function (window, document) {
"use strict";
const element = (id) => document.getElementById(id);
const checked = (id) => Boolean(element(id)?.checked);
const requiredWhen = (id) => () => checked(id);
const sectionRule = (id, rule = {}) => Object.assign({ when: requiredWhen(id) }, rule);
const RULES = {
applno: { required: true, format: "AlphaNumeric", requiredMessage: "Application number is required." },
bank_branch_id: { required: true, requiredMessage: "Bank branch is required." },
product: { required: true, requiredMessage: "Product is required." },
customername: { required: true, format: "AlphaSpace", requiredMessage: "Customer name is required." },
apptype: { required: true, requiredMessage: "Application type is required." },
bankcode: { format: "AlphaNumeric" }, fathername: { format: "AlphaSpace" }, dob: { format: "Date" },
mobileno: { format: "AllowWrong" }, loanamount: { format: "LoanAmount" },
contactperson: { format: "AlphaSpace" }, specialinst: { format: "SplInstruction" },
raddr1: sectionRule("rv", { required: true, format: "SplInstruction" }), raddr2: sectionRule("rv", { format: "SplInstruction" }),
raddr3: sectionRule("rv", { required: true, format: "SplInstruction" }), rlandmark: sectionRule("rv", { format: "SplInstruction" }),
rcity: sectionRule("rv", { required: true }), colr: sectionRule("rv", { required: true, format: "SplInstruction" }),
rpincode: sectionRule("rv", { format: "Pincode" }), rphone: sectionRule("rtv", { required: true, format: "Phone" }),
companyname: sectionRule("ov", { format: "SplInstruction" }), oaddr1: sectionRule("ov", { required: true, format: "SplInstruction" }),
oaddr2: sectionRule("ov", { format: "SplInstruction" }), oaddr3: sectionRule("ov", { required: true, format: "SplInstruction" }),
olandmark: sectionRule("ov", { format: "SplInstruction" }), ocity: sectionRule("ov", { required: true }),
colo: sectionRule("ov", { required: true, format: "SplInstruction" }), opincode: sectionRule("ov", { format: "Pincode" }),
department: sectionRule("ov", { format: "SplInstruction" }), designation: sectionRule("ov", { format: "SplInstruction" }),
ophone: sectionRule("otv", { required: true, format: "Phone" }), extension: sectionRule("otv", { format: "Extension" }),
paddr1: sectionRule("pv", { required: true, format: "SplInstruction" }), paddr2: sectionRule("pv", { format: "SplInstruction" }),
paddr3: sectionRule("pv", { required: true, format: "SplInstruction" }), plandmark: sectionRule("pv", { format: "SplInstruction" }),
pcity: sectionRule("pv", { required: true }), colp: sectionRule("pv", { required: true, format: "SplInstruction" }),
ppincode: sectionRule("pv", { format: "Pincode" }), refname1: sectionRule("refv", { required: true, format: "AlphaSpace" }),
refaddress1: sectionRule("refv", { format: "SplInstruction" }),
refcontactno1: sectionRule("refv", { required: true, format: "Phone" }),
refname2: sectionRule("refv", { format: "AlphaSpace" }), refaddress2: sectionRule("refv", { format: "SplInstruction" }),
refcontactno2: sectionRule("refv", { format: "Phone" })
};
function registerDynamicRules(form) {
if (!form) return;
form.querySelectorAll("#FormPanel6 [data-validation-required]").forEach(function (field) {
const label = field.closest(".widget")?.querySelector(".lblcontainer")?.textContent.trim();
RULES[field.id] = {
required: field.dataset.validationRequired === "true",
format: field.dataset.validationFormat || "",
requiredMessage: (label || "This dynamic field") + " is required."
};
});
}
function validateField(field) {
const target = typeof field === "string" ? element(field) : field;
const rule = target && RULES[target.id];
return !target || !rule || window.CygnusFormValidation.validateElement(target, rule);
}
function validateForm() {
return window.CygnusFormValidation.validateRules(RULES);
}
function bind(form) {
if (!form || form.dataset.initiationValidationBound === "true") return;
registerDynamicRules(form);
form.dataset.initiationValidationBound = "true";
form.addEventListener("focusout", function (event) {
window.CygnusFormValidation.sanitizeElement(event.target);
validateField(event.target);
});
}
window.CygnusInitiationValidation = Object.freeze({
rules: RULES,
bind: bind,
validateField: validateField,
validateForm: validateForm
});
}(window, document));

View File

@@ -42,25 +42,25 @@ function InitPage()
{
if(document.getElementById("ajaxmsg") !== null)
{
CallMessage('1001AJX:warning:Another operation is being processed, please wait..',3000,200,300);
CygnusNotifications.show({type:"warning",code:"1001AJX",message:"Another operation is being processed, please wait.",duration:3000});
return;
}
LoadingMsg("Fetching records, please wait...","ajaxmsg");
RunAjax("GET","punchedrecs","val0="+port+"&val1="+($("#dynamicfields").val())+"&val2="+($("#uuid").val()),1);
RunAjax("GET","punchedrecs","val0="+encodeURIComponent(port)+"&val1="+encodeURIComponent($("#dynamicfields").val())+"&val2="+encodeURIComponent($("#uuid").val()),1);
}
}
function GotoRecord(el,searchtype)
{
recno=el.value;
var recno=el.value;
if(recno!='')
{
if(searchtype == 'recno')
{
if(recno > recIndx || recno <=0)
{
CallMessage('1001IRNG:error:Invalid input. Out of range',3000,200,300);
CygnusNotifications.show({type:"danger",code:"1001IRNG",message:"Invalid input. Out of range",duration:3000});
}
else
{
@@ -70,7 +70,7 @@ if(recno!='')
}
else
{
for(index = 0; index < records.length; index++ )
for(var index = 0; index < records.length; index++ )
{
if( records[index][4] === recno ) {
recpos = index;
@@ -140,7 +140,7 @@ function AfterResponse(response,oprID)
}
else
{
CallMessage(response,3000,200,300);
CygnusNotifications.showLegacy(response,{duration:3000});
}
recIndx= rindx==0 ? rindx : rindx-1;
$("#recfound").html("<b>( 0 / "+(recIndx==0 ? "0" : recIndx)+" )</b>");
@@ -149,7 +149,7 @@ function AfterResponse(response,oprID)
}
else if(oprID==2)
{
collen=fields[0].length;
var collen=fields[0].length;
$("#ajaxmsg").remove();
if(response.trim().search('Error')==-1)
{
@@ -168,23 +168,23 @@ function AfterResponse(response,oprID)
records[recpos][collen-1]=response.split(ColDelim)[2];
AddNewRecord();
}
CallMessage('1001IRNG:info:Record updated successfully',3000,200,300);
CygnusNotifications.show({type:"info",code:"1001IRNG",message:"Record updated successfully",duration:3000});
}
else
{
records[recpos][collen-4]='-1';
CallMessage(response,3000,200,300);
CygnusNotifications.showLegacy(response,{duration:3000});
}
}
else if(oprID==19 || oprID==20 || oprID==21 || oprID==22)
{
TabRows=response.split(RowDelim);
for(indx=0;indx<TabRows.length-1;indx++)
var TabRows=response.split(RowDelim);
for(var indx=0;indx<TabRows.length-1;indx++)
{
if($("#portfolio_id").val()==81)
{
var appl = $("#applno").val();
alert('Application number '+appl+' already exists.');
CygnusNotifications.show({type:"warning",code:"APP-DUPLICATE",message:"Application number "+appl+" already exists.",duration:3000});
appl= (appl.search('_1') < 0 ? appl+'_1' : appl.split('_')[0]+'_'+(parseInt(appl.split('_')[1])+1));
$("#applno").val(appl);
validate(document.getElementById('applno'),'t','AlphaNumeric');
@@ -192,9 +192,9 @@ function AfterResponse(response,oprID)
}
else
{
TabCols=TabRows[indx].split(ColDelim);
var TabCols=TabRows[indx].split(ColDelim);
SameAddr[indx]=new Array(TabCols.length);
for(cindx=0;cindx<TabCols.length;cindx++)
for(var cindx=0;cindx<TabCols.length;cindx++)
{
SameAddr[indx][cindx]=TabCols[cindx];
}
@@ -205,8 +205,8 @@ function AfterResponse(response,oprID)
}
function findRecord(arrOpr)
{
tempPos= recpos;
maxLen= recIndx-1;
var tempPos= recpos;
var maxLen= recIndx-1;
if(arrOpr==1) tempPos=0;
if(arrOpr==2)
{
@@ -276,7 +276,7 @@ function FillDetails(indx)
}
else
{
CallMessage('5005MQRY:error:No records found',3000,200,300);
CygnusNotifications.show({type:"danger",code:"5005MQRY",message:"No records found",duration:3000});
AddNewRecord();
}
}
@@ -331,9 +331,9 @@ function HandleClick(el)
EnableDisableFields(el.checked,'paddr1,paddr2,paddr3,plandmark,colp,ppincode',',');
if(!el.checked)
{
chkrcp=document.getElementById('rcp');
var chkrcp=document.getElementById('rcp');
chkrcp.checked=false;
chkocp=document.getElementById('ocp');
var chkocp=document.getElementById('ocp');
chkocp.checked=false;
}
}
@@ -342,9 +342,9 @@ function HandleClick(el)
if(el.checked)
{
AutoFill('rcp',1);
chkocp=document.getElementById('ocp');
var chkocp=document.getElementById('ocp');
chkocp.checked=false;
chkprop=document.getElementById('pv');
var chkprop=document.getElementById('pv');
chkprop.checked=true;
HandleClick(chkprop);
}
@@ -356,9 +356,9 @@ function HandleClick(el)
if(el.checked)
{
AutoFill('ocp',1);
chkrcp=document.getElementById('rcp');
var chkrcp=document.getElementById('rcp');
chkrcp.checked=false;
chkprop=document.getElementById('pv');
var chkprop=document.getElementById('pv');
chkprop.checked=true;
HandleClick(chkprop);
}
@@ -372,19 +372,6 @@ function HandleClick(el)
}
function setFormValidation(Elem,FormPanel,ChildElems,IsRequired,Validation,CounterPartElem)
{
/*if(Elem.checked && !CounterPartElem)
{
hideForm(Elem.id, FormPanel);
}
if(!Elem.checked)
{
CheckForm(Elem,ChildElems,IsRequired,Validation);
if(!CounterPartElem)
{
hideForm(Elem.id, FormPanel);
}
}*/
if(Elem.checked || CounterPartElem)
{
UnhideSections(FormPanel+ColDelim, ColDelim);
@@ -399,11 +386,9 @@ function setFormValidation(Elem,FormPanel,ChildElems,IsRequired,Validation,Count
function CheckForm(Elem,ChildElems,IsRequired,Validation)
{
var Childs=ChildElems.split(",");
var IsChildReq=IsRequired.split(",");
var ValidString=Validation.split(",");
for(Indx=0;Indx<Childs.length;Indx++)
for(var Indx=0;Indx<Childs.length;Indx++)
{
validate(document.getElementById(Childs[Indx]),Elem.checked ? IsChildReq[Indx]:'f',ValidString[Indx]);
CygnusInitiationValidation.validateField(document.getElementById(Childs[Indx]));
}
}
function AutoFill(Opt,FillMode)
@@ -456,7 +441,7 @@ function ToggleChks(IsVisible,ChildElems,Delim)
else
{
var Childs=ChildElems.split(Delim);
for(indx=0;indx<Childs.length-1;indx++)
for(var indx=0;indx<Childs.length-1;indx++)
{
HideSections(Childs[indx]);
document.getElementById(Childs[indx]).checked=false;
@@ -469,15 +454,12 @@ function ClearDetails(TargetFields)
if(TargetFields.length!=0)
{
var TargetList=TargetFields.split(ColDelim);
if(TargetList.length==TargetList.length)
{
for(pos=0;pos<TargetList.length;pos++)
for(var pos=0;pos<TargetList.length;pos++)
{
$("#"+TargetList[pos]).val("");
}
}
}
}
function CopyDetails(SourceFields,TargetFields)
{
if(SourceFields.length!=0 && TargetFields.length!=0)
@@ -486,7 +468,7 @@ function CopyDetails(SourceFields,TargetFields)
var TargetList=TargetFields.split(ColDelim);
if(SourceList.length==TargetList.length)
{
for(pos=0;pos<SourceList.length;pos++)
for(var pos=0;pos<SourceList.length;pos++)
{
$("#"+TargetList[pos]).val($("#"+SourceList[pos]).val());
}
@@ -507,13 +489,13 @@ function ShowAddrOptions(OprID)
optDiv.setAttribute("class","FormPanel");
optDiv.setAttribute("style","font-family:Tahoma;overflow:visible");
var OptionPanel="<div id='TablePanel' class='tableContainer'><table border='0' cellspacing='0' width='100%' id='cutlist'><thead class='thead'><tr title='Row Title'><td colspan='2'>Available Addresses</td></tr></thead><tbody class='scrollContent'>";
for(indx=0;indx<SameAddr.length;indx++)
for(var indx=0;indx<SameAddr.length;indx++)
{
OptionPanel=OptionPanel+"<tr><td><input type='radio' name='rb1' id='rb"+indx+"' value='"+indx+"' onclick='selectedAddr=this.value;' /></td>";
OptionPanel=OptionPanel+"<td style='padding-right:5px'>";
for(cindx=0;cindx<4;cindx++)
for(var cindx=0;cindx<4;cindx++)
{
Addr=Addr+" "+SameAddr[indx][cindx];
Addr=Addr+" "+escapeHtml(SameAddr[indx][cindx]);
}
OptionPanel=OptionPanel+""+Addr+"</td></tr>";
Addr="";
@@ -524,12 +506,18 @@ function ShowAddrOptions(OprID)
ShowInputDialog(optDiv,"Select Address","hint","inptDialog");
document.getElementById('rb0').focus();
}
function escapeHtml(value)
{
return String(value == null ? "" : value).replace(/[&<>"']/g, function(character) {
return ({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[character];
});
}
function FillSameDet(AddrIndex,OprID)
{
if(!(AddrIndex < 0))
{
for(cindx=0;cindx<SameAddr[AddrIndex].length;cindx++)
for(var cindx=0;cindx<SameAddr[AddrIndex].length;cindx++)
{
$("#"+AddrElem[OprID][cindx+1]).val((SameAddr[AddrIndex][cindx]));
}
@@ -549,10 +537,14 @@ function SelectAddr(OprID)
{
ShowAddrOptions(OprID);
}
else
else if(SameAddr.length===1)
{
FillSameDet(0,OprID);
}
else
{
FillSameDet(-1,OprID);
}
}
function FindSameDet(Elm,Visit,focAfter)
{
@@ -570,19 +562,19 @@ function FindSameDet(Elm,Visit,focAfter)
}
if(procFlag)
{
Applno=document.getElementById('applno').value;
var Applno=document.getElementById('applno').value;
if(Applno.length==0)
{
if(Elm.type=='checkbox'){Elm.checked=false;}
CallMessage('VLFRM:error:Please enter application number.',3000,200,300);
CygnusNotifications.show({type:"danger",code:"VLFRM",message:"Please enter application number.",duration:3000});
document.getElementById('applno').focus();
return false;
}
else
{
SameAddr=new Array(0); // Empty Address Array
oprId=(Visit=='R' ? 19:Visit=='O' ? 20:Visit=='P' ? 21:22);
QryStr="val="+Applno+"&val1="+$("#portfolio_id").val()+"&val2="+oprId;
var oprId=(Visit=='R' ? 19:Visit=='O' ? 20:Visit=='P' ? 21:22);
var QryStr="val="+encodeURIComponent(Applno)+"&val1="+encodeURIComponent($("#portfolio_id").val())+"&val2="+encodeURIComponent(oprId);
RunAjax("GET","findsdet",QryStr,oprId);
}
}
@@ -620,12 +612,12 @@ function HandleBlur(el)
var chk= (el.id=='rcity' ? 'rv':(el.id=='ocity' ? 'ov':'pv'));
if(!FindStr(el,cel+'2!C0L!'+cel+'3'))
{
CallMessage("1001AREA:error:Invalid area.", 3000, 200, 300);
CygnusNotifications.show({type:"danger",code:"1001AREA",message:"Invalid area.",duration:3000});
$(el).val("-1");
$("#"+pel).val("");
$("#"+hel).val("");
}
validate(el,document.getElementById(chk).checked ? 't':'f','');
CygnusInitiationValidation.validateField(el);
}
if(el.id=='colr' || el.id=='colo' || el.id=='colp')
{
@@ -633,7 +625,7 @@ function HandleBlur(el)
var cel= (el.id=='colr' ? 'raddr':(el.id=='colo' ? 'oaddr':'paddr'));
if(!FindStr(el,cel+'2!C0L!'+cel+'3'))
{
CallMessage("1001AREA:error:Invalid colony.", 3000, 200, 300);
CygnusNotifications.show({type:"danger",code:"1001AREA",message:"Invalid colony.",duration:3000});
$(el).val("");
}
if(el.value=='')
@@ -644,6 +636,6 @@ function HandleBlur(el)
{
el.value='';
}
validate(el,document.getElementById(pel).checked ? 't':'f','SplInstruction');
CygnusInitiationValidation.validateField(el);
}
}

View File

@@ -0,0 +1,150 @@
(function (window, document) {
"use strict";
const FORMATS = Object.freeze({
Email: /^\S*\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,8}\b\S*$/,
Numeric: /^\d*$/,
AlphaNumeric: /^[a-zA-Z0-9_*\/\-]*$/,
AlphaSpace: /^[a-zA-Z0-9()\/ &]*$/,
LoanAmount: /^[a-zA-Z0-9. ]*$/,
SplInstruction: /^[a-zA-Z0-9():,#@.\-\/ ]*$/,
Remarks: /^[a-zA-Z0-9,(),:+&#@'.\-\/ ]*$/,
Pincode: /^\d{6}$/,
Phone: /^((\d{6,8}|\d{10}|\d{3}-\d{6,8})([\/](\d{6,8}|\d{10}|\d{3}-\d{6,8})){0,2})$/,
Extension: /^\d{3,4}$/
});
const DATE_PATTERN = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
function sanitize(value, options) {
const multiline = Boolean(options && options.multiline);
let sanitized = String(value == null ? "" : value).replace(/\t/g, "");
if (multiline) {
sanitized = sanitized.replace(/\r\n?/g, "\n").replace(/[^\x20-\x7E\n]/g, "");
} else {
sanitized = sanitized.replace(/[\r\n]/g, "").replace(/[^\x20-\x7E]/g, "");
}
return sanitized.trim();
}
function sanitizeElement(element) {
if (!element || typeof element.value !== "string") return "";
const tagName = element.tagName ? element.tagName.toLowerCase() : "";
const inputType = (element.type || "text").toLowerCase();
const sanitizableInput = tagName === "input" &&
["text", "search", "tel", "email", "url", "password"].includes(inputType);
if (tagName !== "textarea" && !sanitizableInput) return element.value;
const sanitized = sanitize(element.value, { multiline: tagName === "textarea" });
if (element.value !== sanitized) element.value = sanitized;
return sanitized;
}
function valueOf(element) {
return element && typeof element.value === "string" ? element.value.trim() : "";
}
function isEmpty(element) {
const value = valueOf(element);
return value === "" || (element.type === "select-one" && value === "-1");
}
function isDate(value) {
const parts = DATE_PATTERN.exec(value);
if (!parts) return false;
const day = Number(parts[1]);
const month = Number(parts[2]);
const year = Number(parts[3]);
if (year < 1900 || year > 2100 || month < 1 || month > 12) return false;
const date = new Date(year, month - 1, day);
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
}
function matchesFormat(value, format) {
if (!value || !format || format === "AllowWrong") return true;
const normalized = Object.keys(FORMATS).find((name) => name.toLowerCase() === format.toLowerCase());
if (format.toLowerCase() === "date") return isDate(value);
return normalized ? FORMATS[normalized].test(value) : true;
}
function errorHost(element) {
let current = element.parentNode;
let host = current;
while (current && current !== document.body) {
if ((" " + (current.className || "") + " ").indexOf(" inputcontainer ") !== -1) return current;
current = current.parentNode;
}
return host;
}
function clearError(element) {
if (!element) return;
const icon = document.getElementById("err" + element.id);
if (icon && icon.parentNode) icon.parentNode.removeChild(icon);
element.classList.remove("errtxt");
if (element.parentNode) element.parentNode.classList.remove("errdiv");
element.removeAttribute("aria-invalid");
element.removeAttribute("aria-describedby");
if (typeof element.setCustomValidity === "function") element.setCustomValidity("");
}
function showError(element, message) {
if (!element) return;
clearError(element);
const host = errorHost(element);
const icon = document.createElement("img");
icon.src = "/matrix/images/exclamation.png";
icon.id = "err" + element.id;
icon.alt = message;
icon.title = message;
icon.className = "matrix-validation-error-icon" +
(element.type === "select-one" ? " matrix-validation-error-icon--select" : "");
icon.style.cssText = "position:absolute;right:" + (element.type === "select-one" ? "24px" : "5px") +
";top:50%;width:14px;height:14px;transform:translateY(-50%);z-index:3;pointer-events:none";
host.style.position = "relative";
host.appendChild(icon);
if (element.type === "select-one") element.parentNode.classList.add("errdiv");
else element.classList.add("errtxt");
element.setAttribute("aria-invalid", "true");
element.setAttribute("aria-describedby", icon.id);
if (typeof element.setCustomValidity === "function") element.setCustomValidity(message);
}
function validateElement(element, rule) {
if (!element) return true;
sanitizeElement(element);
if (typeof rule.when === "function" && !rule.when()) {
clearError(element);
return true;
}
const required = typeof rule.required === "function" ? rule.required() : Boolean(rule.required);
let message = "";
if (required && isEmpty(element)) message = rule.requiredMessage || "This field is required.";
else if (!isEmpty(element) && !matchesFormat(valueOf(element), rule.format)) {
message = rule.formatMessage || "Enter a valid value.";
}
if (message) showError(element, message);
else clearError(element);
return message === "";
}
function validateLegacy(element, requiredFlag, format) {
return validateElement(element, { required: requiredFlag === "t", format: format });
}
function validateRules(rules) {
const invalid = [];
Object.keys(rules).forEach(function (id) {
const element = document.getElementById(id);
if (!validateElement(element, rules[id])) invalid.push(element);
});
return { valid: invalid.length === 0, invalid: invalid };
}
window.CygnusFormValidation = Object.freeze({
clearError: clearError,
sanitize: sanitize,
sanitizeElement: sanitizeElement,
validateElement: validateElement,
validateLegacy: validateLegacy,
validateRules: validateRules
});
}(window, document));

View File

@@ -74,5 +74,22 @@
document.getElementById("cygnus-notifications")?.replaceChildren();
}
window.CygnusNotifications = Object.freeze({ show, clear });
function showLegacy(serialized, options) {
const text = String(serialized || "");
const firstSeparator = text.indexOf(":");
const secondSeparator = firstSeparator < 0 ? -1 : text.indexOf(":", firstSeparator + 1);
const settings = Object.assign({}, options);
if (secondSeparator > firstSeparator) {
settings.code = text.slice(0, firstSeparator);
const legacyType = text.slice(firstSeparator + 1, secondSeparator).toLowerCase();
settings.type = legacyType === "error" ? "danger" : legacyType;
settings.message = text.slice(secondSeparator + 1);
} else {
settings.type = settings.type || "danger";
settings.message = text;
}
return show(settings);
}
window.CygnusNotifications = Object.freeze({ show, showLegacy, clear });
}(window, document));

View File

@@ -7,8 +7,12 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CommonFunctions {
private static final Pattern DYNAMIC_VALIDATION = Pattern.compile(
"(?i)validate\\s*\\(\\s*this\\s*,\\s*'([tf])'\\s*,\\s*'([^']*)");
private String ErrMsg;
private String ErrCode;
private String ErrDesc;
@@ -110,6 +114,7 @@ public class CommonFunctions {
String CtrlEvents="";
String isSelected="";
String maxLength="maxlength";
String validationAttributes=dynamicValidationAttributes(Controls[9]);
String unit="px";
setCtrlType(Controls[14]);
ControlVal=(ControlVal==null || ControlVal.equals("")) ? Controls[17] : ControlVal;
@@ -151,11 +156,11 @@ public class CommonFunctions {
CtrlHtml=CtrlHtml+"</div><div class='inputcontainer'>";
if(getCtrlType().equals("text"))
{
CtrlHtml=CtrlHtml+"<input type=\"text\" id='"+Controls[2]+"' name='"+Controls[2]+"' "+maxLength+" "+CtrlEvents+" "+CtrlStyle+" "+CtrlClass+" value=\""+ControlVal+"\" />";
CtrlHtml=CtrlHtml+"<input type=\"text\" id='"+Controls[2]+"' name='"+Controls[2]+"' "+maxLength+" "+validationAttributes+" "+CtrlEvents+" "+CtrlStyle+" "+CtrlClass+" value=\""+ControlVal+"\" />";
}
else if(getCtrlType().equals("checkbox"))
{
CtrlHtml=CtrlHtml+"<input id='"+Controls[2]+"' name='"+Controls[2]+"' "+maxLength+" "+CtrlEvents+" "+CtrlStyle+" "+CtrlClass+" value='"+ControlVal+"' />";
CtrlHtml=CtrlHtml+"<input id='"+Controls[2]+"' name='"+Controls[2]+"' "+maxLength+" "+validationAttributes+" "+CtrlEvents+" "+CtrlStyle+" "+CtrlClass+" value='"+ControlVal+"' />";
}
CtrlHtml=CtrlHtml+"</div></div>";
}
@@ -167,7 +172,7 @@ public class CommonFunctions {
}
CtrlHtml="<div class='widget'><div class='lblcontainer'>"+Controls[1];
CtrlHtml=CtrlHtml+"</div><div class='inputcontainer'>";
CtrlHtml=CtrlHtml+"<textarea id='"+Controls[2]+"' name='"+Controls[2]+"' "+maxLength+" "+CtrlEvents+" "+CtrlStyle+" "+CtrlClass+" >"+ControlVal+"</textarea>";
CtrlHtml=CtrlHtml+"<textarea id='"+Controls[2]+"' name='"+Controls[2]+"' "+maxLength+" "+validationAttributes+" "+CtrlEvents+" "+CtrlStyle+" "+CtrlClass+" >"+ControlVal+"</textarea>";
CtrlHtml=CtrlHtml+"</div></div>";
}
else if(getCtrlType().equals("select"))
@@ -194,7 +199,7 @@ public class CommonFunctions {
CtrlHtml="<div class='widget'><div class='lblcontainer'>"+Controls[1];
CtrlHtml=CtrlHtml+"</div><div class='inputcontainer'>";
CtrlHtml=CtrlHtml+"<div "+CtrlClass+" id='div"+Controls[2]+"' "+CtrlStyle+" >";
CtrlHtml=CtrlHtml+"<select id='"+Controls[2]+"' name='"+Controls[2]+"' "+CtrlEvents+" "+CtrlStyle1+" >";
CtrlHtml=CtrlHtml+"<select id='"+Controls[2]+"' name='"+Controls[2]+"' "+validationAttributes+" "+CtrlEvents+" "+CtrlStyle1+" >";
CtrlHtml=CtrlHtml+"<option value='-1' selected>NA</option>";
CtrlHtml=CtrlHtml+"<option value='"+Controls[19]+"' "+isSelected+" >"+Controls[19]+"</option></select></div></div></div>";
}
@@ -213,6 +218,16 @@ public class CommonFunctions {
}
return Controls[4];
}
private String dynamicValidationAttributes(String onBlur)
{
if(onBlur==null || onBlur.isBlank()) return "";
Matcher matcher=DYNAMIC_VALIDATION.matcher(onBlur);
if(!matcher.find()) return "";
String format=matcher.group(2).trim().replaceFirst("[^A-Za-z0-9]+$", "");
return "data-validation-required='"+(matcher.group(1).equalsIgnoreCase("t") ? "true" : "false")+
"' data-validation-format='"+format+"'";
}
public String DesignControls(String ControlType,String Controlid,String TypeScript,String ValidationScript,String Style, String CssClass,String Fieldid,DBFunctions DBFunc,StringFunctions SFunc,String ControlVal)
{
String HtmlControl="";

View File

@@ -515,7 +515,7 @@ class RoleVisibleBatchMigrationTest {
String initialCase = Files.readString(punching.resolve("initcase.jsp"));
assertTrue(initialCase.contains("GotoRecord(this,'recno')"));
assertTrue(initialCase.contains("CygnusInitiation.save(event)"));
assertTrue(initialCase.contains("/matrix/js/edp/initiation.js"));
assertTrue(initialCase.contains("/matrix/js/edp/punching/initiation.js"));
assertTrue(initialCase.contains("AddNewRecord()"));
String initialDocs = Files.readString(punching.resolve("initdocs.jsp"));

View File

@@ -0,0 +1,49 @@
package matrix.nimble.utilities;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
class CommonFunctionsTest {
@Test
void dynamicControlIncludesConfiguredValidationMetadata() {
CommonFunctions functions = functions();
functions.DynamicControls(control("validate(this,'t','SplInstruction')"), "");
assertTrue(functions.getGeneratedHtml().contains("data-validation-required='true'"));
assertTrue(functions.getGeneratedHtml().contains("data-validation-format='SplInstruction'"));
}
@Test
void dynamicControlNormalizesMalformedTrailingDateRule() {
CommonFunctions functions = functions();
functions.DynamicControls(control("validate(this,'f','Date)"), "");
assertTrue(functions.getGeneratedHtml().contains("data-validation-required='false'"));
assertTrue(functions.getGeneratedHtml().contains("data-validation-format='Date'"));
}
private CommonFunctions functions() {
CommonFunctions functions = new CommonFunctions();
functions.setPrevControl("");
functions.setDynamicCtrls("");
functions.setGeneratedHtml("");
return functions;
}
private String[] control(String onBlur) {
String[] control = new String[27];
Arrays.fill(control, "");
control[0] = "1";
control[1] = "Dynamic field";
control[2] = "field1";
control[5] = "40";
control[9] = onBlur;
control[14] = "text";
control[17] = "";
control[26] = "1";
return control;
}
}