fleet-contractor/Site/js/mapview/mapviewsearch.js
2023-05-30 17:34:56 +08:00

303 lines
11 KiB
JavaScript

$(function () {
InitSavedSearchGrid();
InitSaveSearchGrid();
$("#btnSavedSearches").click(openSavedSearches);
$("#btnSaveSearchDetault").click(openSaveSearch);
$('#dialog_savedsearches').dialog(function () {
showmaskbg(false);
});
$('#dialog_savesearch').dialog(function () {
showmaskbg(false);
});
});
function showGridList(grid_dt) {
showSearchList(grid_dt, userParams.MapViewSearches);
}
function showSearchList(grid_dt, data) {
grid_dt.setData([]);
if (!data || data.length === 0)
return;
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
for (var j in r) {
if (j === "IsDefault") {
r.IsDefaultText = r.IsDefault ? GetTextByKey("P_MV_YES", "Yes") : GetTextByKey("P_MV_NO", "No");
}
}
r.Text = false;
r.Email = false;
var fr = { Values: r };
rows.push(fr);
}
grid_dt.setData(rows);
}
/**********************Saved Searches***********************************/
function openSavedSearches() {
showmaskbg(true);
$('#dialog_savedsearches .dialog-title span.title').text(GetTextByKey("P_MV_SAVEDSEARCHES", 'Saved Searches'));
$('#dialog_savedsearches')
.attr('act', 'edit')
.css({
'width': 450,
'top': (document.documentElement.clientHeight - $('#dialog_savedsearches').height()) / 4,
'left': (document.documentElement.clientWidth - $('#dialog_savedsearches').width()) / 2
})
.showDialogfixed();
showGridList(savedsearches_dt)
}
var savedsearches_dt;
function InitSavedSearchGrid() {
savedsearches_dt = new GridView('#savedsearchlist');
savedsearches_dt.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_MV_SEARCHNAME", "Search Name"), valueIndex: 'Name', css: { 'width': 250, 'text-align': 'left' } },
{ name: 'IsDefault', caption: GetTextByKey("P_MV_DEFAULT", "Default"), valueIndex: 'IsDefaultText', css: { 'width': 70, 'text-align': 'left' } },
{ name: 'Apply', caption: "", css: { 'width': 30, 'text-align': 'center' } },
{ name: 'Delete', caption: "", css: { 'width': 30, 'text-align': 'center' } }
];
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 === "Apply") {
col.isurl = true;
col.text = "\uf1da";
col.events = {
onclick: function () {
onLoadSavedSearches(this);
}
};
col.classFilter = function (e) {
return "icon-col";
}
col.attrs = { 'title': GetTextByKey("P_MV_APPLY", 'Apply') };
}
else if (col.name === "Delete") {
col.isurl = true;
col.text = "\uf00d";
col.events = {
onclick: function () {
OnDeleteSavedSearches(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': GetTextByKey("P_MV_DELETE", 'Delete') };
}
columns.push(col);
}
savedsearches_dt.canMultiSelect = false;
savedsearches_dt.columns = columns;
savedsearches_dt.init();
savedsearches_dt.selectedrowchanged = function (rowindex) {
var rowdata = savedsearches_dt.source[rowindex];
if (rowdata) {
$('#savedsearch_searchname').val(rowdata.Values.Name);
}
};
savedsearches_dt.rowdblclick = function (rowindex) {
var rowdata = savedsearches_dt.source[rowindex];
if (rowdata) {
onLoadSavedSearches(rowdata.Values);
}
};
}
function OnDeleteSavedSearches(search) {
if (!search) {
return;
}
showConfirm(GetTextByKey("P_MV_SEARCHDELETEWANTTOCONTINUE", 'Search {0} will be permanently deleted.Do you want to continue?').replace('{0}', search.Name), GetTextByKey("P_MV_DELETESEARCH", 'Delete Search'), function () {
_network.mapviewquery("DeleteMapViewSearch", search.Name, function (data) {
if (data) {
userParams.MapViewSearches = data;
showGridList(savedsearches_dt);
}
}, function (err) {
_dialog.showAlert(GetTextByKey("P_MV_FAILEDTODELETETHISSEARCH", 'Failed to delete this search.'), GetTextByKey("P_MV_DELETESEARCH", 'Delete Search'));
});
});
}
function onLoadSavedSearches(search) {
if (!search) {
var name = $('#savedsearch_searchname').val();
if (name === "")
return;
if (!userParams.MapViewSearches || userParams.MapViewSearches.length == 0) {
_dialog.showAlert(GetTextByKey("P_MV_YOUHAVENOSAVEDSEARCHES", 'You have no saved searches.'), '');
return;
}
for (var i = 0; i < userParams.MapViewSearches.length; i++) {
if (userParams.MapViewSearches[i].Name.toLowerCase() === name.toLowerCase()) {
search = userParams.MapViewSearches[i];
break;
}
}
}
if (!search) {
_dialog.showAlert(GetTextByKey("P_MV_SEARCHDOESNOTEXIST", 'Search {0} does not exist.').replace('{0}', $('#savedsearch_searchname').val()), '');
return;
}
setSavedSearche(search);
refreshData();
$('#dialog_savedsearches').hideDialog();
showmaskbg(false);
}
function setSavedSearche(search) {
$("#selOnroad").val(search.Onroad);
$("#selAttachment").val(search.Attachment);
$('#txtMachineSearchText').val(search.AssetDefaultSearch);
$('#txtJobSiteSearchText').val(search.JobSiteDefaultSearch);
$('#txtAssetGroupSearchText').val(search.AssetGroupDefaultSearch);
//$('#chkExcludeNoLoc').prop("checked", search.ExcludeNoLocation);
setExclude00(search.ExcludeNoLocation);
assetObject.setUnShownMachines(search.UnShownMachines);
jobsiteObject.setUnShownJobsites(search.UnShownJobsites);
jobsiteObject.setUnShownMachines(search.UnShownJobsiteMachines);
resetMachineState();
}
/**********************Save Searche***********************************/
function openSaveSearch() {
$('#savesearch_searchname').val('');
$('#savesearch_default').prop('checked', false);
showmaskbg(true);
$('#dialog_savesearch .dialog-title span.title').text(GetTextByKey("P_MV_SAVESEARCH", 'Save Search'));
$('#dialog_savesearch')
.attr('act', 'edit')
.css({
'width': 450,
'top': (document.documentElement.clientHeight - $('#dialog_savesearch').height()) / 4,
'left': (document.documentElement.clientWidth - $('#dialog_savesearch').width()) / 2
})
.showDialogfixed();
showGridList(savesearch_dt);
}
var savesearch_dt;
function InitSaveSearchGrid() {
savesearch_dt = new GridView('#savesearchlist');
savesearch_dt.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_MV_SEARCHNAME", "Search Name"), valueIndex: 'Name', css: { 'width': 250, 'text-align': 'left' } },
{ name: 'IsDefault', caption: GetTextByKey("P_MV_DEFAULT", "Default"), valueIndex: 'IsDefaultText', css: { 'width': 70, '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;
}
columns.push(col);
}
savesearch_dt.canMultiSelect = false;
savesearch_dt.columns = columns;
savesearch_dt.init();
savesearch_dt.selectedrowchanged = function (rowindex) {
var rowdata = savesearch_dt.source[rowindex];
if (rowdata) {
}
}
}
function onSaveSearch() {
var name = $('#savesearch_searchname').val();
var item = {
'Name': name,
'IsDefault': $('#savesearch_default').prop('checked'),
'Onroad': $("#selOnroad").val(),
'Attachment': $("#selAttachment").val(),
'AssetDefaultSearch': $('#txtMachineSearchText').val(),
'JobSiteDefaultSearch': $('#txtJobSiteSearchText').val(),
'AssetGroupDefaultSearch': $('#txtAssetGroupSearchText').val(),
'ExcludeNoLocation': $("#exclude00Div").attr("state") != "0", //$("#chkExcludeNoLoc").prop("checked"),
'UnShownMachines': assetObject.getUnShownMachines(),
'UnShownJobsites': jobsiteObject.getUnShownJobsites(),
'UnShownJobsiteMachines': jobsiteObject.getUnShownMachines()
};
if (item.Name === "") {
_dialog.showAlert(GetTextByKey("P_MV_SEARCHNAMEISREQUIRED", 'Search Name is required.'), GetTextByKey("P_MV_SAVESEARCH", 'Save Search'));
return;
}
var exists = false;
if (userParams.MapViewSearches) {
for (var i = 0; i < userParams.MapViewSearches.length; i++) {
var search = userParams.MapViewSearches[i];
if (search.Name.toLowerCase() === item.Name.toLowerCase()) {
exists = true;
break;
}
}
}
if (exists) {
showConfirm(GetTextByKey("P_MV_SEARCHALREADYEXIST", 'Search {0} already exists. Would you like to replace?').replace('{0}', item.Name), GetTextByKey("P_MV_SAVESEARCH", 'Save Search'), function () {
SaveMapViewSearch(item);
});
} else
SaveMapViewSearch(item);
}
function SaveMapViewSearch(item) {
_network.mapviewquery("SaveMapViewSearch", JSON.stringify(item), function (data) {
if (data) {
userParams.MapViewSearches = data;
showGridList(savesearch_dt);
$('#savesearch_searchname').val('');
$('#savesearch_default').prop('checked', false);
_dialog.showAlert(GetTextByKey("P_MV_SAVSUCCESSFULLY", 'Saved successfully.'), GetTextByKey("P_MV_SAVESEARCH", 'Save Search'));
$('#dialog_savesearch').hideDialog();
showmaskbg(false);
}
}, function (err) {
_dialog.showAlert(GetTextByKey("P_MV_FAILEDTOSAVETHISSEARCH", 'Failed to save this search.'), GetTextByKey("P_MV_SAVESEARCH", 'Save Search'));
});
}