var ALL_TEXT = "(All)";
var ALL_VALUE = "@all";
$(function () {
// global event
}());
function showMapAlertLayer(data) {
var opt = $('').val("").text("(None)");
var sel = $("#selMapAlertLayer");
sel.empty();
sel.append(opt);
for (var i = 0; i < data.length; i++) {
var mal = data[i];
opt = $('').val(mal.ID).text(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) {
//var tr = $("
").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('commoninput'))
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];
var criteriaparam = layer.CriteriaSQLParameters;
var alertparam = layer.AlertSQLParameters;
if (layer && (criteriaparam || alertparam)) {
var li = $("").data("layerid", layer.ID).click(layerHasParam++, layerclick);
if (layer.IconColor.length == 9)
layer.IconColor = "#" + layer.IconColor.substring(3);
var img = $("").attr("src", layer.LegendUrl).css({ "width": 18, "vertical-align": "middle" });
var span = $("").text(layer.Title).css({ "margin-left": 10, "vertical-align": "middle" });
li.append(img).append(span);
ul.append(li);
var tb = $("
").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);
}
}
}
}
function createParameters(params, tb, type) {
var tr = $("
").append("
Criteria
");
tb.append(tr);
for (var j = 0; j < params.length; j++) {
var param = params[j];
var tr_param = $("
");
tb.append(tr_param);
tr_param.append($("
").addClass('td_paramtype').html(param.Caption));
var td = $("
");
var ipt = createParameterInput(param, type, j);
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; }
function createParameterInput(param, type) {
var paramvalue = getParameterValue(param.ID, type);
if (paramvalue == null)
paramvalue = param.DefaultValue;
if (param.DisplayStyle == 0) {//inputbox
return $("").val(paramvalue).data("parameter", param).data('commoninput', true)
.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 defaultcheckall = false;
if (param.IsAllAllowed && paramvalue === ALL_VALUE)
defaultcheckall = true;
if (param.IsField && param.MutipleSelect) {//多选
var divcontrol = $('').data("parameter", param);
var seldiv = $('');
var span = $('');
var spanimg = $('');
var divpanel = $('');
var ul = $('
');
divpanel.append(ul).mousedown(FALSE);
seldiv.append(span).append(spanimg).append(divpanel);
seldiv.mousedown(function () {
$('.div_panel').each(function () {
var t = $(this);
if (!t.is(divpanel))
t.css('display', 'none');
});
var display = divpanel.css('display');
if (display == 'none') {
divpanel.css({ 'display': 'block' });
} else {
divpanel.css('display', 'none');
}
return false;
});
var itemclick = function (isall, checked) {
var chks = ul.find('input');
if (isall) {
chks.prop('checked', checked);
if (checked) {
span.attr('title', ALL_TEXT).text(ALL_TEXT);
param.ParameterValue = ALL_VALUE;
}
else {
span.attr('title', "").text("");
param.ParameterValue = "";
}
return;
}
else {
if (chkall)
chkall.prop('checked', false);//(ALL)取消选中
}
var texts = [];
var paramvalues = [];
for (var i = 0; i < chks.length; i++) {
var c = $(chks[i]);
if (c.prop('checked')) {
var text = c.next('label').text();
if (!text) text = c.val();
texts.push(text);
paramvalues.push(c.val());
}
}
texts = texts.join(', ');
span.attr('title', texts).text(texts);
paramvalues = paramvalues.join('^');
param.ParameterValue = paramvalues;
};
var chkall = undefined;
if (param.IsAllAllowed) {
var liall = $('');
chkall = $('');
if (defaultcheckall)
chkall.attr('checked', true);
chkall.change(function () {//全选
itemclick(true, $(this).prop('checked'));
});
liall.append(chkall);
liall.append($('').text(ALL_TEXT));
ul.append(liall);
}
var ds = getLookupDatasource(param.LookupDatasourceID)
if (ds && ds.Items) {
var paramvalueAry = paramvalue.split("^");
var texts = [];
for (var s = 0; s < ds.Items.length; s++) {
var item = ds.Items[s];
var txt = param.DisplayCaptionField ? item.Value : item.Key;
var li = $('');
var chk = $('').val(item.Key).attr("id", "chkp" + ++paramindex);
chk.change(function () {
itemclick(false, $(this).prop('checked'));
});
li.append(chk);
li.append($('').text(txt));
ul.append(li);
if (defaultcheckall || paramvalueAry.indexOf(item.Key) > -1) {//选中默认值
chk.attr('checked', true);
var text = chk.next('label').text();
if (!text) text = chk.val();
texts.push(text);
}
}
if (defaultcheckall)
texts = ALL_TEXT;
else
texts = texts.join(', ');
span.attr('title', texts).text(texts);
param.ParameterValue = paramvalue;
}
divcontrol.append(seldiv);
return divcontrol;
}
else {
var sel = $("").data("parameter", param).data('commoninput', true)
.attr("paramcaption", param.Name.toLowerCase())
.change(function () {
$("[paramcaption='" + param.Name.toLowerCase() + "']").val($(this).val());
});
var ds = getLookupDatasource(param.LookupDatasourceID)
if (ds && ds.Items) {
if (param.IsField && param.IsAllAllowed) {
var opall = $("").val(ALL_VALUE).text(ALL_TEXT);
sel.append(opall);
}
for (var s = 0; s < ds.Items.length; s++) {
var item = ds.Items[s];
var opt = $("").val(item.Key);
var txt = param.DisplayCaptionField ? item.Value : item.Key;
opt.text(txt);
sel.append(opt);
}
sel.val(paramvalue);
}
return sel;
}
}
}
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, paramtype) {
if (parametervalues && parametervalues.length > 0) {
for (var i = 0; i < parametervalues.length; i++) {
var layer = parametervalues[i];
var params;
if (paramtype == 1)
params = layer.CriteriaSQLParameters;
else
params = layer.AlertSQLParameters;
if (layer && (params || params)) {
for (var j = 0; j < params.length; j++) {
var param = params[j];
if (param.ID == paramid)
return param.ParameterValue;
}
}
}
}
return null;
}
function openSetAlertLayerParameters() {
setAlertLayerParameters();
showmaskbg(true);
$('#dialog_parameter .dialog-title span.title').text('Pivots');
$('#dialog_parameter')
.attr('act', 'edit')
.css({
'width': 570,
'top': (document.documentElement.clientHeight - $('#dialog_parameter').height()) / 4,
'left': (document.documentElement.clientWidth - $('#dialog_parameter').width()) / 2
})
.showDialog();
pivotsDialogOpend = true;
}
var parametervalues;
function setParameterCompleted() {
parametervalues = getAlertLayerParameters();
machineObject.searchMachine(false);
$('#dialog_parameter').hideDialog();
showmaskbg(false);
pivotsDialogOpend = false;
}