289 lines
7.3 KiB
JavaScript
289 lines
7.3 KiB
JavaScript
var records=new Array();
|
|
var fields=new Array(1);
|
|
var recIndx = 0;
|
|
var recpos = 0;
|
|
var precpos = 0;
|
|
var precIndx = 0;
|
|
var precs = new Array();
|
|
function InitPage()
|
|
{
|
|
if(document.getElementById("ajaxmsg") !== null)
|
|
{
|
|
CallMessage('1001AJX:warning:Another operation is being processed, please wait..',3000,200,300);
|
|
return;
|
|
}
|
|
LoadingMsg("Fetching records, please wait...","ajaxmsg");
|
|
RunAjax("GET","emprecords","val0="+($("#branch").val()),2);
|
|
}
|
|
function findRecords(key)
|
|
{
|
|
key = key.toUpperCase().trim();
|
|
if(precs.length > 0)
|
|
{
|
|
clearSearch();
|
|
}
|
|
if(key.length > 0)
|
|
{
|
|
var filtered = new Array();
|
|
var rlength = records.length;
|
|
for(rindx=0;rindx < rlength;rindx++)
|
|
{
|
|
var clength = records[rindx].length;
|
|
if((records[rindx][0].toUpperCase().search(key.toUpperCase()) > -1) || (records[rindx][clength-5].toUpperCase() == key.toUpperCase()))
|
|
{
|
|
filtered[filtered.length] = records[rindx];
|
|
}
|
|
}
|
|
if(filtered.length == 0)
|
|
{
|
|
CallMessage('1001AJX:error:No match found.',3000,200,300);
|
|
}
|
|
else
|
|
{
|
|
precs = records;
|
|
records = filtered;
|
|
precpos = recpos;
|
|
recpos = 0;
|
|
precIndx = recIndx;
|
|
recIndx = records.length;
|
|
$("#recfound").html("<b>( 0 / "+(recIndx==0 ? "0" : recIndx)+" )</b>");
|
|
}
|
|
}
|
|
FillDetails(recpos);
|
|
}
|
|
function clearSearch()
|
|
{
|
|
recpos = precpos;
|
|
precpos = 0;
|
|
records = precs;
|
|
precs = new Array();
|
|
recIndx = records.length;
|
|
precIndx = 0;
|
|
$("#recfound").html("<b>( 0 / "+(recIndx==0 ? "0" : recIndx)+" )</b>");
|
|
}
|
|
function uploadDocs(fid)
|
|
{
|
|
$("#dusid").val($("#usid").val());
|
|
$("#doctype").val("div"+fid);
|
|
getFile();
|
|
}
|
|
function startUpload(felem)
|
|
{
|
|
uploadFile(document.getElementById("updoc"),"docForm",$("#updoc").attr("ext"));
|
|
}
|
|
function getEntity(design)
|
|
{
|
|
if(design==21)
|
|
{
|
|
QueryStr="val0=69&val1="+($("#branch").val());
|
|
}
|
|
else
|
|
{
|
|
QueryStr="val0=341&val1="+design;
|
|
}
|
|
RunAjax('POST','getddvalues', QueryStr, 1);
|
|
}
|
|
function AfterResponse(response,oprID)
|
|
{
|
|
if(oprID==1)
|
|
{
|
|
if(response.trim().search('Error')==-1)
|
|
{
|
|
$("#entity_id").html(response);
|
|
if($("#designation").val()==21)
|
|
{
|
|
$("#lblentity").html("Code");
|
|
}
|
|
else
|
|
{
|
|
$("#lblentity").html("Nimble ID");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CallMessage(response,2000,200,300);
|
|
}
|
|
}
|
|
if(oprID==2)
|
|
{
|
|
$("#ajaxmsg").remove();
|
|
if(response.trim().search('Error')==-1)
|
|
{
|
|
var rows=response.split(RowDelim);
|
|
for(rindx=0;rindx<rows.length-1;rindx++)
|
|
{
|
|
var cindx=0;
|
|
var cols=rows[rindx].split(ColDelim);
|
|
if(rindx==0)
|
|
{
|
|
fields[rindx]=new Array(cols.length);
|
|
}
|
|
else
|
|
{
|
|
records[rindx-1]=new Array(cols.length);
|
|
}
|
|
for(cindx=0;cindx<cols.length;cindx++)
|
|
{
|
|
if(rindx==0)
|
|
{
|
|
fields[rindx][cindx]=cols[cindx];
|
|
}
|
|
else
|
|
{
|
|
records[rindx-1][cindx]=cols[cindx];
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
CallMessage(response,3000,200,300);
|
|
}
|
|
recIndx= rindx==0 ? rindx : rindx-1;
|
|
$("#recfound").html("<b>( 0 / "+(recIndx==0 ? "0" : recIndx)+" )</b>");
|
|
recpos=recIndx==0 ? 0 : recIndx-1;
|
|
FillDetails(recpos);
|
|
}
|
|
}
|
|
function findRecord(arrOpr)
|
|
{
|
|
tempPos= recpos;
|
|
maxLen= recIndx-1;
|
|
if(arrOpr==1) tempPos=0;
|
|
if(arrOpr==2)
|
|
{
|
|
if(tempPos>0) tempPos=tempPos-1;
|
|
else return false;
|
|
}
|
|
if(arrOpr==3)
|
|
{
|
|
if(tempPos<maxLen) tempPos=tempPos+1;
|
|
else return false;
|
|
}
|
|
if(arrOpr==4) tempPos=maxLen;
|
|
recpos= tempPos;
|
|
FillDetails(recpos);
|
|
}
|
|
function GotoRecord(el)
|
|
{
|
|
recno=el.value;
|
|
if(recno!='')
|
|
{
|
|
if(recno > recIndx || recno <=0)
|
|
{
|
|
CallMessage('1001IRNG:error:Invalid input. Out of range',3000,200,300);
|
|
}
|
|
else
|
|
{
|
|
recpos=recno-1;
|
|
FillDetails(recpos);
|
|
}
|
|
}
|
|
}
|
|
function FillDetails(indx)
|
|
{
|
|
if(recIndx > 0)
|
|
{
|
|
document.forms['empdetailsform'].reset();
|
|
$("#divcpv_documents").html("<div class=\"container\"></div>");
|
|
$("#divemp_documents").html("<div class=\"container\"></div>");
|
|
$("#recfound").html("<b>( "+(indx+1)+" / "+(recIndx==0 ? "0" : recIndx)+" )</b>");
|
|
var findx=0;
|
|
for(findx=0;findx<fields[0].length;findx++)
|
|
{
|
|
if($("#"+fields[0][findx]).length > 0)
|
|
{
|
|
$("#"+fields[0][findx]).val(records[indx][findx]);
|
|
if((fields[0][findx]=='cpv_documents' || fields[0][findx]=='emp_documents') && records[indx][findx] !== undefined )
|
|
{
|
|
var farr = records[indx][findx].split(";");
|
|
for(aindx=0;aindx < farr.length; aindx++)
|
|
{
|
|
if(farr[aindx].length > 0 && farr[aindx].search(".pdf") > -1)
|
|
{
|
|
$(".container",$("#div"+fields[0][findx])).append("<div class=\"widget\"><div class=\"lblcontainer\"><a href='http://192.168.10.205/output/employee/"+fields[0][findx]+"/"+farr[aindx]+"' target=\"_blank\"><input type='button' id='btnpdf' class='button' value='"+(fields[0][findx]=='cpv_documents' ? 'Open CPV Report':'Open Document')+"' style='margin-top:5px;padding-left:30px;height:36px' /></a></div></div>");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CallMessage('5005MQRY:error:No records found',3000,200,300);
|
|
}
|
|
}
|
|
function AddNewRecord()
|
|
{
|
|
if(precs.length > 0)
|
|
{
|
|
clearSearch();
|
|
}
|
|
if(recIndx== 0 || records[recIndx-1][fields[0].length-1]!='0')
|
|
{
|
|
var cols=fields[0].length;
|
|
recIndx = recIndx+1;
|
|
recpos = recIndx-1;
|
|
records[recpos]=new Array(cols);
|
|
records[recpos][cols-1]='0';
|
|
records[recpos][30]=$("#branch").val();
|
|
document.getElementById("empname").focus();
|
|
}
|
|
else
|
|
{
|
|
recpos=recIndx-1;
|
|
}
|
|
FillDetails(recpos);
|
|
}
|
|
function SaveDetails()
|
|
{
|
|
var cols=fields[0].length;
|
|
/*var Qstr="val="+$("#usid").val();
|
|
for(rindx=0;rindx < cols;rindx++)
|
|
{
|
|
if($("#"+fields[0][rindx]).length > 0)
|
|
{
|
|
records[recpos][rindx]=$("#"+fields[0][rindx]).val();
|
|
Qstr=Qstr+"&val"+rindx+"="+($("#"+fields[0][rindx]).val());
|
|
}
|
|
}*/
|
|
|
|
var jsonString = JSON.stringify($('#empdetailsform').serializeObject()).substring();
|
|
jsonString = '{'+jsonString.substring(1, jsonString.length-1)+',"branch":"'+$("#branch").val()+'","usid":"'+$("#usid").val()+'"}';
|
|
$.ajax({
|
|
url:"updemprecords",
|
|
type:"POST",
|
|
contentType: "application/json; charset=utf-8",
|
|
data: jsonString, //Stringified Json Object
|
|
async: false, //Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation
|
|
cache: false, //This will force requested pages not to be cached by the browser
|
|
processData:false, //To avoid making query String instead of JSON
|
|
success: function(resposeJsonObject){
|
|
if(resposeJsonObject.search("Error") > -1)
|
|
{
|
|
CallMessage(resposeJsonObject,3000,200,300);
|
|
}
|
|
else
|
|
{
|
|
SubmitForm("empdetform", "_parent", "empdetailsform");
|
|
}
|
|
}
|
|
});
|
|
}
|
|
$.fn.serializeObject = function()
|
|
{
|
|
var o = {};
|
|
var a = this.serializeArray();
|
|
$.each(a, function() {
|
|
if (o[this.name] !== undefined) {
|
|
if (!o[this.name].push) {
|
|
o[this.name] = [o[this.name]];
|
|
}
|
|
o[this.name].push(this.value || '');
|
|
} else {
|
|
o[this.name] = this.value || '';
|
|
}
|
|
});
|
|
return o;
|
|
}; |