516 lines
20 KiB
JavaScript
516 lines
20 KiB
JavaScript
|
|
function showAssignedAssetsList(data) {
|
|
|
|
grid_assignedassetdt.setData(data);
|
|
grid_assignedassetdt.reload();
|
|
}
|
|
var grid_assignedassetdt;
|
|
function InitAssignedAssetsGridData() {
|
|
grid_assignedassetdt = createGridView('#divScheduleAssets');
|
|
grid_assignedassetdt.isEditable = true;
|
|
var list_columns = [
|
|
{ name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, css: { 'width': 45, 'text-align': 'center' } },
|
|
{ name: 'VIN', caption: GetTextByKey("P_PM_SN", 'SN'), valueIndex: 'VIN', css: { 'width': 140, 'text-align': 'left' } },
|
|
{ name: 'Name', caption: GetTextByKey("P_PM_NAME", 'Name'), valueIndex: 'Name', css: { 'width': 140, 'text-align': 'left' } },
|
|
{ name: 'MakeName', caption: GetTextByKey("P_PM_MAKE", 'Make'), valueIndex: 'MakeName', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'ModelName', caption: GetTextByKey("P_PM_MODEL", 'Model'), valueIndex: 'ModelName', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'EngineHours', caption: GetTextByKey("P_PM_CURRENTHOURS", 'Current Hours'), valueIndex: 'EngineHours', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'StartHours', caption: GetTextByKey("P_PM_STARTINGHOURS", 'Starting Hours'), valueIndex: 'StartHours', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'Odometer', caption: GetTextByKey("P_PM_CURRENTODOMETER", 'Current Odometer'), valueIndex: 'Odometer', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'StartOdometer', caption: GetTextByKey("P_PM_STARTODOMETER", 'Start Odometer'), valueIndex: 'StartOdometer', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'StartDateString', caption: GetTextByKey("P_PM_PLANSTARTDATE", 'Plan Start Date'), valueIndex: 'StartDateString', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'StartIntervalValue', caption: GetTextByKey("P_PM_STARTINTERVAL", 'Start Interval'), valueIndex: 'StartIntervalValue', css: { 'width': 100, 'text-align': 'left' } }
|
|
];
|
|
var columns = [];
|
|
var DateColumn = window['lib-ui'].GridDateColumn;
|
|
// 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;
|
|
col.allowFilter = list_columns[hd].allowFilter;
|
|
col.oldFilterValues = col.filterValues;
|
|
col.styleFilter = function (item) {
|
|
if (item.Highlight)
|
|
return { 'background-color': 'yellow' };
|
|
}
|
|
if (list_columns[hd].type) {
|
|
col.type = list_columns[hd].type;
|
|
}
|
|
|
|
col.alwaysshow = list_columns[hd].alwaysshow;
|
|
|
|
if (col.name === "EngineHours" && ["HM", "PM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
else if (col.name === "Odometer" && ["RDM", "ADM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
else if (col.name === "StartHours") {
|
|
if (["HM", "PM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
col.type = GridView.ColumnTypes.Input;
|
|
}
|
|
else if (col.name === "StartOdometer") {
|
|
if (["RDM", "ADM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
col.type = GridView.ColumnTypes.Input;
|
|
}
|
|
else if (col.name === "StartDateString") {
|
|
if (["TBM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
col.type = DateColumn;
|
|
col.onChanged = function (item, value) {
|
|
item.StartDate = item.StartDateString = DateColumn.formatDate(value);
|
|
};
|
|
}
|
|
else if (col.name === "StartIntervalValue") {
|
|
if (["HM", "RDM", "TBM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
col.type = GridView.ColumnTypes.Dropdown;
|
|
col.sourceCache = false;
|
|
col.source = function (item) {
|
|
var source = [];
|
|
if (item.TempIntervals && item.TempIntervals.length > 0) {
|
|
for (var i = 0; i < item.TempIntervals.length; i++) {
|
|
var t = item.TempIntervals[i];
|
|
var kv = { value: '' + t, text: '' + t };
|
|
source.push(kv);
|
|
}
|
|
}
|
|
return source;
|
|
};
|
|
}
|
|
columns.push(col);
|
|
}
|
|
grid_assignedassetdt.multiSelect = true;
|
|
grid_assignedassetdt.columns = columns;
|
|
grid_assignedassetdt.init();
|
|
}
|
|
|
|
function showSelectedAssetsList(data) {
|
|
|
|
grid_selectedassetdt.setData(data);
|
|
grid_selectedassetdt.reload();
|
|
}
|
|
var grid_selectedassetdt;
|
|
function InitSelectedAssetsGridData() {
|
|
grid_selectedassetdt = createGridView('#selectedassets');
|
|
grid_selectedassetdt.isEditable = true;
|
|
var list_columns = [
|
|
{ name: 'VIN', caption: GetTextByKey("P_PM_SN", 'SN'), valueIndex: 'VIN', css: { 'width': 140, 'text-align': 'left' } },
|
|
{ name: 'Name', caption: GetTextByKey("P_PM_NAME", 'Name'), valueIndex: 'Name', css: { 'width': 140, 'text-align': 'left' } },
|
|
{ name: 'EngineHours', caption: GetTextByKey("P_PM_CURRENTHOURS", 'Current Hours'), valueIndex: 'EngineHours', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'StartHours', caption: GetTextByKey("P_PM_STARTINGHOURS", 'Starting Hours'), valueIndex: 'StartHours', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'Odometer', caption: GetTextByKey("P_PM_CURRENTODOMETER", 'Current Odometer'), valueIndex: 'Odometer', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'StartOdometer', caption: GetTextByKey("P_PM_STARTODOMETER", 'Start Odometer'), valueIndex: 'StartOdometer', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'StartDateString', caption: GetTextByKey("P_PM_PLANSTARTDATE", 'Plan Start Date'), valueIndex: 'StartDateString', css: { 'width': 100, 'text-align': 'left' } },
|
|
{ name: 'StartIntervalValue', caption: GetTextByKey("P_PM_STARTINTERVAL", 'Start Interval'), valueIndex: 'StartIntervalValue', css: { 'width': 100, 'text-align': 'left' } }
|
|
];
|
|
var columns = [];
|
|
var DateColumn = window['lib-ui'].GridDateColumn;
|
|
// 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;
|
|
col.allowFilter = list_columns[hd].allowFilter;
|
|
col.oldFilterValues = col.filterValues;
|
|
col.styleFilter = function (item) {
|
|
if (item.Highlight)
|
|
return { 'background-color': 'yellow' };
|
|
}
|
|
if (list_columns[hd].type) {
|
|
col.type = list_columns[hd].type;
|
|
}
|
|
|
|
col.alwaysshow = list_columns[hd].alwaysshow;
|
|
|
|
if (col.name === "EngineHours" && ["HM", "PM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
else if (col.name === "Odometer" && ["RDM", "ADM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
else if (col.name === "StartHours") {
|
|
if (["HM", "PM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
col.type = GridView.ColumnTypes.Input;
|
|
}
|
|
else if (col.name === "StartOdometer") {
|
|
if (["RDM", "ADM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
col.type = GridView.ColumnTypes.Input;
|
|
}
|
|
else if (col.name === "StartDateString") {
|
|
if (["TBM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
col.type = DateColumn;
|
|
col.onChanged = function (item, value) {
|
|
item.StartDate = item.StartDateString = DateColumn.formatDate(value);
|
|
};
|
|
}
|
|
else if (col.name === "StartIntervalValue") {
|
|
if (["HM", "RDM", "TBM"].indexOf(scheduletype) < 0) {
|
|
col.visible = false;
|
|
continue;
|
|
}
|
|
col.type = GridView.ColumnTypes.Dropdown;;
|
|
col.sourceCache = false;
|
|
col.source = function (item) {
|
|
var source = [];
|
|
if (item.TempIntervals && item.TempIntervals.length > 0) {
|
|
for (var i = 0; i < item.TempIntervals.length; i++) {
|
|
var t = item.TempIntervals[i];
|
|
var kv = { value: '' + t, text: '' + t };
|
|
source.push(kv);
|
|
}
|
|
}
|
|
return source
|
|
};
|
|
}
|
|
columns.push(col);
|
|
}
|
|
grid_selectedassetdt.multiSelect = true;
|
|
grid_selectedassetdt.columns = columns;
|
|
grid_selectedassetdt.init();
|
|
}
|
|
|
|
function getIntervalValues(currentValue) {
|
|
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 - parseInt(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;
|
|
}
|
|
|
|
|
|
/******************************Assets********************************/
|
|
function getMachineTypes() {
|
|
pmquery('GetMachineTypes', '', function (data) {
|
|
var types = [];
|
|
types.push($('<option value="-1">' + GetTextByKey("P_SELECT_ALL", "All") + '</option>'));
|
|
if (data && data.length > 0) {
|
|
for (var i = 0; i < data.length; i++) {
|
|
types.push($('<option></option>').val(data[i].ID).text(data[i].Name));
|
|
}
|
|
}
|
|
types[0].prop('selected', true);
|
|
$('#sel_machine_type').empty().append(types);
|
|
GetSelectedMachines();
|
|
});
|
|
}
|
|
|
|
function GetSelectedMachines() {
|
|
_ScheduleAssets = [];
|
|
|
|
pmquery('GetSelectedMachines', iid, function (data) {
|
|
if (typeof data === "string") {
|
|
showAlert(data, GetTextByKey("P_PM_ASSETASSIGNMENT", 'Asset Assignment'));
|
|
return;
|
|
}
|
|
_ScheduleAssets = data;
|
|
for (var i = 0; i < _SelectedUnSavedMachines.length; i++) {
|
|
_ScheduleAssets.push(_SelectedUnSavedMachines[i]);
|
|
}
|
|
|
|
getMatchSelectedMachines();
|
|
});
|
|
}
|
|
|
|
function getMatchSelectedMachines() {
|
|
var typeid = parseInt($('#sel_machine_type').val());
|
|
var machinefilter = $('#txt_machine_key').val().toLowerCase();
|
|
var showallassigned = $('#chk_showallassignedassets').prop('checked');
|
|
|
|
_showSelectedMachines = [];
|
|
var unMatched = [];
|
|
for (var i = 0; i < _ScheduleAssets.length; i++) {
|
|
var m = _ScheduleAssets[i];
|
|
m.Enabled = !m.AlertsCount || m.AlertsCount == 0;
|
|
m.Highlight = false;
|
|
if (((typeid == -1 || typeid == m.TypeID)
|
|
&& (machinefilter == "" || m.VIN.toLowerCase().indexOf(machinefilter) >= 0
|
|
|| m.Name.toLowerCase().indexOf(machinefilter) >= 0))) {
|
|
m.Highlight = showallassigned && (machinefilter !== "" || typeid != -1);
|
|
|
|
if (scheduletype == "HM" || scheduletype == "RDM") {
|
|
var value = 0;
|
|
if (scheduletype == "HM")
|
|
value = m.StartHours;
|
|
else
|
|
value = m.StartOdometer;
|
|
m.TempIntervals = getIntervalValues(value);
|
|
m.TempIntervals.splice(0, 0, "");
|
|
}
|
|
else {
|
|
m.TempIntervals = [];
|
|
m.TempIntervals.push("");
|
|
if (allintervals) {
|
|
for (var j = 0; j < allintervals.length; j++)
|
|
m.TempIntervals.push(allintervals[j]);
|
|
}
|
|
}
|
|
|
|
_showSelectedMachines.push(m);//Show All时,满足是啥条件的放在前面并高亮显示
|
|
}
|
|
else if (showallassigned)
|
|
unMatched.push(m);
|
|
}
|
|
|
|
if (showallassigned) {
|
|
for (var i in unMatched)
|
|
_showSelectedMachines.push(unMatched[i]);
|
|
}
|
|
|
|
showAssignedAssetsList(_showSelectedMachines);
|
|
}
|
|
|
|
function OnSaveMachines() {
|
|
var assets = [];
|
|
for (var i = 0; i < _ScheduleAssets.length; i++) {
|
|
var machine = _ScheduleAssets[i];
|
|
var asset = {};
|
|
asset.AssetId = machine.AssetId;
|
|
asset.StartIntervalValue = machine.StartIntervalValue;
|
|
switch (scheduletype) {
|
|
case "TBM":
|
|
asset.StartDate = machine.StartDate;
|
|
if (asset.StartDate == "")
|
|
asset.StartDate = "1900-01-01";
|
|
break;
|
|
case "PM":
|
|
case "HM":
|
|
asset.StartHours = machine.StartHours;
|
|
if (asset.StartHours == "")
|
|
asset.StartHours = "0";
|
|
break;
|
|
case "ADM":
|
|
case "RDM":
|
|
asset.StartOdometer = machine.StartOdometer;
|
|
if (asset.StartOdometer == "")
|
|
asset.StartOdometer = "0";
|
|
break;
|
|
}
|
|
|
|
assets.push(asset);
|
|
}
|
|
var item = {
|
|
'IID': iid,
|
|
'Assets': assets
|
|
};
|
|
|
|
var alerttitle = GetTextByKey("P_MA_SAVEASSETS", 'Save Assets');
|
|
pmquery('SaveMachines', JSON.stringify(item), function (data) {
|
|
if (!data || data.length == 0) {
|
|
// success
|
|
for (var i = 0; i < _ScheduleAssets.length; i++) {
|
|
_ScheduleAssets[i].unSaved = false;
|
|
}
|
|
showAlert(GetTextByKey("P_PM_SAVEASSETLISTSUCCESSFUL", 'Save asset list successful.'), alerttitle);
|
|
} else {
|
|
showAlert(GetTextByKey("P_PM_FAILEDTOSAVEASSETLIST", 'Failed to save asset list.') + "\n" + data, alerttitle);
|
|
}
|
|
});
|
|
}
|
|
|
|
var dialogAssets = undefined;
|
|
function OnAddAssets() {
|
|
if (!dialogAssets) {
|
|
dialogAssets = new $assetselector("dialog_assets");
|
|
dialogAssets.allowhidden = false;
|
|
dialogAssets.onDialogClosed = function () {
|
|
showmaskbg(false);
|
|
}
|
|
dialogAssets.onOK = function (assets) {
|
|
if (assets && assets.length > 0) {
|
|
setNewSelectedAseets(assets);
|
|
}
|
|
}
|
|
}
|
|
showmaskbg(true);
|
|
var assets = [];
|
|
for (var i = 0; i < _ScheduleAssets.length; i++) {
|
|
assets.push(_ScheduleAssets[i].AssetId);
|
|
}
|
|
dialogAssets.exceptSource = assets;
|
|
dialogAssets.showSelector(assets);
|
|
}
|
|
|
|
function convertOdometer(odometer, odounit) {
|
|
var unit = scheduleUom;
|
|
var value = odometer;
|
|
if (odometer > 0 && unit && odounit
|
|
&& unit.toLowerCase().charAt(0) != odounit.toLowerCase().charAt(0)) {
|
|
if (unit.toLowerCase().startsWith("m"))
|
|
value = odometer * 0.6213712;
|
|
else
|
|
value = odometer / 0.6213712;
|
|
}
|
|
return Math.round(value);
|
|
}
|
|
|
|
function setNewSelectedAseets(assets) {
|
|
var newassets = [];
|
|
for (var i = 0; i < assets.length; i++) {
|
|
var a = assets[i];
|
|
if (!a.Selected) continue;
|
|
|
|
var item = {};
|
|
item.AssetId = a.Id;
|
|
item.Selected = false;
|
|
item.VIN = a.VIN;
|
|
item.Name = a.Name;
|
|
item.MakeName = a.MakeName;
|
|
item.ModelName = a.ModelName;
|
|
item.TypeID = a.TypeID;
|
|
item.TypeName = a.TypeName;
|
|
item.EngineHours = a.EngineHours;
|
|
item.StartHours = a.EngineHours;
|
|
item.Odometer = convertOdometer(a.Odometer, a.OdometerUnits);
|
|
item.StartOdometer = item.Odometer;
|
|
item.OdometerUnits = a.OdometerUnits;
|
|
item.StartDate = item.StartDateString = currentdate;
|
|
item.StartIntervalValue = "";
|
|
item.Enabled = true;
|
|
if (scheduletype == "HM" || scheduletype == "RDM") {
|
|
var value = 0;
|
|
if (scheduletype == "HM")
|
|
value = item.StartHours;
|
|
else
|
|
value = item.StartOdometer;
|
|
item.TempIntervals = getIntervalValues(value);
|
|
item.TempIntervals.splice(0, 0, "");
|
|
}
|
|
else {
|
|
item.TempIntervals = [];
|
|
item.TempIntervals.push("");
|
|
if (allintervals) {
|
|
for (var j = 0; j < allintervals.length; j++)
|
|
item.TempIntervals.push(allintervals[j]);
|
|
}
|
|
}
|
|
|
|
newassets.push(item);
|
|
}
|
|
if (newassets.length == 0) {
|
|
showmaskbg(false);
|
|
return;
|
|
}
|
|
|
|
$('#dialog_selectedassets')
|
|
.css({
|
|
'top': (document.documentElement.clientHeight - $('#dialog_machinegroup').height()) / 3,
|
|
'left': (document.documentElement.clientWidth - $('#dialog_machinegroup').width()) / 2
|
|
}).showDialog();
|
|
|
|
showSelectedAssetsList(newassets);
|
|
}
|
|
|
|
function OnSetAssetsDialogOK() {
|
|
var tempsource = grid_selectedassetdt.source;
|
|
for (var i = 0; i < tempsource.length; i++) {
|
|
var asset = tempsource[i];
|
|
asset.unSaved = true;
|
|
_ScheduleAssets.push(asset);
|
|
}
|
|
|
|
getMatchSelectedMachines();
|
|
showmaskbg(false);
|
|
$('#dialog_selectedassets').hideDialog();
|
|
}
|
|
|
|
function OnRemoveAssets() {
|
|
_SelectedUnSavedMachines = [];
|
|
var assets = [];
|
|
var assetwillalerts = "";
|
|
for (var i = 0; i < _ScheduleAssets.length; i++) {
|
|
var asset = _ScheduleAssets[i];
|
|
if (asset.unSaved && !asset.Selected)
|
|
_SelectedUnSavedMachines.push(asset);
|
|
if (asset.Selected) {
|
|
assets.push(asset.AssetId);
|
|
if (asset.UnMaintainedAlert && asset.UnMaintainedAlert > 0) {
|
|
if (assetwillalerts == "")
|
|
assetwillalerts = asset.Name;
|
|
else
|
|
assetwillalerts += ", " + asset.Name;
|
|
}
|
|
}
|
|
}
|
|
if (assets.length == 0)
|
|
return;
|
|
|
|
var item = {
|
|
'ScheduleID': iid,
|
|
'Assets': assets
|
|
};
|
|
|
|
var msg = GetTextByKey("P_PM_DOYOUWANTTOREMOVEHESELECTEDASSETSFROMTHISSCHEDULE", "Do you want to remove the selected assets from this schedule?");
|
|
if (assetwillalerts != "") {
|
|
var msg = GetTextByKey("P_PM_DELETEUNASSIGNEDPMALERTSFORTHEFOLLOWINGASSETSTIPS", "Select OK below will result in the deletion of existing unassigned PM alerts for the following assets: ");
|
|
msg += assetwillalerts + ".<br/>";
|
|
msg += GetTextByKey("P_PM_DELTEALERTSYESORNOTIPS", "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.");
|
|
}
|
|
var alerttitle = GetTextByKey("P_PM_REMOVEASSETS", 'Remove Assets');
|
|
showConfirmOKCancel(msg, alerttitle, function (e) {
|
|
pmquery('RemovePMAssets', JSON.stringify(item), function (data) {
|
|
if (!data || data.length == 0) {
|
|
showAlert(GetTextByKey("P_PM_ASSETSREMOVEDSUCCESSFULLY", 'Assets removed successfully.'), alerttitle);
|
|
GetSelectedMachines();
|
|
} else {
|
|
showAlert(GetTextByKey("P_PM_FAILEDTOREMOVEASSETS", 'Failed to remove assets.') + "\n" + data, alerttitle);
|
|
}
|
|
});
|
|
});
|
|
} |