fleet-contractor/Site/Maintenance/js/workorderalert.js
2023-04-28 12:22:26 +08:00

721 lines
28 KiB
JavaScript

function showAllAlerts(alerts) {
if (alerts.DTCAlerts && alerts.DTCAlerts.length > 0) {
_DTCAlerts = alerts.DTCAlerts;
$("#divdtcalerts").show();
showAlerts(_DTCAlerts, grid_dtcalertdt);
}
else {
_DTCAlerts = [];
showAlerts(_DTCAlerts, grid_dtcalertdt);
}
if (alerts.PMAlerts && alerts.PMAlerts.length > 0) {
_PMAAlerts = alerts.PMAlerts;
//$("#divpmaalerts").show();
showAlerts(_PMAAlerts, grid_pmaalertdt);
$('#dialog_expectedcost').val(alerts.AllExpectedCost === 0 ? '' : alerts.AllExpectedCost);
}
else {
_PMAAlerts = [];
showAlerts(_PMAAlerts, grid_pmaalertdt);
}
if (alerts.InspectAlerts && alerts.InspectAlerts.length > 0) {
_InspectAlerts = alerts.InspectAlerts;
$("#divinspectalerts").show();
showAlerts(_InspectAlerts, grid_inspectalertdt);
}
else {
_InspectAlerts = [];
showAlerts(_InspectAlerts, grid_inspectalertdt);
}
if (alerts.OilAlerts && alerts.OilAlerts.length > 0) {
_OilAlerts = alerts.OilAlerts;
$("#divoilalerts").show();
showAlerts(_OilAlerts, grid_oilalertdt);
}
else {
_OilAlerts = [];
showAlerts(_OilAlerts, grid_oilalertdt);
}
}
function showAlerts(data, grid_dt) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
alertids.push(r.AlertID);
if (r.RepeatedAlerts) {
for (var j = 0; j < r.RepeatedAlerts.length; j++) {
alertids.push(r.RepeatedAlerts[j]);
}
}
for (var j in r) {
r["EngineHoursObj"] = { DisplayValue: r["EngineHours"] == 0 ? "" : r["EngineHours"], Value: r["EngineHours"] };
r["AlertLocalTime"] = { DisplayValue: r["AlertLocalTimeStr"], Value: r["AlertLocalTime"] };
}
var fr = { Values: r };
rows.push(fr);
}
grid_dt.setData(rows);
}
var grid_dtcalertdt;
function InitDTCAlertGridData() {
grid_dtcalertdt = new GridView('#dtcalertslist');
grid_dtcalertdt.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: 'EngineHours', caption: GetTextByKey("P_WO_HOURS", "Hours"), valueIndex: 'EngineHoursObj', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'AlertType', caption: GetTextByKey("P_WO_ALERTTYPE", "Alert Type"), valueIndex: 'AlertType', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Description', caption: GetTextByKey("P_WO_DESCRIPTION", "Description"), valueIndex: 'Description', css: { 'width': 480, 'text-align': 'left' } },
//{ name: 'ServiceDescription', caption: GetTextByKey("P_WO_SERVICEDESCRIPTION", "Service Description"), valueIndex: 'ServiceDescription', css: { 'width': 240, 'text-align': 'left' } },
{ name: 'AlertCount', caption: GetTextByKey("P_WO_COUNT", "Count"), valueIndex: 'AlertCount', css: { 'width': 100, 'text-align': 'left' } },
{ name: 'AlertLocalTime', caption: GetTextByKey("P_WO_LATESTDATETIME", "Latest DateTime"), valueIndex: 'AlertLocalTime', css: { 'width': 150, '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.type = list_columns[hd].type;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
columns.push(col);
if (col.name === "Selected") {
col.allcheck = true;
}
}
grid_dtcalertdt.canMultiSelect = false;
grid_dtcalertdt.columns = columns;
grid_dtcalertdt.init();
grid_dtcalertdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_dtcalertdt.source[rowindex];
if (rowdata) {
}
}
}
var grid_pmaalertdt;
function InitPMAAlertGridData() {
grid_pmaalertdt = new GridView('#pmaalertslist');
grid_pmaalertdt.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: 'EngineHours', caption: GetTextByKey("P_WO_HOURS", "Hours"), valueIndex: 'EngineHoursObj', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'AlertType', caption: GetTextByKey("P_WO_ALERTTYPE", "Alert Type"), valueIndex: 'AlertType', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Description', caption: GetTextByKey("P_WO_DESCRIPTION", "Description"), valueIndex: 'Description', css: { 'width': 240, 'text-align': 'left' } },
{ name: 'ServiceDescription', caption: GetTextByKey("P_WO_SERVICEDESCRIPTION", "Service Description"), valueIndex: 'ServiceDescription', css: { 'width': 240, 'text-align': 'left' } },
{ name: 'ExpectedCost', caption: GetTextByKey("P_PM_EXPECTEDCOST", "Expected Cost"), valueIndex: 'ExpectedCost', css: { 'width': 100, 'text-align': 'left' } },
{ name: 'AlertCount', caption: GetTextByKey("P_WO_COUNT", "Count"), valueIndex: 'AlertCount', css: { 'width': 100, 'text-align': 'left' } },
{ name: 'AlertLocalTime', caption: GetTextByKey("P_WO_LATESTDATETIME", "Latest DateTime"), valueIndex: 'AlertLocalTime', css: { 'width': 150, '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.type = list_columns[hd].type;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
columns.push(col);
if (col.name === "Selected") {
col.allcheck = true;
}
}
grid_pmaalertdt.canMultiSelect = false;
grid_pmaalertdt.columns = columns;
grid_pmaalertdt.init();
grid_pmaalertdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_pmaalertdt.source[rowindex];
if (rowdata) {
}
}
}
var grid_inspectalertdt;
function InitInspectAlertGridData() {
grid_inspectalertdt = new GridView('#inspectalertslist');
grid_inspectalertdt.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: 'EngineHours', caption: GetTextByKey("P_WO_HOURS", "Hours"), valueIndex: 'EngineHoursObj', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'AlertType', caption: GetTextByKey("P_WO_ALERTTYPE", "Alert Type"), valueIndex: 'AlertType', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Description', caption: GetTextByKey("P_WO_DESCRIPTION", "Description"), valueIndex: 'Description', css: { 'width': 480, 'text-align': 'left' } },
//{ name: 'ServiceDescription', caption: GetTextByKey("P_WO_SERVICEDESCRIPTION", "Service Description"), valueIndex: 'ServiceDescription', css: { 'width': 240, 'text-align': 'left' } },
{ name: 'AlertCount', caption: GetTextByKey("P_WO_COUNT", "Count"), valueIndex: 'AlertCount', css: { 'width': 100, 'text-align': 'left' } },
{ name: 'AlertLocalTime', caption: GetTextByKey("P_WO_LATESTDATETIME", "Latest DateTime"), valueIndex: 'AlertLocalTime', css: { 'width': 150, '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.type = list_columns[hd].type;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
columns.push(col);
if (col.name === "Selected") {
col.allcheck = true;
}
}
grid_inspectalertdt.canMultiSelect = false;
grid_inspectalertdt.columns = columns;
grid_inspectalertdt.init();
grid_inspectalertdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_inspectalertdt.source[rowindex];
if (rowdata) {
}
}
}
var grid_oilalertdt;
function InitOilAlertGridData() {
grid_oilalertdt = new GridView('#oilalertslist');
grid_oilalertdt.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: 'EngineHours', caption: GetTextByKey("P_WO_HOURS", "Hours"), valueIndex: 'EngineHoursObj', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'AlertType', caption: GetTextByKey("P_WO_ALERTTYPE", "Alert Type"), valueIndex: 'AlertType', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Description', caption: GetTextByKey("P_WO_DESCRIPTION", "Description"), valueIndex: 'Description', css: { 'width': 480, 'text-align': 'left' } },
//{ name: 'ServiceDescription', caption: GetTextByKey("P_WO_SERVICEDESCRIPTION", "Service Description"), valueIndex: 'ServiceDescription', css: { 'width': 240, 'text-align': 'left' } },
{ name: 'AlertCount', caption: GetTextByKey("P_WO_COUNT", "Count"), valueIndex: 'AlertCount', css: { 'width': 100, 'text-align': 'left' } },
{ name: 'AlertLocalTime', caption: GetTextByKey("P_WO_LATESTDATETIME", "Latest DateTime"), valueIndex: 'AlertLocalTime', css: { 'width': 150, '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.type = list_columns[hd].type;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
columns.push(col);
if (col.name === "Selected") {
col.allcheck = true;
}
}
grid_oilalertdt.canMultiSelect = false;
grid_oilalertdt.columns = columns;
grid_oilalertdt.init();
grid_oilalertdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_oilalertdt.source[rowindex];
if (rowdata) {
}
}
}
function showNoneAssienedAlerts(data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
for (var j in r) {
if (j === "EngineHours")
r[j] = { DisplayValue: r[j] == 0 ? "" : r[j], Value: r[j] };
else if (j === "AlertLocalTime")
r[j] = { DisplayValue: r["AlertLocalTimeStr"], Value: r[j] };
}
var fr = { Values: r };
rows.push(fr);
}
grid_noneassignedalertdt.setData(rows);
}
var grid_noneassignedalertdt;
function InitNoneAssignedAlertGridData() {
grid_noneassignedalertdt = new GridView('#noneassignedalertlist');
grid_noneassignedalertdt.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: 'EngineHours', caption: GetTextByKey("P_WO_HOURS", "Hours"), valueIndex: 'EngineHours', css: { 'width': 80, 'text-align': 'left' } },
{ name: 'AlertType', caption: GetTextByKey("P_WO_ALERTTYPE", "Alert Type"), valueIndex: 'AlertType', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Description', caption: GetTextByKey("P_WO_DESCRIPTION", "Description"), valueIndex: 'Description', css: { 'width': 200, 'text-align': 'left' } },
{ name: 'ServiceDescription', caption: GetTextByKey("P_WO_SERVICEDESCRIPTION", "Service Description"), valueIndex: 'ServiceDescription', css: { 'width': 200, 'text-align': 'left' } },
{ name: 'AlertTime', caption: GetTextByKey("P_WO_LATESTDATETIME", "Latest DateTime"), valueIndex: 'AlertTime', css: { 'width': 125, '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.type = list_columns[hd].type;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
columns.push(col);
if (col.name === "Selected") {
col.allcheck = true;
}
}
grid_noneassignedalertdt.canMultiSelect = false;
grid_noneassignedalertdt.columns = columns;
grid_noneassignedalertdt.init();
grid_noneassignedalertdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_noneassignedalertdt.source[rowindex];
if (rowdata) {
}
}
}
function clearAlertData() {
_DTCAlerts = [];
_PMAAlerts = [];
_InspectAlerts = [];
_OilAlerts = [];
grid_dtcalertdt.setData([]);
grid_pmaalertdt.setData([]);
grid_inspectalertdt.setData([]);
grid_oilalertdt.setData([]);
}
var _DTCAlerts = [];
var _PMAAlerts = [];
var _InspectAlerts = [];
var _OilAlerts = [];
function getAlerts() {
$("#divdtcalerts").hide();
//$("#divpmaalerts").hide();
$("#divinspectalerts").hide();
$("#divoilalerts").hide();
clearAlertData();
alertrequest("GETWORKORDERALERTS", workorderid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
return;
}
showAllAlerts(data);
}, function (err) {
});
}
function getAssetAlerts(mid) {
$("#divdtcalerts").hide();
//$("#divpmaalerts").hide();
$("#divinspectalerts").hide();
$("#divoilalerts").hide();
clearAlertData();
if (!mid)
mid = machineid;
showloading(true);
alertrequest("GETASSETALERTS", mid + String.fromCharCode(170) + JSON.stringify(alertids), function (data) {
showloading(false);
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
return;
}
showAllAlerts(data);
}, function (err) {
showloading(false);
});
}
function reshowgrid() {
setTimeout(function () {
$("#dtcalertslist").css("height", 240);
grid_dtcalertdt && grid_dtcalertdt.resize();
$("#pmaalertslist").css("height", 240);
grid_pmaalertdt && grid_pmaalertdt.resize();
$("#inspectalertslist").css("height", 240);
grid_inspectalertdt && grid_inspectalertdt.resize();
$("#oilalertslist").css("height", 240);
grid_oilalertdt && grid_oilalertdt.resize();
});
}
function showAlertPopup() {
$('#alertpopupmask').show();
$('#alertpopupdialog').show();
$('#alertpopupdialog').css({
"top": ($("#alertpopupmask").height() - $('#alertpopupdialog').height()) / 2,
"left": ($("#alertpopupmask").width() - $('#alertpopupdialog').width()) / 2
});
//$("#noneassignedalertlist").css("height", $('#alertpopupdialog').height() - $("#alertpopupdialog").offset().top - 4);
grid_noneassignedalertdt && grid_noneassignedalertdt.resize();
}
function hideAlertPopup() {
$('#alertpopupdialog').hide();
$('#alertpopupmask').hide();
}
function OnAddAlerts() {
if (!workorderid || workorderid === "") {
showAlert(GetTextByKey("P_WO_SAVEWORKORDERFIRST", "Please save work order first."), GetTextByKey("P_WO_ADDALERTS", 'Add Alerts'));
return;
}
getNoneAssignedAlerts();
}
var noneassignedalerts = [];
function getNoneAssignedAlerts() {
var mid;
if (typeof editableSelectMachine != "undefined") {
var machine = editableSelectMachine.selecteditem();
if (machine)
mid = machine.Id;
}
else
mid = machineid;
if (!mid) {
showAlert(GetTextByKey("P_WO_PLEASESELECTANASSET", "Please select an Asset."), GetTextByKey("P_WO_SENDEMAIL", "Send Email"));
$('#dialog_machine').focus();
return;
}
worequest("GetNoneAssignedAlerts", mid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
return;
}
showAlertPopup();
noneassignedalerts = data;
showNoneAssienedAlerts(noneassignedalerts);
}, function (err) {
});
}
function AddOrRemoveAlertsFromWorkOrder(isadd, alertids) {
worequest("AddOrRemoveAlertsFromWorkOrder", workorderid + String.fromCharCode(170) + JSON.stringify(alertids) + String.fromCharCode(170) + isadd, function (data) {
if (isadd)
hideAlertPopup();
getAlerts();
}, function (err) {
});
}
function OnRemoveAlerts() {
var alerts = [];
alertids = [];
if (_DTCAlerts.length > 0) {
for (var i = _DTCAlerts.length - 1; i >= 0; i--) {
var alert = _DTCAlerts[i];
if (alert.Selected) {
alerts.push(alert.AlertID);
_DTCAlerts.splice(i, 1);
//if (alertids.indexOf(alert.AlertID) >= 0)
// alertids.splice(alertids.indexOf(alert.AlertID), 1);
if (alert.RepeatedAlerts) {
for (var j = 0; j < alert.RepeatedAlerts.length; j++) {
alerts.push(alert.RepeatedAlerts[j]);
//alertids.splice(alertids.indexOf(alert.RepeatedAlerts[j]), 1);
}
}
}
}
showAlerts(_DTCAlerts, grid_dtcalertdt);
}
if (_PMAAlerts.length > 0) {
for (var i = _PMAAlerts.length - 1; i >= 0; i--) {
var alert = _PMAAlerts[i];
if (alert.Selected) {
alerts.push(alert.AlertID);
_PMAAlerts.splice(i, 1);
//if (alertids.indexOf(alert.AlertID) >= 0)
// alertids.splice(alertids.indexOf(alert.AlertID), 1);
if (alert.RepeatedAlerts) {
for (var j = 0; j < alert.RepeatedAlerts.length; j++) {
alerts.push(alert.RepeatedAlerts[j]);
//alertids.splice(alertids.indexOf(alert.RepeatedAlerts[j]), 1);
}
}
}
}
showAlerts(_PMAAlerts, grid_pmaalertdt);
//grid_pmaalertdt.setData(_PMAAlerts);
}
if (_InspectAlerts.length > 0) {
for (var i = _InspectAlerts.length - 1; i >= 0; i--) {
var alert = _InspectAlerts[i];
if (alert.Selected) {
alerts.push(alert.AlertID);
_InspectAlerts.splice(i, 1);
//if (alertids.indexOf(alert.AlertID) >= 0)
// alertids.splice(alertids.indexOf(alert.AlertID), 1);
if (alert.RepeatedAlerts) {
for (var j = 0; j < alert.RepeatedAlerts.length; j++) {
alerts.push(alert.RepeatedAlerts[j]);
//alertids.splice(alertids.indexOf(alert.RepeatedAlerts[j]), 1);
}
}
}
}
showAlerts(_InspectAlerts, grid_inspectalertdt);
}
if (_OilAlerts.length > 0) {
for (var i = _OilAlerts.length - 1; i >= 0; i--) {
var alert = _OilAlerts[i];
if (alert.Selected) {
alerts.push(alert.AlertID);
_OilAlerts.splice(i, 1);
//if (alertids.indexOf(alert.AlertID) >= 0)
// alertids.splice(alertids.indexOf(alert.AlertID), 1);
if (alert.RepeatedAlerts) {
for (var j = 0; j < alert.RepeatedAlerts.length; j++) {
alerts.push(alert.RepeatedAlerts[j]);
//alertids.splice(alertids.indexOf(alert.RepeatedAlerts[j]), 1);
}
}
}
}
showAlerts(_OilAlerts, grid_oilalertdt);
}
if (alerts.length == 0) {
showAlert(GetTextByKey("P_WO_PLEASESELECTANALERT", "Please select an Alert."), GetTextByKey("P_WO_REMOVEALERTS", "Remove Alerts"));
return;
}
if (workorderid && workorderid !== "") {
AddOrRemoveAlertsFromWorkOrder(false, alerts);
}
}
function OnSaveAlerts() {
var alerts = [];
if (noneassignedalerts.length > 0) {
for (var i in noneassignedalerts) {
var alert = noneassignedalerts[i];
if (alert.Selected) {
alerts.push(alert.ID);
}
}
}
if (alerts.length == 0) {
showAlert(GetTextByKey("P_WO_PLEASESELECTANALERT", "Please select an Alert."), GetTextByKey("P_WO_ADDALERTS", "Add Alerts"));
return;
}
AddOrRemoveAlertsFromWorkOrder(true, alerts);
}
//**********************************Add PM Alerts (Alerts not yet triggered)***********************************************/
function showAllPMSchedules(data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
for (var j in r) {
}
var fr = { Values: r };
rows.push(fr);
}
grid_pmschedulesdt.setData(rows);
}
var grid_pmschedulesdt;
function InitAllPMSchedulesGridData() {
grid_pmschedulesdt = new GridView('#allpmpmalertslist');
grid_pmschedulesdt.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: 'Name', caption: GetTextByKey("P_MV_SCHEDULENAME", "Schedule Name"), valueIndex: 'Name', css: { 'width': 300, '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.type = list_columns[hd].type;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
columns.push(col);
if (col.name === "Selected") {
col.allcheck = true;
}
}
grid_pmschedulesdt.canMultiSelect = false;
grid_pmschedulesdt.columns = columns;
grid_pmschedulesdt.init();
grid_pmschedulesdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_pmschedulesdt.source[rowindex];
if (rowdata) {
}
}
}
function showAllPMSchedulePopup() {
$('#allpmschedulepopupmask').show();
$('#allpmschedulepopupdialog').show();
$('#allpmschedulepopupdialog').css({
"top": ($("#allpmschedulepopupmask").height() - $('#allpmschedulepopupdialog').height()) / 2,
"left": ($("#allpmschedulepopupmask").width() - $('#allpmschedulepopupdialog').width()) / 2
});
grid_pmschedulesdt && grid_pmschedulesdt.resize();
}
function hideAllPMSchedulePopup() {
$('#allpmschedulepopupdialog').hide();
$('#allpmschedulepopupmask').hide();
}
function OnAddAllPMSchedules() {
if (!workorderid || workorderid === "") {
showAlert(GetTextByKey("P_WO_SAVEWORKORDERFIRST", "Please save work order first."), GetTextByKey("P_WO_ADDALERTS", 'Add Alerts'));
return;
}
GetPMSchedulesByAsset();
}
var allpmschedules = [];
function GetPMSchedulesByAsset() {
var mid;
if (typeof editableSelectMachine != "undefined") {
var machine = editableSelectMachine.selecteditem();
if (machine)
mid = machine.Id;
}
else
mid = machineid;
if (!mid) {
showAlert(GetTextByKey("P_WO_PLEASESELECTANASSET", "Please select an Asset."), GetTextByKey("P_WO_SENDEMAIL", "Send Email"));
$('#dialog_machine').focus();
return;
}
showAllPMSchedulePopup();
worequest("GetPMSchedulesByAsset", mid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
return;
}
allpmschedules = data;
showAllPMSchedules(allpmschedules);
}, function (err) {
});
}
function GenerateManualPMAlerts() {
var schids = [];
if (allpmschedules.length > 0) {
for (var i in allpmschedules) {
var pmsch = allpmschedules[i];
if (pmsch.Selected) {
schids.push(pmsch.Id);
}
}
}
if (schids.length == 0) {
showAlert(GetTextByKey("P_WO_PLEASESELECTAPLAN", "Please select a plan."), GetTextByKey("P_WO_ADDALERTS", "Add Alerts"));
return;
}
var mid;
if (typeof editableSelectMachine != "undefined") {
var machine = editableSelectMachine.selecteditem();
if (machine)
mid = machine.Id;
}
else
mid = machineid;
if (!mid) {
showAlert(GetTextByKey("P_WO_PLEASESELECTANASSET", "Please select an Asset."), GetTextByKey("P_WO_SENDEMAIL", "Send Email"));
$('#dialog_machine').focus();
return;
}
worequest("GenerateManualPMAlerts", JSON.stringify([mid, workorderid, JSON.stringify(schids)])
, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
return;
}
else {
var msg = "";
for (var i = 0; i < data.length; i++) {
var r = data[i];
if (r.Status == -1)
msg += GetTextByKey("P_WO_FAILEDTOGENERATEALERT", "Failed to generate alert.") + " (" + r.ScheduleName + ")\r\n";
else if (r.Status == 1)
msg += GetTextByKey("P_WO_FAILEDTOGENERATEALERT1", "Unable to generate alert because there already exists an unmaintained alert.") + " (" + r.ScheduleName + ")\r\n";
else if (r.Status == 2) {
if (r.UOM == "hour(s)")
msg += GetTextByKey("P_WO_FAILEDTOGENERATEALERT2", "Unable to generate alert until Hour Meter is higher than ") + r.NextTargetValue.toLocaleString() + " " + r.UOM + " (" + r.ScheduleName + ")\r\n";
else if (r.UOM == "day(s)")
msg += GetTextByKey("P_WO_FAILEDTOGENERATEALERT3", "Unable to generate alert until {0} later {1}").replace('{0}', r.NextTargetValue.toLocaleString() + " " + r.UOM).replace('{1}', " (" + r.ScheduleName + ")\r\n");
else
msg += GetTextByKey("P_WO_FAILEDTOGENERATEALERT4", "Unable to generate alert until odometer is higher than ") + r.NextTargetValue.toLocaleString() + " " + r.UOM + " (" + r.ScheduleName + ")\r\n";
}
}
if (msg !== "")
showAlert(msg, GetTextByKey("P_WO_ERROR", 'Error'));
}
hideAllPMSchedulePopup();
getAlerts();
}, function (err) {
});
}