2023-04-28 12:22:26 +08:00

188 lines
6.9 KiB
JavaScript

var MachineAttributes = [];
function GetMachineAttributes(machineid) {
if (!contractorid)
contractorid = "";
assetrequest('GetMachineAttributes', contractorid + String.fromCharCode(170) + machineid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MA_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
MachineAttributes = data;
ShowMachineAttributes(data);
}
else
MachineAttributes = [];
});
}
function ShowMachineAttributes(categorys) {
//$('.li_attribute').remove();
//$('.divtab').remove();
$('.divtab').empty();
var ulcontainer = $('#ul_container');
var divbefore = $('#tab_pm');
var libefore = $('#li_attachmentinfo');
for (var j = 0; j < categorys.length; j++) {
var cate = categorys[j];
if (cate.TabID == 3) continue;//屏蔽Attachment Info
var cateid = "category" + j;
var tabid = "tab" + cate.TabID;
var divpage = $("#" + tabid);
var tab = null;
if (divpage.length == 0) {
var li = $('<li class="li_attribute"></li>').text(cate.TabName).attr('data-href', tabid);
libefore.after(li);
divpage = $('<div class="divtab"></div>').attr('id', tabid).attr('data-page', tabid);
divbefore.after(divpage);
}
var tab = divpage.children().eq(0);
if (tab.length == 0) {
tab = $('<table></table>');
divpage.append(tab);
}
var tr = $("<tr></tr>");
var tdcate = $('<td class="categoryname minus" colspan="2"></td>').text(" " + cate.DisplayText).data("cid", cateid).data("hide", 0);
tdcate.click(tab, function (e) {
var target = $(e.target);
if (target.data("hide") == 0) {
target.data("hide", 1);
e.data.find("." + target.data("cid")).hide();
target.removeClass("minus").addClass("plus");
}
else {
target.data("hide", 0);
e.data.find("." + target.data("cid")).show();
target.removeClass("plus").addClass("minus");
}
});
tr.append(tdcate);
tab.append(tr);
var atts = cate.MachineAttributes;
if (atts.length > 0) {
for (var i = 0; i < atts.length; i++) {
var att = atts[i];
var tr = $("<tr></tr>").addClass(cateid);
tr.append($('<td class="label"></td>').text(att.DisplayText + ":").attr("title", att.Description));
var attributeid = "attributeid_" + att.ID;
var input = $('<input type="text" />');
if (att.DataType == 0) {
if (att.Multiline)
input = $('<textarea></textarea>');
else if (att.Dropdown) {
input = $('<select style="width:204px;"></select>');
if (att.DataSource) {
var sources = att.DataSource.split(';');
for (var si in sources) {
input.append($("<option value='" + sources[si] + "'>" + sources[si] + "</option >"));
}
}
}
}
else if (att.DataType == 4) {
$(input).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]);
}
});
}
else if (att.DataType == 5)
input = $('<select><option value="Yes">Yes</option ><option value="No">No</option></select>');
$(input).attr('id', 'attributeid_' + att.ID).attr('maxlength', att.Length);
$(input).val(att.Value);
$(input).change(function () {
inputChanged = true;
})
var td1 = $('<td></td>');
td1.append(input);
tr.append(td1);
tab.append(tr);
}
}
}
if (!$('#div_container').data("tabed")) {
ulcontainer.append($('<li style="clear: both;"></li>'));
$('#div_container').data("tabed", true);
$('#div_container').tab();
$(window).resize();
ulcontainer.find("li").click(function (e) {
setRightMask($(e.target).attr("data-href"));
});
}
setRightMask();
}
function ClearMachineAttributeValue() {
if (MachineAttributes) {
for (var i = 0; i < MachineAttributes.length; i++) {
var ma = MachineAttributes[i];
if (ma && ma.MachineAttributes) {
for (var j = 0; j < ma.MachineAttributes.length; j++) {
var att = ma.MachineAttributes[j];
$('#attributeid_' + att.ID).val("");
}
}
}
}
}
function getAttributeInput(alerttitle) {
var attributedata = [];
if (MachineAttributes.length > 0) {
for (var j = 0; j < MachineAttributes.length; j++) {
var atts = MachineAttributes[j].MachineAttributes;
for (var i = 0; i < atts.length; i++) {
var att = atts[i];
var attvalue = $('#attributeid_' + att.ID).val();
if (att.DataType == 1 || att.DataType == 2 || att.DataType == 3) {
if (attvalue !== "") {
if (isNaN(attvalue) || !IsNumber.test(attvalue)) {
showAlert(att.DisplayText + ' is not formatted correctly.', alerttitle);
return false;
}
if (att.DataType == 1 && attvalue.indexOf(".") != -1) {
showAlert(att.DisplayText + ' is not formatted correctly.', alerttitle);
return false;
}
else if (att.DataType == 3)
attvalue = parseFloat(attvalue).toFixed(att.Precision);
}
}
else if (att.DataType == 4) {
if (attvalue.length > 0) {
if (!checkDate(attvalue)) {
showAlert(att.DisplayText + ' is not formatted correctly.', alerttitle);
return false;
}
}
else {
attvalue = "";
}
}
att.Value = attvalue;
attributedata.push(att);
}
}
}
return attributedata;
}