fleet-contractor/Site/Security/CurfewManage.aspx
2023-04-28 12:22:26 +08:00

1267 lines
49 KiB
Plaintext

<%@ Page Title="" Language="C#" MasterPageFile="~/Security/Security.master" AutoEventWireup="true" CodeFile="CurfewManage.aspx.cs" Inherits="Security_CurfewManage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<style type="text/css">
.selectinput {
width: 150px;
margin-right: 10px;
}
.no_wrap th {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.max160 {
max-width: 160px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.dialog-content table {
border-collapse: collapse;
width: 100%;
line-height: 32px;
}
.dialog-content table td.label {
width: 124px;
text-align: right;
padding-right: 10px;
line-height: 24px;
height: 24px;
vertical-align: top;
}
.dialog-content table td input,
.dialog-content table td textarea {
border: 1px solid #a9a9a9;
width: 250px;
height: 18px;
padding: 1px;
}
#dialog_machines .dialog-content table td input {
width: auto;
}
.dialog-content table td select {
width: 254px;
height: 24px;
}
.dialog-content table td input[type="checkbox"] {
border: none;
}
.dialog-content table td textarea {
height: 100px;
max-width: 200px;
}
#dialog_user_randompass {
width: auto;
height: 16px;
margin: 3px 4px 0 4px;
}
.ctl_button {
font-family: 'CalciteWebCoreIcons';
display: block;
margin: 6px auto;
width: 60px;
height: 22px;
line-height: 21px;
padding: 0;
}
#dialog_machinegroup {
z-index: 500;
width: 870px;
top: 60px;
left: 150px;
}
.inputbox {
width: 500px;
padding: 1px;
}
.group_table .main_table {
table-layout: fixed;
}
.group_table .main_table thead tr {
display: block;
}
.group_table .main_table tbody {
height: 280px;
display: block;
overflow-y: auto;
}
.group_table .main_table th {
width: 165px;
}
.group_table .main_table td {
width: 165px;
white-space: nowrap;
word-break: keep-all;
}
.group_table .main_table td div {
width: 165px;
overflow: hidden;
white-space: nowrap;
word-break: keep-all;
text-overflow: ellipsis;
}
.table_holder {
border-collapse: collapse;
height: 400px;
}
.table_holder thead th {
text-align: left;
}
.table_holder tbody tr {
line-height: 28px;
height: 28px;
}
/*.table_holder td {
vertical-align: top;
}*/
.table_holder .td_controller {
vertical-align: middle;
padding: 40px 8px;
}
.table_holder .scroller {
height: 400px;
overflow-y: auto;
width: 410px;
}
.ctl_button {
font-family: 'CalciteWebCoreIcons';
display: block;
margin: 6px auto;
width: 60px;
height: 22px;
line-height: 21px;
padding: 0;
}
/*.machine_filter {
height: 32px;
line-height: 32px;
}
.machine_filter select {
height: 23px;
min-width: 100px;
max-width: 300px;
}
.machine_filter span {
margin-left: 8px;
}*/
.ybutton {
width: auto;
line-height: normal;
margin-left: 6px;
border: none;
background: rgb(249, 189, 117);
padding: 5px 14px;
cursor: pointer;
}
.ybutton:hover {
background: #d7690E;
}
.machines {
/*table-layout: fixed;*/
word-break: keep-all;
}
.machines td {
padding-right: 5px;
white-space: nowrap;
}
.middlechk {
width: auto;
height: 13px;
margin-top: 0px;
margin-bottom: 1px;
vertical-align: middle;
}
.machine_maskbg {
top: 0;
left: 0;
width: 100%;
height: 100%;
position: absolute;
background: #000;
opacity: 0.2;
}
</style>
<script src="<%=GetFileUrlWithVersion("../js/assetselector.js")%>" type="text/javascript"></script>
<script>
var IsDealer = <%=IsDealer ?"true":"false"%>;
var IsAdmin =<%=IsAdmin ?"true":"false"%>;
curfewquery = function (method, param, callback, error, nolog) {
_network.request("Security/CurfewManage.aspx", -1, method, param, callback, error || function (e) {
showAlert(GetTextByKey("P_CM_FAILEDTOLOADDATA", 'Failed to load data: ') + e.statusText, GetTextByKey("P_CM_SCHEDULEASSETS", 'Schedule Assets'));
});
}
function pmquery(method, param, callback, error) {
_network.request("Maintenance/ScheduleMachines.aspx", -1, method, param, callback, error || function (e) {
showAlert(GetTextByKey("P_CM_FAILEDTOLOADDATA", 'Failed to load data: ') + e.statusText, GetTextByKey("P_CM_SCHEDULEASSETS", 'Schedule Assets'));
});
}
function devicerequest(method, param, callback, error) {
_network.request("MachineDeviceManagement/ManageMachines.aspx", -1, method, param, callback, error || function (e) {
console.log(e);
showmaskbg(false, true);
showAlert(GetTextByKey('P_CM_PAGEERROR', 'An unknown error occurred. Please refresh page.'), GetTextByKey('P_CM_QUERY', 'Query'));
});
}
function getText(s, flag) {
return (s == null)
? (flag ? '<i>null</i>' : '')
: htmlencode(s, $('#span_text_holder')).replace(/ /g, '&nbsp;');
}
function trim_str(s) {
if (s == null)
return "";
else
return s.replace(/(^\s*)|(\s*$)/g, "");
}
var _allCurfews;
/***************************Curfews***************************/
function OnDelete(curfew) {
if (!curfew) {
return;
}
var contractorid = htmlencode($.trim($('#sel_contractor').val()));
showConfirm(GetTextByKey("P_CM_DOYOUWANTTODELETETHECURFEW", 'Do you want to delete the curfew?'), GetTextByKey("P_CM_DELETECURFEWCONFIGURATION", 'Delete curfew configuration'), function () {
curfewquery("DeleteCurfew", contractorid + String.fromCharCode(170) + curfew.Id, function (data) {
OnRefresh();
}, function (err) {
showAlert(GetTextByKey("P_CM_FAILEDTODELETETHISCURFEW", 'Failed to delete this curfew.'), GetTextByKey("P_CM_DELETECURFEWCONFIGURATION", 'Delete curfew configuration'));
});
});
}
//执行iframe中函数
var doIFrameFunc = function (v_mymethod, v_params, v_frmName) {
if (document.getElementById(v_frmName)) {
var fn = document.getElementById(v_frmName).contentWindow[v_mymethod];
if (fn) {
if (v_params == null)
return fn();
else {
return fn.apply(this, v_params);
}
}
return null;
}
}
function CloseDialog(type) {
$('#dialog_curfew').hideDialog();
OnRefresh();
}
function OnAdd() {
var contractorid = htmlencode($.trim($('#sel_contractor').val()));
doIFrameFunc("init", [contractorid], "iframecurfew");
showmaskbg(true);
$('#dialog_curfew')
.attr('act', 'add')
.showDialogRight();
}
var curfewid;
function OnEdit() {
var curfew = grid_dt.source[grid_dt.selectedIndex].Values;
if (!curfew) {
curfewid = undefined;
return;
}
curfewid = curfew.Id;
var contractorid = htmlencode($.trim($('#sel_contractor').val()));
doIFrameFunc("init", [contractorid, curfewid], "iframecurfew");
showmaskbg(true);
$('#dialog_curfew')
.attr('act', 'edit')
.showDialogRight();
}
function OnDblClick(e) {
OnEdit();
}
function OnRefresh() {
showloading(true);
var contractorid = htmlencode($.trim($('#sel_contractor').val()));
var searchtxt = "";
searchtxt = htmlencode($.trim($('#searchinputtxt').val()));
curfewquery("GetCurfews", contractorid + String.fromCharCode(170) + searchtxt, function (data) {
showloading(false);
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_CM_ERROR", 'Error'));
showmaskbg(false);
return;
}
_allCurfews = data;
showCurfewList(data);
}, function (err) {
showloading(false);
});
}
//admin用户 获取所有contractor
function getContractors() {
devicerequest('GetContractors', '', function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_CM_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
var sel_search = $('#sel_contractor').empty();
for (var i = 0; i < data.length; i++) {
var kv = data[i];
var op_search = $('<option></option>').val(kv.Key).text(kv.Value);
sel_search.append(op_search);
}
}
OnRefresh();
});
}
//普通用户 获取可操作的contractor
function GetContractorsByUser() {
devicerequest('GetContractorsByUser', '', function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_CM_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
var sel_search = $('#sel_contractor').empty();
for (var i = 0; i < data.length; i++) {
var kv = data[i];
var op_search = $('<option></option>').val(kv.Key).text(kv.Value);
sel_search.append(op_search);
}
}
OnRefresh();
});
}
function showCurfewList(data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
var fr = { Values: r };
rows.push(fr);
}
grid_dt.setData(rows);
}
var grid_dt;
function InitGridData() {
grid_dt = new GridView('#curfewlist');
grid_dt.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'Title', caption: GetTextByKey("P_CM_TITLE", "Title"), valueIndex: 'Title', css: { 'width': 400, 'text-align': 'left' } },
{ name: 'Day', caption: GetTextByKey("P_CM_DAYS", "Day(s)"), valueIndex: 'Day', css: { 'width': 280, 'text-align': 'left' } },
{ name: 'TimePeriod', caption: GetTextByKey("P_CM_PERIOD", "Period"), valueIndex: 'TimePeriod', css: { 'width': 300, 'text-align': 'left' } },
//{ name: 'StartTime', caption: "Start Time", valueIndex: 'StartTime', css: { 'width': 140, 'text-align': 'left' } },
//{ name: 'EndTime', caption: "End Time", valueIndex: 'EndTime', css: { 'width': 140, 'text-align': 'left' } },
{ name: 'Edit', caption: "", css: { 'width': 30, 'text-align': 'center' } },
{ name: 'Delete', caption: "", css: { 'width': 30, 'text-align': 'center' } },
{ name: 'AssetAssignment', caption: "", css: { 'width': 30, 'text-align': 'center' } },
{ name: 'JobsiteAssignment', 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 (col.name === "Edit") {
col.isurl = true;
col.text = "\uf044";
col.events = {
onclick: function () {
OnEdit()
}
};
col.classFilter = function (e) {
return "icon-col";
}
col.attrs = { 'title': GetTextByKey("P_CM_EDIT", 'Edit') };
}
else if (col.name === "Delete") {
col.isurl = true;
col.text = "\uf00d";
col.events = {
onclick: function () {
OnDelete(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': GetTextByKey("P_CM_DELETE", 'Delete') };
}
else if (col.name === "AssetAssignment") {
//col.visible = !IsDealer;
col.isurl = true;
col.text = "\uf63c";
col.events = {
onclick: function () {
OnManageMachine(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': GetTextByKey("P_CM_ASSETASSIGNMENT", 'Asset Assignment') };
}
else if (col.name === "JobsiteAssignment") {
//col.visible = !IsDealer;
col.isurl = true;
col.text = "\uf312";
col.events = {
onclick: function () {
OnManageJobsite(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.attrs = { 'title': GetTextByKey("P_CM_JOBSITEASSIGNMENT", 'Jobsite Assignment') };
}
columns.push(col);
}
grid_dt.canMultiSelect = false;
grid_dt.columns = columns;
grid_dt.init();
grid_dt.rowdblclick = OnEdit;
grid_dt.selectedrowchanged = function (rowindex) {
var rowdata = grid_dt.source[rowindex];
if (rowdata) {
curfewid = rowdata.Values.Id;
}
}
}
/************************** Machine********************************/
/*************************************************************************/
function OnMachineAdd() {
showmaskbg(true);
dialogAssets.exceptSource = grid_dtsm.innerSource.map(function (s) {
return s.Values.ID;
});
dialogAssets.companyId = $('#sel_contractor').val();
dialogAssets.showSelector();
$('#mask_bg').css('height', '100%');
}
var allMachines;
var _availableMachines = [];
var _selectedMachines = [];
var _showSelectedMachines = [];
function OnManageMachine(cur) {
$('#chk_showallassignedassets').prop('checked', false);
$('#txt_machine_key').val('');
var title = GetTextByKey("P_CM_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);
$('.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();
//getMachineTypes();
grid_dtsm.setData([]);
$('#selectedmachinelist input[type="checkbox"]').prop('checked', false);
GetSelectedMachines();
}
function getMachineTypes() {
pmquery('GetMachineTypes', '', function (data) {
var types = [];
types.push($('<option value="-1">All</option>'));
if (data && data.length > 0) {
for (var i = 0; i < data.length; i++) {
types.push($('<option></option>').val(data[i].ID).text(data[i].Name));
}
}
types[0].prop('selected', true);
$('#sel_machine_type').empty().append(types);
GetSelectedMachines();
});
}
// 获取已选中的machines
function GetSelectedMachines() {
_selectedMachines = [];
var contractorid = htmlencode($.trim($('#sel_contractor').val()));
$("#dialogmask").show();
curfewquery('GetSelectedAssets', contractorid + String.fromCharCode(170) + curfewid, function (data) {
if (typeof data === "string") {
showAlert(data, GetTextByKey("P_CM_ASSETASSIGNMENT", 'Asset Assignment'));
return;
}
_selectedMachines = data;
showSelectedMachine(_selectedMachines);
$("#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_CM_DELETEASSIGNEDASSET", 'Are you sure you want to delete the assigned asset: {0}?').replace('{0}', item.Name), GetTextByKey("P_CM_ASSETASSIGNMENT", 'Asset Assignment'), function () {
var params = [
htmlencode($.trim($('#sel_contractor').val())),
curfewid,
JSON.stringify([item.ID])
];
$("#dialogmask").show();
curfewquery('RemoveAssignedAssetsFromUser', params.join(String.fromCharCode(170)), function (r) {
$("#dialogmask").hide();
if (r !== 'OK') {
showAlert(r, GetTextByKey("P_CM_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_CM_DELETESELECTEDASSET", 'Are you sure you want to delete these selected assets?'), GetTextByKey("P_CM_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 = [
htmlencode($.trim($('#sel_contractor').val())),
curfewid,
JSON.stringify(ids)
];
$("#dialogmask").show();
curfewquery('RemoveAssignedAssetsFromUser', params.join(String.fromCharCode(170)), function (r) {
$("#dialogmask").hide();
if (r !== 'OK') {
showAlert(r, GetTextByKey("P_CM_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_CM_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_CM_MAKE", "Make"), valueIndex: 'MakeName', css: { 'width': 90, 'text-align': 'left' } },
{ name: 'ModelName', caption: GetTextByKey("P_CM_MODEL", "Model"), valueIndex: 'ModelName', css: { 'width': 90, 'text-align': 'left' } },
{ name: 'TypeName', caption: GetTextByKey("P_CM_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_CM_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) {
}
}
}
function OnSaveMachines() {
var machineids = [];
for (var i = 0; i < _selectedMachines.length; i++) {
var m = _selectedMachines[i];
machineids.push(m.MachineID);
}
var contractorid = htmlencode($.trim($('#sel_contractor').val()));
curfewquery("SaveCurfewMachines", contractorid + String.fromCharCode(170) + curfewid + String.fromCharCode(170) + JSON.stringify(machineids), function (data) {
if (data !== 'OK') {
showAlert(data, GetTextByKey("P_CM_SAVEASSET", 'Save asset'));
} else {
$('#dialog_managemahchine').hideDialog();
OnRefresh();
}
}, function (err) {
showAlert(GetTextByKey("P_CM_FAILEDTOSAVEASSET", 'Failed to save asset.'), GetTextByKey("P_CM_SAVEASSET", 'Save asset'));
});
}
/**************************End Machine********************************/
/*****************************************************************************/
/************************** Jobsite Assignment********************************/
/*************************************************************************/
var allJobsites;
var _availableJobsites = [];
var _selectedJobsites = [];
var _showSelectedJobsites = [];
function OnManageJobsite(cur) {
$('#txt_jobsite_key').val('');
$('#chk_showallassignedjobsites').prop('checked', false);
var title = GetTextByKey("P_CM_JOBSITEASSIGNMENT", "Jobsite Assignment");
$('#dialog_managejobsite .dialog-title span.title').html(title);
$('#mask_bg').show();
$('#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 = [];
var contractorid = htmlencode($.trim($('#sel_contractor').val()));
$("#jobsitedialogmask").show();
curfewquery('GetSelectedJobsites', contractorid + String.fromCharCode(170) + curfewid, function (data) {
if (typeof data === "string") {
showAlert(data, GetTextByKey("P_CM_JOBSITEASSIGNMENT", "Jobsite Assignment"));
return;
}
_selectedJobsites = data;
queryJobsites();
}, function (e) {
$("#jobsitedialogmask").hide();
});
}
function queryJobsites() {
var contractorid = htmlencode($.trim($('#sel_contractor').val()));
var searchtxt = htmlencode($('#txt_jobsite_key').val());
$('#button_jobsite_filter').prop('disabled', true);
setTimeout(function () {
$('#button_jobsite_filter').prop('disabled', false);
}, 1000);
_availableJobsites = [];
$("#jobsitedialogmask").show();
curfewquery('GetJobsiteList', contractorid + String.fromCharCode(170) + searchtxt, function (data) {
if (typeof data === "string") {
showAlert(data, GetTextByKey("P_CM_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;
if (jobsitefilter == "" || m.Name.toLowerCase().indexOf(jobsitefilter) >= 0) {
matched = true;
m.Highlight = showallassigned && jobsitefilter !== "";
_showSelectedJobsites.push(m);
}
else if (showallassigned)
unMatched.push(m);
}
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');
var list_columns = [
{ name: 'Name', caption: GetTextByKey("P_CM_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');
var list_columns = [
{ name: 'Name', caption: GetTextByKey("P_CM_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);
}
var contractorid = htmlencode($.trim($('#sel_contractor').val()));
curfewquery("SaveCurfewJobsites", contractorid + String.fromCharCode(170) + curfewid + String.fromCharCode(170) + JSON.stringify(jobsiteids), function (data) {
if (data !== 'OK') {
showAlert(data, GetTextByKey("P_CM_JOBSITEASSIGNMENT", "Jobsite Assignment"));
} else {
$('#dialog_managejobsite').hideDialog();
OnRefresh();
}
}, function (err) {
showAlert(GetTextByKey("P_CM_FAILEDTOSAVEJOBSITEASSIGNMENT", 'Failed to save jobsite assignment.'), GetTextByKey("P_CM_JOBSITEASSIGNMENT", "Jobsite Assignment"));
});
}
/**************************End JobSite Assignment********************************/
/*****************************************************************************/
var dialogAssets;
$(function () {
setPageTitle(GetTextByKey("P_CURFEWCONFIGURATION", 'Curfew Configuration'), true);
InitGridData();
//InitGridAvailableMachines();
InitGridSelectedMachines();
InitGridAvailableJobsites();
InitGridSelectedJobsites();
$('#tbody_curfew').click(function (e) {
var target = $(e.target);
if (!target.is('tr')) {
target = target.parents('tr');
}
$('#tbody_curfew tr').removeClass('selected');
target.addClass('selected');
});
$('#dialog_managemahchine').dialog(function () {
$('.machine_maskbg').hide();
});
$('#dialog_managejobsite').dialog(function () {
showmaskbg(false);
});
$('#button_jobsite_filter').click(getMatchAvailableJobsites);
$('#chk_showallassignedjobsites').click(getMatchSelectedJobsites);
if (IsDealer == true) {
$('#span_contractor').css('display', '');
if (IsAdmin)
getContractors();
else {
GetContractorsByUser();
}
}
else
OnRefresh();
$("#sel_contractor").change(function () {
OnRefresh();
});
$('#searchinputtxt').keydown(searchEnter);
$(window).resize(function () {
$("#curfewlist").css("height", $(window).height() - $("#curfewlist").offset().top - 4);
grid_dt && grid_dt.resize();
}).resize();
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 params = [
htmlencode($.trim($('#sel_contractor').val())),
curfewid,
JSON.stringify(items.map(function (f) { return f.Values.ID; }))
];
$("#dialogmask").show();
curfewquery('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_CM_ASSETASSIGNMENT", 'Asset Assignment'));
}
});
};
});
function searchEnter(e) {
if (e.keyCode == 13 || e.keyCode == 9) {
OnRefresh();
}
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div style="min-width: 400px;">
<div class="page_title" data-lgid="P_CURFEWCONFIGURATION">Curfew Configuration</div>
<div class="search_bar">
<input type="password" autocomplete="new-password" style="display: none" />
<span id="span_contractor" style="display: none;"><span data-lgid="P_CM_CONTRACTOR_COLON">Contractor:</span>
<select id="sel_contractor"></select></span>
<input type="text" id="searchinputtxt" autocomplete="off" />
<input class="search" type="button" onclick="OnRefresh();" value="Search" data-lgid="P_CM_SEARCH" style="margin-left: 5px;" />
</div>
<div class="function_title">
<span class="sbutton iconadd" onclick="OnAdd();" data-lgid="P_CM_ADD">Add</span>
<span class="sbutton iconrefresh" onclick="OnRefresh();" data-lgid="P_CM_REFRESH">Refresh</span>
</div>
<div class="clear"></div>
<div id="curfewlist"></div>
<div class="machine_maskbg" style="display: none;"></div>
<div class="dialog" id="dialog_managemahchine" style="display: none;">
<div id="dialogmask" class="maskbg" style="display: none; z-index: 1;">
<div class="loading_icon icon c-spin"></div>
</div>
<div class="dialog-title"><span class="title" data-lgid="P_CM_ASSETASSIGNMENT">Asset Assignment</span><em class="dialog-close"></em></div>
<div class="machine_filter" style="display: none">
<span data-lgid="P_CM_TYPE_COLON">Type: </span>
<select id="sel_machine_type" tabindex="20"></select>
<input type="text" id="txt_machine_key" tabindex="21" />
<input type="button" class="ybutton" id="button_machine_filter" value="Filter" data-lgid="P_CM_FILTER" tabindex="22" />
<span id="span_text_holder" style="display: none;"></span>
</div>
<div class="machine_filter" style="margin: 9px 6px 7px">
<span class="sbutton iconadd" onclick="OnMachineAdd()" data-lgid="P_CM_ADD">Add</span>
<span class="sbutton icondelete" onclick="OnMachineDelete()" data-lgid="P_CM_DELETE">Delete</span>
</div>
<div class="div_machines">
<table class="table_holder">
<thead>
<tr style="display: none">
<td>Available Assets</td>
<td></td>
<td>Assigned Assets
<input type="checkbox" id="chk_showallassignedassets" title="When checked, all associated or linked items will display regardless of filter. " /><label for="chk_showallassignedassets">Show All Assigned</label>
</td>
</tr>
</thead>
<tbody>
<tr>
<td style="padding: 2px 4px 4px">
<div id="selectedmachinelist" style="height: 500px; width: 780px;"></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="dialog-func">
<input type="button" value="Close" data-lgid="P_CM_CLOSE" class="dialog-close" tabindex="28" />
<input type="button" onclick="OnSaveMachines();" value="OK" data-lgid="P_CM_OK" tabindex="27" style="display: none" />
<div class="clear"></div>
</div>
</div>
<div id="mask_bg" style="display: none;">
<div class="loading c-spin"></div>
</div>
<div class="dialog" id="dialog_curfew" style="display: none; height: 100%; border-bottom: 0; border-top: 0;">
<iframe id="iframecurfew" src="AddCurfew.aspx" style="width: 100%; height: 100%; display: block; border: none;"></iframe>
<div class="maskbg" style="display: none;"></div>
</div>
<div class="dialog" id="dialog_managejobsite" style="display: none;">
<div id="jobsitedialogmask" class="maskbg" style="display: none; z-index: 1;">
<div class="loading_icon icon c-spin"></div>
</div>
<div class="dialog-title"><span class="title" data-lgid="P_CM_JOBSITEASSIGNMENT">Jobsite Assignment</span><em class="dialog-close"></em></div>
<div class="machine_filter">
<input type="text" id="txt_jobsite_key" style="margin-left: 8px; width: 280px;" tabindex="40" />
<input type="button" class="ybutton" id="button_jobsite_filter" data-lgid="P_CM_FILTER" value="Filter" tabindex="42" />
</div>
<div class="div_machines">
<table class="table_holder">
<thead>
<tr>
<td data-lgid="P_CM_AVAILABLEJOBSITES">Available Jobsites</td>
<td></td>
<td data-lgid="P_CM_ASSIGNEDJOBSITES">Assigned Jobsites
<input type="checkbox" id="chk_showallassignedjobsites" title="When checked, all associated or linked items will display regardless of filter. " data-title-lgid="P_CM_SHOWALLASSIGNEDCONTACTSTITLE" /><label for="chk_showallassignedjobsites" data-lgid="P_CURFEWCONFIGURATION">Show All Assigned</label>
</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<div id="availablejobsitelist" style="height: 400px; width: 410px;"></div>
</td>
<td class="td_controller">
<input class="ctl_button" type="button" value="&#xe62b;" onclick="OnJobsiteEditorAdd();" tabindex="42" />
<input class="ctl_button" type="button" value="&#xe632;" onclick="OnJobsiteEditorAddAll();" tabindex="43" />
<input class="ctl_button" type="button" value="&#xe62a;" onclick="OnJobsiteEditorRemove();" tabindex="44" />
<input class="ctl_button" type="button" value="&#xe631;" onclick="OnJobsiteEditorRemoveAll();" tabindex="45" />
</td>
<td>
<div id="selectedjobsitelist" style="height: 400px; width: 410px;"></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="dialog-func">
<input type="button" value="Cancel" data-lgid="P_CM_CANCEL" class="dialog-close" tabindex="47" />
<input type="button" onclick="OnSaveJobsites();" value="OK" data-lgid="P_CM_OK" tabindex="46" />
<div class="clear"></div>
</div>
</div>
</div>
</asp:Content>