$(function () { getWorkOrderCollapsed(); $('#addfollowerpopupdialog').dialog(function () { showmaskbg(false); }); $('#dialog_completedstatus').dialog(function () { showmaskbg(false); }); $('#selfollower_search').bind('input propertychange', function () { searchFollower(false); }); $('#selfollower_search').keydown(function () { searchFollower(false); }); }); function getWorkOrderCollapsed() { worequest("GetWorkOrderCollapsed", '', function (data) { if (typeof (data) === "string") { return; } if (data) { for (var i = 0; i < data.length; i++) { var item = data[i]; if (item.Value == "1" && $("#span" + item.Key).is(":visible")) { $("#span" + item.Key).removeClass("iconchevronright").addClass("iconchevrondown"); $("#tb" + item.Key).show(); //if ("customer" == item.Key) // grid_dtcontact && grid_dtcontact.resize(); //else if ("follower" == item.Key) // grid_dtfollower && grid_dtfollower.resize(); } else { $("#span" + item.Key).removeClass("iconchevrondown").addClass("iconchevronright"); $("#tb" + item.Key).hide(); } if (!AllowCustomer && item.Key === "customer") { $("#tb" + item.Key).hide(); } } } }, function (err) { }); } function saveWorkOrderCollapsed() { var items = []; items.push({ 'Key': 'asset', 'Value': $("#spanasset").hasClass('iconchevrondown') ? "1" : "0" }); items.push({ 'Key': 'customer', 'Value': $("#spancustomer").hasClass('iconchevrondown') ? "1" : "0" }); items.push({ 'Key': 'follower', 'Value': $("#spanfollower").hasClass('iconchevrondown') ? "1" : "0" }); items.push({ 'Key': 'summary', 'Value': $("#spansummary").hasClass('iconchevrondown') ? "1" : "0" }); items.push({ 'Key': 'cost', 'Value': $("#spancost").hasClass('iconchevrondown') ? "1" : "0" }); var param = JSON.stringify(items); param = htmlencode(param); worequest("SetWorkOrderCollapsed", param, function (data) { }, function (err) { }); } /*************************Customer********************************/ var customerid; var grid_dtcustomer; function InitGridCustomers() { grid_dtcustomer = createGridView('#customerlist'); var list_columns = [ { name: 'Code', caption: GetTextByKey("P_CR_CODE", "Code"), valueIndex: 'Code', css: { 'width': 120, 'text-align': 'left' } }, { name: 'Name', caption: GetTextByKey("P_CR_COMPANYNAME", "Company Name"), valueIndex: 'Name', css: { 'width': 200, 'text-align': 'left' } }, { name: 'Address', caption: GetTextByKey("P_CR_ADDRESS", "Address"), valueIndex: 'Address', css: { 'width': 150, 'text-align': 'left' } }, { name: 'Notes', caption: GetTextByKey("P_CR_NOTES", "Notes"), valueIndex: 'Notes', css: { 'width': 200, 'text-align': 'left' } } ]; var columns = []; for (var hd in list_columns) { var col = {}; col.name = list_columns[hd].name; col.caption = list_columns[hd].caption; col.visible = true; col.sortable = true; col.width = list_columns[hd].css.width; col.align = list_columns[hd].css["text-align"] col.key = list_columns[hd].valueIndex; columns.push(col); } grid_dtcustomer.multiSelect = true; grid_dtcustomer.columns = columns; grid_dtcustomer.init(); grid_dtcustomer.onRowDblClicked = function (rowindex) { var rowdata = grid_dtcustomer.source[rowindex]; if (rowdata) { OnSetSelectCustomer(); } }; } function showCustomerList(data) { grid_dtcustomer.setData(data); } function onSelectCustomer() { grid_dtcustomer.setData([]); $('#txt_customer_key').val(''); $('#txt_customer_key').attr('disabled', true); $('#chkshowallcust').attr('checked', false); $('#dialog_customer .dialog-title span.title').text(GetTextByKey("P_WO_SELECTCUSTOMER", 'Select Customer')); showmaskbg(true); $('#dialog_customer') .attr('act', 'edit') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_customer').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_customer').width()) / 2 }) .showDialogfixed(); GetCustomerList(); } var allcustomers; function GetCustomerList() { grid_dtcustomer.setData([]); var chk = $('#chkshowallcust').prop('checked'); if (chk) { $('#txt_customer_key').attr('disabled', false); getAllCustomer(); } else { $('#txt_customer_key').attr('disabled', true); $('#txt_customer_key').val(''); getAssetCustomer(); } } function getAllCustomer() { if (allcustomers) getMatchCustomers(); else { customerquery('GetPartners', '', function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showmaskbg(false); return; } allcustomers = data; getMatchCustomers(); }, function (err) { }); } } function getAssetCustomer() { if (!machineid) return; customerquery('GetAssignedPartnersByMachine', machineid, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showmaskbg(false); return; } showCustomerList(data); }, function (err) { }); } function getMatchCustomers() { var filter = $('#txt_customer_key').val().toLowerCase(); var _availablecustomers = []; if (allcustomers) { for (var i = 0; i < allcustomers.length; i++) { var m = allcustomers[i]; if (filter == "" || m.Code.toLowerCase().indexOf(filter) >= 0 || m.Name.toLowerCase().indexOf(filter) >= 0) { _availablecustomers.push(m); } } } showCustomerList(_availablecustomers); } function onCustomerKeyPress(e) { if (e.keyCode === 13) { GetCustomerList(); } }; function OnSetSelectCustomer() { var index = grid_dtcustomer.selectedIndex; if (index < 0) { showAlert(GetTextByKey("P_WO_PLEASESELECTACUSTOMER", "Please select a customer."), GetTextByKey("P_WO_SELECTCUSTOMER", "Select Customer")); return; } var cust = grid_dtcustomer.source[index]; setCustomerData(cust); } function setCustomerData(cust) { customerid = cust.Id; $('#dialog_salesperson').dropdownVal(cust.SalespersonIID); $('#dialog_custcustomername').text(cust.Name); $('#dialog_custcustomercode').text(cust.Code); $(".custcode").show(); if (typeof customer !== 'undefined') { customer.companyName = cust.Name; customer.companyCode = cust.Code; customer.setData('companyCode', cust.Code); } getCustomerContacts(cust.Id); getCustomerFollowers(cust.Id); $('#dialog_customer').hideDialog(); showmaskbg(false); } function OnAddCustomer() { execIframeFunc("init", [null, machineid], "iframecr"); $('#contatcmask').show(); $('#dialog_addcustomer') .showDialogRight(); } function CloseCustomerDialog(type) { $('#dialog_addcustomer').hideDialog(); allcustomers = null; GetCustomerList(); $('#contatcmask').hide(); } /************************* Customer********************************/ //*************************Contact********************************// function getWorkOrderContacts(woid) { worequest('GetWorkOrderContacts', woid, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showmaskbg(false); return; } customercontacts = data || []; showCustomerContacts(customercontacts); }, function (err) { }); } var contact; function getCustomerContacts(custid, next) { worequest('GetCustomerContacts', custid, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); if (next) next([]);//next 在Communication选Contacts时传入 else showcontatcmask(false); return; } if (next) { next(data);//next 在Communication选Contacts时传入 return; } showCustomerContacts(data); SaveWorkorderContact(); }, function (err) { }); } function showCustomerContacts(data) { if (customercontacts) { var temp = []; for (var i = 0; i < customercontacts.length; i++) {//移除上一个Customer的Contacts if (customercontacts[i].Id > 0) continue; temp.push(customercontacts[i]); } customercontacts = temp; } for (var i = 0; i < data.length; i++) { var r = data[i]; var item = { ...r }; var contactexists = false; if (customercontacts) { for (var j = 0; j < customercontacts.length; j++) { var ct = customercontacts[j]; if (ct.Name === item.Name && ct.MobilePhone === item.MobilePhone) { ct.Id = item.Id; contactexists = true; break; } } } if (!contactexists) customercontacts.push(item); } if (customer) { //customer.setData('contacts', customercontacts); customer.contacts = customercontacts; } if (internal) { internal.contacts = customercontacts; } woestimateobj?.updatecontact(customercontacts); woinvoiceobj?.updatecontact(customercontacts); woattachmentobj?.updatecontact(customercontacts); setPhoneNumber_statuschange(); } function SaveWorkorderContact(data, next) { if (!workorderid || workorderid == "") return; var custid = customerid; if (!custid) custid = -1; var param = JSON.stringify([workorderid, custid, JSON.stringify(data ?? customercontacts)]); param = htmlencode(param); worequest("SaveWorkOrderContact", param, function (data) { if (typeof next === 'function') { next(data); return; } if (typeof data === "string") { showAlert(data, GetTextByKey("P_WO_ERROR", 'Error')); return; } }, function (err) { //showmaskbg(false); }); } /*************************End Contact********************************/ //*************************Follwer********************************// function showWorkOrderFollowers(data) { if (typeof customer !== 'undefined') { customer.followers = data; } } function getWorkOrderFollowers(woid) { worequest('GetWorkOrderFollowers', woid, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showmaskbg(false); return; } followers = data; showWorkOrderFollowers(followers); }, function (err) { }); } function getCustomerFollowers(custid) { worequest('GetCustomerFollowers', custid, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showcontatcmask(false); return; } for (var i = 0; i < data.length; i++) { var fl = data[i]; var item = {}; item.Id = -1; item.UserIID = fl.UserIID; item.Name = fl.Name; item.Email = fl.Email; item.MobilePhone = fl.MobilePhone; item.SendEmail = fl.SendEmail; item.SendText = fl.SendText; var followerexists = false; if (followers) { for (var j = 0; j < followers.length; j++) { var ct = followers[j]; if (ct.UserIID === item.UserIID) { followerexists = true; break; } } } if (!followerexists) followers.push(item); } SaveWorkOrderFollower(); showWorkOrderFollowers(followers); }, function (err) { }); } var isloadfollower = false; var allfollowers = []; function getAllFollowers(next) { worequest('GetAllFollowers', '', function (data) { if (typeof next === 'function') { next(data); } else { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showmaskbg(false); return; } isloadfollower = true; allfollowers = data; showAllFollower(data); } }, function (err) { }); } function showAllFollower(data) { if (typeof customer !== 'undefined') { customer.setData('allfollowers', data); } } function SaveWorkOrderFollower(next) { if (!workorderid || workorderid == "") return; var param = JSON.stringify([workorderid, JSON.stringify(followers)]); param = htmlencode(param); worequest("SaveWorkOrderFollower", param, function (data) { if (typeof next === 'function') { next(data); } else { if (data !== "OK") { showAlert(data, GetTextByKey("P_WO_ERROR", 'Error')); return; } } }, function (err) { //showmaskbg(false); }); } /*************************End Follwer********************************/ /*****************************************Begin Completed Status**************************************************/ var cur_exit = 0; var cur_callback = undefined; function openCompletedStatusDialog(exit, callback) { cur_exit = exit; cur_callback = callback; $('#dialog_completed_status').dropdownVal(''); showmaskbg(true); $('#dialog_completedstatus').css({ 'top': (document.documentElement.clientHeight - $('#dialog_completedstatus').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_completedstatus').width()) / 2 }).showDialogfixed(); } function hideCompletedStatusPopup() { showmaskbg(false); $('#dialog_completedstatus').hide(); } function onSaveCompletedStatus() { var s = $('#dialog_completed_status').dropdownVal(); $('#dialog_status').dropdownVal(s); $('.span_required').show(); hideCompletedStatusPopup(); OnSave(cur_exit, cur_callback); } /*****************************************End Completed Status**************************************************/ /********************************************Begin Stauts Change Select Attachment*************************************************/ var imgTypes = [".jfif", ".jpg", ".jpeg", ".bmp", ".png", ".tiff", ".gif"]; var grid_selectattachments; function InitGridSelectedAttachments() { grid_selectattachments = new GridView("#div_selectattachmentlist"); var list_columns = [ { name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, css: { 'width': 45, 'text-align': 'center' } }, { name: 'ThumbnailUrl', caption: "", valueIndex: 'ThumbnailUrl', css: { 'width': 42, 'text-align': 'center' } }, { name: 'Notes', caption: GetTextByKey("P_WO_NAME", "Name"), valueIndex: 'Notes', css: { 'width': 280, 'text-align': 'left' } } ]; var columns = []; for (var hd in list_columns) { var col = {}; if (list_columns[hd].type) { col.type = list_columns[hd].type; } col.name = list_columns[hd].name; col.caption = list_columns[hd].caption; col.visible = true; col.sortable = true; col.width = list_columns[hd].css.width; col.align = list_columns[hd].css["text-align"] col.key = list_columns[hd].valueIndex; columns.push(col); if (col.name == "Selected") { col.allcheck = false; col.sortable = false; col.events = { onchange: function () { if (this.Selected) { for (var i in grid_selectattachments.source) { var a = grid_selectattachments.source[i]; if (a.Id !== this.Id) a.Selected = false; } grid_selectattachments.reload(); } } }; } else if (col.name == "ThumbnailUrl") { col.type = ThumbnailUrlColumn; //col.filter = function (item) { // if (imgTypes.indexOf(item.FileType.toLowerCase()) >= 0) // return $('').attr('src', item.ThumbnailUrl); // else { // var sdown = $('') // setAttachemntIcon(item.FileType, sdown); // return sdown; // } //} //col.styleFilter = function () { // return { "width": "100%", 'margin': 0 }; //} } } grid_selectattachments.multiSelect = false; grid_selectattachments.columns = columns; grid_selectattachments.init(); } function showSelectAttachment(data) { var rows = []; for (var i = 0; i < data.length; i++) { var att = data[i]; if (att.FileType.toLowerCase() == "url") continue; var fr = { Id: att.AttachmentIdStr, AttaType: att.AttachmentType, FileName: att.FileName, Caption: att.Notes, FileType: att.FileType, Url: att.Url, ThumbnailUrl: att.ThumbnailUrl, Notes: att.Notes === "" ? att.FileName : att.Notes, Selected: false, }; rows.push(fr); } grid_selectattachments.setData(rows); $('#dialogattmask').hide(); } function openSelectAttachment() { $('#dialogattmask').show(); $('#statuschange_maskbg').show(); GetWorkorderAttachemnt(); $('#dialog_selecteattachments .dialog-title span.title').text(GetTextByKey("P_WO_SELECTATTACHMENT", 'Select Attachment')); $('#dialog_selecteattachments') .attr('act', 'add') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_selecteattachments').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_selecteattachments').width()) / 2 }) .showDialogfixed(); } var woattachments; function GetWorkorderAttachemnt() { grid_selectattachments.setData([]); if (!workorderid || workorderid == "") return; worequest('GetWorkOrderAttachments', htmlencode(workorderid), function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_WO_SELECTATTACHMENT', "Select Attachment")); $('#dialogattmask').hide(); $('#statuschange_maskbg').hide(); return; } showSelectAttachment(data); }, function () { }); } var _selectedattachment; function onSetSelectAttachment() { $("#dialogattmask").show(); $('#statuschange_maskbg').show(); _selectedattachment = undefined; $('#span_attachmentname').text('').attr('title', ''); $('#span_attachmentdelete').hide(); var alerttitle = GetTextByKey('P_WO_SELECTATTACHMENT', "Select Attachment"); var selatt; if (grid_selectattachments) { var tempsource = grid_selectattachments.source || []; for (var i = 0; i < tempsource.length; i++) { var a = tempsource[i]; if (a.Selected) { selatt = a; break; } } } if (selatt) { if (imgTypes.indexOf(selatt.FileType.toLowerCase()) >= 0) {//图片无需验证大小 _selectedattachment = selatt; $('#span_attachmentname').text(_selectedattachment.Notes).attr('title', _selectedattachment.Notes); $('#span_attachmentdelete').show(); $("#dialogattmask").hide(); $('#statuschange_maskbg').hide(); $('#dialog_selecteattachments').hideDialog(); } else { worequest('IsAttachmentExceedsLimit', htmlencode(selatt.Id), function (data) { $("#dialogattmask").hide(); if (typeof (data) === "string") { showAlert(data, alerttitle); return; } if (data) { showAlert(GetTextByKey('P_WO_ATTACHMENTSIZEEXCEEDSTHEMAXIMUMTIPS', 'Attachment size exceeds the maximum allowed to be sent (1.2MB).'), alerttitle); return; } else { _selectedattachment = selatt; $('#span_attachmentname').text(_selectedattachment.Notes).attr('title', _selectedattachment.Notes); $('#span_attachmentdelete').show(); $('#statuschange_maskbg').hide(); $('#dialog_selecteattachments').hideDialog(); } }, function () { $("#dialogattmask").hide(); $('#statuschange_maskbg').hide(); }); } } else { $('#dialog_selecteattachments').hideDialog(); $("#dialogattmask").hide(); $('#statuschange_maskbg').hide(); } } function onRemoveSelectedAttachment() { _selectedattachment = undefined; $('#span_attachmentname').text('').attr('title', ''); $('#span_attachmentdelete').hide(); } /********************************************End Stauts Change Select Attachment*************************************************/