fleet-contractor/Site/Maintenance/js/customerrecord.js
2024-03-26 15:56:31 +08:00

227 lines
7.6 KiB
JavaScript

var dialogAssets;
$(function () {
InitGridSelectedMachines();
dialogAssets = new $assetselector('dialog_machines');
dialogAssets.onDialogClosed = function () {
showmaskbg(false);
};
dialogAssets.onOK = function (source) {
var items = [];
for (var i = 0; i < source.length; i++) {
var it = source[i];
if (it.Selected) {
items.push({
ID: it.Id,
VIN: it.VIN,
Name: it.Name,
MakeName: it.MakeName,
ModelName: it.ModelName,
TypeName: it.TypeName
});
}
}
var p = [
custrecordid,
JSON.stringify(items.map(function (f) { return f.ID; }))
];
$("#dialogmask").show();
customerquery('AssignMachines', htmlencode(JSON.stringify(p)), function (r) {
showmaskbg(false);
$("#dialogmask").hide();
if (r === 'OK') {
grid_dtsm.setData(grid_dtsm.source.concat(items));
} else {
showAlert(r, GetTextByKey("P_UM_ASSETASSIGNMENT", 'Asset Assignment'));
}
});
};
});
/************************** Machine********************************/
/*************************************************************************/
function OnMachineAdd() {
showmaskbg(true);
dialogAssets.exceptSource = grid_dtsm.source.map(function (s) {
return s.ID;
});
dialogAssets.showSelector();
}
var _selectedMachines = [];
function OnManageMachine(u) {
$('#chk_showallassignedassets').prop('checked', false);
$('#txt_machine_key').val('');
if (!u) {
custrecordid = undefined;
return;
}
custrecordid = u.Id;
var title = GetTextByKey("P_UM_ASSETASSIGNMENT", "Asset Assignment");// + "&nbsp;&nbsp;&nbsp;&nbsp;" + jobsite.Name + "&nbsp;&nbsp;&nbsp;&nbsp;" + "Radius_UOM: " + jobsite.Radius_UOM
$('#dialog_managemahchine .dialog-title span.title').html(title);
showmaskbg(true);
$('#dialog_managemahchine')
.attr('init', 1)
.css({
'top': (document.documentElement.clientHeight - $('#dialog_managemahchine').height()) / 5,
'left': (document.documentElement.clientWidth - $('#dialog_managemahchine').width()) / 2
}).showDialogfixed();
grid_dtsm.setData([]);
$('#selectedmachinelist input[type="checkbox"]').prop('checked', false);
GetAssignedMachines();
}
// 获取已选中的machines
function GetAssignedMachines() {
$("#dialogmask").show();
customerquery('GetAssignedMachines', custrecordid, function (data) {
if (typeof data === "string") {
showAlert(data, GetTextByKey("P_UM_ASSETASSIGNMENT", "Asset Assignment"));
return;
}
showSelectedMachine(data);
$("#dialogmask").hide();
}, function (e) {
$("#dialogmask").hide();
});
}
function showSelectedMachine(data) {
grid_dtsm.setData(data);
}
function OnMachineDeleteSingle(item) {
showConfirm(GetTextByKey("P_UM_DELETEASSIGNEDASSET", 'Are you sure you want to delete the assigned asset: {0}?').replace('{0}', item.Name), GetTextByKey("P_UM_ASSETASSIGNMENT", "Asset Assignment"), function () {
var params = [
custrecordid,
JSON.stringify([item.ID])
];
$("#dialogmask").show();
customerquery('RemoveAssignedMachines', htmlencode(JSON.stringify(params)), function (r) {
$("#dialogmask").hide();
if (r !== 'OK') {
showAlert(r, GetTextByKey("P_UM_ASSETASSIGNMENT", "Asset Assignment"));
} else {
var tmp = grid_dtsm.source;
if (tmp != null) {
for (var j = 0; j < tmp.length; j++) {
if (item.ID === tmp[j].ID) {
tmp.splice(j, 1);
break;
}
}
}
grid_dtsm.setData(tmp);
}
});
});
}
function OnMachineDelete() {
showConfirm(GetTextByKey("P_UM_DELETESELECTEDASSET", 'Are you sure you want to delete these selected assets?'), GetTextByKey("P_UM_ASSETASSIGNMENT", "Asset Assignment"), function () {
var ids = grid_dtsm.source.filter(function (s) { return s.selected; }).map(function (s) { return s.ID; });
var params = [
custrecordid,
JSON.stringify(ids)
];
$("#dialogmask").show();
customerquery('RemoveAssignedMachines', htmlencode(JSON.stringify(params)), function (r) {
$("#dialogmask").hide();
if (r !== 'OK') {
showAlert(r, GetTextByKey("P_UM_ASSETASSIGNMENT", "Asset Assignment"));
} else {
var tmp = grid_dtsm.source;
if (tmp != null) {
for (var j = tmp.length - 1; j >= 0; j--) {
var l = tmp[j];
if (l.selected) {
tmp.splice(j, 1);
}
}
}
grid_dtsm.setData(tmp);
grid_dtsm.reload(true);
}
});
});
}
var grid_dtsm;
function InitGridSelectedMachines() {
grid_dtsm = createGridView('#selectedmachinelist');
var list_columns = [
{ name: 'VIN', caption: GetTextByKey("P_UM_SN", "SN"), valueIndex: 'VIN', css: { 'width': 160, 'text-align': 'left' } },
{ name: 'Name', caption: GetTextByKey("P_UM_NAME", "Name"), valueIndex: 'Name', css: { 'width': 160, 'text-align': 'left' } },
{ name: 'MakeName', caption: GetTextByKey("P_UM_MAKE", "Make"), valueIndex: 'MakeName', css: { 'width': 90, 'text-align': 'left' } },
{ name: 'ModelName', caption: GetTextByKey("P_UM_MODEL", "Model"), valueIndex: 'ModelName', css: { 'width': 90, 'text-align': 'left' } },
{ name: 'TypeName', caption: GetTextByKey("P_UM_ASSETSTYPE", "Type"), valueIndex: 'TypeName', css: { 'width': 170, 'text-align': 'left' } }
];
var columns = [
{
// checkbox
name: 'check',
key: 'selected',
width: 45,
align: 'center',
sortable: false,
allcheck: true,
type: 3
}
];
// 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 = col.name === 'TypeName';
col.styleFilter = function (item) {
if (item.Highlight)
return { 'background-color': 'yellow' };
}
columns.push(col);
}
columns.push({
name: 'delete',
width: 30,
align: 'center',
sortable: false,
resizable: false,
type: GridView.ColumnTypes.Icon,
text: 'times',
events: {
onclick: function () {
OnMachineDeleteSingle(this);
}
},
classFilter: function (e) {
return "icon-col";
},
attrs: { 'title': GetTextByKey("P_UM_DELETE", 'Delete') }
});
grid_dtsm.multiSelect = true;
grid_dtsm.columns = columns;
grid_dtsm.init();
}
/**************************End Machine********************************/
/*****************************************************************************/