This commit is contained in:
2023-04-28 12:22:26 +08:00
parent 88e0a25ecd
commit c9723008af
1047 changed files with 443540 additions and 1 deletions

View File

@ -0,0 +1,171 @@

//************************Add Engine Hours**************************************//
var isAddEH = true;
var primarydatadourceADEH;
function openAddEnginHours() {
primarydatadourceADEH = undefined;
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];
$('#dialogaddgenginehours_enginehours').val('');
$('#dialogadd_enginehourstimezone').val(customertimezone ? customertimezone : "UTC");
$('#dialogaddenginehours_date').val(time);
$('#dialogaddenginehours_timehour').val(hours);
$('#dialogaddenginehours_timeminute').val(minutes);
$('#dialogaddenginehours_Notes').val('');
if (assetdata.TelematicsEnabled && !assetdata.CurrentHours.IsEmpty &&
(assetdata.CurrentHours.DataSource.toLowerCase() == "calamp" || assetdata.CurrentHours.DataSource.toLowerCase() == "pedigree")) {
isAddEH = false;
primarydatadourceADEH = assetdata.CurrentHours.DataSource;
}
else
isAddEH = true;
$('#dialog_addenginehours .dialog-title span.title').text(isAddEH ? GetTextByKey("P_MV_ADDENGINEHOURS", 'Add Engine Hours') : GetTextByKey("P_MV_ADJUSTENGINEHOURS", 'Adjust Engine Hours'));
showmaskbg(true);
$('#dialog_addenginehours')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_addenginehours').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_addenginehours').width()) / 2
})
.showDialogfixed();
$('#dialogaddgenginehours_enginehours').focus();
}
function OnAddEngineHours() {
$('#addenginehoursmask').show();
var alerttitle = isAddEH ? GetTextByKey("P_MV_ADDENGINEHOURS", 'Add Engine Hours') : GetTextByKey("P_MV_ADJUSTENGINEHOURS", 'Adjust Engine Hours');
var item = {
'CustomerID': contractorid,
'AssetID': assetid,
'EngineHours': $('#dialogaddgenginehours_enginehours').val(),
'EngineHoursDate': $('#dialogaddenginehours_date').val(),
'Notes': $('#dialogaddenginehours_Notes').val(),
'DataSource': primarydatadourceADEH
};
if (item.EngineHours !== "") {
if (isNaN(item.EngineHours)) {
showAlert(GetTextByKey("P_MV_ENGINEHOURSFORMATERROR", 'Engine Hours format error.'), alerttitle);
$('#addenginehoursmask').hide();
return;
}
else {
if (item.EngineHours <= 0) {
showAlert(GetTextByKey("P_MV_ENGINEHOURSMUSTBEGREATERTHAN0", 'Engine Hours must be greater than 0.'), alerttitle);
$('#addenginehoursmask').hide();
return;
}
}
}
else {
showAlert(GetTextByKey("P_MV_ENGINEHOURSCANNOTBEEMPTY", "Engine Hours cannot be empty."), alerttitle);
$('#addenginehoursmask').hide();
return;
}
if (item.EngineHoursDate === "") {
showAlert(GetTextByKey("P_MV_ENGINEHOURSDATECANNOTBEEMPTY", "Engine Hours Date cannot be empty."), alerttitle);
$('#addenginehoursmask').hide();
return;
}
var offset = $('#dialogadd_enginehourstimezone').find("option:selected").attr("offset");
item.OffsetMinute = offset;
var timezonetext = $('#dialogadd_enginehourstimezone').find("option:selected").text();
var hour = $('#dialogaddenginehours_timehour').val();
var minute = $('#dialogaddenginehours_timeminute').val();
item.EngineHoursDate = item.EngineHoursDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00";
var time = hour + ":" + minute
var alertmsg = "";
if (isAddEH) {
alertmsg = GetTextByKey("P_MV_UPDATEENGINEHOURS", "Do you want to update the engine hours to reflect: {0} hours at {1} {2}?").replace('{0}', item.EngineHours).replace('{1}', time).replace('{2}', timezonetext);
}
else {
alertmsg = GetTextByKey("P_MV_UPDATEENGINEHOURS1", "If you proceed, engine hours will be updated to reflect: {0} hours at {1} <br/>" +
" {2}. <br/><br/>Note that this asset is telematic enabled and the primary data source is {3}." +
"<br/><br/> Would you like to proceed?").replace('{0}', item.EngineHours).replace('{1}', time).replace('{2}', timezonetext).replace('{3}', assetdata.CurrentHours.DataSourceName);
}
showConfirm1(alertmsg, alerttitle, function () {
$('#addenginehoursmask').hide();
if (isAddEH)
AddManuallyInputEngineHours(item, alerttitle);
else
CheckEngineHourMinimumTime(item, alerttitle);
}, function () {
$('#addenginehoursmask').hide();
});
}
function AddManuallyInputEngineHours(item, alerttitle) {
showloading(true);
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("AddManuallyInputEngineHours", param, function (data) {
showloading(false);
if (data !== 'OK') {
showAlert(data, alerttitle);
} else {
loadAssetInfo();
showAlert(GetTextByKey("P_MV_ENGINEHOURSUPDATESUCCESSFUL", "Engine Hours Update Successful."), alerttitle);
}
$('#dialog_addenginehours').hideDialog();
$('#addenginehoursmask').hide();
}, function (err) {
console.log(err);
showloading(false);
showAlert(GetTextByKey("P_MV_FAILEDTOADDENGINEHOURS", 'Failed to add Engine Hours.'), alerttitle);
$('#addenginehoursmask').hide();
});
}
function CheckEngineHourMinimumTime(item, alerttitle) {
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("CheckEngineHourMinimumTime", param, function (data) {
if (data > 0) {
if (data == 1)
showAlert(GetTextByKey("P_MV_CHECKENGINEHOURSMINNIMUMTIME", "The adjustment cannot be completed as provided. The engine hours reading date provided cannot be prior to initial telematic data available for the asset."), alerttitle);
else
showAlert(GetTextByKey("P_MV_CHECKENGINEHOURSMINNIMUMTIME1", "The adjustment cannot be completed as provided. The engine hours reading date provided must be prior to or equal to the latest telematic data available for the asset."), alerttitle);
$('#addenginehoursmask').hide();
return;
} else {
SaveAdjustEngineHours(item, alerttitle);
}
}, function (err) {
});
}
function SaveAdjustEngineHours(item, alerttitle) {
showloading(true);
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("SaveAdjustEngineHours", param, function (data) {
showloading(false);
if (data !== 'OK') {
showAlert(data, alerttitle);
} else {
loadAssetInfo();
showAlert(GetTextByKey("P_MV_ENGINEHOURSUPDATESUCCESSFUL", "Engine Hours Update Successful."), alerttitle);
}
$('#dialog_addenginehours').hideDialog();
$('#addenginehoursmask').hide();
}, function (err) {
console.log(err);
showloading(false);
showAlert(GetTextByKey("P_MV_FAILEDTOADJUSTENGINEHOURS", 'Failed to adjust Engine Hours.'), alerttitle);
$('#addenginehoursmask').hide();
});
}

