1470 lines
48 KiB
JavaScript
1470 lines
48 KiB
JavaScript
var dialogAssets;
|
||
|
||
$(function () {
|
||
InitGridAvailableMachineGroups();
|
||
InitGridSelectedMachineGroups();
|
||
//InitGridAvailableMachines();
|
||
InitGridSelectedMachines();
|
||
InitGridAvailableJobsites();
|
||
InitGridSelectedJobsites();
|
||
|
||
InitGridAvailableAssetTypes();
|
||
InitGridSelectedAssetTypes();
|
||
|
||
//$('#sel_machine_type').change(getMatchAvailableMachines);
|
||
//$('#button_machine_filter').click(getMatchAvailableMachines);
|
||
//$('#chk_showallassignedassets').click(getMatchSelectedMachines);
|
||
|
||
$('#button_jobsite_filter').click(getMatchAvailableJobsites);
|
||
$('#chk_showallassignedjobsites').click(getMatchSelectedJobsites);
|
||
$('#button_assettype_filter').click(getMatchAvailableAssetTypes);
|
||
$('#chk_showallassignedassettypes').click(getMatchSelectedAssetTypes);
|
||
|
||
dialogAssets = new $assetselector('dialog_machines');
|
||
dialogAssets.onDialogClosed = function () {
|
||
$("#dialogmask").hide();
|
||
};
|
||
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 params = [
|
||
'', uiid,
|
||
JSON.stringify(items.map(function (f) { return f.Values.ID; }))
|
||
];
|
||
$("#dialogmask").show();
|
||
_network.userquery('AssignAssetsToUser', params.join(String.fromCharCode(170)), 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() {
|
||
$("#dialogmask").show();
|
||
dialogAssets.exceptSource = grid_dtsm.innerSource.map(function (s) {
|
||
return s.Values.ID;
|
||
});
|
||
dialogAssets.showSelector();
|
||
}
|
||
|
||
var allMachines;
|
||
var _availableMachines = [];
|
||
var _selectedMachines = [];
|
||
var _showSelectedMachines = [];
|
||
|
||
function OnManageMachine(u) {
|
||
$('#chk_showallassignedassets').prop('checked', false);
|
||
$('#txt_machine_key').val('');
|
||
|
||
if (!u) {
|
||
uiid = undefined;
|
||
return;
|
||
}
|
||
|
||
uiid = u.IID;
|
||
|
||
var title = GetTextByKey("P_UM_ASSETASSIGNMENT", "Asset Assignment");// + " " + jobsite.Name + " " + "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
|
||
}).showDialog();
|
||
|
||
grid_dtsm.setData([]);
|
||
$('#selectedmachinelist input[type="checkbox"]').prop('checked', false);
|
||
|
||
GetSelectedMachines();
|
||
}
|
||
|
||
// 获取已选中的machines
|
||
function GetSelectedMachines() {
|
||
_selectedMachines = [];
|
||
$("#dialogmask").show();
|
||
_network.userquery('GetSelectedAssets', String.fromCharCode(170) + uiid, function (data) {
|
||
if (typeof data === "string") {
|
||
showAlert(data, GetTextByKey("P_UM_ASSETASSIGNMENT", "Asset Assignment"));
|
||
return;
|
||
}
|
||
_selectedMachines = data;
|
||
//queryMachines();
|
||
showSelectedMachine(_selectedMachines);
|
||
$("#dialogmask").hide();
|
||
}, function (e) {
|
||
$("#dialogmask").hide();
|
||
});
|
||
}
|
||
|
||
function queryMachines() {
|
||
var param = {
|
||
'Key': -1,
|
||
'Value': '',
|
||
'Tag1': uiid
|
||
};
|
||
$('#button_machine_filter').prop('disabled', true);
|
||
setTimeout(function () {
|
||
$('#button_machine_filter').prop('disabled', false);
|
||
}, 1000);
|
||
|
||
$("#dialogmask").show();
|
||
_availableMachines = [];
|
||
_network.userquery('GetMachineList', JSON.stringify(param), function (data) {
|
||
allMachines = data;
|
||
getMatchAvailableMachines();
|
||
|
||
$("#dialogmask").hide();
|
||
}, function (e) {
|
||
$("#dialogmask").hide();
|
||
});
|
||
}
|
||
|
||
function getMatchAvailableMachines() {
|
||
getMatchSelectedMachines();
|
||
|
||
var selected = [];
|
||
for (var i = 0; i < _showSelectedMachines.length; i++) {
|
||
var m = _showSelectedMachines[i];
|
||
selected.push(m.MachineID);
|
||
}
|
||
var typeid = $('#sel_machine_type').val();
|
||
var machinefilter = $('#txt_machine_key').val().toLowerCase();
|
||
|
||
_availableMachines = [];
|
||
for (var i = 0; i < allMachines.length; i++) {
|
||
var m = allMachines[i];
|
||
if ((typeid == -1 || typeid == m.TypeID)
|
||
&& (machinefilter == "" || m.VIN.toLowerCase().indexOf(machinefilter) >= 0
|
||
|| m.DisplayName.toLowerCase().indexOf(machinefilter) >= 0)
|
||
&& $.inArray(m.MachineID, selected) < 0) {
|
||
_availableMachines.push(m);
|
||
}
|
||
}
|
||
showAvailableMachine(_availableMachines);
|
||
}
|
||
|
||
function getMatchSelectedMachines() {
|
||
var typeid = $('#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 < _selectedMachines.length; i++) {
|
||
var m = _selectedMachines[i];
|
||
m.Highlight = false;
|
||
var matched = false;
|
||
if (((typeid == -1 || typeid == m.TypeID)
|
||
&& (machinefilter == "" || m.VIN.toLowerCase().indexOf(machinefilter) >= 0
|
||
|| m.DisplayName.toLowerCase().indexOf(machinefilter) >= 0))) {
|
||
matched = true;
|
||
m.Highlight = showallassigned && (machinefilter !== "" || typeid != -1);
|
||
_showSelectedMachines.push(m);//Show All时,满足是啥条件的放在前面并高亮显示
|
||
}
|
||
else if (showallassigned)
|
||
unMatched.push(m);
|
||
}
|
||
|
||
if (showallassigned) {
|
||
for (var i in unMatched)
|
||
_showSelectedMachines.push(unMatched[i]);
|
||
}
|
||
|
||
showSelectedMachine(_showSelectedMachines);
|
||
}
|
||
|
||
function showMachines() {
|
||
showAvailableMachine(_availableMachines);
|
||
showSelectedMachine(_showSelectedMachines);
|
||
}
|
||
|
||
function showAvailableMachine(data) {
|
||
var rows = [];
|
||
for (var i = 0; i < data.length; i++) {
|
||
var r = data[i];
|
||
var fr = { Values: r };
|
||
rows.push(fr);
|
||
}
|
||
|
||
grid_dtam.setData(rows);
|
||
}
|
||
|
||
var grid_dtam;
|
||
function InitGridAvailableMachines() {
|
||
grid_dtam = new GridView('#availablemachinelist');
|
||
grid_dtam.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: 'DisplayName', caption: GetTextByKey("P_UM_NAME", "Name"), valueIndex: 'DisplayName', css: { 'width': 160, 'text-align': 'left' } },
|
||
{ name: 'Make', caption: GetTextByKey("P_UM_MAKE", "Make"), valueIndex: 'Make', css: { 'width': 90, 'text-align': 'left' } },
|
||
{ name: 'Model', caption: GetTextByKey("P_UM_MODEL", "Model"), valueIndex: 'Model', css: { 'width': 90, '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;
|
||
columns.push(col);
|
||
}
|
||
grid_dtam.canMultiSelect = true;
|
||
grid_dtam.columns = columns;
|
||
grid_dtam.init();
|
||
grid_dtam.rowdblclick = function (rowindex) {
|
||
var rowdata = grid_dtam.source[rowindex];
|
||
if (rowdata) {
|
||
var machine = rowdata.Values;
|
||
_availableMachines.splice(_availableMachines.indexOf(machine), 1);
|
||
_selectedMachines.push(machine);
|
||
_showSelectedMachines.push(machine);
|
||
|
||
showMachines();
|
||
}
|
||
};
|
||
|
||
grid_dtam.selectedrowchanged = function (rowindex) {
|
||
var rowdata = grid_dtam.source[rowindex];
|
||
if (rowdata) {
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
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 = [
|
||
'', uiid,
|
||
JSON.stringify([item.ID])
|
||
];
|
||
$("#dialogmask").show();
|
||
_network.userquery('RemoveAssignedAssetsFromUser', params.join(String.fromCharCode(170)), 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 = [
|
||
'', uiid,
|
||
JSON.stringify(ids)
|
||
];
|
||
$("#dialogmask").show();
|
||
_network.userquery('RemoveAssignedAssetsFromUser', params.join(String.fromCharCode(170)), 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: 30,
|
||
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.rowdblclick = function (rowindex) {
|
||
// var rowdata = grid_dtsm.source[rowindex];
|
||
// if (rowdata) {
|
||
// var machine = rowdata.Values;
|
||
// _selectedMachines.splice(_selectedMachines.indexOf(machine), 1);
|
||
// _showSelectedMachines.splice(_showSelectedMachines.indexOf(machine), 1);
|
||
// _availableMachines.push(machine);
|
||
|
||
// showMachines();
|
||
// }
|
||
//};
|
||
|
||
grid_dtsm.selectedrowchanged = function (rowindex) {
|
||
var rowdata = grid_dtsm.source[rowindex];
|
||
if (rowdata) {
|
||
}
|
||
}
|
||
}
|
||
function OnEditorAdd() {
|
||
var indexs = grid_dtam.selectedIndexes;
|
||
if (indexs.length <= 0)
|
||
return;
|
||
for (var i = 0; i < indexs.length; i++) {
|
||
var index = indexs[i];
|
||
var m = grid_dtam.source[index].Values;
|
||
_availableMachines.splice(_availableMachines.indexOf(m), 1);
|
||
_selectedMachines.push(m);
|
||
_showSelectedMachines.push(m);
|
||
}
|
||
showMachines();
|
||
}
|
||
function OnEditorAddAll() {
|
||
for (var i = 0; i < _availableMachines.length; i++) {
|
||
var m = _availableMachines[i];
|
||
_selectedMachines.push(m);
|
||
_showSelectedMachines.push(m);
|
||
}
|
||
_availableMachines = [];
|
||
showMachines();
|
||
}
|
||
function OnEditorRemove() {
|
||
var indexs = grid_dtsm.selectedIndexes;
|
||
if (indexs.length <= 0)
|
||
return;
|
||
for (var i = 0; i < indexs.length; i++) {
|
||
var index = indexs[i];
|
||
var m = grid_dtsm.source[index].Values;
|
||
_selectedMachines.splice(_selectedMachines.indexOf(m), 1);
|
||
_showSelectedMachines.splice(_showSelectedMachines.indexOf(m), 1);
|
||
_availableMachines.push(m);
|
||
}
|
||
showMachines();
|
||
}
|
||
function OnEditorRemoveAll() {
|
||
for (var i = 0; i < _showSelectedMachines.length; i++) {
|
||
var m = _showSelectedMachines[i];
|
||
_selectedMachines.splice(_selectedMachines.indexOf(m), 1);
|
||
_availableMachines.push(m);
|
||
}
|
||
_showSelectedMachines = [];
|
||
showMachines();
|
||
}
|
||
|
||
function OnSaveMachines() {
|
||
var machineids = [];
|
||
for (var i = 0; i < _selectedMachines.length; i++) {
|
||
var m = _selectedMachines[i];
|
||
machineids.push(m.MachineID);
|
||
}
|
||
showloading(true);
|
||
_network.userquery("SaveContactMachines", uiid + String.fromCharCode(170) + JSON.stringify(machineids), function (data) {
|
||
showloading(false);
|
||
if (data !== 'OK') {
|
||
showAlert(data, GetTextByKey("P_UM_SAVEASSET", 'Save asset'));
|
||
} else {
|
||
$('#dialog_managemahchine').hideDialog();
|
||
OnRefresh();
|
||
}
|
||
}, function (err) {
|
||
console.log(err);
|
||
showloading(false);
|
||
showAlert(GetTextByKey("P_UM_FAILEDTOSAVEASSET", 'Failed to save asset.'), GetTextByKey("P_UM_SAVEASSET", 'Save asset'));
|
||
});
|
||
}
|
||
|
||
|
||
/**************************End Machine********************************/
|
||
/*****************************************************************************/
|
||
|
||
|
||
|
||
/**************************Start Manage Group********************************/
|
||
/*****************************************************************************/
|
||
|
||
var allMachineGroups;
|
||
function OnManageMachineGroup(u) {
|
||
if (!u) {
|
||
uiid = undefined;
|
||
return;
|
||
}
|
||
|
||
uiid = u.IID;
|
||
$('#dialog_machinegroup .dialog-title span.title').text(GetTextByKey("P_UM_MANAGEASSETGROUPS", 'Manage Asset Groups'));
|
||
showmaskbg(true);
|
||
$('#dialog_machinegroup')
|
||
.attr('act', 'edit')
|
||
.css({
|
||
'top': (document.documentElement.clientHeight - $('#dialog_machinegroup').height()) / 3,
|
||
'left': (document.documentElement.clientWidth - $('#dialog_machinegroup').width()) / 2
|
||
})
|
||
.showDialog();
|
||
|
||
|
||
// 加载用户信息
|
||
$('#dialog_machinegroup .maskbg').css('display', '');
|
||
_network.userquery('GetUserMachineGroup', uiid, function (data) {
|
||
allMachineGroups = data.AllMachineGroups;
|
||
showSelectedMachineGroup(!data.MachineGroups ? [] : data.MachineGroups);
|
||
getMatchAvailableMachineGroups();
|
||
$('#dialog_machinegroup .maskbg').css('display', 'none');
|
||
}, function (err) {
|
||
showAlert(GetTextByKey("P_UM_FAILEDTOLOADASSETGROUPS", 'Failed to load asset groups.'), GetTextByKey("P_UM_MANAGEASSETS", 'Manage Assets'));
|
||
});
|
||
}
|
||
|
||
function getMatchAvailableMachineGroups() {
|
||
var selected = [];
|
||
for (var i = 0; i < grid_dtsmg.source.length; i++) {
|
||
var m = grid_dtsmg.source[i].Values;
|
||
selected.push(m.GroupID);
|
||
}
|
||
|
||
var _availableMachineGroups = [];
|
||
for (var i = 0; i < allMachineGroups.length; i++) {
|
||
var m = allMachineGroups[i];
|
||
if ($.inArray(m.GroupID, selected) < 0) {
|
||
_availableMachineGroups.push(m);
|
||
}
|
||
}
|
||
showAvailableMachineGroups(_availableMachineGroups);
|
||
}
|
||
function showAvailableMachineGroups(data) {
|
||
var rows = [];
|
||
for (var i = 0; i < data.length; i++) {
|
||
var r = data[i];
|
||
var fr = { Values: r };
|
||
rows.push(fr);
|
||
}
|
||
|
||
grid_dtamg.setData(rows);
|
||
}
|
||
|
||
var grid_dtamg;
|
||
function InitGridAvailableMachineGroups() {
|
||
grid_dtamg = new GridView('#availableassetgrouplist');
|
||
grid_dtamg.lang = {
|
||
all: GetTextByKey("P_GRID_ALL", "(All)"),
|
||
ok: GetTextByKey("P_GRID_OK", "OK"),
|
||
reset: GetTextByKey("P_GRID_RESET", "Reset")
|
||
};
|
||
var list_columns = [
|
||
{ name: 'GroupName', caption: GetTextByKey("P_UM_GROUPNAME", "Group Name"), valueIndex: 'GroupName', css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'Description', caption: GetTextByKey("P_UM_DESCRIPTION", "Description"), valueIndex: 'Description', css: { 'width': 180, 'text-align': 'right' } }
|
||
];
|
||
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;
|
||
columns.push(col);
|
||
}
|
||
grid_dtamg.canMultiSelect = true;
|
||
grid_dtamg.columns = columns;
|
||
grid_dtamg.init();
|
||
grid_dtamg.rowdblclick = function (rowindex) {
|
||
var rowdata = grid_dtamg.source[rowindex];
|
||
if (rowdata) {
|
||
grid_dtamg.source.splice(rowindex, 1);
|
||
grid_dtamg.setData(grid_dtamg.source);
|
||
|
||
grid_dtsmg.source.push(rowdata);
|
||
grid_dtsmg.setData(grid_dtsmg.source);
|
||
}
|
||
};
|
||
|
||
grid_dtamg.selectedrowchanged = function (rowindex) {
|
||
var rowdata = grid_dtamg.source[rowindex];
|
||
if (rowdata) {
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
function showSelectedMachineGroup(data) {
|
||
var rows = [];
|
||
for (var i = 0; i < data.length; i++) {
|
||
var r = data[i];
|
||
var fr = { Values: r };
|
||
rows.push(fr);
|
||
}
|
||
|
||
grid_dtsmg.setData(rows);
|
||
}
|
||
|
||
var grid_dtsmg;
|
||
function InitGridSelectedMachineGroups() {
|
||
grid_dtsmg = new GridView('#selectedassetgrouplist');
|
||
grid_dtsmg.lang = {
|
||
all: GetTextByKey("P_GRID_ALL", "(All)"),
|
||
ok: GetTextByKey("P_GRID_OK", "OK"),
|
||
reset: GetTextByKey("P_GRID_RESET", "Reset")
|
||
};
|
||
var list_columns = [
|
||
{ name: 'GroupName', caption: GetTextByKey("P_UM_GROUPNAME", "Group Name"), valueIndex: 'GroupName', css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'Description', caption: GetTextByKey("P_UM_DESCRIPTION", "Description"), valueIndex: 'Description', css: { 'width': 180, 'text-align': 'right' } }
|
||
];
|
||
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;
|
||
}
|
||
columns.push(col);
|
||
}
|
||
grid_dtsmg.canMultiSelect = true;
|
||
grid_dtsmg.columns = columns;
|
||
grid_dtsmg.init();
|
||
grid_dtsmg.rowdblclick = function (rowindex) {
|
||
var rowdata = grid_dtsmg.source[rowindex];
|
||
if (rowdata) {
|
||
grid_dtsmg.source.splice(rowindex, 1);
|
||
grid_dtsmg.setData(grid_dtsmg.source);
|
||
|
||
grid_dtamg.source.push(rowdata);
|
||
grid_dtamg.setData(grid_dtamg.source);
|
||
}
|
||
};
|
||
|
||
grid_dtsmg.selectedrowchanged = function (rowindex) {
|
||
var rowdata = grid_dtsmg.source[rowindex];
|
||
if (rowdata) {
|
||
}
|
||
}
|
||
}
|
||
|
||
function OnAssetGroupEditorAdd() {
|
||
var indexs = grid_dtamg.selectedIndexes;
|
||
if (indexs.length <= 0)
|
||
return;
|
||
|
||
var rowstemp = [];
|
||
for (var i = 0; i < indexs.length; i++) {
|
||
var rowindex = indexs[i];
|
||
var rowdata = grid_dtamg.source[rowindex];
|
||
rowstemp.push(rowdata);
|
||
}
|
||
var index = grid_dtsmg.source.length;
|
||
for (var i = 0; i < rowstemp.length; i++) {
|
||
var rowdata = rowstemp[i];
|
||
grid_dtamg.source.splice(grid_dtamg.source.indexOf(rowdata), 1);
|
||
grid_dtsmg.source.splice(index, 0, rowdata);
|
||
index++;
|
||
}
|
||
grid_dtamg.setData(grid_dtamg.source);
|
||
grid_dtsmg.setData(grid_dtsmg.source);
|
||
}
|
||
|
||
function OnAssetGroupEditorAddAll() {
|
||
for (var i = 0; i < grid_dtamg.source.length; i++) {
|
||
var rowindex = grid_dtamg.source[i];
|
||
var rowdata = grid_dtamg.source[i];
|
||
grid_dtsmg.source.push(rowdata);
|
||
}
|
||
grid_dtsmg.setData(grid_dtsmg.source);
|
||
grid_dtamg.source = [];
|
||
grid_dtamg.setData(grid_dtamg.source);
|
||
}
|
||
function OnAssetGroupEditorRemove() {
|
||
var indexs = grid_dtsmg.selectedIndexes;
|
||
if (indexs.length <= 0)
|
||
return;
|
||
|
||
var rowstemp = [];
|
||
for (var i = 0; i < indexs.length; i++) {
|
||
var rowindex = indexs[i];
|
||
var rowdata = grid_dtsmg.source[rowindex];
|
||
rowstemp.push(rowdata);
|
||
}
|
||
var index = grid_dtamg.source.length;
|
||
for (var i = 0; i < rowstemp.length; i++) {
|
||
var rowdata = rowstemp[i];
|
||
grid_dtsmg.source.splice(grid_dtsmg.source.indexOf(rowdata), 1);
|
||
grid_dtamg.source.splice(index, 0, rowdata);
|
||
index++;
|
||
}
|
||
grid_dtsmg.setData(grid_dtsmg.source);
|
||
grid_dtamg.setData(grid_dtamg.source);
|
||
}
|
||
function OnAssetGroupEditorRemoveAll() {
|
||
for (var i = 0; i < grid_dtsmg.source.length; i++) {
|
||
var rowindex = grid_dtsmg.source[i];
|
||
var rowdata = grid_dtsmg.source[i];
|
||
grid_dtamg.source.push(rowdata);
|
||
}
|
||
grid_dtamg.setData(grid_dtamg.source);
|
||
grid_dtsmg.source = [];
|
||
grid_dtsmg.setData(grid_dtsmg.source);
|
||
}
|
||
|
||
function OnSaveUserMG() {
|
||
var item = {
|
||
};
|
||
if (uiid) {
|
||
item.UserIID = uiid;
|
||
}
|
||
else
|
||
return;
|
||
|
||
item.GroupIDs = [];
|
||
for (var i = 0; i < grid_dtsmg.source.length; i++) {
|
||
var m = grid_dtsmg.source[i].Values;
|
||
item.GroupIDs.push(m.GroupID);
|
||
}
|
||
|
||
$('#dialog_machinegroup .maskbg').css('display', '');
|
||
var param = JSON.stringify(item);
|
||
param = htmlencode(param);
|
||
_network.userquery("SaveUserMachineGroup", param, function (data) {
|
||
//alert('Save user info successfully.');
|
||
if (data !== 'OK') {
|
||
showAlert(data, GetTextByKey("P_UM_SAVEUSERASSETGROUPS", 'Save user asset groups'));
|
||
$('#dialog_machinegroup .maskbg').css('display', 'none');
|
||
} else {
|
||
$('#dialog_machinegroup').hideDialog();
|
||
showmaskbg(false);
|
||
}
|
||
}, function (err) {
|
||
showAlert(GetTextByKey("P_UM_FAILEDTOSAVEASSETGROUPS", 'Failed to save asset groups.'), GetTextByKey("P_UM_SAVEUSERASSETGROUPS", 'Save user asset groups'));
|
||
$('#dialog_machinegroup .maskbg').css('display', 'none');
|
||
});
|
||
}
|
||
|
||
|
||
/**************************End Manage Group********************************/
|
||
/*****************************************************************************/
|
||
|
||
|
||
|
||
|
||
|
||
/************************** Jobsite Assignment********************************/
|
||
/*************************************************************************/
|
||
|
||
var allJobsites;
|
||
var _availableJobsites = [];
|
||
var _selectedJobsites = [];
|
||
var _showSelectedJobsites = [];
|
||
function OnManageJobsite(u) {
|
||
$('#chk_showallassignedjobsites').prop('checked', false);
|
||
$('#txt_jobsite_key').val('');
|
||
|
||
if (!u) {
|
||
uiid = undefined;
|
||
return;
|
||
}
|
||
|
||
uiid = u.IID;
|
||
|
||
var title = GetTextByKey("P_UM_JOBSITEASSIGNMENT", 'Jobsite Assignment');
|
||
$('#dialog_managejobsite .dialog-title span.title').html(title);
|
||
showmaskbg(true);
|
||
$('#dialog_managejobsite')
|
||
.css({
|
||
'top': (document.documentElement.clientHeight - $('#dialog_managejobsite').height()) / 5,
|
||
'left': (document.documentElement.clientWidth - $('#dialog_managejobsite').width()) / 2
|
||
}).showDialog();
|
||
|
||
GetSelectedJobsites();
|
||
}
|
||
|
||
// 获取已选中的Jobsites
|
||
function GetSelectedJobsites() {
|
||
_selectedJobsites = [];
|
||
$("#jobsitedialogmask").show();
|
||
_network.userquery('GetSelectedJobsites', uiid, function (data) {
|
||
if (typeof data === "string") {
|
||
showAlert(data, GetTextByKey("P_UM_JOBSITEASSIGNMENT", 'Jobsite Assignment'));
|
||
return;
|
||
}
|
||
_selectedJobsites = data;
|
||
queryJobsites();
|
||
}, function (e) {
|
||
$("#jobsitedialogmask").hide();
|
||
});
|
||
}
|
||
|
||
function queryJobsites() {
|
||
$('#button_jobsite_filter').prop('disabled', true);
|
||
setTimeout(function () {
|
||
$('#button_jobsite_filter').prop('disabled', false);
|
||
}, 1000);
|
||
|
||
_availableJobsites = [];
|
||
$("#jobsitedialogmask").show();
|
||
_network.userquery('GetJobsiteList', '', function (data) {
|
||
if (typeof data === "string") {
|
||
showAlert(data, GetTextByKey("P_UM_JOBSITEASSIGNMENT", 'Jobsite Assignment'));
|
||
return;
|
||
}
|
||
allJobsites = data;
|
||
getMatchAvailableJobsites();
|
||
$("#jobsitedialogmask").hide();
|
||
}, function (e) {
|
||
$("#jobsitedialogmask").hide();
|
||
});
|
||
}
|
||
|
||
|
||
function getMatchAvailableJobsites() {
|
||
getMatchSelectedJobsites();
|
||
|
||
var selected = [];
|
||
for (var i = 0; i < _showSelectedJobsites.length; i++) {
|
||
var m = _showSelectedJobsites[i];
|
||
selected.push(m.ID);
|
||
}
|
||
var jobsitefilter = $('#txt_jobsite_key').val().toLowerCase();
|
||
|
||
_availableJobsites = [];
|
||
for (var i = 0; i < allJobsites.length; i++) {
|
||
var m = allJobsites[i];
|
||
if ((jobsitefilter == "" || m.Name.toLowerCase().indexOf(jobsitefilter) >= 0)
|
||
&& $.inArray(m.ID, selected) < 0) {
|
||
_availableJobsites.push(m);
|
||
}
|
||
}
|
||
showAvailableJobsite(_availableJobsites);
|
||
}
|
||
|
||
function getMatchSelectedJobsites() {
|
||
var jobsitefilter = $('#txt_jobsite_key').val().toLowerCase();
|
||
var showallassigned = $('#chk_showallassignedjobsites').prop('checked');
|
||
|
||
_showSelectedJobsites = [];
|
||
var unMatched = [];
|
||
for (var i = 0; i < _selectedJobsites.length; i++) {
|
||
var m = _selectedJobsites[i];
|
||
m.Highlight = false;
|
||
var matched = false;
|
||
if (jobsitefilter == "" || m.Name.toLowerCase().indexOf(jobsitefilter) >= 0) {
|
||
matched = true;
|
||
m.Highlight = showallassigned && jobsitefilter !== "";
|
||
_showSelectedJobsites.push(m);
|
||
}
|
||
else if (showallassigned)
|
||
unMatched.push(m);
|
||
}
|
||
|
||
if (showallassigned) {
|
||
for (var i in unMatched)
|
||
_showSelectedJobsites.push(unMatched[i]);
|
||
}
|
||
|
||
showSelectedJobsite(_showSelectedJobsites);
|
||
}
|
||
|
||
function showJobsites() {
|
||
showAvailableJobsite(_availableJobsites);
|
||
showSelectedJobsite(_showSelectedJobsites);
|
||
}
|
||
|
||
|
||
|
||
function showAvailableJobsite(data) {
|
||
var rows = [];
|
||
for (var i = 0; i < data.length; i++) {
|
||
var r = data[i];
|
||
var fr = { Values: r };
|
||
rows.push(fr);
|
||
}
|
||
|
||
grid_dtaj.setData(rows);
|
||
}
|
||
|
||
function showSelectedJobsite(data) {
|
||
var rows = [];
|
||
for (var i = 0; i < data.length; i++) {
|
||
var r = data[i];
|
||
var fr = { Values: r };
|
||
rows.push(fr);
|
||
}
|
||
|
||
grid_dtsj.setData(rows);
|
||
}
|
||
|
||
|
||
var grid_dtaj;
|
||
function InitGridAvailableJobsites() {
|
||
grid_dtaj = new GridView('#availablejobsitelist');
|
||
grid_dtaj.lang = {
|
||
all: GetTextByKey("P_GRID_ALL", "(All)"),
|
||
ok: GetTextByKey("P_GRID_OK", "OK"),
|
||
reset: GetTextByKey("P_GRID_RESET", "Reset")
|
||
};
|
||
var list_columns = [
|
||
{ name: 'Name', caption: GetTextByKey("P_UM_NAME", "Name"), valueIndex: 'Name', css: { 'width': 380, '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;
|
||
columns.push(col);
|
||
}
|
||
grid_dtaj.canMultiSelect = true;
|
||
grid_dtaj.columns = columns;
|
||
grid_dtaj.init();
|
||
grid_dtaj.rowdblclick = function (rowindex) {
|
||
var rowdata = grid_dtaj.source[rowindex];
|
||
if (rowdata) {
|
||
var Jobsite = rowdata.Values;
|
||
_availableJobsites.splice(_availableJobsites.indexOf(Jobsite), 1);
|
||
_selectedJobsites.push(Jobsite);
|
||
_showSelectedJobsites.push(Jobsite);
|
||
|
||
showJobsites();
|
||
}
|
||
};
|
||
|
||
grid_dtaj.selectedrowchanged = function (rowindex) {
|
||
var rowdata = grid_dtaj.source[rowindex];
|
||
if (rowdata) {
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
var grid_dtsj;
|
||
function InitGridSelectedJobsites() {
|
||
grid_dtsj = new GridView('#selectedjobsitelist');
|
||
grid_dtsj.lang = {
|
||
all: GetTextByKey("P_GRID_ALL", "(All)"),
|
||
ok: GetTextByKey("P_GRID_OK", "OK"),
|
||
reset: GetTextByKey("P_GRID_RESET", "Reset")
|
||
};
|
||
var list_columns = [
|
||
{ name: 'Name', caption: GetTextByKey("P_UM_NAME", "Name"), valueIndex: 'Name', css: { 'width': 380, '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;
|
||
col.styleFilter = function (item) {
|
||
if (item.Highlight)
|
||
return { 'background-color': 'yellow' };
|
||
}
|
||
columns.push(col);
|
||
}
|
||
grid_dtsj.canMultiSelect = true;
|
||
grid_dtsj.columns = columns;
|
||
grid_dtsj.init();
|
||
grid_dtsj.rowdblclick = function (rowindex) {
|
||
var rowdata = grid_dtsj.source[rowindex];
|
||
if (rowdata) {
|
||
var Jobsite = rowdata.Values;
|
||
_selectedJobsites.splice(_selectedJobsites.indexOf(Jobsite), 1);
|
||
_showSelectedJobsites.splice(_showSelectedJobsites.indexOf(Jobsite), 1);
|
||
_availableJobsites.push(Jobsite);
|
||
|
||
showJobsites();
|
||
}
|
||
};
|
||
|
||
grid_dtsj.selectedrowchanged = function (rowindex) {
|
||
var rowdata = grid_dtsj.source[rowindex];
|
||
if (rowdata) {
|
||
}
|
||
}
|
||
}
|
||
|
||
function OnJobsiteEditorAdd() {
|
||
var indexs = grid_dtaj.selectedIndexes;
|
||
if (indexs.length <= 0)
|
||
return;
|
||
for (var i = 0; i < indexs.length; i++) {
|
||
var index = indexs[i];
|
||
var m = grid_dtaj.source[index].Values;
|
||
_availableJobsites.splice(_availableJobsites.indexOf(m), 1);
|
||
_selectedJobsites.push(m);
|
||
_showSelectedJobsites.push(m);
|
||
}
|
||
showJobsites();
|
||
}
|
||
function OnJobsiteEditorAddAll() {
|
||
for (var i = 0; i < _availableJobsites.length; i++) {
|
||
var m = _availableJobsites[i];
|
||
_selectedJobsites.push(m);
|
||
_showSelectedJobsites.push(m);
|
||
}
|
||
_availableJobsites = [];
|
||
showJobsites();
|
||
}
|
||
function OnJobsiteEditorRemove() {
|
||
var indexs = grid_dtsj.selectedIndexes;
|
||
if (indexs.length <= 0)
|
||
return;
|
||
for (var i = 0; i < indexs.length; i++) {
|
||
var index = indexs[i];
|
||
var m = grid_dtsj.source[index].Values;
|
||
_selectedJobsites.splice(_selectedJobsites.indexOf(m), 1);
|
||
_showSelectedJobsites.splice(_showSelectedJobsites.indexOf(m), 1);
|
||
_availableJobsites.push(m);
|
||
}
|
||
showJobsites();
|
||
}
|
||
function OnJobsiteEditorRemoveAll() {
|
||
for (var i = 0; i < _showSelectedJobsites.length; i++) {
|
||
var m = _showSelectedJobsites[i];
|
||
_selectedJobsites.splice(_selectedJobsites.indexOf(m), 1);
|
||
_availableJobsites.push(m);
|
||
}
|
||
_showSelectedJobsites = [];
|
||
showJobsites();
|
||
}
|
||
|
||
|
||
|
||
function OnSaveJobsites() {
|
||
var jobsiteids = [];
|
||
for (var i = 0; i < _selectedJobsites.length; i++) {
|
||
var j = _selectedJobsites[i];
|
||
jobsiteids.push(j.ID);
|
||
}
|
||
|
||
showloading(true);
|
||
_network.userquery("SaveContactJobsites", uiid + String.fromCharCode(170) + JSON.stringify(jobsiteids), function (data) {
|
||
showloading(false);
|
||
if (data !== 'OK') {
|
||
showAlert(data, GetTextByKey("P_UM_JOBSITEASSIGNMENT", 'Jobsite Assignment'));
|
||
} else {
|
||
$('#dialog_managejobsite').hideDialog();
|
||
OnRefresh();
|
||
}
|
||
}, function (err) {
|
||
console.log(err);
|
||
showloading(false);
|
||
showAlert(GetTextByKey("P_UM_FAILEDTOSAVEJOBSITEASSIGNMENT", 'Failed to save jobsite assignment.'), GetTextByKey("P_UM_JOBSITEASSIGNMENT", 'Jobsite Assignment'));
|
||
});
|
||
}
|
||
|
||
/**************************End JobSite Assignment********************************/
|
||
/*****************************************************************************/
|
||
|
||
|
||
|
||
|
||
|
||
/************************** AssetType Assignment********************************/
|
||
/*************************************************************************/
|
||
|
||
var allAssetTypes;
|
||
var _availableAssetTypes = [];
|
||
var _selectedAssetTypes = [];
|
||
var _showSelectedAssetTypes = [];
|
||
function OnManageAssetType(u) {
|
||
$('#chk_showallassignedassettypes').prop('checked', false);
|
||
$('#txt_assettype_key').val('');
|
||
|
||
if (!u) {
|
||
uiid = undefined;
|
||
return;
|
||
}
|
||
|
||
uiid = u.IID;
|
||
|
||
var title = GetTextByKey("P_UM_ASSETTYPEASSIGNMENT", 'Asset Type Assignment');
|
||
$('#dialog_manageassettype .dialog-title span.title').html(title);
|
||
showmaskbg(true);
|
||
$('#dialog_manageassettype')
|
||
.css({
|
||
'top': (document.documentElement.clientHeight - $('#dialog_manageassettype').height()) / 5,
|
||
'left': (document.documentElement.clientWidth - $('#dialog_manageassettype').width()) / 2
|
||
}).showDialog();
|
||
|
||
GetSelectedAssetTypes();
|
||
}
|
||
|
||
// 获取已选中的AssetTypes
|
||
function GetSelectedAssetTypes() {
|
||
_selectedAssetTypes = [];
|
||
$("#assettypedialogmask").show();
|
||
_network.userquery('GetSelectedAssetTypes', uiid, function (data) {
|
||
if (typeof data === "string") {
|
||
showAlert(data, GetTextByKey("P_UM_ASSETTYPEASSIGNMENT", 'Asset Type Assignment'));
|
||
return;
|
||
}
|
||
_selectedAssetTypes = data;
|
||
queryAssetTypes();
|
||
}, function (e) {
|
||
$("#assettypedialogmask").hide();
|
||
});
|
||
}
|
||
|
||
function queryAssetTypes() {
|
||
$('#button_assettype_filter').prop('disabled', true);
|
||
setTimeout(function () {
|
||
$('#button_assettype_filter').prop('disabled', false);
|
||
}, 1000);
|
||
|
||
_availableAssetTypes = [];
|
||
$("#assettypedialogmask").show();
|
||
_network.userquery('GetAssetTypes', '', function (data) {
|
||
if (typeof data === "string") {
|
||
showAlert(data, GetTextByKey("P_UM_ASSETTYPEASSIGNMENT", 'AssetType Assignment'));
|
||
return;
|
||
}
|
||
allAssetTypes = data;
|
||
getMatchAvailableAssetTypes();
|
||
$("#assettypedialogmask").hide();
|
||
}, function (e) {
|
||
$("#assettypedialogmask").hide();
|
||
});
|
||
}
|
||
|
||
|
||
function getMatchAvailableAssetTypes() {
|
||
getMatchSelectedAssetTypes();
|
||
|
||
var selected = [];
|
||
for (var i = 0; i < _showSelectedAssetTypes.length; i++) {
|
||
var m = _showSelectedAssetTypes[i];
|
||
selected.push(m.ID);
|
||
}
|
||
var assettypefilter = $('#txt_assettype_key').val().toLowerCase();
|
||
|
||
_availableAssetTypes = [];
|
||
for (var i = 0; i < allAssetTypes.length; i++) {
|
||
var m = allAssetTypes[i];
|
||
if ((assettypefilter == "" || m.Name.toLowerCase().indexOf(assettypefilter) >= 0)
|
||
&& $.inArray(m.ID, selected) < 0) {
|
||
_availableAssetTypes.push(m);
|
||
}
|
||
}
|
||
showAvailableAssetType(_availableAssetTypes);
|
||
}
|
||
|
||
function getMatchSelectedAssetTypes() {
|
||
var assettypefilter = $('#txt_assettype_key').val().toLowerCase();
|
||
var showallassigned = $('#chk_showallassignedassettypes').prop('checked');
|
||
|
||
_showSelectedAssetTypes = [];
|
||
var unMatched = [];
|
||
for (var i = 0; i < _selectedAssetTypes.length; i++) {
|
||
var m = _selectedAssetTypes[i];
|
||
m.Highlight = false;
|
||
var matched = false;
|
||
if (assettypefilter == "" || m.Name.toLowerCase().indexOf(assettypefilter) >= 0) {
|
||
matched = true;
|
||
m.Highlight = showallassigned && assettypefilter !== "";
|
||
_showSelectedAssetTypes.push(m);
|
||
}
|
||
else if (showallassigned)
|
||
unMatched.push(m);
|
||
}
|
||
|
||
if (showallassigned) {
|
||
for (var i in unMatched)
|
||
_showSelectedAssetTypes.push(unMatched[i]);
|
||
}
|
||
|
||
showSelectedAssetType(_showSelectedAssetTypes);
|
||
}
|
||
|
||
function showAssetTypes() {
|
||
showAvailableAssetType(_availableAssetTypes);
|
||
showSelectedAssetType(_showSelectedAssetTypes);
|
||
}
|
||
|
||
|
||
|
||
function showAvailableAssetType(data) {
|
||
var rows = [];
|
||
for (var i = 0; i < data.length; i++) {
|
||
var r = data[i];
|
||
var fr = { Values: r };
|
||
rows.push(fr);
|
||
}
|
||
|
||
grid_dtaat.setData(rows);
|
||
}
|
||
|
||
function showSelectedAssetType(data) {
|
||
var rows = [];
|
||
for (var i = 0; i < data.length; i++) {
|
||
var r = data[i];
|
||
var fr = { Values: r };
|
||
rows.push(fr);
|
||
}
|
||
|
||
grid_dtsat.setData(rows);
|
||
}
|
||
|
||
|
||
var grid_dtaat;
|
||
function InitGridAvailableAssetTypes() {
|
||
grid_dtaat = new GridView('#availableassettypelist');
|
||
grid_dtaat.lang = {
|
||
all: GetTextByKey("P_GRID_ALL", "(All)"),
|
||
ok: GetTextByKey("P_GRID_OK", "OK"),
|
||
reset: GetTextByKey("P_GRID_RESET", "Reset")
|
||
};
|
||
var list_columns = [
|
||
{ name: 'Name', caption: GetTextByKey("P_UM_NAME", "Name"), valueIndex: 'Name', css: { 'width': 380, '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;
|
||
columns.push(col);
|
||
}
|
||
grid_dtaat.canMultiSelect = true;
|
||
grid_dtaat.columns = columns;
|
||
grid_dtaat.init();
|
||
grid_dtaat.rowdblclick = function (rowindex) {
|
||
var rowdata = grid_dtaat.source[rowindex];
|
||
if (rowdata) {
|
||
var AssetType = rowdata.Values;
|
||
_availableAssetTypes.splice(_availableAssetTypes.indexOf(AssetType), 1);
|
||
_selectedAssetTypes.push(AssetType);
|
||
_showSelectedAssetTypes.push(AssetType);
|
||
|
||
showAssetTypes();
|
||
}
|
||
};
|
||
|
||
grid_dtaat.selectedrowchanged = function (rowindex) {
|
||
var rowdata = grid_dtaat.source[rowindex];
|
||
if (rowdata) {
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
var grid_dtsat;
|
||
function InitGridSelectedAssetTypes() {
|
||
grid_dtsat = new GridView('#selectedassettypelist');
|
||
grid_dtsat.lang = {
|
||
all: GetTextByKey("P_GRID_ALL", "(All)"),
|
||
ok: GetTextByKey("P_GRID_OK", "OK"),
|
||
reset: GetTextByKey("P_GRID_RESET", "Reset")
|
||
};
|
||
var list_columns = [
|
||
{ name: 'Name', caption: GetTextByKey("P_UM_NAME", "Name"), valueIndex: 'Name', css: { 'width': 380, '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;
|
||
col.styleFilter = function (item) {
|
||
if (item.Highlight)
|
||
return { 'background-color': 'yellow' };
|
||
}
|
||
columns.push(col);
|
||
}
|
||
grid_dtsat.canMultiSelect = true;
|
||
grid_dtsat.columns = columns;
|
||
grid_dtsat.init();
|
||
grid_dtsat.rowdblclick = function (rowindex) {
|
||
var rowdata = grid_dtsat.source[rowindex];
|
||
if (rowdata) {
|
||
var AssetType = rowdata.Values;
|
||
_selectedAssetTypes.splice(_selectedAssetTypes.indexOf(AssetType), 1);
|
||
_showSelectedAssetTypes.splice(_showSelectedAssetTypes.indexOf(AssetType), 1);
|
||
_availableAssetTypes.push(AssetType);
|
||
|
||
showAssetTypes();
|
||
}
|
||
};
|
||
|
||
grid_dtsat.selectedrowchanged = function (rowindex) {
|
||
var rowdata = grid_dtsat.source[rowindex];
|
||
if (rowdata) {
|
||
}
|
||
}
|
||
}
|
||
|
||
function OnAssetTypeEditorAdd() {
|
||
var indexs = grid_dtaat.selectedIndexes;
|
||
if (indexs.length <= 0)
|
||
return;
|
||
for (var i = 0; i < indexs.length; i++) {
|
||
var index = indexs[i];
|
||
var m = grid_dtaat.source[index].Values;
|
||
_availableAssetTypes.splice(_availableAssetTypes.indexOf(m), 1);
|
||
_selectedAssetTypes.push(m);
|
||
_showSelectedAssetTypes.push(m);
|
||
}
|
||
showAssetTypes();
|
||
}
|
||
function OnAssetTypeEditorAddAll() {
|
||
for (var i = 0; i < _availableAssetTypes.length; i++) {
|
||
var m = _availableAssetTypes[i];
|
||
_selectedAssetTypes.push(m);
|
||
_showSelectedAssetTypes.push(m);
|
||
}
|
||
_availableAssetTypes = [];
|
||
showAssetTypes();
|
||
}
|
||
function OnAssetTypeEditorRemove() {
|
||
var indexs = grid_dtsat.selectedIndexes;
|
||
if (indexs.length <= 0)
|
||
return;
|
||
for (var i = 0; i < indexs.length; i++) {
|
||
var index = indexs[i];
|
||
var m = grid_dtsat.source[index].Values;
|
||
_selectedAssetTypes.splice(_selectedAssetTypes.indexOf(m), 1);
|
||
_showSelectedAssetTypes.splice(_showSelectedAssetTypes.indexOf(m), 1);
|
||
_availableAssetTypes.push(m);
|
||
}
|
||
showAssetTypes();
|
||
}
|
||
function OnAssetTypeEditorRemoveAll() {
|
||
for (var i = 0; i < _showSelectedAssetTypes.length; i++) {
|
||
var m = _showSelectedAssetTypes[i];
|
||
_selectedAssetTypes.splice(_selectedAssetTypes.indexOf(m), 1);
|
||
_availableAssetTypes.push(m);
|
||
}
|
||
_showSelectedAssetTypes = [];
|
||
showAssetTypes();
|
||
}
|
||
|
||
|
||
|
||
function OnSaveAssetTypes() {
|
||
var assettypeids = [];
|
||
for (var i = 0; i < _selectedAssetTypes.length; i++) {
|
||
var j = _selectedAssetTypes[i];
|
||
assettypeids.push(j.ID);
|
||
}
|
||
|
||
showloading(true);
|
||
_network.userquery("SaveUserAssetTypes", uiid + String.fromCharCode(170) + JSON.stringify(assettypeids), function (data) {
|
||
showloading(false);
|
||
if (data !== 'OK') {
|
||
showAlert(data, GetTextByKey("P_UM_ASSETTYPEASSIGNMENT", 'AssetType Assignment'));
|
||
} else {
|
||
$('#dialog_manageassettype').hideDialog();
|
||
OnRefresh();
|
||
}
|
||
}, function (err) {
|
||
console.log(err);
|
||
showloading(false);
|
||
showAlert(GetTextByKey("P_UM_FAILEDTOSAVEASSETTYPEASSIGNMENT", 'Failed to save assettype assignment.'), GetTextByKey("P_UM_ASSETTYPEASSIGNMENT", 'Asset Type Assignment'));
|
||
});
|
||
}
|
||
|
||
/**************************End AssetType Assignment********************************/
|
||
/*****************************************************************************/
|
||
|
||
|
||
|
||
|
||
/**************************Start Reset Password********************************/
|
||
/*****************************************************************************/
|
||
|
||
function OnResetPassword(u) {
|
||
if (!u) {
|
||
uiid = undefined;
|
||
return;
|
||
}
|
||
uiid = u.IID;
|
||
$('#dialog_user_randompass').prop('checked', true);
|
||
$('#dialog_user_password').prop('disabled', true);
|
||
$('#dialog_user_password1').prop('disabled', true);
|
||
$('#dialog_user_password').val('');
|
||
$('#dialog_user_password1').val('');
|
||
showmaskbg(true);
|
||
$('#dialog_password')
|
||
.css({
|
||
'top': (document.documentElement.clientHeight - $('#dialog_password').height()) / 3,
|
||
'left': (document.documentElement.clientWidth - $('#dialog_password').width()) / 2
|
||
}).showDialogfixed();
|
||
|
||
}
|
||
|
||
function ResetPassword() {
|
||
var alerttitle = GetTextByKey("P_UM_RESETPASSWORD", "Reset Password");
|
||
var password = "";
|
||
if (!$('#dialog_user_randompass').prop('checked')) {
|
||
password = $('#dialog_user_password').val();
|
||
if (password.length < 8) {
|
||
showAlert(GetTextByKey("P_UM_PASSWORDTIPS", 'The password must have at least 8 characters.'), alerttitle, undefined, function () { $('#dialog_user_password').focus(); });
|
||
return;
|
||
}
|
||
if (getStrength(password) < 2) {
|
||
showAlert(GetTextByKey("P_UM_PASSWORDTIPS1", 'The password must contain both uppercase and lowercase characters and at lease one number.'), alerttitle, undefined, function () { $('#dialog_user_password').focus(); });
|
||
return;
|
||
}
|
||
var pass2 = $('#dialog_user_password1').val();
|
||
if (password !== pass2) {
|
||
showAlert(GetTextByKey("P_UM_PASSWORDTIPS2", 'The two passwords are different. Please reenter.'), alerttitle, undefined, function () { $('#dialog_user_password1').focus(); });
|
||
return;
|
||
}
|
||
}
|
||
|
||
showloading(true);
|
||
_network.userquery("ResetPassword", uiid + String.fromCharCode(170) + password, function (data) {
|
||
showloading(false);
|
||
if (data !== 'OK') {
|
||
showAlert(data, alerttitle);
|
||
} else {
|
||
showAlert(GetTextByKey("P_UM_RESETUSERPASSWORDSUCCESSFULLY", 'Reset user password successfully.'), alerttitle);
|
||
$('#dialog_password').hideDialog();
|
||
OnRefresh();
|
||
}
|
||
}, function (err) {
|
||
console.log(err);
|
||
showloading(false);
|
||
showAlert(GetTextByKey("P_UM_FAILEDTORESETUSERPASSWORD", 'Failed to reset user password.'), alerttitle);
|
||
});
|
||
}
|
||
|
||
/**************************End Reset Password********************************/
|
||
/*****************************************************************************/ |