2023-04-28 12:22:26 +08:00

444 lines
14 KiB
JavaScript

$(function () {
InitJobSiteGridData();
InitContactGridData();
InitAssetGroupGridData();
$('#dialog_addmake').dialog(function () {
showmaskbg(false);
});
$('#dialog_addmodel').dialog(function () {
showmaskbg(false);
});
$('#dialog_assetduplicates').dialog(function () {
showmaskbg(false);
});
$('#dialog_mergeasset').dialog(function () {
showmaskbg(false);
});
});
var activejobsitedata;
function GetActiveJobsites() {
devicerequest('GetActiveJobsites', contractorid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
activejobsitedata = data;
SetJobSites(jobsitsata);
}
});
}
var contactdata;
function GetContacts() {
devicerequest('GetContacts', contractorid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
contactdata = data;
SetContacts(contactids);
}
});
}
function SetJobSites(data) {
if (!activejobsitedata)
return;
for (var i = 0; i < activejobsitedata.length; i++) {
var js = activejobsitedata[i];
js.OnSite = false;
js.InJobSite = false;
js.Sugguested = false;
js.StatusText = "";
if (data && data.length > 0) {
for (var j = 0; j < data.length; j++) {
var js1 = data[j];
if (js.ID == js1.JobSiteID) {
js.OnSite = js1.OnSite;
js.InJobSite = js1.InJobSite;
js.Sugguested = js1.Sugguested;
if (js.InJobSite && !js.OnSite)
js.StatusText = "Auto-Assigned";
if (js.OnSite)
js.StatusText = "Manually-Assigned";
if (js.Sugguested && !js.InJobSite)
js.StatusText = "Current Location";
break;
}
}
}
}
ShowActiveJobSites(activejobsitedata);
}
function SetContacts(ids) {
if (!contactdata)
return;
for (var i = 0; i < contactdata.length; i++) {
var contact = contactdata[i];
contact.Assigned = false;
if (ids && ids.length > 0) {
for (var j = 0; j < ids.length; j++) {
if (contact.IID == ids[j]) {
contact.Assigned = true;
break;
}
}
}
}
ShowContacts(contactdata);
}
function ShowActiveJobSites(data) {
var onsiterows = [];
var injobsiterows = [];
var sugguestedrows = [];
var otherrows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
var fr = { Values: r };
if (r.OnSite)
onsiterows.push(fr)
else if (r.InJobSite)
injobsiterows.push(fr);
else if (r.Sugguested)
sugguestedrows.push(fr);
else
otherrows.push(fr);
}
var rows = [];
for (var i = 0; i < onsiterows.length; i++) {
rows.push(onsiterows[i]);
}
for (var i = 0; i < injobsiterows.length; i++) {
rows.push(injobsiterows[i]);
}
for (var i = 0; i < sugguestedrows.length; i++) {
rows.push(sugguestedrows[i]);
}
for (var i = 0; i < otherrows.length; i++) {
rows.push(otherrows[i]);
}
grid_jobsitedt.sortDirection = -1;
grid_jobsitedt.setData(rows);
}
var grid_jobsitedt;
function InitJobSiteGridData() {
grid_jobsitedt = new GridView('#jobsitelist');
grid_jobsitedt.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'OnSite', caption: GetTextByKey("P_MA_ONSITE", "On Site"), valueIndex: 'OnSite', type: 3, css: { 'width': 60, 'text-align': 'center' } },
{ name: 'Name', caption: GetTextByKey("P_MA_JOBSITENAME", "Jobsite Name"), valueIndex: 'Name', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'StatusText', caption: GetTextByKey("P_MA_ASSIGNMENT", "Assignment"), valueIndex: 'StatusText', css: { 'width': 120, '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.bgFilter = function (item) {
if (item.OnSite || item.InJobSite || item.Sugguested)
return 'silver';
}
if (list_columns[hd].type) {
col.type = list_columns[hd].type;
}
if (col.name === "OnSite") {
col.events = {
onchange: function () {
inputChanged = true;
jobsiteinputChanged = true;
}
};
col.tooltip = GetTextByKey("P_MA_ONSITETITLE", "The On Site box should only be checked if the asset has a permanent assignment not based on location. Geofence and Jobsite Add/Remove will not be triggered if checked.");
}
columns.push(col);
}
grid_jobsitedt.canMultiSelect = true;
grid_jobsitedt.columns = columns;
grid_jobsitedt.init();
grid_jobsitedt.selectedrowchanged = function (rowindex) {
var rowdata = grid_jobsitedt.source[rowindex];
if (rowdata) {
}
}
}
function ShowContacts(data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
var fr = { Values: r };
rows.push(fr);
}
grid_contactdt.sortIndex = 0;//已选默认拍在前面
grid_contactdt.sortDirection = -1;
grid_contactdt.setData(rows);
}
var grid_contactdt;
function InitContactGridData() {
grid_contactdt = new GridView('#contactlist');
grid_contactdt.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'Assigned', caption: GetTextByKey("P_MA_ASSIGNED", "Assigned"), valueIndex: 'Assigned', type: 3, css: { 'width': 75, 'text-align': 'center' } },
{ name: 'DisplayName', caption: GetTextByKey("P_MA_CONTACTNAME", "Contact Name"), valueIndex: 'DisplayName', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'ContactTypeName', caption: GetTextByKey("P_MA_CONTACTTYPE", "Contact Type"), valueIndex: 'ContactTypeName', css: { 'width': 100, '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;
if (list_columns[hd].type) {
col.type = list_columns[hd].type;
}
if (col.name === "Assigned") {
col.events = {
onchange: function () {
inputChanged = true;
}
};
}
columns.push(col);
}
grid_contactdt.canMultiSelect = false;
grid_contactdt.columns = columns;
grid_contactdt.init();
grid_contactdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_contactdt.source[rowindex];
if (rowdata) {
}
}
}
function reshowgrid() {
setTimeout(function () {
$("#jobsitelist").css("height", $(window).height() - $("#jobsitelist").offset().top - 10);
grid_jobsitedt && grid_jobsitedt.resize();
$("#contactlist").css("height", $(window).height() - $("#contactlist").offset().top - 10);
grid_contactdt && grid_contactdt.resize();
});
}
/****** Groups******/
var assetgroups
var grid_assetgroups;
function InitAssetGroupGridData() {
grid_assetgroups = new GridView('#assetgrouplist');
grid_assetgroups.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: 'GroupName', caption: GetTextByKey("P_MA_GROUPNAME", "Group Name"), valueIndex: 'GroupName', 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.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;
}
if (col.name === "Selected") {
col.events = {
onchange: function () {
inputChanged = true;
}
};
}
columns.push(col);
}
grid_assetgroups.canMultiSelect = false;
grid_assetgroups.columns = columns;
grid_assetgroups.init();
}
function GetMachineGroups() {
$('#tbodymachinegroup').empty();
devicerequest('GetMachineGroups', contractorid + String.fromCharCode(170) + "", function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
assetgroups = data;
ShowMachineGroups(data);
}
});
}
function ShowMachineGroups() {
var rows = [];
for (var i = 0; i < assetgroups.length; i++) {
var r = assetgroups[i];
r.Selected = false
var fr = { Values: r };
rows.push(fr);
}
grid_assetgroups.setData(rows);
}
function SetMachineGroups(ids) {
if (!assetgroups)
return;
for (var i = 0; i < assetgroups.length; i++) {
var group = assetgroups[i];
group.Selected = false;
if (ids && ids.length > 0) {
for (var j = 0; j < ids.length; j++) {
if (ids[j].toLowerCase() == group.GroupID.toLowerCase()) {
group.Selected = true;
break;
}
}
}
}
grid_assetgroups.reload();
}
function reshowgroupgrid() {
setTimeout(function () {
$("#assetgrouplist").css("height", $(window).height() - $("#assetgrouplist").offset().top - 10);
grid_assetgroups && grid_assetgroups.resize();
});
}
function OnAddMake() {
showmaskbg(true);
$('#dialog_addmake')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_addmake').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_addmake').width()) / 2
})
.showDialog();
$('#dialog_makename').focus();
}
function OnSaveMake() {
var item = {
'Name': $.trim($('#dialog_makename').val()),
'AlterActiveName': $.trim($('#dialog_makename').val())
};
var alerttitle = GetTextByKey("P_MA_ADDMAKE", "Add Make");
item.ID = -1;
if (!item.Name || item.Name.length == 0) {
showAlert(GetTextByKey("P_MA_MAKENAMEEMPTY", 'Make name cannot be empty.'), alerttitle);
$('#dialog_makename').focus();
return;
}
$("#addmakemask").show();
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("SaveMachineMake", param, function (data) {
if (data !== 'OK') {
showAlert(data, alerttitle);
$("#addmakemask").hide();
} else {
GetMachineMakes(item.Name);
$('#dialog_addmake').hideDialog();
showmaskbg(false);
$("#addmakemask").hide();
}
}, function (err) {
showAlert(GetTextByKey("P_MA_FAILEDTOSAVEMAKE", 'Failed to save Make.'), alerttitle);
$("#addmakemask").hide();
});
}
function OnAddModel() {
showmaskbg(true);
$('#dialog_addmodel')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_addmodel').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_addmodel').width()) / 2
})
.showDialog();
$('#dialog_modelname').val("");
$('#dialog_modelname').focus();
$('#dialog_makeforaddmodel').val($('#dialog_make').val());
$('#dialog_typeforaddmodel').dropdownVal("");
}
function OnSaveModel() {
var item = {
'Name': $.trim($('#dialog_modelname').val()),
'MakeID': $.trim($('#dialog_makeforaddmodel').val()),
'TypeID': $.trim($('#dialog_typeforaddmodel').dropdownVal())
};
var alerttitle = "Add Model";
item.ID = -1;
if (!item.Name || item.Name.length == 0) {
showAlert(GetTextByKey("P_MA_MODELNAMECANNOTBEEMPTY", 'Model name cannot be empty.'), alerttitle);
$('#dialog_modelname').focus();
return;
}
$("#addmodelmask").show();
var param = JSON.stringify(item);
param = htmlencode(param);
devicerequest("SAVEMACHINEMODEL", param, function (data) {
if (data !== 'OK') {
showAlert(data, alerttitle);
$("#addmodelmask").hide();
} else {
GetMachineModels(item.MakeID, item.Name);
$('#dialog_addmodel').hideDialog();
$("#addmodelmask").hide();
showmaskbg(false);
}
}, function (err) {
showAlert(GetTextByKey("P_MA_FAILEDTOSAVEMODEL", 'Failed to save model.'), alerttitle);
$("#addmodelmask").hide();
});
}