266 lines
11 KiB
JavaScript
266 lines
11 KiB
JavaScript
/// <reference path="../../js/jquery-3.6.0.min.js" />
|
|
/// <reference path="../../js/utility.js" />
|
|
|
|
_am = {};
|
|
|
|
(function () {
|
|
_am.focusAlertMappingItem = function (tr) {
|
|
tr.find('.general').css('display', 'none');
|
|
tr.find('.editing').css('display', 'block');
|
|
};
|
|
|
|
_am.addAlertMappingItem = function (mappingid, edesc) {
|
|
$('#dialog_make').dropdownVal(null);
|
|
$('#dialog_model').dropdownVals([]);
|
|
$('#dialog_alerttype').dropdownVal(null);
|
|
//$('#dialog_description').dropdownVal(null);
|
|
$('#dialog_description').text(edesc);
|
|
$('#dialog_category').dropdownVal(null);
|
|
|
|
showmaskbg(true);
|
|
$('#dialog_alertmappingitem').attr('data-mappingid', mappingid)
|
|
.css({
|
|
'top': ($(window).height() - $('#dialog_alertmappingitem').height()) / 3,
|
|
'left': ($(window).width() - $('#dialog_alertmappingitem').width()) / 3
|
|
}).showDialogfixed();
|
|
$('#dig_name').focus();
|
|
};
|
|
_am.deleteAlertMappingItem = function (e, alertmapping) {
|
|
var tr = $(this).parents('tr:first');
|
|
var id = tr.attr('data-id');
|
|
var alerttitle = GetTextByKey("P_AMP_DELETE", 'Delete');
|
|
var comfirmmsg = GetTextByKey("P_AMP_DOYOUWANTTODELETETHISALERTMAPPINGITEM", 'Do you want to delete this alert mapping item?');
|
|
if (e.data || !id) {
|
|
showConfirm(comfirmmsg, alerttitle, function (e) {
|
|
tr.remove();
|
|
});
|
|
} else {
|
|
showConfirm(comfirmmsg, alerttitle, function (e) {
|
|
alertquery('DeleteAlertMappingItem', id, function (data) {
|
|
if (!data || data.length == 0) {
|
|
var subctrls = tr.data('subctrls');
|
|
alertmapping.Items.splice(alertmapping.Items.indexOf(subctrls.item), 1);
|
|
tr.remove();
|
|
} else {
|
|
showAlert(data, alerttitle);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
};
|
|
|
|
_am.checkAlertMappingItem = function (item) {
|
|
var alerttitle = GetTextByKey("P_AMP_SAVEALERTMAPPINGITEM", 'Save Alert Mapping Item');
|
|
if (!item.Make) {
|
|
showAlert(GetTextByKey("P_AMP_MAKEISREQUIRED", 'Make is required.'), alerttitle);
|
|
return false;
|
|
}
|
|
if (!item.Models || item.Models.length == 0) {
|
|
showAlert(GetTextByKey("P_AMP_MODELISREQUIRED", 'Model is required.'), alerttitle);
|
|
return false;
|
|
}
|
|
//if (!item.AlertType || item.AlertType.length == 0) {
|
|
// showAlert(GetTextByKey("P_AMP_ALERTTYPEISREQUIRED", 'Alert Type is required.'), alerttitle);
|
|
// return false;
|
|
//}
|
|
//if (!item.DescriptionId || item.DescriptionId <= 0) {
|
|
// showAlert(GetTextByKey("P_AMP_DESCRIPTIONISREQUIRED", 'Description is required.'), alerttitle);
|
|
// return false;
|
|
//}
|
|
//if (!item.CategoryId || item.CategoryId <= 0) {
|
|
// showAlert(GetTextByKey("P_AMP_CATEGORYISREQUIRED", 'Category is required.'), alerttitle);
|
|
// return false;
|
|
//}
|
|
return true;
|
|
};
|
|
|
|
_am.saveAlertMappingItem = function (alertmapping) {
|
|
var tr = $(this).parents('tr:first');
|
|
function next() {
|
|
subctrls.item.Make = item.Make;
|
|
subctrls.item.Models = item.Models;
|
|
subctrls.item.AlertType = item.AlertType;
|
|
//subctrls.item.DescriptionId = item.DescriptionId;
|
|
subctrls.item.CategoryId = item.CategoryId;
|
|
|
|
createAlertMappingItem(alertmapping, tr.parents('tbody:first'));
|
|
}
|
|
|
|
var subctrls = tr.data('subctrls');
|
|
var item = {
|
|
'Id': parseInt(tr.attr('data-id')),
|
|
'MappingId': parseInt(tr.attr('data-mappingid')),
|
|
'Make': subctrls.divmake.dropdownVal(),
|
|
'Models': subctrls.divmodel.dropdownVals(),
|
|
'AlertType': subctrls.divalerttype.dropdownVal(),
|
|
//'DescriptionId': subctrls.divdesc.dropdownVal(),
|
|
'CategoryId': subctrls.divcategory.dropdownVal() || "-1"
|
|
};
|
|
if (item.Models.length == 0 && subctrls.divmodel.allselected())
|
|
item.Models = [-1];
|
|
if (!_am.checkAlertMappingItem(item)) {
|
|
return;
|
|
}
|
|
|
|
alertquery('SaveAlertMappingItem', htmlencode(JSON.stringify(item)), function (data) {
|
|
if (data > 0) {
|
|
next();
|
|
}
|
|
else if (data == -1) {
|
|
showAlert(GetTextByKey('P_AMP_THISCOMBINATIONOFMAKEANDMODELSALREADYEXISTS', 'This combination of Make and Models already exists. '), title);
|
|
}
|
|
else {
|
|
showAlert(data, GetTextByKey("P_AMP_SAVEALERTMAPPINGITEM", 'Save Alert Mapping Item'));
|
|
}
|
|
});
|
|
};
|
|
_am.cancelAlertMappingSave = function (e) {
|
|
var tr = $(this).parents('tr:first');
|
|
tr.find('input[type="text"]').removeClass('focused');
|
|
tr.find('textarea').removeClass('focused');
|
|
tr.find('select').removeClass('focused');
|
|
tr.find('.general').css('display', 'block');
|
|
tr.find('.editing').css('display', 'none');
|
|
var inps = tr.find('input');
|
|
for (var i = 0; i < inps.length; i++) {
|
|
var inp = $(inps[i]);
|
|
var data = inp.attr('data-ori');
|
|
if (inp.attr('type') == 'text') {
|
|
inp.val(data || '');
|
|
} else if (inp.attr('type') == 'checkbox') {
|
|
inp.prop('checked', eval(data));
|
|
}
|
|
}
|
|
var recurring = tr.find('.inp_recurring').prop('checked');
|
|
var inp = tr.find('.inp_priority');
|
|
inp.prop('disabled', !recurring);
|
|
if (recurring) {
|
|
inp.parent('td').removeClass('gray_field');
|
|
} else {
|
|
inp.parent('td').addClass('gray_field');
|
|
}
|
|
|
|
var textarea = tr.find('.textarea_desc');
|
|
var desc = $(textarea).attr('data-ori');
|
|
$(textarea).val(desc);
|
|
};
|
|
|
|
_am.createAlertMappingTr = function (item, alertmapping) {
|
|
|
|
var tr = $('<tr></tr>').attr('data-id', item.Id).attr('data-mappingid', item.MappingId);
|
|
var td;
|
|
td = $('<td></td>');
|
|
var divmake = $('<div></div>');
|
|
td.append(divmake);
|
|
tr.append(td);
|
|
divmake.css('width', 200).css('position', 'relative').dropdown(alertMappingDataSource.Makes, {
|
|
search: true,
|
|
valueKey: 'ID',
|
|
textKey: 'Name'
|
|
}).on('select', function (_e, it) {
|
|
_am.focusAlertMappingItem(tr);
|
|
if (it) {
|
|
var r = filterModels(it.ID, item.Id, alertmapping);
|
|
divmodel.allowselectall(r.allowAll).dropdownSource(r.models).dropdownVals([]);
|
|
if (it.ID == -1 && r.allowAll)
|
|
divmodel.allselected(true);
|
|
else
|
|
divmodel.dropdownVals([]);
|
|
}
|
|
}).dropdownVal(item.Make);
|
|
|
|
td = $('<td></td>');
|
|
var divmodel = $('<div></div>');
|
|
td.append(divmodel);
|
|
tr.append(td);
|
|
divmodel.css('width', 320).css('position', 'relative').dropdown([], {
|
|
search: true,
|
|
multiselect: true,
|
|
//allowselectall: false,
|
|
valueKey: 'ID',
|
|
textKey: 'Name',
|
|
enableKey: 'Enable'
|
|
}).on('collapsed', function (_e) {
|
|
if (item.Models.toString() != divmodel.dropdownVals().toString())
|
|
_am.focusAlertMappingItem(tr);
|
|
});
|
|
var r = filterModels(item.Make, item.Id, alertmapping);
|
|
divmodel.allowselectall(r.allowAll).dropdownSource(r.models).dropdownVals(item.Models);
|
|
if (item.Models.length == 1 && item.Models[0] == -1)
|
|
divmodel.allselected(true);
|
|
|
|
|
|
td = $('<td></td>');
|
|
var divalerttype = $('<div></div>');
|
|
td.append(divalerttype);
|
|
tr.append(td);
|
|
divalerttype.css('width', 200).css('position', 'relative').dropdown(alertMappingDataSource.AlertTypes, {
|
|
search: false,
|
|
valueKey: 'ID',
|
|
textKey: 'Name'
|
|
}).on('select', function (_e, it) {
|
|
_am.focusAlertMappingItem(tr);
|
|
}).dropdownVal(item.AlertType);
|
|
|
|
td = $('<td></td>');
|
|
var divdesc = $('<div></div>').css('width', 400).text(alertmapping.EnhancedDescription);
|
|
td.append(divdesc);
|
|
tr.append(td);
|
|
|
|
//td = $('<td></td>');
|
|
//var divdesc = $('<div class="descdropdown"></div>');
|
|
//td.append(divdesc);
|
|
//tr.append(td);
|
|
//divdesc.css('width', 400).css('position', 'relative').dropdown(alertMappingDataSource.Descriptions, {
|
|
// search: true,
|
|
// valueKey: 'ID',
|
|
// textKey: 'Name'
|
|
//}).on('select', function (_e, it) {
|
|
// if (it && it.ID == "") {
|
|
// divdesc.dropdownVal(item.DescriptionId);
|
|
// OnAddAlertMappingSource(1);
|
|
// }
|
|
// else
|
|
// _am.focusAlertMappingItem(tr);
|
|
//}).dropdownVal(item.DescriptionId);
|
|
|
|
td = $('<td></td>');
|
|
var divcategory = $('<div class="categorydropdown"></div>');
|
|
td.append(divcategory);
|
|
tr.append(td);
|
|
divcategory.css('width', 200).css('position', 'relative').dropdown(alertMappingDataSource.Categories, {
|
|
search: true,
|
|
valueKey: 'ID',
|
|
textKey: 'Name'
|
|
}).on('select', function (_e, it) {
|
|
if (it && it.ID == "") {
|
|
divcategory.dropdownVal(item.CategoryId);
|
|
OnAddAlertMappingSource(2);
|
|
}
|
|
else
|
|
_am.focusAlertMappingItem(tr);
|
|
}).dropdownVal(item.CategoryId);
|
|
|
|
td = $('<td class="td_funcs"></td>');
|
|
// 常规操作
|
|
var div = $('<div class="general"></div>');
|
|
div.append($('<a onclick="return false;">' + GetTextByKey("P_PM_DELETE", "Delete") + '</a>').on('click', function (e) { _am.deleteAlertMappingItem.call(this, e, alertmapping) }));
|
|
td.append(div);
|
|
div = $('<div class="editing" style="display:none;"></div>');
|
|
div.append($('<input type="button" value="' + GetTextByKey("P_PM_SAVE", "Save") + '"/>').on('click', function () { _am.saveAlertMappingItem.call(this, alertmapping) }));
|
|
div.append($('<input type="button" style="margin-left:5px;" value="' + GetTextByKey("P_PM_CANCEL", "Cancel") + '"/>').on('click', _am.cancelAlertMappingSave));
|
|
td.append(div);
|
|
tr.append(td);
|
|
|
|
tr.data('subctrls', {
|
|
item: item,
|
|
divmake: divmake,
|
|
divmodel: divmodel,
|
|
divalerttype: divalerttype,
|
|
//divdesc: divdesc,
|
|
divcategory: divcategory
|
|
});
|
|
return tr;
|
|
};
|
|
})();
|