353 lines
13 KiB
JavaScript
353 lines
13 KiB
JavaScript
var ALL_TEXT = "(All)";
|
|
var ALL_VALUE = "@all";
|
|
|
|
$(function () {
|
|
// global event
|
|
|
|
$(document).mousedown(function (e) {
|
|
var t = $(e.target);
|
|
if (!t.hasClass("div_filter"))
|
|
t = t.parents(".div_filter");
|
|
if (t.length == 0) $('.div_panel').hide();
|
|
var divpanel = t.find(".div_panel");
|
|
$('.div_panel').each(function () {
|
|
if (!$(this).is(divpanel))
|
|
divpanel.hide();
|
|
});
|
|
});
|
|
}());
|
|
|
|
|
|
function getMapAlertLayerLang(texts, defaulttext) {
|
|
if (!texts || texts.length == 0)
|
|
return defaulttext;
|
|
|
|
var fr_langs = ["fr-fr", "fr-ca"];
|
|
for (var i = 0; i < texts.length; i++) {
|
|
var t = texts[i];
|
|
if (_fleet.currentLang === t.Key) {
|
|
if (t.Value === "") {
|
|
if (fr_langs.indexOf(t.Key) >= 0) {//需先找父语种 fr 是否有值
|
|
for (var j = 0; j < texts.length; j++) {
|
|
if (texts[j].Key === "fr") {
|
|
if (texts[j].Value === "")
|
|
return defaulttext
|
|
else
|
|
return texts[j].Value;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
return defaulttext;
|
|
}
|
|
else
|
|
return t.Value;
|
|
}
|
|
}
|
|
return defaulttext;
|
|
}
|
|
|
|
function showMapAlertLayer(data) {
|
|
var opt = $('<option></option>').val("").text("(None)");
|
|
var sel = $("#selMapAlertLayer");
|
|
sel.empty();
|
|
sel.append(opt);
|
|
for (var i = 0; i < data.length; i++) {
|
|
var mal = data[i];
|
|
opt = $('<option></option>').val(mal.ID).text(getMapAlertLayerLang(mal.LocalNames, mal.Name)).data("mal", mal);
|
|
sel.append(opt);
|
|
}
|
|
if (userParams && userParams.MapAlertLayer) {
|
|
sel.val(userParams.MapAlertLayer);
|
|
}
|
|
showMapAlertLayerDetail();
|
|
}
|
|
|
|
function showMapAlertLayerDetail() {
|
|
var mal = $("#selMapAlertLayer").find("option:selected").data("mal");
|
|
var tb = $("#tbLegend");
|
|
tb.empty();
|
|
var haspramameter = false;
|
|
if (mal && mal.Layers) {
|
|
for (var i = 0; i < mal.Layers.length; i++) {
|
|
var layer = mal.Layers[i];
|
|
if ((layer.Pivots && layer.Pivots.length > 0))
|
|
haspramameter = true;
|
|
|
|
var tr = $("<tr style='border-bottom: 1px solid lightgray;'></tr>");
|
|
tb.append(tr);
|
|
|
|
var td = $("<td></td>").css("width", 30);
|
|
td.append($("<img></img>").attr("src", layer.LegendUrl).css({ "width": 18, "vertical-align": "middle" }));
|
|
tr.append(td);
|
|
|
|
td = $("<td></td>").html(getMapAlertLayerLang(layer.LocalTitles, layer.Title)).css({ "padding-left": 10, "width": 220 });
|
|
tr.append(td);
|
|
}
|
|
}
|
|
|
|
var staticlegend = ["InMotion", "StoppedOn", "StoppedOff", "CGain", "CLoss", "RoadClosure", "LaneClosure", "DriverInsights", "SeatBelt"];
|
|
var staticlegendtitle = [GetTextByKey("P_MA_INMOTION", "In Motion"), GetTextByKey("P_MA_STOPPEDON", "Stopped On"), GetTextByKey("P_MA_STOPPEDOFF", "Stopped Off"), GetTextByKey("P_MA_CONNECTIVITYRECOVERY", "Connectivity Recovery"), GetTextByKey("P_MA_CONNECTIVITYLOSS", "Connectivity Loss"), GetTextByKey("P_MA_ROADCLOSURE", "Road Closure"), GetTextByKey("P_MA_LANECLOSURE", "Lane Closure"), GetTextByKey("P_MA_DRIVERINSIGHTS", "Driver Insights"), GetTextByKey("P_MV_SEATBELTNOTDETECTED", "Seat Belt Not Detected")];
|
|
for (var i = 0; i < staticlegend.length; i++) {
|
|
var tr = $("<tr style='border-bottom: 1px solid lightgray;'></tr>");
|
|
tb.append(tr);
|
|
|
|
var url = userParams.MachineIconURL + "?legend=" + staticlegend[i];
|
|
var td = $("<td></td>").css("width", 30);
|
|
td.append($("<img></img>").attr("src", url).css({ "width": 18, "vertical-align": "middle" }));
|
|
tr.append(td);
|
|
|
|
td = $("<td></td>").html(staticlegendtitle[i]).css({ "padding-left": 10, "width": 220 });
|
|
tr.append(td);
|
|
}
|
|
|
|
var harshdrivinglegend = ["#ff3f48cc", "#ff00a8f3", "#ffff89e6", "#ffff7f27", "#ffec1c24"];
|
|
var harshdrivingtitle = [GetTextByKey("P_MA_HARDACCELERATION", "Hard Acceleration"), GetTextByKey("P_MA_HARDBRAKE", "Hard Brake"), GetTextByKey("P_MA_HARDTURN", "Hard Turn"), GetTextByKey("P_MA_SPEEDINGLOWSEVERITY", "Speeding: Low Severity"), GetTextByKey("P_MA_SPEEDINGHIGHSEVERITY", "Speeding: High Severity")];
|
|
for (var i = 0; i < harshdrivinglegend.length; i++) {
|
|
var tr = $("<tr style='border-bottom: 1px solid lightgray;'></tr>");
|
|
tb.append(tr);
|
|
|
|
var ironurl = userParams.MachineMovingIconURL;
|
|
var url = ironurl + "?tp=0&bkcolor=" + encodeURIComponent(harshdrivinglegend[i]) + "&heading=45";
|
|
var td = $("<td></td>").css("width", 30);
|
|
td.append($("<img></img>").attr("src", url).css({ "width": 18, "vertical-align": "middle" }));
|
|
tr.append(td);
|
|
|
|
td = $("<td></td>").html(harshdrivingtitle[i]).css({ "padding-left": 10, "width": 220 });
|
|
tr.append(td);
|
|
}
|
|
|
|
if (haspramameter) {
|
|
$('#setparameter').css('display', '');
|
|
}
|
|
else {
|
|
$('#setparameter').css('display', 'none');
|
|
}
|
|
var right = $('#mapAlertLayerDiv').width() + 100;
|
|
$('#filterIconDiv').css('right', right);
|
|
}
|
|
|
|
function setParameterDatimeTimePicker(ipt) {
|
|
ipt.datetimepicker({
|
|
timepicker: false,
|
|
format: 'm/d/Y',
|
|
enterLikeTab: false,
|
|
onSelectDate: function (v, inp) {
|
|
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
|
|
inp.parent().data('val', [date]);
|
|
}
|
|
});
|
|
}
|
|
|
|
function getAlertLayerParameters() {
|
|
if (parameterinput.length > 0) {//更新参数选择的值
|
|
for (var l = 0; l < parameterinput.length; l++) {
|
|
var ipt = parameterinput[l];
|
|
var param = ipt.data("parameter");
|
|
if (ipt.data('inputtype') == "dropdown") {
|
|
if (ipt.allselected())
|
|
param.ParameterValue = ALL_VALUE;
|
|
else if (param.IsField && param.MutipleSelect)
|
|
param.ParameterValue = ipt.dropdownVals().join(',');
|
|
else
|
|
param.ParameterValue = ipt.dropdownVal();
|
|
}
|
|
else
|
|
param.ParameterValue = ipt.val();
|
|
}
|
|
}
|
|
|
|
var mal = $("#selMapAlertLayer").find("option:selected").data("mal");
|
|
if (mal)
|
|
return mal.Layers;
|
|
return null;
|
|
}
|
|
|
|
|
|
var parameterinput = [];
|
|
var paramindex = -1;
|
|
function setAlertLayerParameters() {
|
|
parameterinput = [];
|
|
paramindex = -1;
|
|
var ul = $("#ul_parameter");
|
|
ul.empty();
|
|
var pdiv = $("#parameter_right");
|
|
pdiv.empty();
|
|
var mal = $("#selMapAlertLayer").find("option:selected").data("mal");
|
|
|
|
var layerHasParam = 0;
|
|
if (mal && mal.Layers) {
|
|
for (var i = 0; i < mal.Layers.length; i++) {
|
|
var layer = mal.Layers[i];
|
|
|
|
if (layer && layer.Pivots) {
|
|
var li = $("<li class='nav_item'></li>").data("layerid", layer.ID).click(layerHasParam++, layerclick);
|
|
|
|
var img = $("<img></img>").attr("src", layer.LegendUrl).css({ "width": 18, "vertical-align": "middle" });
|
|
var span = $("<span></span>").text(getMapAlertLayerLang(layer.LocalTitles, layer.Title)).css({ "margin-left": 10, "vertical-align": "middle" });
|
|
li.append(img).append(span);
|
|
ul.append(li);
|
|
var tb = $("<table class='tb_parameter'></table>").data("layerid", layer.ID);
|
|
if (layerHasParam == 1)
|
|
li.addClass("selected");
|
|
else
|
|
tb.css('display', 'none');
|
|
|
|
pdiv.append(tb);
|
|
//if (criteriaparam && criteriaparam.length > 0)
|
|
// createParameters(criteriaparam, tb, 1);
|
|
|
|
//if (alertparam && alertparam.length > 0)
|
|
// createParameters(alertparam, tb, 2);
|
|
|
|
if (layer.Pivots && layer.Pivots.length > 0)
|
|
createParameters(layer.Pivots, tb);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function createParameters(params, tb) {
|
|
var criteriaTitle = false;
|
|
var alertTitle = false;
|
|
for (var j = 0; j < params.length; j++) {
|
|
var param = params[j];
|
|
|
|
if (param.IsCriteriaSQL && !criteriaTitle) {
|
|
var tr = $("<tr></tr>").append("<td colspan='2' style='padding-left:10px;font-weight:bold;font-size:16px;'>" + GetTextByKey("P_MV_CRITERIA", "Criteria") + "</td>");
|
|
tb.append(tr);
|
|
criteriaTitle = true;
|
|
}
|
|
|
|
if (!param.IsCriteriaSQL && !alertTitle) {
|
|
var tr = $("<tr></tr>").append("<td colspan='2' style='padding-left:10px;font-weight:bold;font-size:16px;'>" + GetTextByKey("P_MV_ALERT", "Alert") + "</td>");
|
|
tb.append(tr);
|
|
alertTitle = true;
|
|
}
|
|
|
|
var tr_param = $("<tr></tr>");
|
|
tb.append(tr_param);
|
|
tr_param.append($("<td></td>").addClass('td_paramtype').html(getMapAlertLayerLang(param.LocalCaptions, param.Caption)));
|
|
var td = $("<td></td>");
|
|
|
|
var ipt = createParameterInput(param);
|
|
parameterinput.push(ipt);
|
|
if (param.DataType == 3 && param.DisplayStyle != 1 && param.DisplayStyle != 2) {
|
|
setParameterDatimeTimePicker(ipt);
|
|
}
|
|
td.append(ipt);
|
|
tr_param.append(td);
|
|
}
|
|
}
|
|
|
|
function FALSE() { return false; }
|
|
var idindex = 0;
|
|
|
|
function createParameterInput(param) {
|
|
var paramvalue = getParameterValue(param.ID, param.IsCriteriaSQL);
|
|
if (paramvalue == null)
|
|
paramvalue = param.DefaultValue;
|
|
|
|
if (param.DisplayStyle == 0) {//inputbox
|
|
return $("<input type='text' />").val(paramvalue).data("parameter", param)
|
|
.attr("paramcaption", param.Name.toLowerCase())
|
|
.keyup(function () {
|
|
$("[paramcaption='" + param.Name.toLowerCase() + "']").val($(this).val());
|
|
}).change(function () {
|
|
$("[paramcaption='" + param.Name.toLowerCase() + "']").val($(this).val());
|
|
});
|
|
}
|
|
else if (param.DisplayStyle == 1 || param.DisplayStyle == 2) {//Dropdown or Combobox
|
|
var divcontrol = $('<div class="div_filter"></div>').data("parameter", param).data('inputtype', "dropdown");
|
|
var ds = getLookupDatasource(param.LookupDatasourceID);
|
|
var source = [...ds.Items];
|
|
if (param.IsAllAllowed && !(param.IsField && param.MutipleSelect))//单选加入all选项
|
|
source.splice(0, 0, { Key: ALL_VALUE, Value: ALL_TEXT });
|
|
divcontrol.css('width', 200).dropdown(source, {
|
|
search: true,
|
|
multiselect: param.IsField && param.MutipleSelect,
|
|
valueKey: 'Key',
|
|
allowselectall: param.IsAllAllowed,
|
|
textKey: param.DisplayCaptionField ? "Value" : "Key"
|
|
});
|
|
if (param.IsField && param.MutipleSelect) {
|
|
if (paramvalue == ALL_VALUE)
|
|
divcontrol.allselected(true);
|
|
else if (paramvalue)
|
|
divcontrol.dropdownVals(paramvalue.split(','));
|
|
}
|
|
else
|
|
divcontrol.dropdownVal(paramvalue);
|
|
return divcontrol;
|
|
}
|
|
}
|
|
|
|
function getLookupDatasource(dsid) {
|
|
var mal = $("#selMapAlertLayer").find("option:selected").data("mal");
|
|
if (mal && mal.LookupDataSources) {
|
|
for (var i = 0; i < mal.LookupDataSources.length; i++) {
|
|
var ds = mal.LookupDataSources[i];
|
|
if (ds.ID.toLowerCase() == dsid.toLowerCase())
|
|
return ds;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function layerclick(e) {
|
|
$('#ul_parameter li').removeClass("selected");
|
|
$(this).addClass("selected");
|
|
var index = e.data;
|
|
var tbs = $('.tb_parameter');
|
|
tbs.hide();
|
|
$(tbs[index]).show();
|
|
|
|
}
|
|
|
|
function getParameterValue(paramid, isCriteria) {
|
|
if (parametervalues && parametervalues.length > 0) {
|
|
for (var i = 0; i < parametervalues.length; i++) {
|
|
var layer = parametervalues[i];
|
|
if (!layer.Pivots) continue;
|
|
var params = [];
|
|
for (var j = 0; j < layer.Pivots.length; j++) {
|
|
if (layer.Pivots[j].IsCriteriaSQL == isCriteria)
|
|
params.push(layer.Pivots[j])
|
|
}
|
|
|
|
if (layer && (params || params)) {
|
|
for (var k = 0; k < params.length; k++) {
|
|
var param = params[k];
|
|
if (param.ID == paramid)
|
|
return param.ParameterValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function openSetAlertLayerParameters() {
|
|
setAlertLayerParameters();
|
|
showmaskbg(true);
|
|
$('#dialog_parameter .dialog-title span.title').text(GetTextByKey("P_MV_PIVOTS", 'Pivots'));
|
|
$('#dialog_parameter')
|
|
.attr('act', 'edit')
|
|
.css({
|
|
'width': 570,
|
|
'top': (document.documentElement.clientHeight - $('#dialog_parameter').height()) / 2,
|
|
'left': (document.documentElement.clientWidth - $('#dialog_parameter').width()) / 2
|
|
})
|
|
.showDialogfixed();
|
|
pivotsDialogOpend = true;
|
|
}
|
|
|
|
var parametervalues;
|
|
function setParameterCompleted() {
|
|
parametervalues = getAlertLayerParameters();
|
|
assetObject.searchMachine(false);
|
|
$('#dialog_parameter').hideDialog();
|
|
showmaskbg(false);
|
|
pivotsDialogOpend = false;
|
|
}
|