everseiko/asset/js/form_view.js
2020-01-02 23:02:57 +07:00

311 lines
9.0 KiB
JavaScript

function load(id, base_url)
{
var dataJson;
$.ajax({
url: base_url+'form/getDataAjax/'+id,
success: function(msg)
{
//alert("masuk");
dataJson=msg;
dataJson = jQuery.parseJSON(msg);
var data = dataJson['visit'];
var vehicle = dataJson['vehicle'];
var purchase = dataJson['purchase'];
var rcm = dataJson['recommendation'];
var pic = dataJson['pictures'];
loadinput(data);
loadcheckbox(data);
loadradio(data);
loadvehicle(vehicle);
loadpurchase(purchase);
loadrecommendation(rcm);
loadpictures(pic);
}
});
}
function loadinput(data)
{
//general location
$('#province').val(data.province);
$('#kota').val(data.kota);
//company details
$('#sos').val(data.sender);
$('#cust_name').val(data.customer);
//addr n phone
$('#head_address').val(data.head_address);
$('#head_phone').val(data.head_phone);
$('#branch_address').val(data.branch_address);
$('#branch_phone').val(data.branch_phone);
//contact person
$('#cp_name').val(data.cp_name);
$('#cp_phone').val(data.cp_phone);
//destination
$('#destination').val(data.destination);
$('#road_condition_good').val(data.road_condition_good);
$('#road_condition_toll').val(data.road_condition_toll);
$('#road_condition_bad').val(data.road_condition_bad);
$('#road_condition_other').val(data.road_condition_other);
$('#mileage_front').val(data.mileage_front);
$('#mileage_rear').val(data.mileage_rear);
$('#psi_front').val(data.psi_front);
$('#psi_rear').val(data.psi_rear);
$('#otr').val(data.otr);
$("textarea#mileage_detail").val(data.mileage_detail);
$('textarea#problem').val(data.problem);
}
function loadcheckbox(data)
{
//nature bisnis
var nb = data.nature_bisnis;
var arr_nb = nb.split(',');
var list_nb = "Expedition, Bus, Minning, Loging, Cement, Bulk, Container";
for (var i = 0; i < arr_nb.length; i++) {
var teks = arr_nb[i];
var patt = new RegExp(arr_nb[i]);
//alert(teks);
if (patt.test(list_nb))
{
$("input[value='"+teks+"']").prop("checked", true);
}
}
//loads
var ld = data.loads;
var arr_ld = ld.split(',');
var list_ld = "Materials, Passenger, Goods, Soil, General Cargo";
for (var i = 0; i < arr_ld.length; i++) {
var teks = arr_ld[i];
var patt = new RegExp(teks);
if (patt.test(list_ld))
{
$("input[value='"+teks+"']").prop("checked", true);
}
else
{
$("input[name=vdCb_6]").val(teks);
$("input[name=vdCb_6]").prop("checked", true);
}
}
//tyre brands
var br = data.tire_brands;
var arr_br = br.split(',');
var list_ld = "MRF, Goodyear, Bridgestone, GT, Dunlop, Chinese, Kumho, Hankook, Ceat, Thai, Maxxis, Chengsin, Epco, Swallow, ChaoYang";
for (var i = 0; i < arr_br.length; i++) {
var teks = arr_br[i];
var patt = new RegExp(arr_br[i]);
if (patt.test(list_ld))
{
$("input[value='"+teks+"']").prop("checked", true);
}
}
//type purchase
var tp = data.tire_purchases;
var tp1 = new RegExp('New Tyre');
var tp2 = new RegExp('Retreads');
if (tp1.test(tp))$("input[name='tpCb2_1']").prop("checked", true);
if (tp2.test(tp))$("input[name='tpCb2_2']").prop("checked", true);
//type
var ti = data.tire_types;
var ti1 = new RegExp('Rib');
var ti2 = new RegExp('Lug');
var ti3 = new RegExp('Bias');
var ti4 = new RegExp('Radial');
var ti5 = new RegExp('Mix');
if (ti1.test(ti))$("input[name='tpCb3_1']").prop("checked", true);
if (ti2.test(ti))$("input[name='tpCb3_2']").prop("checked", true);
if (ti3.test(ti))$("input[name='tpCb3_3']").prop("checked", true);
if (ti4.test(ti))$("input[name='tpCb3_4']").prop("checked", true);
if (ti5.test(ti))$("input[name='tpCb3_5']").prop("checked", true);
//front method
var fm = data.condition_front;
var fm1 = new RegExp('New Tyre');
var fm2 = new RegExp('Retreads');
if (fm1.test(fm))$("input[name='cb31']").prop("checked", true);
if (fm2.test(fm))$("input[name='cb32']").prop("checked", true);
//rear method
var rm = data.condition_rear;
var rm1 = new RegExp('New Tyre');
var rm2 = new RegExp('Retreads');
if (rm1.test(rm))$("input[name='cb41']").prop("checked", true);
if (rm2.test(rm))$("input[name='cb42']").prop("checked", true);
}
function loadradio(data)
{
$("input:radio[name=rbCd][value='"+data.visit_status+"']").prop('checked', true);
//$("input:radio[name=rbCd2][value='"+data.method+"']").prop('checked', true);
$("input:radio[name=trRb][value='"+data.mileage_method+"']").prop('checked', true);
$("input:radio[name=trRb2][value='"+data.purchase_method+"']").prop('checked', true);
}
function loadvehicle(vehicle)
{
var a = vehicle.length;
//var b = vehicle[3];
//alert(JSON.stringify(b));
for (var i = 0; i < a; i++) {
if (vehicle[i]['category'].toLowerCase()=='truck')
{
if (vehicle[i]['type'].toLowerCase()=='light')
{
if (vehicle[i]['total_tire']=='4')
{
$("input[name=vdTr4]").val(vehicle[i]['qty']);
$("input[name=vdTr4wt]").val(vehicle[i]['load_weight']);
}
if (vehicle[i]['total_tire']=='6')
{
$("input[name=vdTr6]").val(vehicle[i]['qty']);
$("input[name=vdTr6wt]").val(vehicle[i]['load_weight']);
}
if (vehicle[i]['total_tire']=='10')
{
$("input[name=vdTr10]").val(vehicle[i]['qty']);
$("input[name=vdTr10wt]").val(vehicle[i]['load_weight']);
}
}
if (vehicle[i]['type'].toLowerCase()=='normal')
{
if (vehicle[i]['total_tire']=='6')
{
$("input[name=vdLt6]").val(vehicle[i]['qty']);
$("input[name=vdLt6wt]").val(vehicle[i]['load_weight']);
}
if (vehicle[i]['total_tire']=='8')
{
$("input[name=vdLt8]").val(vehicle[i]['qty']);
$("input[name=vdLt8wt]").val(vehicle[i]['load_weight']);
}
if (vehicle[i]['total_tire']=='10')
{
$("input[name=vdLt10]").val(vehicle[i]['qty']);
$("input[name=vdLt10wt]").val(vehicle[i]['load_weight']);
}
if (vehicle[i]['total_tire']=='12')
{
$("input[name=vdLt12]").val(vehicle[i]['qty']);
$("input[name=vdLt12wt]").val(vehicle[i]['load_weight']);
}
if (vehicle[i]['total_tire']=='14')
{
$("input[name=vdLt14]").val(vehicle[i]['qty']);
$("input[name=vdLt14wt]").val(vehicle[i]['load_weight']);
}
if (vehicle[i]['total_tire']=='18')
{
$("input[name=vdLt18]").val(vehicle[i]['qty']);
$("input[name=vdLt18wt]").val(vehicle[i]['load_weight']);
}
if (vehicle[i]['total_tire']=='-1')
{
$("input[name=vdLtot]").val(vehicle[i]['qty']);
$("input[name=vdLtotwt]").val(vehicle[i]['load_weight']);
}
}
}
}
}
function loadpurchase(purchase)
{
//alert(purchase.length);
for (var i=0;i<purchase.length;i++)
{
if(purchase[i]['brand']=='MRF')
{
var a = "<div class='MRF"+i+"'>"
+"<input class='span3' type='text' name='pattern[]' value='"+purchase[i]['pattern']+"' disabled>"
+"<input class='span3' type='text' name='size[]' value='"+purchase[i]['size']+"' disabled>"
+"<input class='span3' type='text' name='qty[]' value='"+purchase[i]['qty']+"' disabled>"
+"</div>";
$(a).appendTo('#MRFtype');
}
else
{
var a = "<div class='Other"+i+"'>"
+"<input class='span3' type='text' name='pattern[]' value='"+purchase[i]['pattern']+"' disabled>"
+"<input class='span3' type='text' name='size[]' value='"+purchase[i]['size']+"' disabled>"
+"<input class='span3' type='text' name='qty[]' value='"+purchase[i]['qty']+"' disabled>"
+"</div>";
$(a).appendTo('#Othertype');
}
}
/*
var a = "<div class='MRF0'>"
+"<input class='span3' id='MRF00' type='text' name='pattern[]' placeholder='pattern'>"
+"<input class='span3' id='MRF01' type='text' name='size[]' placeholder='size'>"
+"<input class='span3' id='MRF02' type='text' name='qty[]' placeholder='qty'>"
+"</div>";
$(a).appendTo('#MRFtype');
*/
}
function loadrecommendation(rcm)
{
if(rcm=='')
{
$('#space').css('display','block');
}
else{
$('#space').css('display','none');
for (var i=0;i<rcm.length;i++)
{
var a = "<div style='margin-bottom:10px;'>"
+"<input class='span3' style='margin-right:10px;' type='text' name='pattern[]' value='"+rcm[i]['pattern']+"' disabled>"
+"<input class='span3' style='margin-right:10px;' type='text' name='size[]' value='"+rcm[i]['size']+"' disabled>"
+"<input class='span3' style='margin-right:10px;' type='text' name='qty[]' value='"+rcm[i]['remark']+"' disabled>"
+"</div>";
$(a).prependTo('#recommendation');
}
}
}
function loadpictures(pic)
{
if (pic=='')
{
$('#nopic').css('display','block');
}
else
{
$('#nopic').css('display','none');
for (var i=0;i<pic.length;i++)
{
var a = "<img src='"+pic[i]+"' style='border:inset 1px;'>";
$(a).prependTo('#gambar');
}
}
}
//fungsi untuk enable edit form
function edited()
{
$("#pending").hide();
$("#saved").hide();
$("#edit").show();
$(":input").prop("disabled", false);
//$("form").attr('action','<?php echo base_url(); ?>form/updateform/<?php echo $form->id; ?>');
}
//fungsi cek inputan user
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
{
alert('Number Only');
return false;
}
return true;
}