462 lines
22 KiB
JavaScript
462 lines
22 KiB
JavaScript
define(['modules/inspects/inspect', 'modules/inspects/editinspection'], function (Inspect, EditModule) {
|
|
var gs = {};
|
|
gs.title = GetTextByKey("P_INSPECTIONS", 'Inspections');
|
|
gs.description = GetTextByKey("P_INSPECTIONS", 'Inspections');
|
|
gs.version = '1.0';
|
|
gs.status = 0;
|
|
|
|
var datacontent = null;
|
|
var startdateinputcontrol = undefined;
|
|
var enddateinputcontrol = undefined;
|
|
var searchinputcontrol = undefined;
|
|
var makeinputcontrol = undefined;
|
|
var modelinputcontrol = undefined;
|
|
var typeinputcontrol = undefined;
|
|
var grid_dt;
|
|
gs.createContent = function (args) {
|
|
var _this = this;
|
|
if (args && args.length > 0)
|
|
gs.status = eval(args[0]);
|
|
|
|
var content = $('<div style="width:100%;" ></div>');
|
|
|
|
function createHeader() {
|
|
var header = $('<div></div>');
|
|
header.append($('<div class="page_title"></div>').text(gs.title));
|
|
setPageTitle(gs.title, true);
|
|
var search_bar = $('<div class="search_bar"></div>');
|
|
header.append(search_bar);
|
|
search_bar.append('<input type="password" autocomplete="new-password" style="display: none" />');
|
|
search_bar.append('<span style="margin-left:5px;">' + GetTextByKey("P_IPT_BEGINDATE_COLON", "Begin Date:") + '</span>');
|
|
startdateinputcontrol = $('<input type="date" class="type-date" required min="1900-01-01" style="margin-left: 5px; width: 100px;" autocomplete="off" />').val(begindate);
|
|
search_bar.append($('<span></span>').append(startdateinputcontrol));
|
|
|
|
search_bar.append('<span style="margin-left:10px;">' + GetTextByKey("P_IPT_ENDDATE_COLON", "End Date:") + '</span>');
|
|
enddateinputcontrol = $('<input type="date" class="type-date" required min="1900-01-01" style="margin-left: 5px; width: 100px;" autocomplete="off" />').val(enddate);
|
|
search_bar.append($('<span></span>').append(enddateinputcontrol));
|
|
|
|
makeinputcontrol = $('<select type="text" style="margin-left: 5px; width: 80px;" autocomplete="off" />').val(enddate);
|
|
|
|
searchinputcontrol = $('<input type="text" style="margin-left:10px;" autocomplete="off" />');
|
|
search_bar.append(searchinputcontrol);
|
|
searchinputcontrol.keydown(function (e) {
|
|
if (e.keyCode == 13 || e.keyCode == 9)
|
|
gs.refresh();
|
|
});
|
|
var btnRefresh = $('<input class="search" type="button" value="' + GetTextByKey("P_IPT_SEARCH", "Search") + '" style="margin-left:10px;"/>');
|
|
search_bar.append(btnRefresh);
|
|
btnRefresh.click(function () {
|
|
gs.refresh();
|
|
});
|
|
|
|
var func = $('<div class="function_title"></div>');
|
|
if (!ReportReadonly) {
|
|
var iconEdit = $('<span class="sbutton iconedit">' + GetTextByKey("P_IPT_EDIT", "Edit") + '</span>').click(function () {
|
|
if (grid_dt.selectedIndex >= 0) {
|
|
gs.onedit();
|
|
}
|
|
});
|
|
func.append(iconEdit);
|
|
}
|
|
var iconRefresh = $('<span class="sbutton iconrefresh">' + GetTextByKey("P_IPT_REFRESH", "Refresh") + '</span>').click(function () {
|
|
gs.refresh();
|
|
});
|
|
func.append(iconRefresh);
|
|
var iconResetPivots = $('<span class="sbutton iconfilter">' + GetTextByKey("P_IPT_RESETPIVOTS", "Reset Pivots") + '</span>').click(function () {
|
|
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();
|
|
}
|
|
});
|
|
func.append(iconResetPivots);
|
|
|
|
var iconprints = $('<span class="sbutton iconprint">' + GetTextByKey("P_IPT_PRINT", "Print") + '</span>').click(function () {
|
|
var tempsource = grid_dt.source;
|
|
for (var i = 0; i < tempsource.length; i++) {
|
|
var inspect = tempsource[i];
|
|
if (inspect.Selected) {
|
|
if (navigator.userAgent.indexOf('Firefox') >= 0 ||
|
|
navigator.userAgent.indexOf('Opera') >= 0) {
|
|
window.open("Inspection.aspx?rt=f&t=2&id=" + inspect.Id + "&team=" + (teamintelligence ? 1 : 0), '_blank');
|
|
}
|
|
else
|
|
openPrintFrame(inspect.Id);
|
|
}
|
|
}
|
|
});
|
|
func.append(iconprints);
|
|
|
|
var icondownloads = $('<span class="sbutton icondownload">' + GetTextByKey("P_IPT_DOWNLOAD", "Download") + '</span>').click(function () {
|
|
var tempsource = grid_dt.source;
|
|
for (var i = 0; i < tempsource.length; i++) {
|
|
var inspect = tempsource[i];
|
|
if (inspect.Selected) {
|
|
openDownloadFrame(inspect.Id);
|
|
}
|
|
}
|
|
});
|
|
func.append(icondownloads);
|
|
|
|
|
|
header.append(func)
|
|
|
|
return header;
|
|
}
|
|
|
|
function InitGridData() {
|
|
var div_grid = $('<div></div>');
|
|
div_grid.css({ "height": $(window).height() - 185, "position": "relative" });
|
|
|
|
grid_dt = createGridView(div_grid);
|
|
var list_columns = [
|
|
{ name: 'TemplateName', caption: GetTextByKey("P_TEMPLATE", "Template"), allowFilter: true, valueIndex: 'TemplateName', css: { 'width': 250, 'text-align': 'left' } },
|
|
{ name: 'AssetName', caption: GetTextByKey("P_IPT_ASSETNAME", "Asset Name"), valueIndex: 'AssetName', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } },
|
|
{ name: 'WorkOrderNumber', caption: GetTextByKey("P_IPT_WORKORDER", "Work Order"), valueIndex: 'WorkOrderId', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } },
|
|
{ name: 'CustomerName', caption: GetTextByKey("P_IPT_CUSTOMERNAME", "Customer Name"), valueIndex: 'CustomerName', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } },
|
|
{ name: 'VisibleToCustomer', caption: GetTextByKey("P_IPT_CUSTOMERVISIBLE", "Customer Visible"), valueIndex: 'VisibleToCustomer', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } },
|
|
{ name: 'VIN', caption: GetTextByKey("P_IPT_VIN", "VIN"), valueIndex: 'VIN', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } },
|
|
{ name: 'MakeName', caption: GetTextByKey("P_IPT_MAKE", "Make"), valueIndex: 'MakeName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
|
{ name: 'ModelName', caption: GetTextByKey("P_IPT_MODEL", "Model"), valueIndex: 'ModelName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
|
{ name: 'TypeName', caption: GetTextByKey("P_IPT_ASSETTYPE", "Asset Type"), valueIndex: 'TypeName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
|
{ name: 'Status', caption: GetTextByKey("P_IPT_STATUS", "Status"), valueIndex: 'Status', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
|
|
{ name: 'CommitTimeLocal', caption: GetTextByKey("P_IPT_COMMITTIME", "Commit Time"), valueIndex: 'CommitTimeLocal', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
|
{ name: 'CommitedByUserName', caption: GetTextByKey("P_IPT_COMMITUSER", "Commit User"), valueIndex: 'CommitedByUserName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
|
{ name: 'LastUpdatedTimeLocal', caption: GetTextByKey("P_IPT_LASTUPDATEDTIME", "Last Updated Time"), valueIndex: 'LastUpdatedTimeLocal', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
|
{ name: 'LastUpdatedByUserName', caption: GetTextByKey("P_IPT_LASTUPDATEDUSER", "Last Updated User"), valueIndex: 'LastUpdatedByUserName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
|
|
{ name: 'Edit', caption: "", css: { 'width': 30, 'text-align': 'center' } },
|
|
{ name: 'Detail', caption: "", css: { 'width': 30, 'text-align': 'center' } },
|
|
{ name: 'DownloadPDF', caption: "", css: { 'width': 30, 'text-align': 'center' } },
|
|
{ name: 'Print', caption: "", css: { 'width': 30, 'text-align': 'center' } },
|
|
{ name: 'ViewChangeHistory', caption: "", css: { 'width': 30, 'text-align': 'center' } }
|
|
];
|
|
var columns = [
|
|
{
|
|
// checkbox
|
|
name: 'check',
|
|
key: 'Selected',
|
|
width: 45,
|
|
align: 'center',
|
|
sortable: false,
|
|
allcheck: true,
|
|
type: 3
|
|
}
|
|
];
|
|
// head
|
|
for (var hd in list_columns) {
|
|
var col = {};
|
|
col.name = list_columns[hd].name;
|
|
if (ReportReadonly && col.name === 'Edit') {
|
|
continue;
|
|
}
|
|
|
|
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;
|
|
if (!IsCustomerRecord && (col.name === "CustomerName")) {
|
|
continue;
|
|
}
|
|
|
|
if (col.name === "TemplateName" || col.name === "AssetName") {
|
|
col.events = {
|
|
onclick: function () {
|
|
_this.openReport();
|
|
}
|
|
};
|
|
col.styleFilter = function () {
|
|
return {
|
|
'color': 'black',
|
|
'cursor': 'pointer',
|
|
//'text-decoration': 'none'
|
|
};
|
|
}
|
|
}
|
|
else if (col.name === "Edit") {
|
|
col.sortable = false;
|
|
col.resizable = false;
|
|
col.type = GridView.ColumnTypes.Icon;
|
|
col.text = 'edit';
|
|
col.events = {
|
|
onclick: function () {
|
|
_this.onedit();
|
|
}
|
|
};
|
|
col.attrs = { 'title': GetTextByKey("P_IPT_EDIT", 'Edit') };
|
|
}
|
|
else if (col.name === "Detail") {
|
|
col.sortable = false;
|
|
col.resizable = false;
|
|
col.type = GridView.ColumnTypes.Icon;
|
|
col.text = "info-circle";
|
|
col.events = {
|
|
onclick: function () {
|
|
_this.openReport();
|
|
}
|
|
};
|
|
col.attrs = { 'title': GetTextByKey("P_IPT_DETAIL", 'Detail') };
|
|
}
|
|
else if (col.name === "DownloadPDF") {
|
|
col.sortable = false;
|
|
col.resizable = false;
|
|
col.type = GridView.ColumnTypes.Icon;
|
|
col.text = "download";
|
|
col.visible = canExport;
|
|
col.events = {
|
|
onclick: function () {
|
|
window.open("Inspection.aspx?rt=f&t=1&id=" + this.Id + "&team=" + (teamintelligence ? 1 : 0), '_blank');
|
|
}
|
|
};
|
|
col.classFilter = function (e) {
|
|
return "icon-col";
|
|
}
|
|
col.attrs = { 'title': GetTextByKey("P_IPT_DOWNLOADPDF", 'Download PDF') };
|
|
}
|
|
else if (col.name === "Print") {
|
|
col.sortable = false;
|
|
col.resizable = false;
|
|
col.type = GridView.ColumnTypes.Icon;
|
|
col.text = "print";
|
|
col.visible = canExport;
|
|
col.events = {
|
|
onclick: function () {
|
|
if (navigator.userAgent.indexOf('Firefox') >= 0 ||
|
|
navigator.userAgent.indexOf('Opera') >= 0) {
|
|
window.open("Inspection.aspx?rt=f&t=2&id=" + this.Id + "&team=" + (teamintelligence ? 1 : 0), '_blank');
|
|
}
|
|
else
|
|
OnPrint(this.Id);
|
|
}
|
|
};
|
|
col.classFilter = function (e) {
|
|
return "icon-col";
|
|
}
|
|
col.attrs = { 'title': GetTextByKey("P_IPT_PRINT", 'Print') };
|
|
}
|
|
else if (col.name === "ViewChangeHistory") {
|
|
col.sortable = false;
|
|
col.resizable = false;
|
|
col.type = GridView.ColumnTypes.Icon;
|
|
col.text = "history";
|
|
col.events = {
|
|
onclick: function () {
|
|
_this.onViewChangeHistory();
|
|
}
|
|
};
|
|
col.classFilter = function (e) {
|
|
return "icon-col";
|
|
}
|
|
col.attrs = { 'title': GetTextByKey("P_IPT_VIEWCHANGEHIS", 'View Change History') };
|
|
}
|
|
|
|
if (col.name === "AssetName" || col.name === "VIN" || col.name === "MakeName" || col.name === "ModelName" || col.name === "TypeName" || col.name === "WorkOrderNumber" || col.name === "VisibleToCustomer" || col.name === "CustomerName") {
|
|
col.visible = !teamintelligence;
|
|
}
|
|
if (!teamintelligence && AllowReassignWorkorders && col.name === "WorkOrderNumber") {
|
|
col.type = GridView.ColumnTypes.Dropdown;
|
|
col.filter = function (item, editing) {
|
|
return editing ? String(item.WorkOrderId) : item.WorkOrderNumber;
|
|
};
|
|
|
|
col.dropOptions = {
|
|
search: true,
|
|
textKey: 'WorkOrderNumber',
|
|
valueKey: 'Id'
|
|
};
|
|
col.sourceCache = false;
|
|
col.source = function (item) {
|
|
return item.WorkOrders ??= [{ Id: -1, WorkOrderNumber: "Not Assigned" }];
|
|
};
|
|
col.onDropExpanded = function (item, drop) {
|
|
if (!item.WorkOrdersLoaded) {
|
|
item.WorkOrdersLoaded = true;
|
|
inspectionrequest('GetAssetWorkOrders', item.AssetId, function (data) {
|
|
if (typeof data === 'string') {
|
|
}
|
|
else if (data && data.length > 0) {
|
|
var source = [
|
|
{ Id: -1, WorkOrderNumber: "Not Assigned" }
|
|
];
|
|
|
|
var sel = null;
|
|
var exists = false;
|
|
var selected;
|
|
if (item.WorkOrders && item.WorkOrders.length == 1)
|
|
sel = item.WorkOrders[0];
|
|
else
|
|
exists = true;
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
var u = data[i];
|
|
source.push(u);
|
|
if (item.WorkOrderId == u.Id)
|
|
item.WorkOrderId = selected = u.Id;
|
|
|
|
if (sel && (sel.Id < 0 || sel.Id == u.Id))
|
|
exists = true;
|
|
|
|
}
|
|
if (!exists) {
|
|
source.push(sel);
|
|
}
|
|
|
|
item.WorkOrders = source;
|
|
|
|
drop.source = source;
|
|
drop.select(selected, true);
|
|
}
|
|
}, function () {
|
|
});
|
|
}
|
|
};
|
|
col.onChanged = function (item, value, old, wo) {
|
|
if (value != old) {
|
|
if (wo) {
|
|
var msg1 = GetTextByKey('P_WO_AREYOUSURETHATYOUWANTTOPROCEED', 'Are you sure that you want to proceed ?');
|
|
var msg = GetTextByKey('P_WO_YOUAREREASSIGNINGTHISWORKORDER', 'You are reassigning this work order. ') + "<br/>" + msg1;
|
|
if (wo.Completed)
|
|
msg = GetTextByKey('P_WO_YOUAREREASSIGNINGTHISWORKORDERTOACLOSEDWORKORDER', 'You are reassigning this Work Order to a CLOSED Work Order.') + "<br/>" + msg1;
|
|
showConfirm(msg, GetTextByKey("P_WO_WORKORDERASSIGNMENT", 'Work Order Assignment'), function () {
|
|
item.WorkOrderId = wo.Id;
|
|
item.WorkOrderNumber = wo.WorkOrderNumber;
|
|
updateInspectionWorkOrder(item.Id, value, old, wo.CustomerName);
|
|
}, function () {
|
|
item.WorkOrderId = old;
|
|
grid_dt?.refresh();
|
|
});
|
|
}
|
|
}
|
|
};
|
|
col.styleFilter = function () {
|
|
return { "width": "100%", 'margin': 0 };
|
|
}
|
|
}
|
|
|
|
columns.push(col);
|
|
}
|
|
grid_dt.canMultiSelect = false;
|
|
grid_dt.columns = columns;
|
|
grid_dt.init();
|
|
grid_dt.onRowDblClicked = _this.openReport;
|
|
return div_grid;
|
|
}
|
|
|
|
content.append(createHeader());
|
|
content.append(InitGridData());
|
|
datacontent = $('<div></div>');
|
|
content.append(datacontent);
|
|
|
|
_this.refresh();
|
|
return content;
|
|
}
|
|
|
|
gs.onedit = function () {
|
|
var _this = this;
|
|
var index = grid_dt.selectedIndex;
|
|
var inspect = grid_dt.source[index];
|
|
|
|
|
|
// check permissions
|
|
var ei = new EditModule.EditInspection(_this, inspect.Id);
|
|
$('#right_popup').empty().append(ei.createContent());
|
|
showRightPopup(true);
|
|
|
|
|
|
}
|
|
|
|
gs.openReport = function () {
|
|
var index = grid_dt.selectedIndex;
|
|
var inspect = grid_dt.source[index];
|
|
window.open("report.aspx?rid=" + inspect.Id + "&ro=" + (ReportReadonly ? 1 : 0), "_blank");
|
|
}
|
|
|
|
gs.onViewChangeHistory = function () {
|
|
var index = grid_dt.selectedIndex;
|
|
var inspect = grid_dt.source[index];
|
|
window.open("InspectionChangeHistory.aspx?rid=" + inspect.Id, "_blank");
|
|
}
|
|
|
|
function updateInspectionWorkOrder(id, woid, oldwoid, custname) {
|
|
var p = JSON.stringify([id, woid, oldwoid]);
|
|
inspectionrequest("UpdateInspectionWorkOrder", htmlencode(p), function (data) {
|
|
if (typeof (data) === "string") {
|
|
return;
|
|
}
|
|
if (grid_dt.selectedIndex >= 0) {
|
|
grid_dt.source[grid_dt.selectedIndex].CustomerName = custname;
|
|
grid_dt && grid_dt.reload();
|
|
}
|
|
|
|
}, function (err) {
|
|
});
|
|
}
|
|
|
|
function showInspections(data) {
|
|
var rows = [];
|
|
for (var i = 0; i < data.length; i++) {
|
|
var r = data[i];
|
|
var statustext = "";
|
|
if (r.Status == 0)
|
|
statustext = 'Draft';
|
|
else if (r.Status == 1)
|
|
statustext = 'Committed';
|
|
for (var j in r) {
|
|
if (j === "Status") {
|
|
r[j] = { DisplayValue: statustext, Value: r[j] };
|
|
} else if (j === "CommitTimeLocal") {
|
|
r[j] = { DisplayValue: r["CommitTimeLocalStr"], Value: r[j] };
|
|
} else if (j === "LastUpdatedTimeLocal") {
|
|
r[j] = { DisplayValue: r["LastUpdatedTimeLocalStr"], Value: r[j] };
|
|
} else if (j === "VisibleToCustomer") {
|
|
r[j] = { DisplayValue: r["VisibleToCustomer"] ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No"), Value: r[j] };
|
|
}
|
|
}
|
|
rows.push(r);
|
|
}
|
|
|
|
grid_dt.setData(rows);
|
|
}
|
|
|
|
gs.refresh = function () {
|
|
var begindate = startdateinputcontrol.val();
|
|
var enddate = enddateinputcontrol.val();
|
|
if (begindate && !startdateinputcontrol.is(':valid')) {
|
|
showAlert(GetTextByKey('P_COMMON_BEGINDATEISINVALID', "The begin date is invalid."), GetTextByKey("P_FR_ERROR", 'Error'));
|
|
return;
|
|
}
|
|
if (enddate && !enddateinputcontrol.is(':valid')) {
|
|
showAlert(GetTextByKey('P_COMMON_ENDDATEISINVALID', "The end date is invalid."), GetTextByKey("P_FR_ERROR", 'Error'));
|
|
return;
|
|
}
|
|
if (begindate && enddate && begindate > enddate) {
|
|
showAlert(GetTextByKey("P_JS_ENDDATEMUSTBELATERTHANBEGINDATE", "End Date must be later than Begin Date."), GetTextByKey("P_FR_ERROR", 'Error'));
|
|
return;
|
|
}
|
|
|
|
datacontent.empty();
|
|
var searchtxt = searchinputcontrol.val();
|
|
searchtxt = htmlencode(searchtxt);
|
|
var p = JSON.stringify([teamintelligence, begindate, enddate, searchtxt]);
|
|
|
|
showloading(true);
|
|
inspectionrequest("GetInspectItems", htmlencode(p), function (data) {
|
|
showloading(false);
|
|
datacontent.empty();
|
|
if (typeof (data) === "string") {
|
|
showAlert(data, GetTextByKey("P_AM_ERROR", 'Error'));
|
|
return;
|
|
}
|
|
if (data) {
|
|
showInspections(data);
|
|
}
|
|
}, function (err) {
|
|
showloading(false);
|
|
});
|
|
}
|
|
return gs;
|
|
}); |