434 lines
15 KiB
JavaScript
434 lines
15 KiB
JavaScript
$(function () {
|
|
if ($("#contactlist").length > 0)//contactlist在AddWorkOrder中使用
|
|
InitContactGridData();
|
|
InitICContactGridData();
|
|
|
|
$('#sendworkorder_search').bind('input propertychange', function () {
|
|
showContactList(false);
|
|
});
|
|
|
|
$('#sendworkorder_search').keydown(function () {
|
|
showContactList(false);
|
|
});
|
|
|
|
$('#sendinternalcomments_search').bind('input propertychange', function () {
|
|
showICContactList(false);
|
|
});
|
|
|
|
$('#sendinternalcomments_search').keydown(function () {
|
|
showICContactList(false);
|
|
});
|
|
|
|
$('#sendemailpopupdialog').dialog(function () {
|
|
showmaskbg(false);
|
|
});
|
|
|
|
$('#sendicemailpopupdialog').dialog(function () {
|
|
showmaskbg(false);
|
|
if (typeof internal !== 'undefined') {
|
|
internal.loading = false;
|
|
}
|
|
});
|
|
});
|
|
|
|
var machineContacts = [];
|
|
function getMachineContacts(assetid) {
|
|
grid_contactdt && grid_contactdt.setData([]);
|
|
grid_iccontactdt && grid_iccontactdt.setData([]);
|
|
worequest("GetMachineContacts", assetid, function (data) {
|
|
if (typeof (data) === "string") {
|
|
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
|
|
return;
|
|
}
|
|
machineContacts = data;
|
|
if (grid_contactdt)//grid_contactdt在AddWorkOrder中使用
|
|
showContactList(true);
|
|
showICContactList(true);
|
|
}, function (err) {
|
|
});
|
|
}
|
|
|
|
|
|
function showContactList(newopen) {
|
|
var rows = [];
|
|
if (machineContacts && machineContacts.length > 0) {
|
|
var filter = $('#sendworkorder_search').val()?.trim()?.toLowerCase();
|
|
var assignedto = $.trim($('#dialog_assignto').val());
|
|
for (var i = 0; i < machineContacts.length; i++) {
|
|
var r = machineContacts[i];
|
|
|
|
if (newopen) {
|
|
if (assignedto.toLowerCase() === r.IID.toLowerCase())
|
|
r.Email = true;
|
|
else
|
|
r.Email = false;
|
|
if (assignedto.toLowerCase() === r.IID.toLowerCase())
|
|
rows.splice(0, 0, r);
|
|
else
|
|
rows.push(r);
|
|
}
|
|
else {
|
|
if (!r.Text && !r.Email) {
|
|
if (r.DisplayName.toLowerCase().indexOf(filter) >= 0) {
|
|
if (assignedto.toLowerCase() === r.IID.toLowerCase())
|
|
rows.splice(0, 0, r);
|
|
else
|
|
rows.push(r);
|
|
}
|
|
}
|
|
else {
|
|
if (assignedto.toLowerCase() === r.IID.toLowerCase())
|
|
rows.splice(0, 0, r);
|
|
else
|
|
rows.push(r);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
rows = rows.sort(function (a, b) { return ((b.Text || b.Email) ? 1 : 0) - ((a.Text || a.Email) ? 1 : 0) });
|
|
|
|
grid_contactdt.setData(rows);
|
|
}
|
|
|
|
var grid_contactdt;
|
|
function InitContactGridData() {
|
|
grid_contactdt = createGridView('#contactlist');
|
|
var list_columns = [
|
|
{ name: 'DisplayName', caption: GetTextByKey("P_WO_CONTACTNAME", "Contact Name"), valueIndex: 'DisplayName', css: { 'width': 148, 'text-align': 'left' } },
|
|
{ name: 'ContactTypeName', caption: GetTextByKey("P_WO_CONTACTTYPE", "Contact Type"), valueIndex: 'ContactTypeName', css: { 'width': 148, 'text-align': 'left' } },
|
|
//{ name: 'Text', caption: "Text", valueIndex: 'Text', type: 3, css: { 'width': 45, 'text-align': 'center' } },
|
|
{ name: 'Email', caption: GetTextByKey("P_WO_EMAIL", "Email"), valueIndex: 'Email', type: 3, css: { 'width': 60, 'text-align': 'center' } }
|
|
];
|
|
var columns = [];
|
|
// head
|
|
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;
|
|
if (list_columns[hd].type) {
|
|
col.type = list_columns[hd].type;
|
|
}
|
|
columns.push(col);
|
|
//if (col.name === "Text") {
|
|
// col.enabled = function (item) {
|
|
// return item.TextAddress !== '';
|
|
// };
|
|
//}
|
|
if (col.name === "Email") {
|
|
col.enabled = function (item) {
|
|
return item.ID !== '';
|
|
};
|
|
}
|
|
}
|
|
grid_contactdt.multiSelect = false;
|
|
grid_contactdt.columns = columns;
|
|
grid_contactdt.init();
|
|
}
|
|
|
|
function openSendEmail() {
|
|
$('#sendworkorder_desc').val('');
|
|
$('#sendworkorder_otheremailaddress').val('');
|
|
$('#sendworkorder_search').val('');
|
|
var mid;
|
|
if (typeof editableSelectMachine != "undefined") {
|
|
var machine = editableSelectMachine.selecteditem();
|
|
if (machine)
|
|
mid = machine.Id;
|
|
}
|
|
else
|
|
mid = machineid;
|
|
|
|
if (!mid) {
|
|
showAlert(GetTextByKey("P_WO_PLEASESELECTANASSET", "Please select an Asset."), GetTextByKey("P_WO_SENDEMAIL", "Send Email"));
|
|
$('#dialog_machine').focus();
|
|
return;
|
|
}
|
|
getMachineContacts(mid);
|
|
|
|
showmaskbg(true);
|
|
$('#sendemailpopupdialog').css({
|
|
'top': (document.documentElement.clientHeight - $('#sendemailpopupdialog').height()) / 3,
|
|
'left': (document.documentElement.clientWidth - $('#sendemailpopupdialog').width()) / 2
|
|
}).showDialogfixed();
|
|
}
|
|
|
|
|
|
function hideSendEmailPopup() {
|
|
showmaskbg(false);
|
|
$('#sendemailpopupdialog').hide();
|
|
}
|
|
|
|
function CheckEmail(mail) {
|
|
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
|
|
if (mail.length == 0)
|
|
return true;
|
|
return filter.test(mail);
|
|
}
|
|
|
|
function onSendWorkOrder() {
|
|
var alerttitle = GetTextByKey("P_WO_SENDWORKORDER", "Send Work Order");
|
|
if (!workorderid || workorderid === "") {
|
|
showAlert(GetTextByKey("P_WO_SAVEWORKORDERFIRST", "Please save work order first."), alerttitle);
|
|
return;
|
|
}
|
|
|
|
var emailaddress = [];
|
|
var otheremailaddressstr = $('#sendworkorder_otheremailaddress').val();
|
|
if (otheremailaddressstr !== "") {
|
|
var address = otheremailaddressstr.split(';');
|
|
for (var i = 0; i < address.length; i++) {
|
|
if (!CheckEmail($.trim(address[i]))) {
|
|
_dialog.showAlert(GetTextByKey("P_WO_OTHERADDRESSINVALID", 'The other email address {0} is invalid.').replace('{0}', emailaddress[i]), alerttitle);
|
|
return;
|
|
}
|
|
emailaddress.push({ 'Key': '', 'Value': address[i] });
|
|
}
|
|
}
|
|
|
|
var tempsource = grid_contactdt.source;
|
|
for (var i = 0; i < tempsource.length; i++) {
|
|
var ct = tempsource[i];
|
|
if (ct.Email) {
|
|
emailaddress.push({ 'Key': ct.IID, 'Value': ct.ID });
|
|
}
|
|
}
|
|
|
|
if (emailaddress.length == 0) {
|
|
hideSendEmailPopup();
|
|
return;
|
|
}
|
|
var desc = $('#sendworkorder_desc').val();
|
|
worequest("SendWorkOrder", workorderid + String.fromCharCode(170) + JSON.stringify(emailaddress) + String.fromCharCode(170) + desc, function (data) {
|
|
if (data !== 'OK') {
|
|
showAlert(data, alerttitle);
|
|
}
|
|
else
|
|
showAlert(GetTextByKey("P_WO_MESSAGESENT", 'Message sent'), alerttitle);
|
|
|
|
hideSendEmailPopup();
|
|
}, function (err) {
|
|
_dialog.showAlert(GetTextByKey("P_WO_FAILEDSENDWORKORDER", 'Failed to send work order.'), alerttitle);
|
|
});
|
|
}
|
|
|
|
|
|
//***********************Send Internal Comments Email Begin***********************************//
|
|
|
|
|
|
var grid_iccontactdt;
|
|
function InitICContactGridData() {
|
|
grid_iccontactdt = createGridView('#iccontactlist');
|
|
var list_columns = [
|
|
{ name: 'DisplayName', caption: GetTextByKey("P_WO_CONTACTNAME", "Contact Name"), valueIndex: 'DisplayName', css: { 'width': 148, 'text-align': 'left' } },
|
|
{ name: 'ContactTypeName', caption: GetTextByKey("P_WO_CONTACTTYPE", "Contact Type"), valueIndex: 'ContactTypeName', css: { 'width': 148, 'text-align': 'left' } },
|
|
{ name: 'Text', caption: "Text", valueIndex: 'Text', type: 3, css: { 'width': 45, 'text-align': 'center' } },
|
|
{ name: 'Email', caption: GetTextByKey("P_WO_EMAIL", "Email"), valueIndex: 'Email', type: 3, css: { 'width': 60, 'text-align': 'center' } }
|
|
];
|
|
var columns = [];
|
|
// head
|
|
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;
|
|
if (list_columns[hd].type) {
|
|
col.type = list_columns[hd].type;
|
|
}
|
|
columns.push(col);
|
|
if (col.name === "Text") {
|
|
col.enabled = function (item) {
|
|
return item.Mobile != null && $.trim(item.Mobile).length > 0;
|
|
};
|
|
}
|
|
if (col.name === "Email") {
|
|
col.enabled = function (item) {
|
|
return item.ID !== '';
|
|
};
|
|
}
|
|
}
|
|
grid_iccontactdt.multiSelect = false;
|
|
grid_iccontactdt.columns = columns;
|
|
grid_iccontactdt.init();
|
|
}
|
|
|
|
function showICContactList(newopen) {
|
|
var filter = $('#sendinternalcomments_search').val().trim().toLowerCase();
|
|
var rows = [];
|
|
if (machineContacts && machineContacts.length > 0) {
|
|
for (var i = 0; i < machineContacts.length; i++) {
|
|
var r = machineContacts[i];
|
|
if (newopen) {
|
|
r.Text = false;
|
|
r.Email = false;
|
|
rows.push(r);
|
|
}
|
|
else {
|
|
if (!r.Text && !r.Email) {
|
|
if (r.DisplayName.toLowerCase().indexOf(filter) >= 0)
|
|
rows.push(r);
|
|
}
|
|
else
|
|
rows.push(r);
|
|
}
|
|
}
|
|
}
|
|
rows = rows.sort(function (a, b) { return ((b.Text || b.Email) ? 1 : 0) - ((a.Text || a.Email) ? 1 : 0) });
|
|
|
|
grid_iccontactdt.setData(rows);
|
|
}
|
|
|
|
function openSendICEmail() {
|
|
var comment = internal?.text;
|
|
if ($.trim(comment) == "") {
|
|
return;
|
|
}
|
|
$('#sendic_otheremailaddress').val('');
|
|
$('#sendic_phonenumber').val('');
|
|
$('#sendinternalcomments_search').val('');
|
|
var mid;
|
|
if (typeof editableSelectMachine != "undefined") {
|
|
var machine = editableSelectMachine.selecteditem();
|
|
if (machine)
|
|
mid = machine.Id;
|
|
}
|
|
else
|
|
mid = machineid;
|
|
|
|
if (!mid) {
|
|
showAlert(GetTextByKey("P_WO_PLEASESELECTANASSET", "Please select an Asset."), GetTextByKey("P_WO_SENDEMAIL", "Send Email"));
|
|
$('#dialog_machine').focus();
|
|
return;
|
|
}
|
|
getMachineContacts(mid);
|
|
|
|
showmaskbg(true);
|
|
$('#sendicemailpopupdialog').css({
|
|
'top': (document.documentElement.clientHeight - $('#sendicemailpopupdialog').height()) / 3,
|
|
'left': (document.documentElement.clientWidth - $('#sendicemailpopupdialog').width()) / 2
|
|
}).showDialogfixed();
|
|
}
|
|
|
|
|
|
function hideSendICEmailPopup() {
|
|
showmaskbg(false);
|
|
$('#sendicemailpopupdialog').hide();
|
|
}
|
|
|
|
var icsending = false;
|
|
function onSendInternalComments() {
|
|
var comment = internal?.text;
|
|
if ($.trim(comment) == "") {
|
|
hideSendICEmailPopup();
|
|
return;
|
|
}
|
|
if (icsending)
|
|
return;
|
|
icsending = true;
|
|
var alerttitle = GetTextByKey("P_WO_SENDINTERNALCOMMENTS", "Send Internal Comments");
|
|
var emailaddress = [];
|
|
var otheremailaddressstr = $('#sendic_otheremailaddress').val();
|
|
if (otheremailaddressstr !== "") {
|
|
var address = otheremailaddressstr.split(';');
|
|
for (var i = 0; i < address.length; i++) {
|
|
if (!CheckEmail($.trim(address[i]))) {
|
|
_dialog.showAlert(GetTextByKey("P_WO_OTHERADDRESSINVALID", 'The other email address {0} is invalid.').replace('{0}', emailaddress[i]), alerttitle);
|
|
return;
|
|
}
|
|
emailaddress.push({ 'Key': '', 'Value': address[i] });
|
|
}
|
|
}
|
|
|
|
var phonenumbers = [];
|
|
var pm = $('#sendic_phonenumber').val();
|
|
if (pm !== "") {
|
|
var pms = pm.split(';');
|
|
for (var i = 0; i < pms.length; i++) {
|
|
if (pms[i] === "")
|
|
continue;
|
|
if (!checkPhoneNumber(pms[i]) && !CheckEmail(pms[i])) {
|
|
showAlert(GetTextByKey("P_WO_THEMOBILENUMBERISINVALID", "The mobile number {0} is invalid.").replace('{0}', pms[i]), alerttitle);
|
|
return;
|
|
}
|
|
phonenumbers.push({ 'Key': '', 'Value': pms[i] });
|
|
}
|
|
}
|
|
|
|
var tempsource = grid_iccontactdt.source;
|
|
for (var i = 0; i < tempsource.length; i++) {
|
|
var ct = tempsource[i];
|
|
if (ct.Email) {
|
|
emailaddress.push({ 'Key': ct.IID, 'Value': ct.ID, 'Tag1': ct.DisplayName });
|
|
}
|
|
if (ct.Text && (checkPhoneNumber(ct.Mobile) || CheckEmail(ct.Mobile))) {
|
|
phonenumbers.push({ 'Key': ct.IID, 'Value': ct.Mobile, 'Tag1': ct.DisplayName });
|
|
}
|
|
}
|
|
|
|
var url = 'Maintenance/AddWorkOrder.aspx';
|
|
var method = 'SendInternalComments';
|
|
var data = new FormData();
|
|
data.append('MethodName', method);
|
|
data.append('WorkorderId', workorderid);
|
|
data.append('Comment', encodeURIComponent(comment));
|
|
data.append('Emails', JSON.stringify(emailaddress));
|
|
data.append('Phones', JSON.stringify(phonenumbers));
|
|
var file = internal?.file;
|
|
if (file != null) {
|
|
data.append('Attachment', file);
|
|
}
|
|
$.ajax({
|
|
url: _network.root + url,
|
|
type: 'POST',
|
|
dataType: 'json',
|
|
processData: false,
|
|
contentType: false,
|
|
cache: false,
|
|
data: data,
|
|
success: function (data) {
|
|
icsending = false;
|
|
$('#mask_over_bg').hide();
|
|
if (data !== "") {
|
|
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
|
|
if (typeof internal !== 'undefined') {
|
|
internal.loading = false;
|
|
}
|
|
return;
|
|
}
|
|
if (typeof internal !== 'undefined') {
|
|
internal.text = '';
|
|
internal.file = null;
|
|
internal.loading = false;
|
|
}
|
|
hideSendICEmailPopup();
|
|
if (typeof wowidgetobj != 'undefined')
|
|
wowidgetobj.reloaddata("InternalComments");
|
|
else
|
|
getComments();
|
|
},
|
|
error: function (request, textStatus, errorThrown) {
|
|
icsending = false;
|
|
hideSendICEmailPopup();
|
|
if (typeof internal !== 'undefined') {
|
|
internal.loading = false;
|
|
}
|
|
if (request?.readyState == 0) {
|
|
console.log(request);
|
|
} else {
|
|
writelog_ironintel("onSendInternalComments", url + ".-1." + method + "." + JSON.stringify(param), JSON.stringify(request), textStatus + errorThrown);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
|
|
//***********************Send Internal Comments Email End***********************************//
|