255 lines
8.7 KiB
JavaScript
255 lines
8.7 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].Values;
|
|
if (it.Selected) {
|
|
items.push({
|
|
Values: {
|
|
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.Values.ID; }))
|
|
];
|
|
|
|
$("#dialogmask").show();
|
|
customerquery('AssignMachines', htmlencode(JSON.stringify(p)), function (r) {
|
|
showmaskbg(false);
|
|
$("#dialogmask").hide();
|
|
if (r === 'OK') {
|
|
grid_dtsm.setData(grid_dtsm.innerSource.concat(items));
|
|
} else {
|
|
showAlert(r, GetTextByKey("P_UM_ASSETASSIGNMENT", 'Asset Assignment'));
|
|
}
|
|
});
|
|
};
|
|
});
|
|
|
|
/************************** Machine********************************/
|
|
/*************************************************************************/
|
|
|
|
function OnMachineAdd() {
|
|
showmaskbg(true);
|
|
dialogAssets.exceptSource = grid_dtsm.innerSource.map(function (s) {
|
|
return s.Values.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");// + " " + jobsite.Name + " " + "Radius_UOM: " + jobsite.Radius_UOM
|
|
$('#dialog_managemahchine .dialog-title span.title').html(title);
|
|
$('.machine_maskbg').show();
|
|
$('#dialog_managemahchine')
|
|
.attr('init', 1)
|
|
.css({
|
|
'top': (document.documentElement.clientHeight - $('#dialog_managemahchine').height()) / 5,
|
|
'left': (document.documentElement.clientWidth - $('#dialog_managemahchine').width()) / 2
|
|
}).showDialog();
|
|
|
|
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) {
|
|
var rows = [];
|
|
for (var i = 0; i < data.length; i++) {
|
|
var r = data[i];
|
|
var fr = { Values: r };
|
|
rows.push(fr);
|
|
}
|
|
|
|
grid_dtsm.setData(rows);
|
|
}
|
|
|
|
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 {
|
|
for (var i = 0; i < grid_dtsm.innerSource.length; i++) {
|
|
var s = grid_dtsm.innerSource[i].Values;
|
|
if (s.ID === item.ID) {
|
|
grid_dtsm.innerSource.splice(i, 1);
|
|
break;
|
|
}
|
|
}
|
|
if (grid_dtsm.source != null) {
|
|
for (var j = 0; j < grid_dtsm.source.length; j++) {
|
|
if (item.ID === grid_dtsm.source[j].Values.ID) {
|
|
grid_dtsm.source.splice(j, 1);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
grid_dtsm.reset();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
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.innerSource.filter(function (s) { return s.Values.selected; }).map(function (s) { return s.Values.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 {
|
|
for (var i = grid_dtsm.innerSource.length - 1; i >= 0; i--) {
|
|
var s = grid_dtsm.innerSource[i].Values;
|
|
if (s.selected) {
|
|
grid_dtsm.innerSource.splice(i, 1);
|
|
}
|
|
}
|
|
if (grid_dtsm.source != null) {
|
|
for (var j = grid_dtsm.source.length - 1; j >= 0; j--) {
|
|
var l = grid_dtsm.source[j].Values;
|
|
if (l.selected) {
|
|
grid_dtsm.source.splice(j, 1);
|
|
}
|
|
}
|
|
}
|
|
grid_dtsm.reset();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
var grid_dtsm;
|
|
function InitGridSelectedMachines() {
|
|
grid_dtsm = new GridView('#selectedmachinelist');
|
|
grid_dtsm.lang = {
|
|
all: GetTextByKey("P_GRID_ALL", "(All)"),
|
|
ok: GetTextByKey("P_GRID_OK", "OK"),
|
|
reset: GetTextByKey("P_GRID_RESET", "Reset")
|
|
};
|
|
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,
|
|
isurl: true,
|
|
text: '\uf00d',
|
|
events: {
|
|
onclick: function () {
|
|
OnMachineDeleteSingle(this);
|
|
}
|
|
},
|
|
classFilter: function (e) {
|
|
return "icon-col";
|
|
},
|
|
attrs: { 'title': GetTextByKey("P_UM_DELETE", 'Delete') }
|
|
});
|
|
grid_dtsm.canMultiSelect = true;
|
|
grid_dtsm.columns = columns;
|
|
grid_dtsm.init();
|
|
|
|
grid_dtsm.selectedrowchanged = function (rowindex) {
|
|
var rowdata = grid_dtsm.source[rowindex];
|
|
if (rowdata) {
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**************************End Machine********************************/
|
|
/*****************************************************************************/
|
|
|
|
|