2023-04-28 12:22:26 +08:00

275 lines
9.2 KiB
JavaScript

$(function () {
initTime();
initTimeZone();
$('#dialog_adjustodometer').dialog(function () {
showmaskbg(false);
});
$('#dialog_addodometer').dialog(function () {
showmaskbg(false);
});
$('#dialog_adjustenginehours').dialog(function () {
showmaskbg(false);
});
$('#dialog_addenginehours').dialog(function () {
showmaskbg(false);
});
$('#dialog_setprimary').dialog(function () {
showmaskbg(false);
});
$('#dialogadjust_odometerdate').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialogadd_odometerdate').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialogaddenginehours_date').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialogenginehours_date').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$("#tdAuditEngineHours").click(auditHide);
$("#tdAuditOdometers").click(auditHide);
$("#tdAuditLocation").click(auditHide);
$("#tdAuditIdlehour").click(auditHide);
$("#tdAuditFuelused").click(auditHide);
$("#tdAuditFuelRemaining").click(auditHide);
});
function auditHide(e) {
var target = $(e.target);
if (target.data("hide") == 1) {
target.data("hide", 0);
var p = target.parent();
p.next().show();
p.next().next().show();
target.removeClass("plus").addClass("minus");
}
else {
target.data("hide", 1);
var p = target.parent();
p.next().hide();
p.next().next().hide();
target.removeClass("minus").addClass("plus");
}
}
function initTime() {
var c = $('#dialogadjust_timehour');
for (var i = 0; i < 24; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogadjust_timeminute');
for (var i = 0; i < 60; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogadd_timehour');
for (var i = 0; i < 24; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogadd_timeminute');
for (var i = 0; i < 60; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogenginehours_timehour');
for (var i = 0; i < 24; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogenginehours_timeminute');
for (var i = 0; i < 60; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogaddenginehours_timehour');
for (var i = 0; i < 24; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
c = $('#dialogaddenginehours_timeminute');
for (var i = 0; i < 60; i++) {
if (i < 10)
c.append($("<option></option>").val("0" + i).text("0" + i))
else
c.append($("<option></option>").val(i).text(i))
}
}
function initTimeZone() {
devicerequest("GetTimeZones", "", function (data) {
if (data) {
var sel = $("#dialogadjust_odometertimezone");
sel.empty();
var sel1 = $("#dialogadjust_enginehourstimezone");
sel1.empty();
var sel2 = $("#dialogadd_odometertimezone");
sel2.empty();
var sel3 = $("#dialogadd_enginehourstimezone");
sel3.empty();
if (data && data.length > 0) {
for (var i = 0; i < data.length; i++) {
sel.append($("<option></option>").val(data[i].Key).text("(" + data[i].Value + ")" + data[i].Key).attr("offset", data[i].Tag1));
sel1.append($("<option></option>").val(data[i].Key).text("(" + data[i].Value + ")" + data[i].Key).attr("offset", data[i].Tag1));
sel2.append($("<option></option>").val(data[i].Key).text("(" + data[i].Value + ")" + data[i].Key).attr("offset", data[i].Tag1));
sel3.append($("<option></option>").val(data[i].Key).text("(" + data[i].Value + ")" + data[i].Key).attr("offset", data[i].Tag1));
}
}
sel.val("UTC");
sel1.val("UTC");
sel2.val("UTC");
sel3.val("UTC");
}
}, function (err) {
});
}
function getCustomerTimeZone() {
assetrequest("GetCustomerTimeZone", contractorid, function (data) {
if (data) {
customertimezone = data.Key;
customerdatetime = data.Value;
var datetime = customerdatetime.split(' ');
var time = datetime[0];
var st = datetime[1].split(':');
var hours = st[0].length == 1 ? "0" + st[0] : st[0];
var minutes = st[1];
$("#dialogadjust_odometertimezone").val(customertimezone);
$("#dialogadd_odometertimezone").val(customertimezone);
$('#dialogadjust_odometerdate').val(time);
$('#dialogadjust_timehour').val(hours);
$('#dialogadjust_timeminute').val(minutes);
$('#dialogadd_odometerdate').val(time);
$('#dialogadd_timehour').val(hours);
$('#dialogadd_timeminute').val(minutes);
$("#dialogadjust_enginehourstimezone").val(customertimezone);
$("#dialogadd_enginehourstimezone").val(customertimezone);
$('#dialogenginehours_date').val(time);
$('#dialogenginehours_timehour').val(hours);
$('#dialogenginehours_timeminute').val(minutes);
$('#dialogaddenginehours_date').val(time);
$('#dialogaddenginehours_timehour').val(hours);
$('#dialogaddenginehours_timeminute').val(minutes);
}
}, function (err) {
});
}
/************************Set As Primary**************************************/
var selectedDataSource = undefined;
var selectedType;
function openSetPrimary(type, datasource) {
selectedDataSource = datasource;
selectedType = type;
$('#dialogprimary_notes').val('');
$('#dialog_setprimary .dialog-title span.title').text('Set As Primary');
showmaskbg(true);
$('#dialog_setprimary')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_setprimary').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_setprimary').width()) / 2
})
.showDialogfixed();
$('#dialogprimary_notes').focus();
}
function OnSetPrimary() {
if (!selectedDataSource)
return;
var item = {
'Type': selectedType,
'CustomerID': contractorid,
'AssetID': machineid,
'DataSource': selectedDataSource.DataSource,
'SubSource': selectedDataSource.SubSource,
'Notes': $('#dialogprimary_notes').val()
};
showloading(true);
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("ChangePrimaryDataSource", param, function (data) {
showloading(false);
if (data !== 'OK') {
showAlert(data, GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary'));
} else {
if (selectedType == 0) {
getOdometers();
getMachineInfo();
}
else if (selectedType == 1) {
getEnineHours();
getMachineInfo();
}
else if (selectedType == 2)
getLocations();
else if (selectedType == 3)
getIdlehours();
else if (selectedType == 4)
getFueluseds();
}
$('#dialog_setprimary').hideDialog();
}, function (err) {
console.log(err);
showloading(false);
showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTDOMETERSETASPRIMARY", 'Failed to set as primary.'), GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary'));
});
}