392 lines
16 KiB
JavaScript
392 lines
16 KiB
JavaScript
|
|
var allassets;
|
|
function GetMachines() {
|
|
worequest("GetMachines", "", function (data) {
|
|
if (data && data.length > 0) {
|
|
allassets = data;
|
|
editableSelectFromAsset.setEnable(true);
|
|
editableSelectToAsset.setEnable(true);
|
|
|
|
editableSelectFromAsset.datasource = data;
|
|
editableSelectFromAsset.valuepath = "Id"
|
|
editableSelectFromAsset.displaypath = "DisplayName";
|
|
|
|
editableSelectToAsset.datasource = data;
|
|
editableSelectToAsset.valuepath = "Id"
|
|
editableSelectToAsset.displaypath = "DisplayName";
|
|
}
|
|
|
|
}, function (err) {
|
|
});
|
|
}
|
|
|
|
function openMergeAssets() {
|
|
ClearAssetDetail();
|
|
if (!allassets)
|
|
GetMachines();
|
|
|
|
showmaskbg(true);
|
|
$('#dialog_mergeassets').css({
|
|
'top': (document.documentElement.clientHeight - $('#dialog_mergeassets').height()) / 3,
|
|
'left': (document.documentElement.clientWidth - $('#dialog_mergeassets').width()) / 2
|
|
}).showDialogfixed();
|
|
}
|
|
|
|
function ClearAssetDetail() {
|
|
$('#tab_assetinfo').show();
|
|
$('#tab_mergeassets').hide();
|
|
$('#btn_mergenext').show();
|
|
$('#btn_mergeprevious').hide();
|
|
editableSelectFromAsset.val('');
|
|
editableSelectToAsset.val('');
|
|
$('#dialog_newhide').attr("checked", false);
|
|
$('#dialog_newonroad').attr("checked", false);
|
|
$('#dialog_newtelematics').attr("checked", false);
|
|
$('#dialog_newattachment').attr("checked", false);
|
|
$('#dialog_newpreloaded').attr("checked", false);
|
|
$('#dialog_newsn').text("");
|
|
$('#dialog_newname').text("");
|
|
$('#dialog_newname2').text("");
|
|
$('#dialog_newdevicesn').text("");
|
|
$('#dialog_newyear').text("");
|
|
$('#dialog_newmake').text("");
|
|
$('#dialog_newmodel').text("");
|
|
$('#dialog_neweqclass').text("");
|
|
$('#dialog_newtype').text("");
|
|
$('#dialog_newdescription').val("");
|
|
$('#dialog_newenginehours').text("");
|
|
$('#dialog_newodometer').text("");
|
|
$('#dialog_newaddedon').text("");
|
|
$('#dialog_newaddedby').text("");
|
|
|
|
$('#dialog_oldhide').attr("checked", false);
|
|
$('#dialog_oldonroad').attr("checked", false);
|
|
$('#dialog_oldtelematics').attr("checked", false);
|
|
$('#dialog_oldAttachment').attr("checked", false);
|
|
$('#dialog_oldpreloaded').attr("checked", false);
|
|
$('#dialog_oldsn').text("");
|
|
$('#dialog_oldname').text("");
|
|
$('#dialog_oldname2').text("");
|
|
$('#dialog_olddevicesn').text("");
|
|
$('#dialog_oldyear').text("");
|
|
$('#dialog_oldmake').text("");
|
|
$('#dialog_oldmodel').text("");
|
|
$('#dialog_oldeqclass').text("");
|
|
$('#dialog_oldtype').text("");
|
|
$('#dialog_olddescription').val("");
|
|
$('#dialog_oldenginehours').text("");
|
|
$('#dialog_oldodometer').text("");
|
|
$('#dialog_oldaddedon').text("");
|
|
$('#dialog_oldaddedby').text("");
|
|
$('.radio_both').prop('checked', true);
|
|
$('#dialog_mergenotes').val('');
|
|
}
|
|
|
|
function showAssetDetail(assetid, type) {
|
|
var contractorid = "";
|
|
if (IsDealer)
|
|
contractorid = htmlencode($.trim($('#sel_contractor').val()));
|
|
assetrequest("GetMachineInfo", contractorid + String.fromCharCode(170) + assetid, function (data) {
|
|
if (typeof (data) === "string") {
|
|
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
|
|
return;
|
|
}
|
|
var asset = data;
|
|
if (type === 1) {
|
|
$('#dialog_newhide').attr("checked", asset.Hidden);
|
|
$('#dialog_newonroad').attr("checked", asset.OnRoad);
|
|
$('#dialog_newtelematics').attr("checked", asset.TelematicsEnabled);
|
|
$('#dialog_newattachment').attr("checked", asset.Attachment);
|
|
$('#dialog_newpreloaded').attr("checked", asset.Preloaded);
|
|
$('#dialog_newsn').text(asset.VIN);
|
|
$('#dialog_newname').text(asset.Name);
|
|
$('#dialog_newname2').text(asset.Name2);
|
|
$('#dialog_newdevicesn').text(asset.PairedDeviceSN);
|
|
$('#dialog_newyear').text(eval(asset.MakeYear) > 0 ? asset.MakeYear : "");
|
|
$('#dialog_newmake').text(asset.MakeName);
|
|
$('#dialog_newmodel').text(asset.ModelName);
|
|
$('#dialog_neweqclass').text(asset.EQClass);
|
|
$('#dialog_newtype').text(asset.TypeName);
|
|
$('#dialog_newdescription').val(asset.Description);
|
|
$('#dialog_newenginehours').text(asset.EngineHours ? asset.EngineHours : "");
|
|
$('#dialog_newodometer').text(asset.Odometer ? asset.Odometer : "");
|
|
$('#dialog_newaddedon').text(asset.AddedOnStr);
|
|
$('#dialog_newaddedby').text(asset.AddedByUserName);
|
|
}
|
|
else {
|
|
$('#dialog_oldhide').attr("checked", asset.Hidden);
|
|
$('#dialog_oldonroad').attr("checked", asset.OnRoad);
|
|
$('#dialog_oldtelematics').attr("checked", asset.TelematicsEnabled);
|
|
$('#dialog_oldAttachment').attr("checked", asset.Attachment);
|
|
$('#dialog_oldpreloaded').attr("checked", asset.Preloaded);
|
|
$('#dialog_oldsn').text(asset.VIN);
|
|
$('#dialog_oldname').text(asset.Name);
|
|
$('#dialog_oldname2').text(asset.Name2);
|
|
$('#dialog_olddevicesn').text(asset.PairedDeviceSN);
|
|
$('#dialog_oldyear').text(eval(asset.MakeYear) > 0 ? asset.MakeYear : "");
|
|
$('#dialog_oldmake').text(asset.MakeName);
|
|
$('#dialog_oldmodel').text(asset.ModelName);
|
|
$('#dialog_oldeqclass').text(asset.EQClass);
|
|
$('#dialog_oldtype').text(asset.TypeName);
|
|
$('#dialog_olddescription').val(asset.Description);
|
|
$('#dialog_oldenginehours').text(asset.EngineHours ? asset.EngineHours : "");
|
|
$('#dialog_oldodometer').text(asset.Odometer ? asset.Odometer : "");
|
|
$('#dialog_oldaddedon').text(asset.AddedOnStr);
|
|
$('#dialog_oldaddedby').text(asset.AddedByUserName);
|
|
}
|
|
}, function (err) {
|
|
});
|
|
}
|
|
|
|
function OnNext() {
|
|
var fromasset = editableSelectFromAsset.selecteditem();
|
|
var toasset = editableSelectToAsset.selecteditem();
|
|
if (!fromasset || !toasset) {
|
|
showAlert(GetTextByKey("P_MA_SELECTANASSETTOMERGE", "Please select two assets to merge."), GetTextByKey("P_MA_MERGEASSET", "Merge Asset"));
|
|
return;
|
|
}
|
|
var tips = GetTextByKey('P_MA_MERGEASSETTIPS', 'Merge asset {0} to asset {1}, please select the data to be retained:').replace('{0}', fromasset.DisplayName).replace('{1}', toasset.DisplayName);
|
|
$('#span_mergetips').text(tips);
|
|
$('.span_asseta').text(fromasset.DisplayName);
|
|
$('.span_assetb').text(toasset.DisplayName);
|
|
$('#tab_assetinfo').hide();
|
|
$('#tab_mergeassets').show();
|
|
$('#btn_mergenext').hide();
|
|
$('#btn_mergeprevious').show();
|
|
}
|
|
|
|
function OnPrevious() {
|
|
$('#tab_mergeassets').hide();
|
|
$('#tab_assetinfo').show();
|
|
$('#btn_mergenext').show();
|
|
$('#btn_mergeprevious').hide();
|
|
}
|
|
|
|
function SaveMergeAsset() {
|
|
var fromasset = editableSelectFromAsset.selecteditem();
|
|
var toasset = editableSelectToAsset.selecteditem();
|
|
if (!fromasset || !toasset) {
|
|
showAlert(GetTextByKey("P_MA_SELECTANASSETTOMERGE", "Please select two assets to merge."), GetTextByKey("P_MA_MERGEASSET", "Merge Asset"));
|
|
return;
|
|
}
|
|
|
|
var contractorid = "";
|
|
if (IsDealer)
|
|
contractorid = htmlencode($.trim($('#sel_contractor').val()));
|
|
var notes = $('#dialog_mergenotes').val();
|
|
var fromassetid = fromasset.Id;
|
|
var toassetid = toasset.Id;
|
|
|
|
var items = [];
|
|
items.push({ 'Key': 0, 'Tag': 'Odometer', 'Value': $('input[name="radio_odometer"]:checked').val() });
|
|
items.push({ 'Key': 1, 'Tag': 'Engine Hours', 'Value': $('input[name="radio_enginehours"]:checked').val() });
|
|
items.push({ 'Key': 2, 'Tag': 'Location', 'Value': $('input[name="radio_location"]:checked').val() });
|
|
items.push({ 'Key': 3, 'Tag': 'Idle Hours', 'Value': $('input[name="radio_idlehours"]:checked').val() });
|
|
items.push({ 'Key': 4, 'Tag': 'Fuel Used', 'Value': $('input[name="radio_fuelused"]:checked').val() });
|
|
items.push({ 'Key': 5, 'Tag': 'Fuel Remaining', 'Value': $('input[name="radio_fuelremaining"]:checked').val() });
|
|
items.push({ 'Key': 6, 'Tag': 'Attribute', 'Value': $('input[name="radio_attribute"]:checked').val() });
|
|
items.push({ 'Key': 7, 'Tag': 'Battery', 'Value': $('input[name="radio_battery"]:checked').val() });
|
|
items.push({ 'Key': 8, 'Tag': 'Preventative Maintenance', 'Value': $('input[name="radio_pmplans"]:checked').val() });
|
|
items.push({ 'Key': 9, 'Tag': 'Jobsite', 'Value': $('input[name="radio_jobsite"]:checked').val() });
|
|
var p = [
|
|
contractorid,
|
|
fromassetid,
|
|
toassetid,
|
|
notes,
|
|
JSON.stringify(items)
|
|
];
|
|
var param = JSON.stringify(p);
|
|
|
|
$("#dialogmask").show();
|
|
assetrequest('SaveMergeAsset', param, function (data) {
|
|
if (data === "") {
|
|
showAlert(GetTextByKey('P_MA_MERGESUCCESSFULLY', 'Merge successfully.'), GetTextByKey('P_MA_MERGEASSET', 'Merge Asset'));
|
|
} else {
|
|
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
|
|
}
|
|
$('#dialog_mergeassets').hideDialog();
|
|
showmaskbg(false);
|
|
$("#dialogmask").hide();
|
|
});
|
|
|
|
}
|
|
|
|
function openAssetMergeHistory() {
|
|
window.open("AssetMergeHistory.aspx");
|
|
}
|
|
|
|
|
|
//************************Begin Merge Asset(New)*********************************//
|
|
|
|
function OnMergeAsset() {
|
|
showmaskbg(true);
|
|
dialogSelectMergeAssets.exceptShareAsset = true;
|
|
dialogSelectMergeAssets.exceptSource = [machineid];
|
|
dialogSelectMergeAssets.showSelector(3, true);//与attachmentInfo中的showSelector冲突,需设置force
|
|
}
|
|
|
|
var mergeassetid;
|
|
var mergeasset;
|
|
function showMergeAsset() {
|
|
showmaskbg(true);
|
|
$('#dialog_mergeasset').css({
|
|
'top': (document.documentElement.clientHeight - $('#dialog_mergeasset').height()) / 3,
|
|
'left': (document.documentElement.clientWidth - $('#dialog_mergeasset').width()) / 2
|
|
}).showDialogfixed();
|
|
|
|
var asset = assetinfo;
|
|
$('#dialog_merge_newhide').attr("checked", asset.Hidden);
|
|
$('#dialog_merge_newonroad').attr("checked", asset.OnRoad);
|
|
$('#dialog_merge_newtelematics').attr("checked", asset.TelematicsEnabled);
|
|
$('#dialog_merge_newattachment').attr("checked", asset.Attachment);
|
|
$('#dialog_merge_newpreloaded').attr("checked", asset.Preloaded);
|
|
$('#dialog_merge_newsn').text(asset.VIN);
|
|
$('#dialog_merge_newname').text(asset.Name);
|
|
$('#dialog_merge_newname2').text(asset.Name2);
|
|
$('#dialog_merge_newdevicesn').text(asset.PairedDeviceSN);
|
|
$('#dialog_merge_newyear').text(eval(asset.MakeYear) > 0 ? asset.MakeYear : "");
|
|
$('#dialog_merge_newmake').text(asset.MakeName);
|
|
$('#dialog_merge_newmodel').text(asset.ModelName);
|
|
$('#dialog_merge_neweqclass').text(asset.EQClass);
|
|
$('#dialog_merge_newtype').text($("#dialog_type").find("option:selected").text());
|
|
$('#dialog_merge_newdescription').val(asset.Description);
|
|
$('#dialog_merge_newenginehours').text(asset.EngineHours);
|
|
$('#dialog_merge_newodometer').text(asset.Odometer);
|
|
$('#dialog_merge_newaddedon').text(asset.AddedOnStr);
|
|
$('#dialog_merge_newaddedby').text(asset.AddedByUserName);
|
|
|
|
GetAssetDatasources(asset.Id, false);
|
|
|
|
showMergeOldAsset();
|
|
GetAssetDatasources(mergeassetid, true);
|
|
}
|
|
|
|
function showMergeOldAsset() {
|
|
$("#mergeassetmask").show();
|
|
assetrequest("GetMachineInfo", contractorid + String.fromCharCode(170) + mergeassetid, function (data) {
|
|
if (typeof (data) === "string") {
|
|
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
|
|
$("#mergeassetmask").hide();
|
|
return;
|
|
}
|
|
mergeasset = data;
|
|
var asset = mergeasset;
|
|
$('#dialog_merge_oldhide').attr("checked", asset.Hidden);
|
|
$('#dialog_merge_oldonroad').attr("checked", asset.OnRoad);
|
|
$('#dialog_merge_oldtelematics').attr("checked", asset.TelematicsEnabled);
|
|
$('#dialog_merge_oldAttachment').attr("checked", asset.Attachment);
|
|
$('#dialog_merge_oldpreloaded').attr("checked", asset.Preloaded);
|
|
$('#dialog_merge_oldsn').text(asset.VIN);
|
|
$('#dialog_merge_oldname').text(asset.Name);
|
|
$('#dialog_merge_oldname2').text(asset.Name2);
|
|
$('#dialog_merge_olddevicesn').text(asset.PairedDeviceSN);
|
|
$('#dialog_merge_oldyear').text(eval(asset.MakeYear) > 0 ? asset.MakeYear : "");
|
|
$('#dialog_merge_oldmake').text(asset.MakeName);
|
|
$('#dialog_merge_oldmodel').text(asset.ModelName);
|
|
$('#dialog_merge_oldeqclass').text(asset.EQClass);
|
|
$('#dialog_merge_oldtype').text(asset.Type);
|
|
$('#dialog_merge_olddescription').val(asset.Description);
|
|
$('#dialog_merge_oldenginehours').text(asset.EngineHours ? asset.EngineHours : "");
|
|
$('#dialog_merge_oldodometer').text(asset.Odometer ? asset.Odometer : "");
|
|
$('#dialog_merge_oldaddedon').text(asset.AddedOnStr);
|
|
$('#dialog_merge_oldaddedby').text(asset.AddedByUserName);
|
|
|
|
$("#mergeassetmask").hide();
|
|
}, function (err) {
|
|
$("#mergeassetmask").hide();
|
|
});
|
|
}
|
|
|
|
function onMergeUseAsset(mergetype) {
|
|
$('#dialog_mergeasset').hideDialog();
|
|
$("#mergeassetmask").hide();
|
|
DoMergeAsset(mergetype);
|
|
}
|
|
|
|
function DoMergeAsset(mergetype) {
|
|
if (mergetype == -1 || !machineid)
|
|
return;
|
|
|
|
var mid = -1;
|
|
var tomid = -1;
|
|
var msg = "";
|
|
var alerttile = "";
|
|
if (mergetype === 0) {
|
|
mid = mergeassetid;
|
|
tomid = machineid;
|
|
alerttile = GetTextByKey("P_MA_XXXXX", 'Merge Asset');
|
|
msg = GetTextByKey("P_MA_XXXXXX", 'WARNING: The merge process will strictly hide the Orphaned Asset and re-assign telematic data sources to the Master Asset for future incoming data. Existing data within the platform will not be assigned to the Master Asset. Are you sure you want to proceed?');
|
|
}
|
|
else if (mergetype === 1) {
|
|
mid = machineid;
|
|
tomid = mergeassetid;
|
|
alerttile = GetTextByKey("P_MA_XXXXX", 'Merge Asset');
|
|
msg = GetTextByKey("P_MA_XXXXXX", 'WARNING: The merge process will strictly hide the Orphaned Asset and re-assign telematic data sources to the Master Asset for future incoming data. Existing data within the platform will not be assigned to the Master Asset. Are you sure you want to proceed?');
|
|
}
|
|
|
|
showConfirm(msg, alerttile, function (e) {
|
|
MergeAsset(mid, tomid, mergetype);
|
|
});
|
|
}
|
|
|
|
function MergeAsset(mid, tomid, mergetype) {
|
|
showmaskbg(true);
|
|
assetrequest("MergeAsset", htmlencode(JSON.stringify([contractorid, mid, tomid, ""])), function (data) {
|
|
showmaskbg(false);
|
|
if (data != "") {
|
|
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
|
|
}
|
|
else {
|
|
needRefreshDataOnCancel = true;
|
|
if (mergetype === 1)
|
|
OnExit(1);
|
|
else
|
|
OnEdit();
|
|
}
|
|
}, function (err) {
|
|
showmaskbg(false);
|
|
});
|
|
}
|
|
|
|
function OnDeleteAsset() {
|
|
if (!machineid)
|
|
return;
|
|
|
|
var mid = machineid;
|
|
var alerttile = GetTextByKey("P_MA_XXXXX", 'Delete Asset');
|
|
var msg = GetTextByKey("P_MA_XXXXXX", 'WARNING: This will delete the Asset. Are you sure you want to proceed?');
|
|
|
|
showConfirm(msg, alerttile, function (e) {
|
|
DeleteAsset(mid);
|
|
});
|
|
}
|
|
|
|
function DeleteAsset(mid) {
|
|
showmaskbg(true);
|
|
assetrequest("DeleteAssets", htmlencode(JSON.stringify([contractorid, JSON.stringify([mid]), ""])), function (data) {
|
|
showmaskbg(false);
|
|
if (data != "") {
|
|
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
|
|
}
|
|
else {
|
|
needRefreshDataOnCancel = true;
|
|
OnExit(1);
|
|
}
|
|
}, function (err) {
|
|
showmaskbg(false);
|
|
});
|
|
}
|
|
|
|
function GetAssetDatasources(mid, isold) {
|
|
assetrequest("GetAssetDatasources", htmlencode(JSON.stringify([contractorid, mid])), function (data) {
|
|
if (data && data.length > 0) {
|
|
var target = isold ? $("#dialog_merge_olddatasource") : $("#dialog_merge_newdatasource");
|
|
for (var i = 0; i < data.length; i++) {
|
|
target.append($("<div></div>").text(data[i]));
|
|
}
|
|
}
|
|
}, function (err) {
|
|
});
|
|
}
|
|
|
|
//**************************End Merge Asset(New)*******************************//
|