var dialogAttachToAssets; $(function () { dialogAttachToAssets = new $assetselector('dialog_machines'); dialogAttachToAssets.forceSingle = true; dialogAttachToAssets.onDialogClosed = function () { showmaskbg(false); }; dialogAttachToAssets.onOK = function (source, selectedIndex) { var selectedAsset = null; if (selectedIndex >= 0) selectedAsset = source[selectedIndex]; $("#dialog_attachtoasset").val(selectedAsset.Name).data("AttachedtoAssetId", selectedAsset.MachineID ? selectedAsset.MachineID : selectedAsset.Id); inputChanged = true; showmaskbg(false); }; $("#btnSelectAttachToAsset").click(function () { showmaskbg(true); dialogAttachToAssets.companyId = contractorid; dialogAttachToAssets.exceptSource = [machineid]; dialogAttachToAssets.showSelector(3, true);//与mergeasset中的showSelector冲突,需设置force }); $("#btnUnattach").click(function () { $("#dialog_attachtoasset").val("").data("AttachedtoAssetId", null); inputChanged = true; }); }); function getAssetAttachmentInfo(machineid) { showAssetAttachmentInfo(null); if (!machineid) return; showLoading(); assetrequest("GetAssetAttachmentInfo", contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } showAssetAttachmentInfo(data); }, function (err) { hideLoading(); }); } function showAssetAttachmentInfo(attachinfo) { if (attachinfo) { $("#dialog_assettypetoattachto").val(attachinfo.AssetTypeToAttachTo); $("#dialog_attachstyle").val(attachinfo.Style); $("#dialog_attachcapacitycyd").val(attachinfo.Capacity_CYD); $("#dialog_attachcapacityweight").val(attachinfo.Capacity_Weight); $("#dialog_attachdimension1").val(attachinfo.Dimension1); $("#dialog_attachdimension2").val(attachinfo.Dimension2); $("#dialog_attacholdnumber").val(attachinfo.OldNumber); $("#dialog_attachtomake").val(attachinfo.AttachToMake); $("#dialog_attachtomodel").val(attachinfo.AttachToModel); $("#dialog_attachedtoanasset").val(attachinfo.AttachedtoAsset ? "1" : "0"); $("#dialog_attachtoasset").val(attachinfo.AttachedtoAssetName).data("AttachedtoAssetId", attachinfo.AttachedtoAssetId); } else { $("#dialog_assettypetoattachto").val(""); $("#dialog_attachstyle").val(""); $("#dialog_attachcapacitycyd").val(""); $("#dialog_attachcapacityweight").val(""); $("#dialog_attachdimension1").val(""); $("#dialog_attachdimension2").val(""); $("#dialog_attacholdnumber").val(""); $("#dialog_attachtomake").val(""); $("#dialog_attachtomodel").val(""); $("#dialog_attachedtoanasset").val(""); $("#dialog_attachtoasset").val("").data("AttachedtoAssetId", null); } } function getAssetAttachmentInfoInput(alerttitle) { var attachinfo = {}; attachinfo.AssetTypeToAttachTo = $("#dialog_assettypetoattachto").val(); attachinfo.Style = $("#dialog_attachstyle").val(); attachinfo.Capacity_CYD = $("#dialog_attachcapacitycyd").val(); var formattedcorrectly = GetTextByKey("P_MA_ISNOTFORMATTEDCORRECTLY", ' is not formatted correctly.'); if (attachinfo.Capacity_CYD !== "" && (isNaN(attachinfo.Capacity_CYD) || !IsNumber.test(attachinfo.Capacity_CYD))) { showAlert(GetTextByKey("P_MA_CAPACITYCYD", 'Capacity (CYD)') + formattedcorrectly, alerttitle); return false; } attachinfo.Capacity_Weight = $("#dialog_attachcapacityweight").val(); if (attachinfo.Capacity_Weight !== "" && (isNaN(attachinfo.Capacity_Weight) || !IsNumber.test(attachinfo.Capacity_Weight))) { showAlert(GetTextByKey("P_MA_CAPACITYWEIGHT", 'Capacity (Weight)') + formattedcorrectly, alerttitle); return false; } attachinfo.Dimension1 = $("#dialog_attachdimension1").val(); if (attachinfo.Dimension1 !== "" && (isNaN(attachinfo.Dimension1) || !IsNumber.test(attachinfo.Dimension1))) { showAlert(GetTextByKey("P_MA_DIMENSION1INCM", 'Dimension #1 (in/cm)') + formattedcorrectly, alerttitle); return false; } attachinfo.Dimension2 = $("#dialog_attachdimension2").val(); if (attachinfo.Dimension2 !== "" && (isNaN(attachinfo.Dimension2) || !IsNumber.test(attachinfo.Dimension2))) { showAlert(GetTextByKey("P_MA_WIDTH", 'Width') + formattedcorrectly, alerttitle); return false; } attachinfo.OldNumber = $("#dialog_attacholdnumber").val(); if (attachinfo.OldNumber !== "" && (isNaN(attachinfo.OldNumber) || !IsNumber.test(attachinfo.OldNumber))) { showAlert(GetTextByKey("P_MA_OLDNUMBER", 'Old Number') + formattedcorrectly, alerttitle); return false; } attachinfo.AttachToMake = $("#dialog_attachtomake").val(); attachinfo.AttachToModel = $("#dialog_attachtomodel").val(); attachinfo.AttachedtoAsset = $("#dialog_attachedtoanasset").val() == "1"; attachinfo.AttachedtoAssetId = $("#dialog_attachtoasset").data("AttachedtoAssetId"); return attachinfo; }