120 lines
4.3 KiB
JavaScript
120 lines
4.3 KiB
JavaScript
var currow=null;
|
|
function ValidateEntry(flag)
|
|
{
|
|
validate(document.getElementById("doctype"),flag,'');
|
|
validate(document.getElementById("docholdername"),flag,'SplInstruction');
|
|
if(validateHidden && $("#serviceprovider_hidden").val()=='')
|
|
{
|
|
$("#serviceprovider").val('');
|
|
}
|
|
validate(document.getElementById("serviceprovider"),flag,'SplInstruction');
|
|
var temp=$("#uniqueno").attr("onblur").replace( "validate(","" ).replace( ")","").replace(/'/g,"").split(",");
|
|
validate(document.getElementById("uniqueno"),flag,temp[2]);
|
|
var temp=$("#yearmonth").attr("onblur").replace( "validate(","" ).replace( ")","").replace(/'/g,"").split(",");
|
|
validate(document.getElementById("yearmonth"),temp[1],temp[2]);
|
|
validate(document.getElementById("city"),flag,'');
|
|
}
|
|
function AddNewDoc()
|
|
{
|
|
ValidateEntry('t');
|
|
if(checkForm())
|
|
{
|
|
UpdateDoc();
|
|
}
|
|
else
|
|
{
|
|
CallMessage('VLFRM:error:There are one or more error(s) in form. Please correct them and try again.',3000,200,300);
|
|
}
|
|
}
|
|
function AddDocRow(data,did,vname)
|
|
{
|
|
var tbody = $('#doclist');
|
|
var totdocs= $('#doclist tr').length;
|
|
var row = null;
|
|
if(data.doc_id=='0')
|
|
{
|
|
row = $('<tr></tr>').attr("did",did).attr("onclick","GetRowData(this)").appendTo(tbody);
|
|
}
|
|
else
|
|
{
|
|
if(currow != null)
|
|
{
|
|
row = $("#doclist tr:eq("+currow+")");
|
|
$(row).html('');
|
|
totdocs = currow;
|
|
}
|
|
}
|
|
$('<td></td>').text(totdocs+1).appendTo(row);
|
|
$('<td></td>').text(data.docholdername).appendTo(row);
|
|
$('<td></td>').attr("dtype",data.doctype).text($("#doctype option[value='"+data.doctype+"']").text()).appendTo(row);
|
|
$('<td></td>').attr("id",data.serviceprovider_hidden).text(data.serviceprovider).appendTo(row);
|
|
$('<td></td>').attr("title",data.city).text(data.uniqueno).appendTo(row);
|
|
$('<td></td>').text(data.yearmonth).appendTo(row);
|
|
$('<td></td>').attr("id",data.vendor_id).text((vname.length > 0 ? vname:$("#vendor_id option[value='"+data.vendor_id+"']").text())).appendTo(row);
|
|
$('<td></td>').text("").appendTo(row);
|
|
}
|
|
function GetRowData(drow)
|
|
{
|
|
currow = $(drow).index();
|
|
$("#doctype").val($(drow).find('td').eq(2).attr("dtype"));
|
|
$("#doctype").trigger("change");
|
|
$("#docholdername").val($(drow).find('td').eq(1).text().trim());
|
|
$("#serviceprovider").val($(drow).find('td').eq(3).text().trim());
|
|
$("#serviceprovider_hidden").val($(drow).find('td').eq(3).attr("id"));
|
|
$("#uniqueno").val($(drow).find('td').eq(4).text().trim());
|
|
$("#yearmonth").val($(drow).find('td').eq(5).text().trim());
|
|
$("#city").val($(drow).find('td').eq(4).attr("title").trim());
|
|
//$("#vendor_id").val($(drow).find('td').eq(6).attr("id"));
|
|
ValidateEntry('t');
|
|
$("#doc_id").val($(drow).attr("did"));
|
|
}
|
|
function resetDocForm()
|
|
{
|
|
validateHidden = false;
|
|
document.getElementById('docdetails').reset();
|
|
$('#city').val("-1");
|
|
$('#vendor_id').empty().append('<option value="-1" selected>SELECT</option>');
|
|
currow = null;
|
|
}
|
|
function UpdateDoc()
|
|
{
|
|
var jsonString = JSON.stringify($('#docdetails').serializeObject()).substring();
|
|
jsonString = '{'+jsonString.substring(1, jsonString.length-1)+',"uuid":"'+$("#uuid").val()+'","usid":"'+$("#usid").val()+'"}';
|
|
$.ajax({
|
|
url:"doc/updcasedocs",
|
|
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){
|
|
var dataArray = jQuery.parseJSON(resposeJsonObject);
|
|
if(dataArray.status.search("error") > -1)
|
|
{
|
|
CallMessage(dataArray.result,3000,200,300);
|
|
}
|
|
else
|
|
{
|
|
AddDocRow(dataArray.result,dataArray.did,'');
|
|
resetDocForm();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
$.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;
|
|
}; |