View File

@ -0,0 +1,167 @@

//************************Add Odometer**************************************//
var isAddOdo = true;
var primarydatadourceADOdo;
function openAddOdometer() {
primarydatadourceADOdo = undefined;
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];
$('#dialogadd_odometer').val('');
$('#dialogadd_sel_odometeruom').val(systemunitofodometer);
$('#dialogadd_odometertimezone').val(customertimezone ? customertimezone : "UTC");
$('#dialogadd_odometerdate').val(time);
$('#dialogadd_timehour').val(hours);
$('#dialogadd_timeminute').val(minutes);
$('#dialogadd_notes').val('');
if (assetdata.TelematicsEnabled && !assetdata.CurrentOdometer.IsEmpty &&
(assetdata.CurrentOdometer.DataSource.toLowerCase() == "calamp" || assetdata.CurrentOdometer.DataSource.toLowerCase() == "pedigree")) {
isAddOdo = false;
primarydatadourceADOdo = assetdata.CurrentOdometer.DataSource;
}
else
isAddOdo = true;
$('#dialog_addodometer .dialog-title span.title').text(isAddOdo ? GetTextByKey("P_MV_ADDODOMETER", 'Add Odometer') : GetTextByKey("P_MV_ADJUSTODOMETER", 'Adjust Odometer'));
showmaskbg(true);
$('#dialog_addodometer')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_addodometer').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_addodometer').width()) / 2
})
.showDialogfixed();
$('#dialogadd_odometer').focus();
}
function OnAddOdometer() {
$('#addodomask').show();
var alerttitle = isAddOdo ? GetTextByKey("P_MV_ADDODOMETER", 'Add Odometer') : GetTextByKey("P_MV_ADJUSTODOMETER", 'Adjust Odometer');
var item = {
'CustomerID': contractorid,
'AssetID': assetid,
'Odometer': $('#dialogadd_odometer').val(),
'UOM': $('#dialogadd_sel_odometeruom').val(),
'OdometerDate': $('#dialogadd_odometerdate').val(),
'Notes': $('#dialogadd_notes').val(),
'DataSource': primarydatadourceADOdo
};
if (item.Odometer !== "") {
if (isNaN(item.Odometer)) {
showAlert(GetTextByKey("P_MV_ODOMETERFORMATERROR", 'Odometer format error.'), alerttitle);
$('#addodomask').hide();
return;
}
else {
if (item.Odometer <= 0) {
showAlert(GetTextByKey("P_MV_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle);
$('#addodomask').hide();
return;
}
}
}
else {
showAlert(GetTextByKey("P_MV_ODOMETRCANNOTBEEMPTY", "Odometer cannot be empty."), alerttitle);
$('#addodomask').hide();
return;
}
if (item.OdometerDate === "") {
showAlert(GetTextByKey("P_MV_ODOMETRDATACANNOTBEEMPTY", "Odometer date cannot be empty."), alerttitle);
$('#addodomask').hide();
return;
}
var offset = $('#dialogadd_odometertimezone').find("option:selected").attr("offset");
item.OffsetMinute = offset;
var timezonetext = $('#dialogadd_enginehourstimezone').find("option:selected").text();
var hour = $('#dialogadd_timehour').val();
var minute = $('#dialogadd_timeminute').val();
item.OdometerDate = item.OdometerDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00";
var time = hour + ":" + minute
var alertmsg = "";
if (isAddOdo) {
alertmsg = GetTextByKey("P_MV_UPDATETHEODOMETER", "Do you want to update the odometer to reflect: {0} {1} at {2} {3}?").replace('{0}', item.Odometer).replace('{1}', item.UOM).replace('{2}', time).replace('{3}', timezonetext);
}
else {
alertmsg = GetTextByKey("P_MV_UPDATETHEODOMETER1", "If you proceed, odometer will be updated to reflect: {0} {1} at {2} <br/> {3}.<br/><br/> Note that this asset is telematic enabled and the primary data source is {4}.<br/><br/>Would you like to proceed?").replace('{0}', item.Odometer).replace('{1}', item.UOM).replace('{2}', time).replace('{3}', timezonetext).replace('{4}', assetdata.CurrentOdometer.DataSourceName);
}
showConfirm1(alertmsg, alerttitle, function () {
$('#addodomask').hide();
if (isAddOdo)
AddManuallyInputOdometer(item, alerttitle);
else
CheckOdometerMinnimumTime(item, alerttitle);
}, function () {
$('#addodomask').hide();
});
}
function AddManuallyInputOdometer(item, alerttitle) {
showloading(true);
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("AddManuallyInputOdometer", param, function (data) {
showloading(false);
if (data !== 'OK') {
showAlert(data, alerttitle);
} else {
loadAssetInfo();
showAlert(GetTextByKey("P_MV_ODOMETERUPDATESUCCESSFUL", "Odometer Update Successful."), alerttitle);
}
$('#dialog_addodometer').hideDialog();
$('#addodomask').hide();
}, function (err) {
showloading(false);
showAlert(GetTextByKey("P_MV_FAILEDTOADDODOMETER", 'Failed to add Odometer.'), alerttitle);
$('#addodomask').hide();
});
}
function CheckOdometerMinnimumTime(item, alerttitle) {
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("CheckOdometerMinnimumTime", param, function (data) {
if (data > 0) {
if (data == 1)
showAlert(GetTextByKey("P_MA_CHECKODOMETERMINNIMUMTIME", "The adjustment cannot be completed as provided. The odometer reading date provided cannot be prior to initial telematic data available for the asset."), alerttitle);
else
showAlert(GetTextByKey("P_MA_CHECKODOMETERMINNIMUMTIME1", "The adjustment cannot be completed as provided. The odometer reading date provided must be prior to or equal to the latest telematic data available for the asset."), alerttitle);
$('#addodomask').hide();
return;
} else {
SaveAdjustOdometer(item, alerttitle);
}
}, function (err) {
});
}
function SaveAdjustOdometer(item, alerttitle) {
showloading(true);
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("SaveAdjustOdometer", param, function (data) {
showloading(false);
if (data !== 'OK') {
showAlert(data, alerttitle);
} else {
loadAssetInfo();
showAlert(GetTextByKey("P_MV_ODOMETERUPDATESUCCESSFUL", "Odometer Update Successful."), alerttitle);
}
$('#dialog_addodometer').hideDialog();
$('#addodomask').hide();
}, function (err) {
showloading(false);
showAlert(GetTextByKey("P_MV_FAILEDTOADJUSTODOMETER", 'Failed to adjust Odometer.'), alerttitle);
$('#addodomask').hide();
});
}

View File

@ -0,0 +1,574 @@
$(function () {
InitPMGridData();
$('#dialog_pm').dialog(function () {
$("#pmschedulelistmask").hide();
});
$('#dialog_pmschedulelist').dialog(function () {
showmaskbg(false);
GetPMInfo();
});
if (!IsDealer && CanEditPM)
$("#btnaddplan").show();
});
function showPMSchedules() {
showmaskbg(true);
$('#dialog_pmschedulelist').css({
'top': (document.documentElement.clientHeight - $('#dialog_pmschedulelist').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_pmschedulelist').width()) / 2
}).showDialogfixed();
SetAssetItem(assetdata);
getAssetPMSchedules();
}
function SetAssetItem(asset) {
if (isNaN(asset.EngineHours))
asset.EngineHours = asset.CurrentHours.Corrected
if (isNaN(asset.Odometer)) {
asset.Odometer = asset.CurrentOdometer.Corrected;
asset.OdometerUnits = asset.CurrentOdometer.UOM;
}
$("#dialog_pm").data("asset", asset);
}
function showConfirmsub(msg, title, fok, fcancel) {
$("#pmschedulelistmask").show();
_dialog.showConfirmOKCancel(msg, title, function (e) {
$("#pmschedulelistmask").hide();
if (typeof fok === 'function') {
fok(e);
}
}, function () {
if (fcancel)
fcancel();
$("#pmschedulelistmask").hide();
});
}
/****** PM******/
var pmschedules
var grid_pmschedules;
function InitPMGridData() {
grid_pmschedules = new GridView('#pmschedulelist');
grid_pmschedules.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, css: { 'width': 30, 'text-align': 'center' } },
{ name: 'PmScheduleName', caption: GetTextByKey("P_MV_SCHEDULENAME", "Schedule Name"), valueIndex: 'PmScheduleName', css: { 'width': 200, 'text-align': 'left' } },
{ name: 'StartValue', caption: GetTextByKey("P_MV_INITIALSERVICEVALUE", "Initial Service Value"), valueIndex: 'StartValue', css: { 'width': 120, 'text-align': 'right' } },
{ name: 'LastAlertTimeString', caption: GetTextByKey("P_MV_LASTSERVICEDATE", "Last Service Date"), valueIndex: 'LastAlertTimeString', css: { 'width': 120, 'text-align': 'left' } },
{ name: 'ServiceName', caption: GetTextByKey("P_MV_LASTSERVICEPERFORMED", "Last Service Performed"), valueIndex: 'ServiceName', css: { 'width': 140, 'text-align': 'left' } }
];
var columns = [];
// head
for (var hd in list_columns) {
var col = {};
col.name = list_columns[hd].name;
col.caption = list_columns[hd].caption;
col.visible = true;
col.sortable = true;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
if (list_columns[hd].type) {
col.type = list_columns[hd].type;
}
if (col.name === "Selected") {
col.events = {
onchange: function () {
if (this.Selected) {
showSetPMDialog(this);
this.Selected = false;//弹出对话框并取消勾选因为此时机器并没有真正加入到计划在对话框OK刷新列表
grid_pmschedules.reload();
}
else {
var item = this;
var msg = GetTextByKey("P_MV_REMOVEASSETFROMSCHEDULE", "Do you want to remove this asset from the schedule?");
if (item.UnMaintainedAlert && item.UnMaintainedAlert > 0) {
var msg = GetTextByKey("P_MV_REMOVEASSETFROMSCHEDULE_TIPS", "Select OK below will result in the deletion of existing unassigned PM alerts for this asset.<br/> If you do not want those alerts deleted, select CANCEL and assign appropriate alerts to a maintenance record or work order in asset health prior to deletion/removal.");
}
showConfirmsub(msg, GetTextByKey("P_MV_REMOVEASSET", 'Remove Asset'), function () {
removeAssetFromPMSchedule(item);
}, function () {
item.Selected = true;
grid_pmschedules.reload();
});
}
}
};
}
columns.push(col);
}
grid_pmschedules.canMultiSelect = false;
grid_pmschedules.columns = columns;
grid_pmschedules.init();
}
function getAssetPMSchedules() {
$("#pmschedulelistmask").show();
assetrequest1('GetPMSchedulesByAsset', assetid, function (data) {
$("#pmschedulelistmask").hide();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MV_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
pmschedules = data;
ShowPMSchedules(data);
}
}, function () {
$("#pmschedulelistmask").hide();
});
}
function ShowPMSchedules() {
var rows = [];
for (var i = 0; i < pmschedules.length; i++) {
var r = pmschedules[i];
if (r.PmScheduleType === "HM" || r.PmScheduleType === "PM")
r.StartValue = r.StartHours;
else if (r.PmScheduleType === "ADM" || r.PmScheduleType === "RDM")
r.StartValue = r.StartOdometer;
else
r.StartValue = r.StartDateString;
var fr = { Values: r };
rows.push(fr);
}
grid_pmschedules.setData(rows);
}
function reshowpmgrid() {
setTimeout(function () {
$("#pmschedulelist").css("height", $(window).height() - $("#pmschedulelist").offset().top - 10);
grid_pmschedules && grid_pmschedules.resize();
});
}
function addAssetToPMSchedule(item) {
$("#pmschedulelistmask").show();
assetrequest1('AddAssetToPMSchedule', JSON.stringify(item), function (data) {
if (data === "OK") {
$("#pmschedulelistmask").hide();
$('#dialog_pm').hideDialog();
//showAlert(data, 'Saved Successfully.');
getAssetPMSchedules();
}
else
showAlert(data, GetTextByKey("P_MV_ERROR", 'Error'));
}, function () {
$("#pmschedulelistmask").hide();
});
}
function removeAssetFromPMSchedule(schedule) {
var assetid = $("#dialog_pm").data("asset").ID;
var scheduleid = schedule.PmScheduleID;
$("#pmschedulelistmask").show();
assetrequest1('RemoveAssetFromPMSchedule', JSON.stringify([assetid, scheduleid]), function (data) {
$("#pmschedulelistmask").hide();
if (data === "OK") {
//showAlert(data, 'Removed Successfully.');
getAssetPMSchedules();
}
else
showAlert(data, GetTextByKey("P_MV_ERROR", 'Error'));
}, function () {
$("#pmschedulelistmask").hide();
});
}
function showSetPMDialog(pmschedule) {
$("#pmschedulelistmask").show();
//$('#dialog_pm .dialog-title span.title').text('Set PM Schedule');
if (pmschedule) {
var contentctrl = $("#dialog_pm .dialog-content");
contentctrl.empty();
//scheduletype === "HM" || scheduletype === "RDM" || scheduletype === "TBM"
if (pmschedule.PmScheduleType === "PM" || pmschedule.PmScheduleType === "ADM") {
createAbsoluteContent(contentctrl, pmschedule);
}
else if (pmschedule.PmScheduleType === "HM" || pmschedule.PmScheduleType === "RDM") {
createRelativeContent(contentctrl, pmschedule);
}
else if (pmschedule.PmScheduleType === "TBM") {
createTBMContent(contentctrl, pmschedule);
}
}
$('#dialog_pm').css({
'top': (document.documentElement.clientHeight - $('#dialog_adjustenginehours').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_adjustenginehours').width()) / 2
}).showDialogfixed();
}
function createAbsoluteContent(contentctrl, pmschedule) {
var text = GetTextByKey("P_MV_WHENWOULDYOULIKETHEFIRSTALERT", "When would you like the first alert?");
contentctrl.append($("<span></span><br />").text(text));
var radio1 = $("<input type='radio' name='pm' checked='checked' />");
contentctrl.append(radio1);
var tag = hasAvailableIntervals(pmschedule);
if (tag)
text = getFirstLineText(pmschedule);
else
text = GetTextByKey("P_MV_NOAVAILABLEINTERVALS", "No available intervals.");
contentctrl.append($("<span></span><br />").text(text));
if (tag) {
var radio2 = $("<input type='radio' name='pm' />");
contentctrl.append(radio2);
text = GetTextByKey("P_MV_ONEORMORESERVICESWASMISSEDALERTMEFOR", "One or more services was missed. Alert me for ");
contentctrl.append($("<span></span>").text(text));
var selInterval = $("<select></select>").prop("disabled", true);
contentctrl.append(selInterval);
contentctrl.append($("<span>" + GetTextByKey("P_MV_NOW", " now.") + "</span>"));
if (pmschedule.Intervals) {
for (var i = 0; i < pmschedule.Intervals.length; i++) {
var interval = pmschedule.Intervals[i];
if (!interval.Recurring) continue;//暂不考虑非周期性Service
selInterval.append($("<option></option>").val(interval.PmIntervalID).text(interval.ServiceName));
}
}
radio1.change(enableInput);
radio2.change(enableInput);
function enableInput() {
if (radio1.prop("checked"))
selInterval.prop("disabled", true);
else
selInterval.prop("disabled", false);
}
}
$("#btnSetPMSchedule").unbind().click(function () {
var asset = $("#dialog_pm").data("asset");
var item = {};
item.AssetID = asset.ID;
item.PmScheduleID = pmschedule.PmScheduleID;
//item.PMType = pmschedule.PmScheduleType;
if (pmschedule.PmScheduleType === "PM")
item.StartHours = asset.EngineHours;
else {
var unit = pmschedule.PmScheduleUom;
var value = asset.Odometer;
if (value > 0 && unit && asset.OdometerUnits
&& unit.toLowerCase().charAt(0) != asset.OdometerUnits.toLowerCase().charAt(0)) {
if (unit.toLowerCase().startsWith("m"))
value = value * 0.6213712;
else
value = value / 0.6213712;
}
item.StartOdometer = Math.round(value);
}
if (radio2 && radio2.prop("checked")) {
item.SelectedIntervalID = selInterval.val();
}
addAssetToPMSchedule(item);
});
}
function createRelativeContent(contentctrl, pmschedule) {
var text = GetTextByKey("P_MV_WHENWOULDYOULIKETHEFIRSTALERT", "When would you like the first alert?");
contentctrl.append($("<span></span><br />").text(text));
var radio1 = $("<input type='radio' name='pm' checked='checked' />");
contentctrl.append(radio1);
var tag = hasAvailableIntervals(pmschedule);
if (tag)
text = getFirstLineText(pmschedule);
else
text = GetTextByKey("P_MV_NOAVAILABLEINTERVALS", "No available intervals.");
contentctrl.append($("<span></span><br />").text(text));
if (tag) {
var radio2 = $("<input type='radio' name='pm' />");
contentctrl.append(radio2);
text = GetTextByKey("P_MV_CALCULATEBASEDUPONLASTSERVICETHE", "Calculate based upon last service. The ");
contentctrl.append($("<span></span>").text(text));
var selInterval = $("<select></select>").prop("disabled", true);
contentctrl.append(selInterval);
contentctrl.append($("<span>" + GetTextByKey("P_MV_SERVICEWASPERFORMEDAT", " service was performed at ") + "</span>"));
var txtStartValue = $("<input type='text' style='width:80px;' />").prop("disabled", true);
contentctrl.append(txtStartValue);
if (pmschedule.AllIntervals) {
var asset = $("#dialog_pm").data("asset");
var value = 0;
if (pmschedule.PmScheduleType === "HM")
value = Math.round(asset.EngineHours);
else
value = Math.round(asset.Odometer);
if (isNaN(value))
value = 0;
var tempIntervals = getIntervalValues(value, pmschedule.AllIntervals);
for (var i = 0; i < tempIntervals.length; i++) {
var interval = tempIntervals[i];
selInterval.append($("<option></option>").val(interval).text(interval));
}
//for (var i = 0; i < pmschedule.AllIntervals.length; i++) {
// var interval = pmschedule.AllIntervals[i];
// selInterval.append($("<option></option>").val(interval).text(interval));
//}
}
radio1.change(enableInput);
radio2.change(enableInput);
function enableInput() {
if (radio1.prop("checked")) {
txtStartValue.prop("disabled", true);
selInterval.prop("disabled", true);
}
else {
txtStartValue.prop("disabled", false);
selInterval.prop("disabled", false);
}
}
}
$("#btnSetPMSchedule").unbind().click(function () {
var asset = $("#dialog_pm").data("asset");
var item = {};
item.AssetID = asset.ID;
item.PmScheduleID = pmschedule.PmScheduleID;
//item.PMType = pmschedule.PmScheduleType;
if (radio1.prop("checked")) {
if (pmschedule.PmScheduleType === "HM")
item.StartHours = asset.EngineHours;
else {
var unit = pmschedule.PmScheduleUom;
var value = asset.Odometer;
if (value > 0 && unit && asset.OdometerUnits
&& unit.toLowerCase().charAt(0) != asset.OdometerUnits.toLowerCase().charAt(0)) {
if (unit.toLowerCase().startsWith("m"))
value = value * 0.6213712;
else
value = value / 0.6213712;
}
item.StartOdometer = Math.round(value);
}
}
else {
if (pmschedule.PmScheduleType === "HM") {
item.StartHours = txtStartValue.val();
if (item.StartHours === "" || isNaN(item.StartHours))
item.StartHours = asset.EngineHours;
}
else {
item.StartOdometer = txtStartValue.val();
if (item.StartOdometer === "" || isNaN(item.StartOdometer)) {
var unit = pmschedule.PmScheduleUom;
var value = asset.Odometer;
if (value > 0 && unit && asset.OdometerUnits
&& unit.toLowerCase().charAt(0) != asset.OdometerUnits.toLowerCase().charAt(0)) {
if (unit.toLowerCase().startsWith("m"))
value = value * 0.6213712;
else
value = value / 0.6213712;
}
item.StartOdometer = Math.round(value);
}
}
item.StartIntervalValue = selInterval.val();
}
addAssetToPMSchedule(item);
});
}
function createTBMContent(contentctrl, pmschedule) {
var text = GetTextByKey("P_MV_WHENWOULDYOULIKETHEFIRSTALERT", "When would you like the first alert?");
contentctrl.append($("<span></span><br />").text(text));
var radio1 = $("<input type='radio' name='pm' checked='checked' />");
contentctrl.append(radio1);
var tag = hasAvailableIntervals(pmschedule);
if (tag)
text = GetTextByKey("P_MV_TRIGGERANALERTASIFSERVICEISDUETODAY", "Trigger an alert as if service is due today.");
else
text = GetTextByKey("P_MV_NOAVAILABLEINTERVALS", "No available intervals.");
contentctrl.append($("<span></span><br />").text(text));
if (tag) {
var radio2 = $("<input type='radio' name='pm' />");
contentctrl.append(radio2);
text = GetTextByKey("P_MV_CALCULATEBASEDUPONLASTSERVICETHELASTSERVICEDATAWAS", "Calculate based upon last service. The last service date was ");
contentctrl.append($("<span></span>").text(text));
var dateparent = $("<span></span>");
contentctrl.append(dateparent);
var txtLastServiceDate = $("<input type='text' style='width:80px;' />").prop("disabled", true);
txtLastServiceDate.datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false
}).text(currentdate);
dateparent.append(txtLastServiceDate);
contentctrl.append($("<span>" + GetTextByKey("P_MV_FOR", " for ") + "</span>"));
var selInterval = $("<select></select>").prop("disabled", true);
contentctrl.append(selInterval);
if (pmschedule.Intervals) {
for (var i = 0; i < pmschedule.AllIntervals.length; i++) {
var interval = pmschedule.AllIntervals[i];
selInterval.append($("<option></option>").val(interval).text(interval));
}
}
radio1.change(enableInput);
radio2.change(enableInput);
function enableInput() {
if (radio1.prop("checked")) {
txtLastServiceDate.prop("disabled", true);
selInterval.prop("disabled", true);
}
else {
txtLastServiceDate.prop("disabled", false);
selInterval.prop("disabled", false);
}
}
}
$("#btnSetPMSchedule").unbind().click(function () {
var asset = $("#dialog_pm").data("asset");
var item = {};
item.AssetId = asset.ID;
item.PmScheduleID = pmschedule.PmScheduleID;
//item.PMType = pmschedule.PmScheduleType;
if (radio1.prop("checked")) {
item.StartDate = nowdate;
}
else {
item.StartDate = txtLastServiceDate.val();
item.StartIntervalValue = selInterval.val();
if (item.StartDate == "")
item.StartDate = "1900-01-01";
}
addAssetToPMSchedule(item);
});
}
function hasAvailableIntervals(pmschedule) {
if (!pmschedule.Intervals || pmschedule.Intervals.length == 0)
return false;
for (var i = 0; i < pmschedule.Intervals.length; i++) {
var ii = pmschedule.Intervals[i];
if (ii.Recurring)
return true;
}
return false;
}
function getIntervalValues(currentValue, allIntervals) {
var result = [];//取当前值的前两个和后10个Interval
if (allIntervals && allIntervals.length > 0) {
var maxInterval = allIntervals[allIntervals.length - 1];
var pervoid = parseInt(currentValue / maxInterval);
var remain = currentValue % maxInterval;
if (remain > 0)
pervoid++;
var maxpervoid = pervoid + 1;
var minpervoid = pervoid - Math.ceil(10 / allIntervals.length) - 1;//10表示向后取10
if (minpervoid < 0)
minpervoid = 0;
for (var pi = maxpervoid; pi >= minpervoid; pi--) {
for (var i = allIntervals.length - 1; i >= 0; i--) {
var interval = allIntervals[i];
var tempinterval = pi * maxInterval + interval;
result.push(tempinterval);
if (tempinterval >= currentValue) {
if (result.length > 2)
result.splice(0, 1);
}
else if (result.length == 12)
break;
}
}
}
return result;
}
function getFirstLineText(pmschedule) {
var text = "";
if (pmschedule.Intervals && pmschedule.Intervals.length > 0) {
var asset = $("#dialog_pm").data("asset");
var unit = "";
var value = 0;
if (pmschedule.PmScheduleType === "PM" || pmschedule.PmScheduleType === "HM") {
unit = "hours";
value = Math.round(asset.EngineHours);
}
else {
unit = pmschedule.PmScheduleUom;
value = asset.Odometer;
if (value > 0 && unit && asset.OdometerUnits
&& unit.toLowerCase().charAt(0) != asset.OdometerUnits.toLowerCase().charAt(0)) {
if (unit.toLowerCase().startsWith("m"))
value = value * 0.6213712;
else
value = value / 0.6213712;
value = Math.round(value);
}
}
if (isNaN(value))
value = 0;
var minoffset = null;
var nextInterval = null;
for (var i = 0; i < pmschedule.Intervals.length; i++) {
var ii = pmschedule.Intervals[i];
if (!ii.Recurring) continue;//暂不考虑非周期性Service
var offset = 0;
if (value == 0)
offset = ii.Interval;
else if (value % ii.Interval > 0)
offset = ii.Interval - value % ii.Interval;
if (!nextInterval || offset < minoffset) {
nextInterval = ii;
minoffset = offset;
continue;
}
if (offset == minoffset && (ii.Priority < nextInterval.Priority
|| (ii.Priority == nextInterval.Priority && ii.Interval > nextInterval.Interval)))
nextInterval = ii;
}
if (nextInterval) {
text = GetTextByKey("P_MV_THEFIRSTALERTWILLBE", "The first alert will be ");
text += nextInterval.NotificationPeriod + " " + unit;
if (value != 0 && value % nextInterval.Interval == 0)
parseInt(value / nextInterval.Interval) * nextInterval.Interval
else
value = (parseInt(value / nextInterval.Interval) + 1) * nextInterval.Interval;
text += GetTextByKey("P_MV_BEFORETHEASSETREADING", " before the asset reading ") + value + " " + unit;
text += GetTextByKey("P_MV_FOR", " for ") + nextInterval.ServiceName + ".";
}
}
return text;
}