1876 lines
81 KiB
JavaScript
1876 lines
81 KiB
JavaScript
|
||
function pad(num, n) {
|
||
if (!num || isNaN(num))
|
||
return num;
|
||
return Array(n > num.length ? (n - num.length + 1) : 0).join(0) + num;
|
||
}
|
||
|
||
function showWorkOrders(wos) {
|
||
var rows = [];
|
||
for (var i = 0; i < wos.length; i++) {
|
||
var r = wos[i];
|
||
for (var j in r) {
|
||
if (j === "Id") {
|
||
r[j] = { DisplayValue: r["Id"] > 0 ? r["Id"] : "MR", Value: r[j] };
|
||
}
|
||
else if (j === "WorkOrderNumber") {
|
||
r[j] = { DisplayValue: r["WorkOrderNumber"], Value: pad(r[j].startsWith('FI') ? r[j].replace('FI', '') : r[j], 50) };
|
||
}
|
||
else if (j === "DueDate") {
|
||
r[j] = { DisplayValue: r["DueDateStr"], Value: r[j] };
|
||
}
|
||
else if (j === "CompleteDate") {
|
||
r[j] = { DisplayValue: r["CompleteDateStr"], Value: r[j] };
|
||
}
|
||
else if (j === "NextFollowUpDate") {
|
||
r[j] = { DisplayValue: r["NextFollowUpDateStr"], Value: r[j] };
|
||
}
|
||
else if (j === "CreateDate") {
|
||
r[j] = { DisplayValue: r["CreateDateStr"], Value: r[j] };
|
||
}
|
||
else if (j === "CreationDate") {
|
||
r[j] = { DisplayValue: r["CreationDateStr"], Value: r[j] };
|
||
}
|
||
else if (j === "LastCommunicationDate") {
|
||
r[j] = { DisplayValue: r["LastCommunicationDateStr"], Value: r[j] };
|
||
}
|
||
else if (j === "LastInternalCommunicationDate") {
|
||
r[j] = { DisplayValue: r["LastInternalCommunicationDateStr"], Value: r[j] };
|
||
}
|
||
else if (j === "PartsExpectedDate") {
|
||
r[j] = { DisplayValue: r["PartsExpectedDateStr"], Value: r[j] };
|
||
}
|
||
else if (j === "LastLaborDate") {
|
||
r[j] = { DisplayValue: r["LastLaborDateStr"], Value: r[j] };
|
||
}
|
||
else if (j === "InspectionRequired") {
|
||
r[j] = { DisplayValue: r["InspectionRequired"] ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No"), Value: r[j] };
|
||
}
|
||
else if (j === "AutoText") {
|
||
r[j] = { DisplayValue: r["AutoText"] ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No"), Value: r[j] };
|
||
}
|
||
else if (j === "WorkOrderType") {
|
||
var wotype = r[j];
|
||
if (wotype == "Maintenance Expense")
|
||
wotype = GetTextByKey("P_WO_MAINTENANCEEXPENSE", "Maintenance Expense");
|
||
else if (wotype == "Repair Expense")
|
||
wotype = GetTextByKey("P_WO_REPAIREXPENSE", "Repair Expense");
|
||
else if (wotype == "Capitalized Expense")
|
||
wotype = GetTextByKey("P_WO_CAPITALIZEDEXPENSE", "Capitalized Expense");
|
||
r[j] = wotype;
|
||
}
|
||
else if (j === "EstimateStatus") {
|
||
r[j] = getEstimateStatus(r[j]);
|
||
}
|
||
else if (j === "Billable") {
|
||
r[j] = { DisplayValue: r.Id.Value > 0 ? (r["Billable"] ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No")) : "", Value: r.Id.Value > 0 ? (r["Billable"] ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No")) : "" };
|
||
}
|
||
|
||
if (r.MaintenanceID && (j === "InspectionCount" || j === "InspectionRequired" || j === "EstimateStatus"
|
||
|| j === "PublishedEstimates" || j === "ApprovedEstimates" || j === "RejectedEstimates" || j === "PendingEstimates"
|
||
|| j === "AutoText" || j === "Billable")) {
|
||
r[j] = { DisplayValue: "", Value: r[j] };
|
||
}
|
||
}
|
||
rows.push(r);
|
||
}
|
||
grid_dt.virtualCount = 30;
|
||
|
||
grid_dt.setData(rows);
|
||
}
|
||
|
||
function getEstimateStatus(s) {
|
||
var text = "";
|
||
if (s === 0)
|
||
text = GetTextByKey('P_WO_DRAFT', 'Draft');
|
||
else if (s === 1)
|
||
text = GetTextByKey('P_WO_AWAITINGCUSTOMERAPPROVAL', 'Awaiting Customer Approval');
|
||
else if (s === 2)
|
||
text = GetTextByKey('P_WO_CANCELLEDBYDEALER', 'Cancelled by Dealer');
|
||
else if (s === 3)
|
||
text = GetTextByKey('P_WO_CUSTOMERREJECTED', 'Customer Rejected');
|
||
else if (s === 4)
|
||
text = GetTextByKey('P_WO_CUSTOMERAPPROVED', 'Customer Approved');
|
||
else if (s === 100)
|
||
text = "";
|
||
return text;
|
||
}
|
||
|
||
|
||
function OnResetPivots() {
|
||
if (grid_dt && grid_dt.columns) {
|
||
for (var i = 0; i < grid_dt.columns.length; i++) {
|
||
if (grid_dt.columns[i].filterValues)
|
||
grid_dt.columns[i].filterValues = null;
|
||
}
|
||
grid_dt.reload();
|
||
}
|
||
}
|
||
|
||
var grid_dt;
|
||
function InitGridData() {
|
||
grid_dt = createGridView('#workorderlist');
|
||
var list_columns = [
|
||
{ name: 'Id', caption: GetTextByKey("P_WO_WORKORDERNUMBER", "Work Order Number"), valueIndex: 'WorkOrderNumber', allowFilter: true, css: { 'width': 130, 'text-align': 'left' } },
|
||
{ name: 'WorkOrderType', caption: GetTextByKey("P_WO_WORKORDERTYPE", "Work Order Type"), valueIndex: 'WorkOrderType', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'AssignedToName', caption: GetTextByKey("P_WO_ASSIGNEDTO", "Assigned To"), valueIndex: 'AssignedTo', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'StatusName', caption: GetTextByKey("P_WO_STATUS", "Status"), valueIndex: 'Status', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'Description', caption: GetTextByKey("P_WO_DESCRIPTION", "Description"), valueIndex: 'Description', allowFilter: true, contentWrap: true, css: { 'width': 320, 'text-align': 'left' } },
|
||
{ name: 'AssetName', caption: GetTextByKey("P_WO_ASSET", "Asset"), valueIndex: 'AssetName', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } },
|
||
{ name: 'VIN', caption: GetTextByKey("P_WO_VIN", "VIN"), valueIndex: 'VIN', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } },
|
||
{ name: 'Make', caption: GetTextByKey("P_WO_MAKE", "Make"), valueIndex: 'Make', allowFilter: true, css: { 'width': 100, 'text-align': 'left' } },
|
||
{ name: 'Model', caption: GetTextByKey("P_WO_MODEL", "Model"), valueIndex: 'Model', allowFilter: true, css: { 'width': 100, 'text-align': 'left' } },
|
||
{ name: 'CustomerCode', caption: GetTextByKey("P_WO_CUSTOMERCODE", "Customer Code"), valueIndex: 'CustomerCode', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'Customer', caption: GetTextByKey("P_CR_COMPANYNAME", "Company Name"), valueIndex: 'CustomerName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'LastCommunication', caption: GetTextByKey("P_WO_LASTCOMMUNICATIONTEXT", "Last Communication Text"), valueIndex: 'LastCommunication', allowFilter: true, contentWrap: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'LastCommunicationBy', caption: GetTextByKey("P_WO_LASTCOMMUNICATIONBY", "Last Communication By"), valueIndex: 'LastCommunicationBy', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'LastCommunicationDate', caption: GetTextByKey("P_WO_LASTCOMMUNICATIONDATE", "Last Communication Date"), valueIndex: 'LastCommunicationDate', allowFilter: true, css: { 'width': 155, 'text-align': 'left' } },
|
||
{ name: 'Department', caption: GetTextByKey("P_WO_DEPARTMENT", "Department"), valueIndex: 'DepartmentId', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'Location', caption: GetTextByKey("P_WO_LOCATION", "Location"), valueIndex: 'LocationId', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'Advisor', caption: GetTextByKey("P_WO_ADVISOR", "Advisor"), valueIndex: 'AdvisorId', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'SalespersonName', caption: GetTextByKey("P_WO_SALESPERSON", "Salesperson"), valueIndex: 'SalespersonId', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'CurrentJobsites', caption: GetTextByKey("P_WO_CURRJOBSITE", "Current Jobsite"), valueIndex: 'CurrentJobsites', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'CreateDate', caption: GetTextByKey("P_WO_CREATEDDATE", "Created Date"), valueIndex: 'CreateDate', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'CreationDate', caption: GetTextByKey("P_WO_CREATIONDATE", "Creation Date"), valueIndex: 'CreationDate', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'DueDate', caption: GetTextByKey("P_WO_DUEDATE", "Due Date"), valueIndex: 'DueDate', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'NextFollowUpDate', caption: GetTextByKey("P_WO_NEXTFOLLOWUPDATE", "Next Follow Up Date"), valueIndex: 'NextFollowUpDate', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'PartsExpectedDate', caption: GetTextByKey("P_WO_PARTSEXPECTEDDATE", "Parts Expected Date"), valueIndex: 'PartsExpectedDate', allowFilter: true, css: { 'width': 130, 'text-align': 'left' } },
|
||
{ name: 'LastLaborDate', caption: GetTextByKey("P_WO_LASTLABORDATE", "Last Labor Date"), valueIndex: 'LastLaborDate', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'CompleteDate', caption: GetTextByKey("P_WO_COMPLETEDDATE", "Completed Date"), valueIndex: 'CompleteDate', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'InvoiceNumber', caption: GetTextByKey("P_WO_INVOICENUMBER", "Invoice Number"), valueIndex: 'InvoiceNumber', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } },
|
||
{ name: 'AlternateStatus', caption: GetTextByKey("P_WO_ALTERNATESTATUS", "Alternate Status"), valueIndex: 'AlternateStatus', allowFilter: true, css: { 'width': 140, 'text-align': 'left' } },
|
||
{ name: 'InspectionCount', caption: GetTextByKey("P_WO_INSPECTIONS", "Inspections"), valueIndex: 'InspectionCount', allowFilter: true, css: { 'width': 110, 'text-align': 'right' } },
|
||
{ name: 'InspectionRequired', caption: GetTextByKey("P_WO_INSPECTIONREQUIRED", "Inspection Required"), valueIndex: 'InspectionRequired', type: 3, allowFilter: true, css: { 'width': 140, 'text-align': 'left' } },
|
||
{ name: 'AutoText', caption: GetTextByKey("P_WO_AUTOSENDCOMMUNICATIONENABLED", "Auto-send Communication Enabled"), valueIndex: 'AutoText', type: 3, allowFilter: true, css: { 'width': 140, 'text-align': 'left' } },
|
||
{ name: 'Notes', caption: GetTextByKey("P_WO_NOTES", "Notes"), valueIndex: 'Notes', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'Contacts', caption: GetTextByKey("P_WO_CONTACTS", "Contacts"), valueIndex: 'Contacts', css: { 'width': 200, 'text-align': 'left' } },
|
||
{ name: 'EstimateStatus', caption: GetTextByKey("P_WO_ESTIMATESTATUS", "Estimate Status"), allowFilter: true, valueIndex: 'EstimateStatus', css: { 'width': 180, 'text-align': 'left' } },
|
||
{ name: 'PublishedEstimates', caption: GetTextByKey("P_WO_PUBLISHEDESTIMATES", "Published Estimates"), valueIndex: 'PublishedEstimates', allowFilter: true, css: { 'width': 110, 'text-align': 'right' } },
|
||
{ name: 'ApprovedEstimates', caption: GetTextByKey("P_WO_APPROVEDESTIMATES", "Approved Estimates"), valueIndex: 'ApprovedEstimates', allowFilter: true, css: { 'width': 110, 'text-align': 'right' } },
|
||
{ name: 'RejectedEstimates', caption: GetTextByKey("P_WO_REJECTEDESTIMATES", "Rejected Estimates"), valueIndex: 'RejectedEstimates', allowFilter: true, css: { 'width': 110, 'text-align': 'right' } },
|
||
{ name: 'PendingEstimates', caption: GetTextByKey("P_WO_PENDINGESTIMATES", "Pending Estimates"), valueIndex: 'PendingEstimates', allowFilter: true, css: { 'width': 110, 'text-align': 'right' } },
|
||
{ name: 'Component', caption: GetTextByKey("P_WO_COMPONENT", "Component"), valueIndex: 'Component', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'Billable', caption: GetTextByKey("P_WO_BILLABLE", "Billable"), valueIndex: 'Billable', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'BillToJob', caption: GetTextByKey("P_WO_BILLTOJOB", "Bill to job"), valueIndex: 'BillToJobName', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'PONumber', caption: GetTextByKey("P_WO_PONUMBER", "PO Number"), valueIndex: 'PONumber', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'PartsOrderNumber', caption: GetTextByKey("P_WO_PARTSORDERNUMBER", "Parts Order Number"), valueIndex: 'PartsOrderNumber', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'PartsStatus', caption: GetTextByKey("P_WO_PARTSSTATUS", "Parts Status"), valueIndex: 'PartsStatus', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
||
{ name: 'LastInternalCommunication', caption: GetTextByKey("P_WO_LASTINTERNALCOMMUNICATION", "Last Internal Communication"), valueIndex: 'LastInternalCommunication', allowFilter: true, contentWrap: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'LastInternalCommunicationBy', caption: GetTextByKey("P_WO_LASTINTERNALCOMMUNICATIONBY", "Last Internal Communication By"), valueIndex: 'LastInternalCommunicationBy', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
||
{ name: 'LastInternalCommunicationDate', caption: GetTextByKey("P_WO_LASTINTERNALCOMMUNICATIONDATE", "Last Internal Communication Date"), valueIndex: 'LastInternalCommunicationDate', allowFilter: true, css: { 'width': 155, 'text-align': 'left' } },
|
||
{ name: 'Edit', caption: "", alwaysshow: true, css: { 'width': 30, 'text-align': 'center' } },
|
||
{ name: 'Print', caption: "", alwaysshow: true, css: { 'width': 30, 'text-align': 'center' } },
|
||
{ name: 'Delete', caption: "", alwaysshow: true, css: { 'width': 30, 'text-align': 'center' } },
|
||
{ name: 'AssetAlert', caption: "", alwaysshow: true, css: { 'width': 30, 'text-align': 'center' } }
|
||
//{ name: 'Surveys', caption: "", alwaysshow: true, css: { 'width': 30, '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;
|
||
col.allowFilter = list_columns[hd].allowFilter;
|
||
col.contentWrap = list_columns[hd].contentWrap;
|
||
col.maxLines = list_columns[hd].maxLines;
|
||
col.oldFilterValues = col.filterValues;
|
||
|
||
col.alwaysshow = list_columns[hd].alwaysshow;
|
||
col.bgFilter = function (item) {
|
||
if (item.Id.Value > 0 && IsAdvisor) {
|
||
if (item.TextMessageStatus == 0//Undelivered
|
||
|| item.TextMessageStatus == 9//Failed
|
||
|| item.TextMessageStatus == 10//Opt-Out
|
||
|| item.TextMessageStatus == 412)//Landline
|
||
return '#FFC107';
|
||
if (!item.CommunicationAcknowledged)
|
||
return '#79B6FF';
|
||
if (!item.EstimateAcknowledged) {
|
||
if (item.ApprovedEstimates > 0)
|
||
return '#07FF93';
|
||
if (item.RejectedEstimates > 0)
|
||
return '#D81B1B';//rgb(216 27 27)
|
||
}
|
||
}
|
||
};
|
||
var styleFilter = function (item) {
|
||
if (item.Id.Value > 0 && IsAdvisor) {
|
||
if (item.TextMessageStatus == 0//Undelivered
|
||
|| item.TextMessageStatus == 9//Failed
|
||
|| item.TextMessageStatus == 10//Opt-Out
|
||
|| item.TextMessageStatus == 412//Landline
|
||
|| !item.CommunicationAcknowledged
|
||
|| (!item.EstimateAcknowledged && (item.ApprovedEstimates > 0 || item.RejectedEstimates > 0))
|
||
)
|
||
return { "font-weight": "bold" };
|
||
}
|
||
return {};
|
||
}
|
||
if (col.name !== 'Edit' && col.name !== "Print" && col.name !== "Delete" && col.name !== "AssetAlert")
|
||
col.styleFilter = styleFilter;
|
||
if (!IsCustomerRecordAllow && (col.name === "Customer")) {
|
||
continue;
|
||
}
|
||
if (!AllowWorkOrderSurveys && (col.name === "Surveys")) {
|
||
continue;
|
||
}
|
||
if (WOReadOnly && (col.name === "AssetAlert")) {
|
||
continue;
|
||
}
|
||
if (!AllowCustomer && (col.name === "Advisor" || col.name === "CustomerCode" || col.name === "Contacts"
|
||
|| col.name === "LastCommunication" || col.name === "LastCommunicationDate" || col.name === "LastCommunicationBy"
|
||
|| col.name === "AlternateStatus" || col.name === "EstimateStatus" || col.name === "Surveys"
|
||
|| col.name === "PublishedEstimates" || col.name === "ApprovedEstimates" || col.name === "RejectedEstimates" || col.name === "PendingEstimates"
|
||
|| col.name === "AutoText")) {
|
||
continue;
|
||
}
|
||
|
||
var DateColumn = window['lib-ui'].GridDateColumn;
|
||
if (col.name === "StatusName") {
|
||
//col.bgFilter = function (item) {
|
||
// if (item.StatusColor && item.StatusColor != null)
|
||
// return item.StatusColor.toLowerCase()
|
||
//}
|
||
col.type = GridView.ColumnTypes.Dropdown;
|
||
col.filter = function (item, editing) {
|
||
return editing ? String(item.Status) : item.StatusName;
|
||
}
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.dropOptions = {
|
||
search: true,
|
||
textKey: 'Name',
|
||
valueKey: 'Id'
|
||
};
|
||
col.attrs = { 'data-radius': '' };
|
||
col.source = function (item) {
|
||
var source = [];
|
||
if (workOrderStatus) {
|
||
var exists = false;
|
||
for (var i = 0; i < workOrderStatus.length; i++) {
|
||
var s = workOrderStatus[i];
|
||
if (!item.CanClose && (s.Status === 100 || s.StatusType === 100))
|
||
continue;
|
||
//option.css('background-color', 'white');
|
||
if (item.Status == s.Id) {
|
||
exists = true;
|
||
}
|
||
source.push({
|
||
Id: String(s.Id),
|
||
Name: s.Name,
|
||
Color: s.Color,
|
||
StatusType: s.StatusType,
|
||
AutoText: s.AutoText,
|
||
Message: s.Message
|
||
});
|
||
}
|
||
if (!exists && !isNaN(item.Status)) {
|
||
var s = {
|
||
Id: String(item.Status),
|
||
Name: item.StatusName,
|
||
Color: item.StatusColor,
|
||
StatusType: item.StatusType
|
||
};
|
||
//option.css('background-color', 'white');
|
||
source.push(s);
|
||
}
|
||
}
|
||
return source;
|
||
};
|
||
col.onChanged = function (item, _value, old, it) {
|
||
if (it && it.Id != old) {
|
||
if ((!AllowCommunicate || COMMReadOnly) && (it.Id != 100 && it.StatusType !== 100)) {
|
||
item.Status = Number(it.Id);
|
||
item.StatusName = it.Name;
|
||
item.StatusColor = it.Color;
|
||
item.StatusType = it.StatusType;
|
||
updateWorkOrder(item);
|
||
}
|
||
else {
|
||
onStatusChange(item, it, function () {
|
||
item.Status = Number(it.Id);
|
||
item.StatusName = it.Name;
|
||
item.StatusColor = it.Color;
|
||
item.StatusType = it.StatusType;
|
||
}, function () {
|
||
item.Status = old;
|
||
grid_dt?.refresh();
|
||
});
|
||
}
|
||
}
|
||
};
|
||
col.styleFilter = function (item) {
|
||
return {
|
||
...styleFilter(item),
|
||
'background-color': item.StatusColor
|
||
};
|
||
}
|
||
}
|
||
else if (col.name === "WorkOrderType") {
|
||
col.type = GridView.ColumnTypes.Dropdown;
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.dropOptions = {
|
||
search: true
|
||
};
|
||
col.source = function (item) {
|
||
var source = [];
|
||
if (workOrderTypes) {
|
||
if (item.WorkOrderType && workOrderTypes.indexOf(item.WorkOrderType) < 0) {
|
||
workOrderTypes.push(item.WorkOrderType);
|
||
workOrderTypes.sort(function (s, t) {
|
||
let a = s.toLowerCase();
|
||
let b = t.toLowerCase();
|
||
if (a < b) return -1;
|
||
if (a > b) return 1;
|
||
return 0;
|
||
});
|
||
}
|
||
for (var i = 0; i < workOrderTypes.length; i++) {
|
||
var t = workOrderTypes[i];
|
||
var kv = { value: t, text: t };
|
||
source.push(kv);
|
||
}
|
||
}
|
||
return source;
|
||
};
|
||
col.onChanged = function (item, value, old) {
|
||
if (old != value) {
|
||
updateWorkOrder(item);
|
||
}
|
||
};
|
||
col.styleFilter = styleFilter;
|
||
}
|
||
else if (col.name === "Advisor") {
|
||
col.type = GridView.ColumnTypes.Dropdown;
|
||
col.filter = function (item, editing) {
|
||
return editing ? item.AdvisorId : item.AdvisorName;
|
||
};
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.dropOptions = {
|
||
search: true,
|
||
textKey: 'Value',
|
||
valueKey: 'Key'
|
||
};
|
||
col.source = function (item) {
|
||
var source = [{ Key: '', Value: ' ' }];
|
||
var selected;
|
||
if (woAdvisors) {
|
||
for (var i = 0; i < woAdvisors.length; i++) {
|
||
var a = woAdvisors[i];
|
||
source.push(a);
|
||
if (item.AdvisorId.toLowerCase() == a.Key.toLowerCase()) {
|
||
item.AdvisorId = selected = a.Key;
|
||
}
|
||
}
|
||
}
|
||
if (selected == null && item.AdvisorId != '' && item.AdvisorId != '-1') {
|
||
source.push({ Key: item.AdvisorId, Value: item.AdvisorName });
|
||
}
|
||
return source;
|
||
};
|
||
col.onChanged = function (item, value, old, a) {
|
||
if (value != old) {
|
||
item.AdvisorId = a.Key;
|
||
item.AdvisorName = a.Value;
|
||
updateWorkOrder(item);
|
||
}
|
||
};
|
||
col.styleFilter = styleFilter;
|
||
}
|
||
else if (col.name === "AssignedToName") {
|
||
col.type = GridView.ColumnTypes.Dropdown;
|
||
col.filter = function (item, editing) {
|
||
return editing ? item.AssignedTo : item.AssignedToName;
|
||
};
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.dropOptions = {
|
||
search: true,
|
||
textKey: 'DisplayName',
|
||
valueKey: 'IID'
|
||
};
|
||
col.sourceCache = false;
|
||
col.source = function (item) {
|
||
return item.AssignedToUsers ??= [{ IID: '', DisplayName: ' ' }];
|
||
};
|
||
col.onDropExpanded = function (item, drop) {
|
||
if (!item.AssignedToUsersLoaded) {
|
||
item.AssignedToUsersLoaded = true;
|
||
worequest("GetAssetContacts", JSON.stringify([item.AssetId, item.LocationId, item.DepartmentId]), function (data) {
|
||
if (data && data.length > 0) {
|
||
var source = [
|
||
{ IID: '', DisplayName: ' ' }
|
||
];
|
||
|
||
var sel = null;
|
||
var exists = false;
|
||
var selected;
|
||
if (item.AssignedToUsers && item.AssignedToUsers.length == 1)
|
||
sel = item.AssignedToUsers[0];
|
||
else
|
||
exists = true;
|
||
|
||
for (var i = 0; i < data.length; i++) {
|
||
var u = data[i];
|
||
source.push(u);
|
||
if (item.AssignedTo.toUpperCase() == u.IID.toUpperCase())
|
||
item.AssignedTo = selected = u.IID;
|
||
|
||
if (sel && sel.IID.toUpperCase() == u.IID.toUpperCase())
|
||
exists = true;
|
||
|
||
}
|
||
if (!exists) {
|
||
source.push(sel);
|
||
}
|
||
|
||
item.AssignedToUsers = source;
|
||
|
||
drop.source = source;
|
||
drop.select(selected, true);
|
||
}
|
||
}, function () {
|
||
});
|
||
}
|
||
};
|
||
col.onChanged = function (item, value, old, u) {
|
||
if (value != old) {
|
||
item.AssignedTo = u.IID;
|
||
item.AssignedToName = u.DisplayName;
|
||
if (u.ContactType === 6) {
|
||
item.HourlyRate = u.HourlyRate;
|
||
}
|
||
updateWorkOrder(item);
|
||
}
|
||
};
|
||
col.styleFilter = styleFilter;
|
||
}
|
||
else if (col.name === "DueDate") {
|
||
col.type = GridView.ColumnTypes.Date;
|
||
col.filter = function (item, editing) {
|
||
return editing ? item.DueDate.Value : item.DueDateStr;
|
||
};
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
//col.attrs = { 'data-radius': '' };
|
||
col.sortFilter = function (a, b) {
|
||
a = a.DueDate.Value;
|
||
b = b.DueDate.Value;
|
||
return a > b ? 1 : (a < b ? -1 : 0);
|
||
};
|
||
col.onChanged = function (item, value) {
|
||
item.DueDateStr = item.DueDate.DisplayValue = DateColumn.formatDate(value);
|
||
updateWorkOrder(item);
|
||
};
|
||
col.styleFilter = function (item) {
|
||
var style = styleFilter(item);
|
||
if (!item.Completed && item.DueDate.DisplayValue && new Date(item.DueDate.DisplayValue) < new Date(currentdate)) {
|
||
style['background-color'] = 'red';
|
||
}
|
||
return style;
|
||
};
|
||
col.background = function (item) {
|
||
if (!item.Completed && item.DueDate.DisplayValue && new Date(item.DueDate.DisplayValue) < new Date(currentdate)) {
|
||
return 'red';
|
||
}
|
||
return this.bgFilter(item);
|
||
};
|
||
}
|
||
else if (col.name === "CompleteDate") {
|
||
col.type = GridView.ColumnTypes.Date;
|
||
col.filter = function (item, editing) {
|
||
return editing ? item.CompleteDate.Value : item.CompleteDateStr;
|
||
};
|
||
col.enabled = function (item) {
|
||
return item.Completed && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.sortFilter = function (a, b) {
|
||
a = a.CompleteDate.Value;
|
||
b = b.CompleteDate.Value;
|
||
return a > b ? 1 : (a < b ? -1 : 0);
|
||
};
|
||
col.dateValueFormatter = function (date) {
|
||
return date;
|
||
};
|
||
col.onChanged = function (item, value) {
|
||
//item.CompleteDateStr = DateColumn.formatDate(value);
|
||
getAssetDetailInfo(item.AssetId, item, value);
|
||
};
|
||
col.styleFilter = styleFilter;
|
||
}
|
||
else if (col.name === "NextFollowUpDate") {
|
||
//col.bgFilter = function (item) {
|
||
// if (!item.Completed && item.NextFollowUpDate.Value && new Date(item.NextFollowUpDate.Value) < new Date(currentdate))
|
||
// return 'red';
|
||
//}
|
||
col.type = GridView.ColumnTypes.Date;
|
||
col.filter = function (item, editing) { return editing ? item.NextFollowUpDate.Value : item.NextFollowUpDateStr };
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
//col.attrs = { 'data-radius': '' };
|
||
col.sortFilter = function (a, b) {
|
||
a = a.NextFollowUpDate.Value;
|
||
b = b.NextFollowUpDate.Value;
|
||
return a > b ? 1 : (a < b ? -1 : 0);
|
||
};
|
||
col.onChanged = function (item, value) {
|
||
item.NextFollowUpDateStr = item.NextFollowUpDate.DisplayValue = DateColumn.formatDate(value);
|
||
updateWorkOrder(item);
|
||
};
|
||
col.styleFilter = function (item) {
|
||
var style = styleFilter(item);
|
||
if (!item.Completed && item.NextFollowUpDate.DisplayValue && new Date(item.NextFollowUpDate.DisplayValue) < new Date(currentdate)) {
|
||
style['background-color'] = 'red';
|
||
}
|
||
return style;
|
||
};
|
||
col.background = function (item) {
|
||
if (!item.Completed && item.NextFollowUpDate.DisplayValue && new Date(item.NextFollowUpDate.DisplayValue) < new Date(currentdate)) {
|
||
return 'red';
|
||
}
|
||
return this.bgFilter(item);
|
||
};
|
||
}
|
||
else if (col.name === "Description") {
|
||
col.type = NoteColumn;
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.onClicked = function (item, element) {
|
||
onEditText(item, 1, function () {
|
||
element.querySelector('.cell-flex-memo').innerHTML = converthtmlurl(item.Description);
|
||
});
|
||
};
|
||
}
|
||
else if (col.name === 'AssetName') {
|
||
col.styleFilter = styleFilter;
|
||
}
|
||
else if (col.name === 'InspectionCount') {
|
||
col.styleFilter = function (item) {
|
||
if (item.InspectionRequired.Value && item.InspectionCount > 0 && item.InspectionTemplateId > 0) {
|
||
return { 'color': item.RequiredInspectionCompleted ? '#2eda2e' : "red", 'font-weight': 'bold' };
|
||
}
|
||
};
|
||
}
|
||
else if (col.name === "Notes") {
|
||
col.type = NoteColumn;
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.onClicked = function (item, element) {
|
||
onEditText(item, 2, function () {
|
||
element.querySelector('.cell-flex-memo').innerText = item.Notes;
|
||
});
|
||
};
|
||
}
|
||
else if (col.name === "Edit") {
|
||
col.sortable = false;
|
||
col.resizable = false;
|
||
col.type = GridView.ColumnTypes.Icon;
|
||
col.text = 'edit';
|
||
col.iconType = 'fa-light';
|
||
col.events = {
|
||
onclick: function () {
|
||
OnEdit();
|
||
}
|
||
};
|
||
col.styleFilter = function (e) {
|
||
return {
|
||
display: (e.MaintenanceID) ? 'none' : ''
|
||
};
|
||
};
|
||
col.attrs = { 'title': GetTextByKey("P_WO_EDIT", 'Edit') };
|
||
}
|
||
else if (col.name === "Print") {
|
||
col.sortable = false;
|
||
col.resizable = false;
|
||
col.type = GridView.ColumnTypes.Icon;
|
||
col.visible = canExport;
|
||
col.text = 'print';
|
||
col.iconType = 'fa-light';
|
||
col.events = {
|
||
onclick: function () {
|
||
OnPrint();
|
||
}
|
||
};
|
||
col.styleFilter = function (e) {
|
||
return {
|
||
display: (e.MaintenanceID) ? 'none' : ''
|
||
};
|
||
};
|
||
col.attrs = { 'title': GetTextByKey("P_WO_PRINT", 'Print') };
|
||
}
|
||
else if (col.name === "Delete") {
|
||
col.sortable = false;
|
||
col.resizable = false;
|
||
col.type = GridView.ColumnTypes.Icon;
|
||
col.text = 'times';
|
||
col.iconType = 'fa-light';
|
||
col.events = {
|
||
onclick: function () {
|
||
OnDelete(this);
|
||
}
|
||
};
|
||
col.styleFilter = function (e) {
|
||
return {
|
||
display: (WOReadOnly || e.Completed || e.MaintenanceID || !e.CanDeleteAndRestore) ? 'none' : ''
|
||
};
|
||
};
|
||
col.attrs = { 'title': GetTextByKey("P_WO_DELETE", 'Delete') };
|
||
}
|
||
else if (col.name === "AssetAlert") {
|
||
col.sortable = false;
|
||
col.resizable = false;
|
||
col.type = GridView.ColumnTypes.Icon;
|
||
col.text = 'exclamation-triangle';
|
||
col.iconType = 'fa-light';
|
||
col.events = {
|
||
onclick: function () {
|
||
ManageAlerts(this);
|
||
}
|
||
};
|
||
col.styleFilter = function (e) {
|
||
return {
|
||
display: (e.Completed || e.MaintenanceID) ? 'none' : ''
|
||
};
|
||
};
|
||
col.attrs = { 'title': GetTextByKey("P_WO_ASSETALERT", 'Asset Alert') };
|
||
}
|
||
else if (col.name === "Surveys") {
|
||
col.sortable = false;
|
||
col.resizable = false;
|
||
col.type = GridView.ColumnTypes.Icon;
|
||
col.text = 'file-alt';
|
||
col.iconType = 'fa-light';
|
||
col.events = {
|
||
onclick: function () {
|
||
onSendWOSurveys(this);
|
||
}
|
||
};
|
||
col.styleFilter = function (e) {
|
||
return {
|
||
display: (!e.Completed || e.MaintenanceID || !e.Contacts || e.Contacts.length == 0) ? 'none' : ''
|
||
};
|
||
};
|
||
col.attrs = { 'title': GetTextByKey("P_WO_SENDWORKORDERSURVEYS", 'Send Work Order Surveys') };
|
||
}
|
||
else if (col.name === "Contacts") {
|
||
col.sortable = false;
|
||
col.type = ContactsColumn;
|
||
col.filter = function (item) {
|
||
return item.Contacts?.map(function (c) {
|
||
var ptext = c.Name;
|
||
switch (c.ContactPreference) {
|
||
case 0:
|
||
ptext += ' - T';
|
||
if (c.MobilePhone !== '') {
|
||
ptext += ' - ' + c.MobilePhoneDisplayText;
|
||
}
|
||
break;
|
||
case 1:
|
||
if (c.Email !== '') {
|
||
ptext += ' - ' + c.Email;
|
||
}
|
||
break;
|
||
case 2:
|
||
ptext += ' - P';
|
||
if (c.MobilePhone !== '') {
|
||
ptext += ' - ' + c.MobilePhoneDisplayText;
|
||
}
|
||
break;
|
||
}
|
||
return ptext;
|
||
}) ?? [];
|
||
};
|
||
col.styleFilter = styleFilter;
|
||
}
|
||
else if (col.name === "PartsExpectedDate") {
|
||
col.type = GridView.ColumnTypes.Date;
|
||
col.filter = function (item, editing) { return editing ? item.PartsExpectedDate.Value : item.PartsExpectedDateStr };
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
//col.attrs = { 'data-radius': '' };
|
||
col.sortFilter = function (a, b) {
|
||
a = a.PartsExpectedDate.Value;
|
||
b = b.PartsExpectedDate.Value;
|
||
return a > b ? 1 : (a < b ? -1 : 0);
|
||
};
|
||
col.onChanged = function (item, value) {
|
||
item.PartsExpectedDateStr = item.PartsExpectedDate.DisplayValue = DateColumn.formatDate(value);
|
||
updateWorkOrder(item);
|
||
};
|
||
col.styleFilter = function (item) {
|
||
var style = styleFilter(item);
|
||
if (!item.Completed && item.PartsExpectedDate.DisplayValue && new Date(item.PartsExpectedDate.DisplayValue) < new Date(currentdate)) {
|
||
style['background-color'] = 'red';
|
||
}
|
||
return style;
|
||
};
|
||
col.background = function (item) {
|
||
if (!item.Completed && item.PartsExpectedDate.DisplayValue && new Date(item.PartsExpectedDate.DisplayValue) < new Date(currentdate)) {
|
||
return 'red';
|
||
}
|
||
return this.bgFilter(item);
|
||
}
|
||
}
|
||
else if (col.name === "LastLaborDate") {
|
||
col.type = GridView.ColumnTypes.Date;
|
||
col.filter = function (item, editing) { return editing ? item.LastLaborDate.Value : item.LastLaborDateStr };
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
//col.attrs = { 'data-radius': '' };
|
||
col.sortFilter = function (a, b) {
|
||
a = a.LastLaborDate.Value;
|
||
b = b.LastLaborDate.Value;
|
||
return a > b ? 1 : (a < b ? -1 : 0);
|
||
};
|
||
col.onChanged = function (item, value) {
|
||
item.LastLaborDateStr = item.LastLaborDate.DisplayValue = DateColumn.formatDate(value);
|
||
updateWorkOrder(item);
|
||
};
|
||
col.styleFilter = styleFilter;
|
||
}
|
||
else if (col.name === "InspectionRequired") {
|
||
col.type = CheckboxColumn;
|
||
col.filter = function (item, editing) {
|
||
if (WOReadOnly || item.Id.Value <= 0) {
|
||
return '';
|
||
}
|
||
if (editing) {
|
||
return item.InspectionRequired.Value;
|
||
}
|
||
return item.InspectionRequired.Value ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No");
|
||
};
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.onChanged = function (item, value, old) {
|
||
if (value != old) {
|
||
item.InspectionRequired.DisplayValue = value ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No");
|
||
updateWorkOrder(item);
|
||
}
|
||
};
|
||
col.styleFilter = styleFilter;
|
||
}
|
||
else if (col.name === "AutoText") {
|
||
col.type = CheckboxColumn;
|
||
col.filter = function (item, editing) {
|
||
if (WOReadOnly || item.Id.Value <= 0) {
|
||
return '';
|
||
}
|
||
if (editing, editing) {
|
||
return item.AutoText.Value;
|
||
}
|
||
return item.AutoText.Value ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No");
|
||
};
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.onChanged = function (item, value, old) {
|
||
if (value != old) {
|
||
item.AutoText.DisplayValue = value ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No");
|
||
updateWorkOrder(item);
|
||
}
|
||
};
|
||
col.styleFilter = styleFilter;
|
||
}
|
||
else if (col.name === "Department") {
|
||
col.type = GridView.ColumnTypes.Dropdown;
|
||
col.filter = function (item, editing) {
|
||
return editing ? item.DepartmentId : item.Department;
|
||
};
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.dropOptions = {
|
||
search: true,
|
||
valueKey: 'Id',
|
||
textKey: 'Name'
|
||
};
|
||
col.sourceCache = false;
|
||
col.source = function (item) {
|
||
return item.Departments ??= [{ Id: '', Name: ' ' }];
|
||
};
|
||
col.onDropExpanded = function (item, drop) {
|
||
if (!item.DepartmentsLoaded) {
|
||
item.DepartmentsLoaded = true;
|
||
worequest("GetDepartments", '', function (data) {
|
||
if (data && data.length > 0) {
|
||
var source = [{ Id: '-1', Name: ' ' }];
|
||
|
||
var sel = null;
|
||
var exists = false;
|
||
var selected;
|
||
if (item.Departments && item.Departments.length == 1)
|
||
sel = item.Departments[0];
|
||
else
|
||
exists = true;
|
||
|
||
for (var i = 0; i < data.length; i++) {
|
||
var dept = data[i];
|
||
if (dept.PId > 0) {
|
||
dept.html = ' ' + dept.Name;
|
||
}
|
||
source.push(dept);
|
||
if (item.DepartmentId == dept.Id)
|
||
selected = dept.Id;
|
||
|
||
if (sel && sel.Id == dept.Id)
|
||
exists = true;
|
||
|
||
}
|
||
if (!exists) {
|
||
if (sel.PId > 0) {
|
||
sel.html = ' ' + sel.Name;
|
||
}
|
||
source.push(sel);
|
||
}
|
||
|
||
item.Departments = source;
|
||
|
||
drop.source = source;
|
||
drop.select(selected, true);
|
||
}
|
||
}, function () {
|
||
});
|
||
}
|
||
};
|
||
col.onChanged = function (item, value, old, dept) {
|
||
if (value != old) {
|
||
item.Department = dept.Name;
|
||
item.AssignedToUsersLoaded = false;
|
||
updateWorkOrder(item);
|
||
}
|
||
};
|
||
col.styleFilter = styleFilter;
|
||
}
|
||
else if (col.name === "Location") {
|
||
col.type = GridView.ColumnTypes.Dropdown;
|
||
col.filter = function (item, editing) {
|
||
return editing ? item.LocationId : item.Location;
|
||
};
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.dropOptions = {
|
||
search: true,
|
||
valueKey: 'ID',
|
||
textKey: 'Name'
|
||
};
|
||
col.sourceCache = false;
|
||
col.source = function (item) {
|
||
return item.Locations ??= [{ ID: '', Name: ' ' }];
|
||
};
|
||
col.onDropExpanded = function (item, drop) {
|
||
if (!item.LocationsLoaded) {
|
||
item.LocationsLoaded = true;
|
||
worequest("GetLocations", '', function (data) {
|
||
if (data && data.length > 0) {
|
||
var source = [{ ID: '-1', Name: ' ' }];
|
||
|
||
var sel = null;
|
||
var exists = false;
|
||
var selected;
|
||
if (item.Locations && item.Locations.length == 1)
|
||
sel = item.Locations[0];
|
||
else
|
||
exists = true;
|
||
|
||
for (var i = 0; i < data.length; i++) {
|
||
var loc = data[i];
|
||
if (loc.PId > 0) {
|
||
loc.html = ' ' + loc.Name;
|
||
}
|
||
source.push(loc);
|
||
if (item.LocationId == loc.ID)
|
||
selected = loc.ID;
|
||
|
||
if (sel && sel.ID == loc.ID)
|
||
exists = true;
|
||
|
||
}
|
||
if (!exists) {
|
||
if (sel.PId > 0) {
|
||
sel.html = ' ' + sel.Name;
|
||
}
|
||
source.push(sel);
|
||
}
|
||
|
||
item.Locations = source;
|
||
|
||
drop.source = source;
|
||
drop.select(selected, true);
|
||
}
|
||
}, function () {
|
||
});
|
||
}
|
||
};
|
||
col.onChanged = function (item, value, old, loc) {
|
||
if (value != old) {
|
||
item.Location = loc.Name;
|
||
item.AssignedToUsersLoaded = false;
|
||
updateWorkOrder(item);
|
||
}
|
||
};
|
||
col.styleFilter = styleFilter;
|
||
}
|
||
else if (col.name === "SalespersonName") {
|
||
col.type = GridView.ColumnTypes.Dropdown;
|
||
col.filter = function (item, editing) {
|
||
return editing ? item.SalespersonId : item.SalespersonName;
|
||
};
|
||
col.enabled = function (item) {
|
||
return (IsAdmin || !item.Completed || AllowReopenWorkorders) && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.dropOptions = {
|
||
search: true,
|
||
valueKey: 'Key',
|
||
textKey: 'Value'
|
||
};
|
||
col.onDropExpanded = function (item, drop) {
|
||
if (!item.SalespersonsLoaded) {
|
||
item.SalespersonsLoaded = true;
|
||
worequest("GetSalespersons", '', function (data) {
|
||
if (data && data.length > 0) {
|
||
var source = [{ Key: '', Value: ' ' }];
|
||
|
||
var exists = false;
|
||
if (!item.SalespersonId || item.SalespersonId == "")
|
||
exists = true;
|
||
|
||
for (var i = 0; i < data.length; i++) {
|
||
var s = data[i];
|
||
source.push(s);
|
||
if (!exists && item.SalespersonId == s.Key)
|
||
exists = true;
|
||
}
|
||
if (!exists) {
|
||
source.push({ Key: item.SalespersonId, Value: item.SalespersonName });
|
||
}
|
||
|
||
item.Salespersons = source;
|
||
|
||
drop.source = source;
|
||
drop.select(item.SalespersonId, true);
|
||
}
|
||
}, function () {
|
||
});
|
||
}
|
||
};
|
||
col.sourceCache = false;
|
||
col.source = function (item) {
|
||
var source = [];
|
||
if (item.Salespersons) {
|
||
for (var i = 0; i < item.Salespersons.length; i++) {
|
||
var s = item.Salespersons[i];
|
||
source.push(s);
|
||
}
|
||
} else {
|
||
source.push({ Key: '', Value: ' ' });
|
||
}
|
||
return source;
|
||
};
|
||
col.onChanged = function (item, value, old, s) {
|
||
if (value != old && s) {
|
||
item.SalespersonName = s.Value;
|
||
updateWorkOrder(item);
|
||
}
|
||
};
|
||
col.styleFilter = styleFilter
|
||
}
|
||
else if (col.name === "LastCommunication") {
|
||
col.type = CommunicationColumn;
|
||
col.enabled = function (item) {
|
||
return IsAdvisor && !item.CommunicationAcknowledged && !WOReadOnly && item.Id.Value > 0;
|
||
};
|
||
col.onClicked = function (item) {
|
||
updateCommunicationAcknowledged(item.Id.Value, true);
|
||
item.CommunicationAcknowledged = true;
|
||
grid_dt?.refresh();
|
||
};
|
||
}
|
||
columns.push(col);
|
||
}
|
||
grid_dt.multiSelect = false;
|
||
|
||
grid_dt.onCellDblClicked = function (_rowindex, colindex) {
|
||
if (colindex >= 0) {
|
||
var col = grid_dt.columns[colindex];
|
||
if (col.name == "Description" || col.name == "Notes") {
|
||
var index = grid_dt.selectedIndex;
|
||
if (index < 0) return;
|
||
var wo = grid_dt.source[index];
|
||
if (wo.Id.Value <= 0) return;
|
||
if (!IsAdmin && wo.Completed && !AllowReopenWorkorders)
|
||
return;
|
||
onEditText(wo, col.name == "Description" ? 1 : 2, function () {
|
||
grid_dt.refresh();
|
||
});
|
||
} else if (!col.type) {
|
||
OnEdit();
|
||
}
|
||
}
|
||
};
|
||
|
||
grid_dt.onSelectedRowChanged = function (rowindex) {
|
||
var rowdata = grid_dt.source[rowindex];
|
||
if (rowdata && rowdata.Id.Value > 0) {
|
||
if (!wowidgetobj) {
|
||
wowidgetobj = new WorkOrderWidget();
|
||
}
|
||
wowidgetobj.changeWorkOrder(rowdata);
|
||
}
|
||
}
|
||
|
||
grid_dt.allcolumns = columns;
|
||
getGridLayout(gridLayoutID, grid_dt, GetLocationsAndDepartments);
|
||
}
|
||
|
||
function updateWorkOrder(wo, sendtextmsg) {
|
||
var item = {
|
||
'Id': wo.Id.Value || wo.Id,
|
||
'AssetID': wo.AssetId,
|
||
'WorkOrderType': wo.WorkOrderType,
|
||
'AdvisorId': wo.AdvisorId,
|
||
'Status': wo.Status,
|
||
'StatusType': wo.StatusType,
|
||
'AssignedTo': wo.AssignedTo,
|
||
'Description': wo.Description,
|
||
'DueDate': wo.DueDateStr,
|
||
'CompleteDate': wo.CompleteDateStr,
|
||
'NextFollowUpDate': wo.NextFollowUpDateStr,
|
||
'Notes': wo.Notes,
|
||
'MeterType': wo.MeterType,
|
||
'HourMeter': wo.HourMeter || 0,
|
||
'Odometer': wo.Odometer || 0,
|
||
'OdometerUnits': wo.OdometerUnits,
|
||
'WorkOrderNumber': wo.WorkOrderNumber.DisplayValue,
|
||
'HourlyRate': wo.HourlyRate,
|
||
'PartsExpectedDate': wo.PartsExpectedDateStr,
|
||
'LastLaborDate': wo.LastLaborDateStr,
|
||
'InspectionRequired': wo.InspectionRequired.Value,
|
||
'AutoText': wo.AutoText.Value,
|
||
'DepartmentId': wo.DepartmentId,
|
||
'LocationId': wo.LocationId,
|
||
'SalespersonId': wo.SalespersonId
|
||
};
|
||
|
||
var alerttitle = GetTextByKey('P_WO_SAVEWORKORDER', 'Save Work Order');
|
||
if (item.NextFollowUpDate.length > 0) {
|
||
if (!checkDate(item.NextFollowUpDate)) {
|
||
showAlert(GetTextByKey("P_WO_NEXTFOLLOWUPDATEFORMATERROR", "Next Follow Up Date format error."), alerttitle);
|
||
return false;
|
||
}
|
||
}
|
||
else {
|
||
item.NextFollowUpDate = "";
|
||
}
|
||
|
||
if (item.DueDate.length > 0) {
|
||
if (!checkDate(item.DueDate)) {
|
||
showAlert(GetTextByKey("P_WO_DUEDATEFORMATERROR", "Due Date format error."), alerttitle);
|
||
return false;
|
||
}
|
||
}
|
||
else {
|
||
item.DueDate = "";
|
||
}
|
||
|
||
if (item.CompleteDate.length > 0) {
|
||
if (!checkDate(item.CompleteDate)) {
|
||
showAlert(GetTextByKey("P_WO_COMPLETEDDATEFORMATERROR", "Completed Date format error."), alerttitle);
|
||
return false;
|
||
}
|
||
}
|
||
else {
|
||
item.CompleteDate = "";
|
||
}
|
||
|
||
if (item.PartsExpectedDate.length > 0) {
|
||
if (!checkDate(item.PartsExpectedDate)) {
|
||
showAlert(GetTextByKey("P_WO_PARTSEXPECTEDDATEFORMATERROR", "Parts Expected Date format error."), alerttitle);
|
||
return false;
|
||
}
|
||
}
|
||
else {
|
||
item.PartsExpectedDate = "";
|
||
}
|
||
|
||
if (item.LastLaborDate.length > 0) {
|
||
if (!checkDate(item.LastLaborDate)) {
|
||
showAlert(GetTextByKey("P_WO_LASTLABORDATEFORMATERROR", "Last Labor Date format error."), alerttitle);
|
||
return false;
|
||
}
|
||
}
|
||
else {
|
||
item.LastLaborDate = "";
|
||
}
|
||
|
||
if (!item.Description || item.Description.length == 0) {
|
||
showAlert(GetTextByKey("P_WO_DESCRIPTIONCANNOTBEEMPTY", 'Description cannot be empty.'), alerttitle);
|
||
$('#dialog_description').focus();
|
||
return;
|
||
}
|
||
if (isNaN(item.Status))
|
||
item.Status = -1;
|
||
|
||
var param = JSON.stringify(item);
|
||
param = htmlencode(param);
|
||
worequest("UpdateWorkOrder", param, function (data) {
|
||
if (typeof (data) === "string") {
|
||
//showmaskbg(false);
|
||
showAlert(data, alerttitle);
|
||
return;
|
||
}
|
||
if (!wo.CompleteDate || wo.CompleteDate == "") {
|
||
wo.CompleteDate = data.CompleteDate;
|
||
wo.CompleteDateStr = data.CompleteDateStr;
|
||
}
|
||
|
||
grid_dt.refresh();
|
||
|
||
if (sendtextmsg)
|
||
SendTextMsg(wo);
|
||
}, function (err) {
|
||
showAlert(GetTextByKey("P_WO_FAILEDTOSAVEWORKORDER", 'Failed to save Work Order.'), alerttitle);
|
||
});
|
||
}
|
||
|
||
function onStatusChange(wo, tostatus, next, cancel) {
|
||
onRemoveSelectedAttachment();
|
||
cur_asset = null;
|
||
if (!AllowCommunicate || COMMReadOnly) {
|
||
$('.tr_sendmsg').hide();
|
||
}
|
||
else {
|
||
$('.tr_sendmsg').show();
|
||
}
|
||
|
||
$('#dialog_statuschange').data("wo", wo);
|
||
$('#dialog_statuschange').data("tostatus", tostatus);
|
||
$('#dialog_statuschange').data("next", next);
|
||
$('#dialog_statuschange').data("cancel", cancel);
|
||
|
||
if (wo.InspectionRequired.Value && wo.InspectionCount == 0 && (tostatus.Id === 100 || tostatus.StatusType === 100)) {
|
||
showAlert(GetTextByKey('P_WO_INSPECTIONREQUIREDTIP', 'The work order cannot be updated Until an inspection is completed.'), GetTextByKey("P_WO_ERROR", "Error"));
|
||
if (cancel)
|
||
cancel();
|
||
return;
|
||
}
|
||
|
||
var iscompleted = false;
|
||
if (tostatus.Id === 100 || tostatus.StatusType === 100)
|
||
iscompleted = true;
|
||
|
||
setPhoneNumber(wo);
|
||
|
||
$('#dialog_variables').val('');
|
||
if (tostatus.AutoText && !COMMReadOnly) {
|
||
$('#dialog_textmsg').val(tostatus.Message);
|
||
$('#dialog_chksendtextmsg').prop('checked', true);
|
||
$('#txtphonenum').prop('disabled', false);
|
||
$('#dialog_chkIncludeStatusLink').prop('disabled', false);
|
||
$('#dialog_textmsg').prop('disabled', false);
|
||
$('#dialog_variables').prop('disabled', false);
|
||
$('#dialog_insertfield').prop('disabled', false);
|
||
} else {
|
||
$('#dialog_textmsg').val("");
|
||
$('#dialog_chksendtextmsg').prop('checked', false).prop('disabled', COMMReadOnly);
|
||
$('#txtphonenum').prop('disabled', true);
|
||
$('#dialog_chkIncludeStatusLink').prop('disabled', true);
|
||
$('#dialog_textmsg').prop('disabled', true);
|
||
$('#dialog_variables').prop('disabled', true);
|
||
$('#dialog_insertfield').prop('disabled', true);
|
||
}
|
||
|
||
if (iscompleted) {
|
||
getAssetDetailInfo(wo.AssetId);
|
||
$('.statuscompleted').show();
|
||
$('#btn_sendtextandsave').show();
|
||
$('#btn_sendtext').hide();
|
||
|
||
$('#dialog_completeddate').val(nowDate);
|
||
meterType = wo.MeterType;
|
||
$('#dialog_metertype').val(meterType);
|
||
setMeterType();
|
||
$('#dialog_hourmeter').val(wo.HourMeter < 0 ? "" : wo.HourMeter);
|
||
$('#dialog_odometer').val(wo.Odometer < 0 ? "" : wo.Odometer);
|
||
$('#dig_odometeruom').val(wo.OdometerUnits);
|
||
}
|
||
else {
|
||
$('.statuscompleted').hide();
|
||
$('#btn_sendtextandsave').hide();
|
||
$('#btn_sendtext').show();
|
||
}
|
||
|
||
showmaskbg(true, true);
|
||
$('#dialog_statuschange .dialog-title span.title').text(GetTextByKey("P_WO_STATUSCHANGE", 'Status Change') + " - " + tostatus.Name);
|
||
$('#dialog_statuschange')
|
||
.attr('act', 'add')
|
||
.css({
|
||
'top': (document.documentElement.clientHeight - $('#dialog_statuschange').height()) / 3,
|
||
'left': (document.documentElement.clientWidth - $('#dialog_statuschange').width()) / 2
|
||
})
|
||
.showDialogfixed();
|
||
|
||
}
|
||
|
||
var cur_asset = null;
|
||
function getAssetDetailInfo(mid, wo, v, ipt) {
|
||
cur_asset = null;
|
||
worequest("GetAssetDetailInfo", "" + String.fromCharCode(170) + mid, function (data) {
|
||
if (typeof (data) === "string") {
|
||
return;
|
||
}
|
||
if (data.ID != mid)
|
||
return;
|
||
var asset = data;
|
||
cur_asset = asset;
|
||
|
||
if ($('#dialog_odometer').val() === "" || $('#dialog_odometer').val() === "0") {
|
||
if (asset.CurrentOdometer && asset.CurrentOdometer.Corrected > 0)
|
||
$("#dialog_odometer").val(Math.round(asset.CurrentOdometer.Corrected));
|
||
else
|
||
$("#dialog_odometer").val("");
|
||
}
|
||
|
||
if ($('#dialog_hourmeter').val() === "" || $('#dialog_hourmeter').val() === "0") {
|
||
if (asset.CurrentHours && asset.CurrentHours.Corrected)
|
||
$("#dialog_hourmeter").val(Math.round(asset.CurrentHours.Corrected));
|
||
else
|
||
$("#dialog_hourmeter").val("");
|
||
}
|
||
|
||
if (wo) {
|
||
var item = wo;
|
||
var date = isNaN(v) ? '' : new DateFormatter().formatDate(v, 'm/d/Y');
|
||
if (date !== "" && date !== nowDate) {
|
||
var rst = false;
|
||
var msg = "";
|
||
if ((item.MeterType === "Odometer" || item.MeterType === "Both")
|
||
&& cur_asset.CurrentOdometer && parseFloat(item.Odometer) === Math.round(cur_asset.CurrentOdometer.Corrected)) {
|
||
if ((item.OdometerUnits.toLowerCase() === "mile" && ['mi', 'm'].indexOf(cur_asset.CurrentOdometer.UOM) >= 0)
|
||
|| (item.OdometerUnits.toLowerCase() === "kilometre" && ['km', 'Kilometres'].indexOf(cur_asset.CurrentOdometer.UOM) >= 0)
|
||
) {
|
||
rst = true;
|
||
var odoumits = (item.OdometerUnits == "Mile" ? "miles" : "kilometers");
|
||
msg = 'mileage (' + item.Odometer.toLocaleString() + ' ' + odoumits + ')';
|
||
}
|
||
}
|
||
if ((item.MeterType === "HourMeter" || item.MeterType === "Both")
|
||
&& cur_asset.CurrentHours && parseFloat(item.HourMeter) === Math.round(cur_asset.CurrentHours.Corrected)) {
|
||
rst = true;
|
||
msg = 'hours (' + item.HourMeter.toLocaleString() + ' hours)';
|
||
}
|
||
|
||
if (rst) {
|
||
showConfirm(GetTextByKey("P_WO_WORKORDERWASCOMPLETEDTIPS", "This work order was completed on {1} but is using the current {0} is this correct? ").replace('{0}', msg).replace('{1}', date), GetTextByKey('P_WO_SAVEWORKORDER', 'Save Work Order'), function () {
|
||
item.CompleteDate.Value = v;
|
||
item.CompleteDateStr = date;
|
||
item.CompleteDate.DisplayValue = date;
|
||
updateWorkOrder(item);
|
||
}, function (err) {
|
||
ipt.val(item.CompleteDateStr);
|
||
});
|
||
}
|
||
else {
|
||
item.CompleteDate.Value = v;
|
||
item.CompleteDateStr = date;
|
||
item.CompleteDate.DisplayValue = date;
|
||
updateWorkOrder(item);
|
||
}
|
||
}
|
||
else {
|
||
item.CompleteDate.Value = v;
|
||
item.CompleteDateStr = date;
|
||
item.CompleteDate.DisplayValue = date;
|
||
updateWorkOrder(item);
|
||
}
|
||
}
|
||
|
||
}, function (err) {
|
||
});
|
||
}
|
||
|
||
function SaveStatusChange() {
|
||
var wo = $('#dialog_statuschange').data("wo");
|
||
if (!wo) return;
|
||
var tostatus = $('#dialog_statuschange').data("tostatus");
|
||
if (tostatus.Id === 100 || tostatus.StatusType === 100) {
|
||
wo.CompleteDateStr = $('#dialog_completeddate').val();
|
||
wo.MeterType = $('#dialog_metertype').val();
|
||
wo.HourMeter = $('#dialog_hourmeter').val();
|
||
wo.Odometer = $('#dialog_odometer').val();
|
||
wo.OdometerUnits = $('#dig_odometeruom').val();
|
||
|
||
var alerttitle = GetTextByKey("P_WO_ERROR", "Error");
|
||
|
||
if (wo.CompleteDateStr === "") {
|
||
showAlert(GetTextByKey("P_WO_COMPLETEDDATECANNOTBEEMPTY", 'Completed Date cannot be empty.'), alerttitle);
|
||
return;
|
||
}
|
||
|
||
if (!wo.MeterType) {
|
||
showAlert(GetTextByKey("P_WO_METERTYPEISREQUIRDED", 'Meter Type is requirded.'), alerttitle);
|
||
return;
|
||
}
|
||
|
||
if (wo.MeterType === "HourMeter") {
|
||
if (wo.HourMeter === "") {
|
||
showAlert(GetTextByKey("P_WO_HOURMETERCANNOTBEEMPTY", 'Hour Meter cannot be empty.'), alerttitle);
|
||
$('#dialog_hourmeter').focus();
|
||
return;
|
||
}
|
||
wo.Odometer = -1;
|
||
wo.OdometerUnits = "";
|
||
}
|
||
else if (wo.MeterType === "Odometer") {
|
||
if (wo.Odometer === "") {
|
||
showAlert(GetTextByKey("P_WO_ODOMETERCANNOTBEEMPTY", 'Odometer cannot be empty.'), alerttitle);
|
||
$('#dialog_odometer').focus();
|
||
return;
|
||
}
|
||
wo.HourMeter = -1;
|
||
}
|
||
else if (wo.MeterType === "Both") {
|
||
if (wo.HourMeter === "") {
|
||
showAlert(GetTextByKey("P_WO_HOURMETERCANNOTBEEMPTY", 'Hour Meter cannot be empty.'), alerttitle);
|
||
$('#dialog_hourmeter').focus();
|
||
return;
|
||
}
|
||
if (wo.Odometer === "") {
|
||
showAlert(GetTextByKey("P_WO_ODOMETERCANNOTBEEMPTY", 'Odometer cannot be empty.'), alerttitle);
|
||
$('#dialog_odometer').focus();
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (wo.CompleteDateStr !== "" && wo.CompleteDateStr !== nowDate && cur_asset) {
|
||
var rst = false;
|
||
var msg = "";
|
||
if ((wo.MeterType === "Odometer" || wo.MeterType === "Both")
|
||
&& cur_asset.CurrentOdometer && parseFloat(wo.Odometer) === Math.round(cur_asset.CurrentOdometer.Corrected)) {
|
||
if ((wo.OdometerUnits.toLowerCase() === "mile" && ['mi', 'm'].indexOf(cur_asset.CurrentOdometer.UOM) >= 0)
|
||
|| (wo.OdometerUnits.toLowerCase() === "kilometre" && ['km', 'Kilometres'].indexOf(cur_asset.CurrentOdometer.UOM) >= 0)
|
||
) {
|
||
rst = true;
|
||
var odoumits = (wo.OdometerUnits == "Mile" ? "miles" : "kilometers");
|
||
msg = 'mileage (' + parseFloat(wo.Odometer).toLocaleString() + ' ' + odoumits + ')';
|
||
}
|
||
}
|
||
if ((wo.MeterType === "HourMeter" || wo.MeterType === "Both")
|
||
&& cur_asset.CurrentHours && parseFloat(wo.HourMeter) === Math.round(cur_asset.CurrentHours.Corrected)) {
|
||
rst = true;
|
||
msg = 'hours (' + parseFloat(wo.HourMeter).toLocaleString() + ' hours)';
|
||
}
|
||
|
||
if (rst) {
|
||
showConfirm1(GetTextByKey("P_WO_WORKORDERWASCOMPLETEDTIPS", "This work order was completed on {1} but is using the current {0} is this correct? ").replace('{0}', msg).replace('{1}', wo.CompleteDateStr), GetTextByKey('P_WO_SAVEWORKORDER', 'Save Work Order'), function () {
|
||
onSaveStatusChange(wo);
|
||
|
||
}, function (err) {
|
||
});
|
||
}
|
||
else
|
||
onSaveStatusChange(wo);
|
||
}
|
||
else {
|
||
onSaveStatusChange(wo);
|
||
}
|
||
}
|
||
else
|
||
onSaveStatusChange(wo);
|
||
}
|
||
|
||
function onSaveStatusChange(wo) {
|
||
|
||
var next = $('#dialog_statuschange').data("next");
|
||
if (next)
|
||
next();
|
||
|
||
var sendtextmsg = $('#dialog_chksendtextmsg').prop('checked');
|
||
|
||
if (!AllowCommunicate || COMMReadOnly)
|
||
sendtextmsg = false;
|
||
|
||
updateWorkOrder(wo, sendtextmsg);
|
||
|
||
$('#dialog_statuschange').hideDialog();
|
||
showmaskbg(false);
|
||
}
|
||
|
||
function SendTextMsg(wo) {
|
||
var phoneemail = $('#txtphonenum').val();
|
||
if ($.trim(phoneemail) == "") {
|
||
return;
|
||
}
|
||
|
||
var phoneemails = phoneemail.split(';');
|
||
var pmemails = [];
|
||
for (var i = 0; i < phoneemails.length; i++) {
|
||
var pm = phoneemails[i];
|
||
if (checkPhoneNumber(pm) || isEmail(pm)) {
|
||
pmemails.push({ 'Key': pm, 'Value': pm });
|
||
}
|
||
else {
|
||
if (wo && wo.Contacts) {
|
||
for (var j = 0; j < wo.Contacts.length; j++) {
|
||
var c = wo.Contacts[j];
|
||
if (c.OptOut || c.OptOut_BC) continue;
|
||
var mp = $.trim(c.MobilePhone);
|
||
var email = $.trim(c.Email);
|
||
if (c.Name === pm) {
|
||
if (c.ContactPreference == "0" && checkPhoneNumber(mp)) {
|
||
pmemails.push({ 'Key': mp, 'Value': pm });
|
||
break;
|
||
}
|
||
if (c.ContactPreference == "1" && isEmail(email)) {
|
||
pmemails.push({ 'Key': email, 'Value': pm });
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
var comm = $('#dialog_textmsg').val();
|
||
if ($.trim(comm) == "") {
|
||
//showAlert(GetTextByKey("P_WO_PLEASEINPUTTHEMESSAGE", "Please input the message."), GetTextByKey("P_WO_ERROR", 'Error'));
|
||
return;
|
||
}
|
||
|
||
var includeStatusLink = $('#dialog_chkIncludeStatusLink').prop("checked");
|
||
|
||
var url = 'WorkOrderMaintenance.aspx';
|
||
var method = 'AddWorkOrderCommunication';
|
||
var data = new FormData();
|
||
data.append('MethodName', method);
|
||
data.append('WorkorderId', wo.Id.Value || wo.Id);
|
||
data.append('PMEmails', JSON.stringify(pmemails));
|
||
data.append('Comment', encodeURIComponent(comm));
|
||
data.append('IncludeStatusLink', includeStatusLink ? "1" : "0");
|
||
if (_selectedattachment) {
|
||
data.append('AttaData', encodeURIComponent(JSON.stringify(_selectedattachment)));
|
||
}
|
||
$.ajax({
|
||
url: url,
|
||
type: 'POST',
|
||
dataType: 'json',
|
||
processData: false,
|
||
contentType: false,
|
||
cache: false,
|
||
data: data,
|
||
success: function (data) {
|
||
//$('#mask_over_bg').hide();
|
||
if (data !== "") {
|
||
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
|
||
return;
|
||
}
|
||
//getCommunications();
|
||
},
|
||
error: function (request, textStatus, errorThrown) {
|
||
if (request?.readyState == 0) {
|
||
console.log(request);
|
||
} else {
|
||
writelog_ironintel("onAddMessage", url + ".-1." + method + "." + JSON.stringify(param), JSON.stringify(request), textStatus + errorThrown);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
function setPhoneNumber(wo) {
|
||
if (wo && wo.Contacts && !COMMReadOnly) {
|
||
var names = "";
|
||
for (var i = 0; i < wo.Contacts.length; i++) {
|
||
var c = wo.Contacts[i];
|
||
if (c.OptOut || c.OptOut_BC) continue;
|
||
var mp = $.trim(c.MobilePhone);
|
||
var email = $.trim(c.Email);
|
||
if ((c.ContactPreference == "0" && (checkPhoneNumber(mp))
|
||
|| (c.ContactPreference == "1" && isEmail(email)))) {
|
||
if (names == "")
|
||
names = c.Name;
|
||
else
|
||
names += ";" + c.Name;
|
||
}
|
||
}
|
||
$('#txtphonenum').val(names);
|
||
}
|
||
else
|
||
$('#txtphonenum').val("");
|
||
}
|
||
|
||
function convert_url_text(text) {
|
||
var $words = text.split(' ');
|
||
for (i in $words) {
|
||
if ($words[i].indexOf('http://') == 0 || $words[i].indexOf('https://') == 0) {
|
||
$words[i] = '<a href="' + $words[i] + '" target="_blank">' + $words[i] + '</a>';
|
||
}
|
||
}
|
||
return $words.join(' ');
|
||
}
|
||
|
||
function checkPhoneNumber(num) {
|
||
if ((/^[1-9]\d{9,}$/.test(num))) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
function onEditText(wo, type, next) {
|
||
showmaskbg(true);
|
||
if (type == 1) {
|
||
$('#dialog_edittext .dialog-title span.title').text(GetTextByKey("P_WO_EDITDESCRIPTION", 'Edit Description'));
|
||
$('#dialog_text').val(wo.Description);
|
||
}
|
||
else {
|
||
$('#dialog_edittext .dialog-title span.title').text(GetTextByKey("P_WO_EDITNOTES", 'Edit Notes'));
|
||
$('#dialog_text').val(wo.Notes);
|
||
}
|
||
$('#dialog_edittext').data('type', type).data('wo', wo).data('next', next)
|
||
.css({
|
||
'top': (document.documentElement.clientHeight - $('#dialog_edittext').height()) / 3,
|
||
'left': (document.documentElement.clientWidth - $('#dialog_edittext').width()) / 2
|
||
}).showDialogfixed();
|
||
}
|
||
|
||
function SaveText() {
|
||
var type = $('#dialog_edittext').data("type");
|
||
var text = $('#dialog_text').val();
|
||
var wo = $('#dialog_edittext').data("wo");
|
||
var next = $('#dialog_edittext').data("next");
|
||
if (type == 1) {
|
||
if (!text || text.length == 0) {
|
||
showAlert(GetTextByKey("P_WO_DESCRIPTIONCANNOTBEEMPTY", 'Description cannot be empty.'), GetTextByKey("P_WO_EDITDESCRIPTION", 'Edit Description'));
|
||
$('#dialog_text').focus();
|
||
return;
|
||
}
|
||
wo.Description = text;
|
||
}
|
||
else
|
||
wo.Notes = text;
|
||
|
||
if (next)
|
||
next();
|
||
|
||
$('#dialog_edittext').hideDialog();
|
||
showmaskbg(false);
|
||
updateWorkOrder(wo);
|
||
}
|
||
|
||
|
||
var surveytemplatedata;
|
||
function GetSurveyTemplateItems() {
|
||
$('#dialog_wosurveytemplates').empty();
|
||
worequest('GetSurveyTemplateItems', '', function (data) {
|
||
$('#dialog_wosurveytemplates').empty();
|
||
if (typeof (data) === "string") {
|
||
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
|
||
return;
|
||
}
|
||
surveytemplatedata = data;
|
||
if (data && data.length > 0) {
|
||
for (var i = 0; i < data.length; i++) {
|
||
var op = $("<option></option>").val(data[i].Id).text(data[i].Name);
|
||
$('#dialog_wosurveytemplates').append(op);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
function onSendWOSurveys(wo) {
|
||
$('#dialog_wosurveytemplates').val('');
|
||
showmaskbg(true);
|
||
$('#dialog_sendwosurveys .dialog-title span.title').text(GetTextByKey("P_WO_SENDWORKORDERSURVEYS", 'Send Work Order Surveys'));
|
||
if (!surveytemplatedata) {
|
||
GetSurveyTemplateItems();
|
||
}
|
||
|
||
if (wo.Contacts && wo.Contacts.length > 0) {
|
||
var tb = $('<table style="width:98%;"></table>');
|
||
for (var i = 0; i < wo.Contacts.length; i++) {
|
||
var contact = wo.Contacts[i];
|
||
var mp = $.trim(contact.MobilePhone);
|
||
var email = $.trim(contact.Email);
|
||
|
||
if ((contact.ContactPreference == "0" && !checkPhoneNumber(mp))
|
||
|| (contact.ContactPreference == "1" && !isEmail(email))
|
||
|| contact.ContactPreference == "2")
|
||
continue;
|
||
|
||
var ptext = contact.Name;
|
||
if (contact.ContactPreference === 0)
|
||
ptext += " – " + contact.MobilePhoneDisplayText;
|
||
else if (contact.ContactPreference === 1)
|
||
ptext += " - " + contact.Email;
|
||
|
||
var tr = $('<tr></tr>');
|
||
var td = $('<td></td>');
|
||
var chk = $('<input name="wocontactsurvey" type="checkbox" style="width: unset;" />').data('contact', contact);
|
||
var span = $('<span></span>').text(ptext);
|
||
td.append(chk).append(span);
|
||
tr.append(td).appendTo(tb);
|
||
}
|
||
$("#dialog_wosurveyscontacts").empty().append(tb);
|
||
}
|
||
|
||
$('#dialog_sendwosurveys').data('wo', wo)
|
||
.css({
|
||
'top': (document.documentElement.clientHeight - $('#dialog_sendwosurveys').height()) / 3,
|
||
'left': (document.documentElement.clientWidth - $('#dialog_sendwosurveys').width()) / 2
|
||
}).showDialogfixed();
|
||
}
|
||
|
||
|
||
function SendWOSurveys() {
|
||
var tempid = $('#dialog_wosurveytemplates').val();
|
||
var wo = $('#dialog_sendwosurveys').data('wo');
|
||
|
||
if (!tempid || tempid == "") {
|
||
showAlert(GetTextByKey("P_WO_PLEASESELECTATEMPLATE", 'Please select a template.'), GetTextByKey("P_WO_SENDWORKORDERSURVEYS", 'Send Work Order Surveys'));
|
||
return;
|
||
}
|
||
|
||
var contacts = [];
|
||
$('#dialog_sendwosurveys input:checkbox[name=wocontactsurvey]:checked').each(function (i, chk) {
|
||
var contact = $(chk).data('contact');
|
||
var key = "";
|
||
if (contact.ContactPreference === 0)
|
||
key = contact.MobilePhone;
|
||
else if (contact.ContactPreference === 1)
|
||
key = contact.Email;
|
||
contacts.push({ Key: key, Value: contact.Name });
|
||
});
|
||
|
||
var param = JSON.stringify([wo.Id.Value, tempid, JSON.stringify(contacts)]);
|
||
param = htmlencode(param);
|
||
worequest("SendWorkOrderSurveys", param, function (data) {
|
||
if (data !== "") {
|
||
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
|
||
return;
|
||
}
|
||
|
||
}, function (err) {
|
||
showAlert(err, GetTextByKey("P_WO_ERROR", 'Error'));
|
||
showmaskbg(false);
|
||
});
|
||
|
||
$('#dialog_sendwosurveys').hideDialog();
|
||
showmaskbg(false);
|
||
}
|
||
|
||
|
||
function updateCommunicationAcknowledged(id, chk) {
|
||
var item = [id, chk];
|
||
var param = JSON.stringify(item);
|
||
param = htmlencode(param);
|
||
|
||
worequest('UpdateCommunicationAcknowledged', param, function (data) {
|
||
if (data !== 'OK') {
|
||
showAlert(data, GetTextByKey("P_WORKORDER", 'Work Order'));
|
||
}
|
||
}, function (err) {
|
||
});
|
||
}
|
||
|
||
|
||
/********************************************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 = {};
|
||
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 == "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 $('<img style="height:30px;width:30px;"></img>').attr('src', item.ThumbnailUrl);
|
||
// else {
|
||
// var sdown = $('<img style="height:30px;width:30px;line-height:40px;" />')
|
||
// setAttachemntIcon(item.FileType, sdown);
|
||
// return sdown;
|
||
// }
|
||
//}
|
||
//col.styleFilter = function () {
|
||
// return { "width": "30px", 'height': '30px', 'line-height':'40px' };
|
||
//}
|
||
}
|
||
}
|
||
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([]);
|
||
var wo = $('#dialog_statuschange').data("wo");
|
||
if (!wo) return;
|
||
worequest('GetWorkOrderAttachments', htmlencode(wo.Id.Value || wo.Id), 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*************************************************/ |