fleet-contractor/Site/JobSite/js/jobsiterequirement.js
2023-05-30 17:34:56 +08:00

1019 lines
39 KiB
JavaScript

var indexInRequirement;
var allRequirements = [];
var currentRequirement;
if (typeof jobsiterequirementCtrl !== 'function') {
$jobsiterequirementCtrl = function jobsiterequirementCtrl() {
this.tmpobj = {
};
this.wizardCtrl = null;
this.vue = null;
};
(function () {
'use strict';
var dataGrid = window.DataGrid || window['g5-datagrid'];
$jobsiterequirementCtrl.prototype.getData = function (/*dataObj, tmpdata*/) {
return this.vue.source;
};
$jobsiterequirementCtrl.prototype.setData = function (assetData) {
if (assetData) {
for (var i = 0; i < assetData.length; i++) {
var a = assetData[i];
a.Selected = false;
}
}
this.vue.source = assetData ? assetData : [];
this.vue.$refs.grid.resize();
};
$jobsiterequirementCtrl.prototype.reload = function () {
this.vue.$refs.grid.reload()
};
$jobsiterequirementCtrl.prototype.Init = function (parent, newselected) {
var ethis = this;
//加载子页面模版
parent.load('../template/JobsiteRequirementCtrl.html?v=8', function () {
ethis.vue = new Vue({
el: parent.find('.JobsiteRequirementCtrl')[0],
components: {
'data-grid': dataGrid
},
data: {
wnd: window.parent,
//editable: true,
columns: [],
source: []
},
computed: {
},
watch: {
source: function (val) {
}
},
methods: {
cellvaluechanged: function (item, key) {
},
rowdblclick: function (e) {
}
}
});
ethis.vue.columns = createGridColumn(newselected);
});
};
function createGridColumn(newselected) {
var editable = true;
var columns = [
{
key: 'BeginDate',
caption: GetTextByKey("P_JS_BEGINDATE", 'Begin Date'),
type: dataGrid.COLUMN_TYPE.datepicker,
width: 100,
orderable: false,
resizable: false,
enabled: editable,
onclick: function (e, item) {
var days = getDaysBetween(item.BeginDate, item.EndDate);
alert(days);
},
onchanged: function (item) {
item.Days = getDaysBetween(item.BeginDate, item.EndDate);
}
},
{
key: 'EndDate',
caption: GetTextByKey("P_JS_ENDDATE", 'End Date'),
type: dataGrid.COLUMN_TYPE.datepicker,
width: 100,
orderable: false,
resizable: false,
enabled: editable,
onchanged: function (item) {
item.Days = getDaysBetween(item.BeginDate, item.EndDate);
}
},
{
key: 'AssetTypeName',
caption: GetTextByKey("P_JS_ASSETTYPE", 'Asset Type'),
type: dataGrid.COLUMN_TYPE.label,
width: 150,
orderable: false,
resizable: false,
enabled: false
},
{
key: 'Quantity',
caption: GetTextByKey("P_JS_QUANTITY", 'Quantity'),
type: dataGrid.COLUMN_TYPE.input,
align: 'right',
width: 100,
orderable: false,
resizable: false,
enabled: editable
},
{
key: 'ScheduledQuantity',
caption: GetTextByKey("P_JS_SCHEDULED", 'Scheduled'),
type: dataGrid.COLUMN_TYPE.label,
align: 'right',
width: 110,
orderable: false,
resizable: false,
enabled: false
},
{
key: 'Days',
caption: GetTextByKey("P_JS_NUMBEROFDAYS", 'Number of Days'),
type: dataGrid.COLUMN_TYPE.label,
align: 'right',
width: 110,
orderable: false,
resizable: false,
enabled: false
},
{
key: 'Notes',
caption: GetTextByKey("P_JS_NOTES", 'Notes'),
type: dataGrid.COLUMN_TYPE.input,
width: 300,
orderable: false,
resizable: false,
enabled: editable
},
{
key: 'PointOfContact',
caption: GetTextByKey("P_JS_POINTOFCONTACT", 'Point Of Contact'),
type: dataGrid.COLUMN_TYPE.input,
width: 120,
orderable: false,
resizable: false,
enabled: editable
},
{
key: 'ManageAssets',
type: dataGrid.COLUMN_TYPE.link,
visible: !IsRequestOnly,
align: 'center',
width: 30,
orderable: false,
resizable: false,
enabled: editable,
filter: function () {
return '\uf63c';
},
onclick: function (e, item) {
onManageAssets(item);
},
styleFilter: function () {
return {
'font-family': 'FontAwesome',
'cursor': 'pointer',
'color': 'rgb(123, 28, 33)'
};
},
attrs: { 'title': GetTextByKey("P_JS_MANAGEASSETS", 'Manage Assets') }
},
{
key: 'Delete',
type: dataGrid.COLUMN_TYPE.link,
visible: !IsRequestOnly,
align: 'center',
width: 30,
orderable: false,
resizable: false,
enabled: editable,
filter: function () {
return '\uf00d';
},
onclick: function (e, item) {
onRemoveRequirement(item);
},
styleFilter: function () {
return {
'font-family': 'FontAwesome',
'cursor': 'pointer',
'color': 'rgb(123, 28, 33)'
};
},
attrs: { 'title': GetTextByKey("P_JS_DELETE", 'Delete') }
}
];
return columns;
}
}());
}
function getDaysBetween(dateString1, dateString2, type) {
var startDate = Date.parse(dateString1);
var endDate = Date.parse(dateString2);
if (!type)
if (startDate > endDate)
return 0;
var days = (endDate - startDate) / (1 * 24 * 60 * 60 * 1000) + 1;
return parseInt(days);
}
function getSearchItem() {
var jsid = $('#dialog_jobsite').find("option:selected").val();
var jsname = $("#dialog_jobsite").find("option:selected").text();
var begindate = $('#begindatetxt').val();
var enddate = $('#enddatetxt').val();
var pointofcontact = $('#pointofcontacttxt').val();
var selassettypes = [];
if (assettypeparam)
selassettypes = assettypeparam.selectedvalue;
var item = {
JobSiteId: jsid,
JobSiteName: jsname,
BeginDate: begindate,
EndDate: enddate,
PointOfContact: pointofcontact,
AssetTypes: selassettypes,
Days: getDaysBetween(begindate, enddate)
};
return item;
}
function getMatchRequirements(ignorebeginpast) {
var item = getSearchItem();
var alerttitle = GetTextByKey('P_JS_JOBSITEREQUIREMENTS', "Jobsite Requirements");
if (!item.JobSiteId) {
showAlert(GetTextByKey("P_JS_PLEASESELECTJOBSITE", "Please select Jobsite."), alerttitle);
return;
}
if (!item.BeginDate) {
showAlert(GetTextByKey("P_JS_PLEASEENTERTHEBEGINDATE", "Please enter the Begin Date."), alerttitle);
return;
}
if (!checkDate(item.BeginDate)) {
showAlert(GetTextByKey("P_JS_BEGINDATEFORMATERROR", "Begin Date format error."), alerttitle);
return;
}
if (!item.EndDate) {
showAlert(GetTextByKey("P_JS_PLEASEENTERTHEENDDATE", "Please enter the End Date."), alerttitle);
return;
}
if (!checkDate(item.EndDate)) {
showAlert(GetTextByKey("P_JS_ENDDATEFORMATERROR", "End Date format error."), alerttitle);
return;
}
var nowdt = new Date(currentdate.replace("-", "/"));
var sdate = item.BeginDate;
var stdt = new Date(sdate.replace("-", "/"));
var edate = item.EndDate;
var etdt = new Date(edate.replace("-", "/"));
if (!ignorebeginpast && stdt < nowdt) {
var msg = GetTextByKey("P_JS_BEGINDATEPAST", "The begin date for this requirement is in the past, do you want to continue?")
showConfirm1(msg, alerttitle, function () {
getMatchRequirements(true);
});
return;
}
//if (etdt < nowdt) {
// showAlert(GetTextByKey("P_JS_ENDDATEMUSTBELATERTHANBEGINDATE1", "End Date must be later than Begin Date. Please select another date range."), alerttitle);
// return;
//}
if (stdt > etdt) {
showAlert(GetTextByKey("P_JS_ENDDATEMUSTBELATERTHANBEGINDATE", "End Date must be later than Begin Date."), alerttitle);
return;
}
if (item.AssetTypes.length == 0) {
showAlert(GetTextByKey("P_JS_PLEASESELECTASSETTYPE", "Please select Asset Type."), alerttitle);
return;
}
//if (!item.PointOfContact) {
// showAlert(GetTextByKey("P_JS_PLEASEENTERTHEPOINTOFCONTACT", "Please enter the Point Of Contact."), alerttitle);
// return;
//}
var items = [];
for (var i = 0; i < item.AssetTypes.length; i++) {
var existitem = getExistsItem(item.AssetTypes[i]);
if (existitem) {
items.push(existitem);
}
else {
var aitem = {
'JobSiteId': item.JobSiteId,
'JobSiteName': item.JobSiteName,
'BeginDate': item.BeginDate,
'EndDate': item.EndDate,
'AssetType': item.AssetTypes[i],
'AssetTypeName': getAssetTypeName(item.AssetTypes[i]),
'Quantity': 1,
'ScheduledQuantity': 0,
'Days': item.Days,
'Notes': '',
'PointOfContact': item.PointOfContact,
};
items.push(aitem);
}
}
allRequirements = items;
if (allRequirements.length > 0)
$("#btnFulfillRequest").show();
else
$("#btnFulfillRequest").hide();
if (jobsiterequirementCtrl) {
jobsiterequirementCtrl.setData(allRequirements);
}
}
function getExistsItem(assettypeid) {
for (var i = 0; i < allRequirements.length; i++) {
if (allRequirements[i].AssetType == assettypeid)
return allRequirements[i];
}
return null;
}
function getAssetTypeName(assettypeid) {
for (var i = 0; i < assettypes.length; i++) {
if (assettypes[i].Key == assettypeid)
return assettypes[i].Value;
}
return "";
}
function onRemoveRequirement(item) {
for (var i = 0; i < allRequirements.length; i++) {
if (item.AssetType == allRequirements[i].AssetType) {
allRequirements.splice(i, 1);
break;
}
}
}
//*********************************************Begin Manage Assets***********************************************//
var dispatchAssetsObj;
var alldispatchassets;
var selecteddispatchassets;
function showAssetList(data) {
alldispatchassets = [];
selecteddispatchassets = [];
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
if (addrequirement) {
r.Selected = false;
if (currentRequirement && currentRequirement.Assets) {
for (var k = 0; k < currentRequirement.Assets.length; k++) {
if (currentRequirement.Assets[k].AssetId === r.AssetId) {
r.Selected = true;
break;
}
}
}
}
else {
if (r.Selected) {
r.Selected = false;
selecteddispatchassets.push(r);
}
else {
r.Selected = false;
alldispatchassets.push(r);
continue;
}
}
for (var j in r) {
if (j === "DistanceToDestJobSite")
r[j] = { DisplayValue: r["DistanceStr"], Value: r[j] };
}
var fr = { Values: r };
rows.push(fr);
}
if (currentRequirement)
currentRequirement.ScheduledQuantity = selecteddispatchassets.length;
grid_assetdt.setData(rows);
grid_assetdt.refresh();
}
var grid_assetdt;
function InitAssetGridData() {
grid_assetdt = new GridView('#selectedmachinelist');
grid_assetdt.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, allcheck: true, css: { 'width': 45, 'text-align': 'center' } },
{ name: 'MakeName', caption: GetTextByKey("P_PM_MAKE", "Make"), valueIndex: 'MakeName', css: { 'width': 100, 'text-align': 'left' } },
{ name: 'ModelName', caption: GetTextByKey("P_PM_MODEL", "Model"), valueIndex: 'ModelName', css: { 'width': 100, 'text-align': 'left' } },
{ name: 'AssetName', caption: GetTextByKey("P_JS_ASSETNAME", "Asset Name"), valueIndex: 'AssetName', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'CurrentJobSite', caption: GetTextByKey("P_JS_CURRJOBSITE", "Current Jobsite"), valueIndex: 'CurrentJobSite', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'DistanceToDestJobSite', caption: GetTextByKey("P_JS_DISTANCEFROMJOBSITE", "Distance from Jobsite"), valueIndex: 'DistanceToDestJobSite', css: { 'width': 100, 'text-align': 'right' } },
{ name: 'AssetGroups', caption: GetTextByKey("P_JS_ASSETGROUP", "Asset Group"), valueIndex: 'AssetGroups', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'EngineHours', caption: GetTextByKey("P_JS_ENGINEHOURS", "Engine Hours"), valueIndex: 'EngineHours', css: { 'width': 100, 'text-align': 'right' } },
{ name: 'AquisitionType', caption: GetTextByKey("P_JS_ACQUISITIONTYPE", "Acquisition Type"), valueIndex: 'AquisitionType', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Schedules', caption: "gantt", valueIndex: 'ScheduleParts', css: { 'width': 320, 'text-align': 'left' } }
];
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 = list_columns[hd].visible === false ? false : 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.type = list_columns[hd].type;
if (col.name === "Selected") {
col.events = {
onchanged: function () {
}
};
col.enabled = function (item) {
return !item.Completed;
};
}
else if (col.name === "Schedules") {
var labelCount = 4;
col.sortable = false;
col.allowHtml = true;
col.caption = function () {
if (!dispatchAssetsObj || !dispatchAssetsObj.HasSchedule) return;
var totalDays = dispatchAssetsObj.TotalDays;
var interval = parseInt(totalDays / labelCount);
if (totalDays % labelCount != 0)
interval += 1;
var container = $('<span></span>').css({ position: 'relative', height: '100%', display: 'block' });
var d = new Date(dispatchAssetsObj.BeginDate);
var w = col.width / labelCount;
for (var i = 0; i < labelCount; i++) {
var label = new DateFormatter().formatDate(d, 'm/d/Y');
var sp = $('<span class="span-caption"></span>').text(label).css({ left: w * i });
container.append(sp);
d = new Date(d.getTime() + interval * 1000 * 60 * 60 * 24);
}
return container;
}
col.filter = function (item) {
if (item.ScheduleParts && dispatchAssetsObj && dispatchAssetsObj.HasSchedule) {
var totalDays = dispatchAssetsObj.TotalDays;
var interval = parseInt(totalDays / labelCount);
if (totalDays % labelCount != 0)
interval += 1;
totalDays = interval * labelCount;
var container = $('<div></div>').css({
position: 'relative',
height: '20px',
});
var d = new Date(dispatchAssetsObj.BeginDate);
for (var i = 0; i < item.ScheduleParts.length; i++) {
var sp = item.ScheduleParts[i];
var bdate = new Date(sp.BeginDate);
var edate = new Date(sp.EndDate);
var l = (bdate.getTime() - d.getTime()) / (1000 * 60 * 60 * 24) / totalDays * col.width;
if (l < i + 1)
l = i + 1;
var w = (edate.getTime() - bdate.getTime()) / (1000 * 60 * 60 * 24) / totalDays * col.width;
if (w < 1)
w = 1;
var color = "";
if (sp.Schedules.length == 1)
color = sp.Schedules[0].Color;
else {
for (var j = 0; j < sp.Schedules.length; j++) {
if (color !== "")
color += ","
color += sp.Schedules[j].Color;
}
}
var title = "";
var df = new DateFormatter();
for (var j = 0; j < sp.Schedules.length; j++) {
var bd = new Date(sp.Schedules[j].BeginDate);
var ed = new Date(sp.Schedules[j].EndDate);
title += sp.Schedules[j].JobSiteName + ": " + df.formatDate(bd, 'm/d/Y') + " - " + df.formatDate(ed, 'm/d/Y');
if (j != sp.Schedules.length - 1)
title += "\n";
}
var bar = $('<span class="span-bar"></span>');
bar.css({
left: l,
width: w,
});
if (sp.Schedules.length == 1)
bar.css("backgroundColor", color);
else
bar.css("background-image", "url(\"data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'><g fill-opacity='0.5'><path d='M0 0L8 8z M0 8L8 0z' style='fill:white;stroke:gray;stroke-width:1'/></g></svg>\")");
bar.attr("title", title)
container.append(bar);
}
return container;
}
};
col.styleFilter = function () {
return {
'margin-top': '3px',
'margin-bottom': '0px',
};
}
}
else {
//col.bgFilter = function (item) {
// if (!addrequirement && item.ConflictDays > 0)
// return '#c55a11';
//};
col.styleFilter = function (item) {
if (addrequirement && item.ConflictDays > 0)
return {
'color': '#c55a11',
};
};
}
col.alwaysshow = list_columns[hd].alwaysshow;
columns.push(col);
}
grid_assetdt.canMultiSelect = false;
grid_assetdt.columns = columns;
grid_assetdt.init();
grid_assetdt.rowdblclick = function (rowindex) {
var rowdata = grid_assetdt.source[rowindex];
if (rowdata) {
}
};
grid_assetdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_assetdt.source[rowindex];
if (rowdata) {
}
}
}
function showAllAssetList(data) {
var rows = [];
for (var i = 0; i < data.length; i++) {
var r = data[i];
if (r.Selected)
continue;
for (var j in r) {
if (j === "DistanceToDestJobSite")
r[j] = { DisplayValue: r["DistanceStr"], Value: r[j] };
}
var fr = { Values: r };
rows.push(fr);
}
grid_allassetdt.setData(rows);
grid_allassetdt.refresh();
}
var grid_allassetdt;
function InitAllAssetGridData() {
grid_allassetdt = new GridView('#allmachinelist');
grid_allassetdt.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
var list_columns = [
{ name: 'Selected', caption: "", valueIndex: 'Selected', type: 3, css: { 'width': 45, 'text-align': 'center' } },
{ name: 'MakeName', caption: GetTextByKey("P_PM_MAKE", "Make"), valueIndex: 'MakeName', css: { 'width': 100, 'text-align': 'left' } },
{ name: 'ModelName', caption: GetTextByKey("P_PM_MODEL", "Model"), valueIndex: 'ModelName', css: { 'width': 100, 'text-align': 'left' } },
{ name: 'AssetName', caption: GetTextByKey("P_JS_ASSETNAME", "Asset Name"), valueIndex: 'AssetName', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'CurrentJobSite', caption: GetTextByKey("P_JS_CURRJOBSITE", "Current Jobsite"), valueIndex: 'CurrentJobSite', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'DistanceToDestJobSite', caption: GetTextByKey("P_JS_DISTANCEFROMJOBSITE", "Distance from Jobsite"), valueIndex: 'DistanceToDestJobSite', css: { 'width': 100, 'text-align': 'right' } },
{ name: 'AssetGroups', caption: GetTextByKey("P_JS_ASSETGROUP", "Asset Group"), valueIndex: 'AssetGroups', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'EngineHours', caption: GetTextByKey("P_JS_ENGINEHOURS", "Engine Hours"), valueIndex: 'EngineHours', css: { 'width': 100, 'text-align': 'right' } },
{ name: 'AquisitionType', caption: GetTextByKey("P_JS_ACQUISITIONTYPE", "Acquisition Type"), valueIndex: 'AquisitionType', css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Schedules', caption: "gantt", valueIndex: 'ScheduleParts', css: { 'width': 320, 'text-align': 'left' } }
];
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 = list_columns[hd].visible === false ? false : 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.type = list_columns[hd].type;
if (col.name === "Selected") {
col.events = {
onclick: function () {
}
};
}
else if (col.name === "Schedules") {
var labelCount = 4;
col.sortable = false;
col.allowHtml = true;
col.caption = function () {
if (!dispatchAssetsObj || !dispatchAssetsObj.HasAllSchedule) return;
var totalDays = dispatchAssetsObj.AllTotalDays;
var interval = parseInt(totalDays / labelCount);
if (totalDays % labelCount != 0)
interval += 1;
var container = $('<span></span>').css({ position: 'relative', height: '100%', display: 'block' });
var d = new Date(dispatchAssetsObj.AllBeginDate);
var w = col.width / labelCount;
for (var i = 0; i < labelCount; i++) {
var label = new DateFormatter().formatDate(d, 'm/d/Y');
var sp = $('<span class="span-caption"></span>').text(label).css({ left: w * i });
container.append(sp);
d = new Date(d.getTime() + interval * 1000 * 60 * 60 * 24);
}
return container;
}
col.filter = function (item) {
if (item.ScheduleParts && dispatchAssetsObj && dispatchAssetsObj.HasAllSchedule) {
var totalDays = dispatchAssetsObj.AllTotalDays;
var interval = parseInt(totalDays / labelCount);
if (totalDays % labelCount != 0)
interval += 1;
totalDays = interval * labelCount;
var container = $('<div></div>').css({
position: 'relative',
height: '20px',
});
var d = new Date(dispatchAssetsObj.AllBeginDate);
for (var i = 0; i < item.ScheduleParts.length; i++) {
var sp = item.ScheduleParts[i];
var bdate = new Date(sp.BeginDate);
var edate = new Date(sp.EndDate);
var l = (bdate.getTime() - d.getTime()) / (1000 * 60 * 60 * 24) / totalDays * col.width;
var w = (edate.getTime() - bdate.getTime()) / (1000 * 60 * 60 * 24) / totalDays * col.width;
var color = "";
if (sp.Schedules.length == 1)
color = sp.Schedules[0].Color;
else {
for (var j = 0; j < sp.Schedules.length; j++) {
if (color !== "")
color += ","
color += sp.Schedules[j].Color;
}
}
var title = "";
var df = new DateFormatter();
for (var j = 0; j < sp.Schedules.length; j++) {
var bd = new Date(sp.Schedules[j].BeginDate);
var ed = new Date(sp.Schedules[j].EndDate);
title += sp.Schedules[j].JobSiteName + ": " + df.formatDate(bd, 'm/d/Y') + " - " + df.formatDate(ed, 'm/d/Y');
if (j != sp.Schedules.length - 1)
title += "\n";
}
var bar = $('<span class="span-bar"></span>');
bar.css({
left: l,
width: w,
});
if (sp.Schedules.length == 1)
bar.css("backgroundColor", color);
else
bar.css("background-image", "url(\"data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'><g fill-opacity='0.5'><path d='M0 0L8 8z M0 8L8 0z' style='fill:white;stroke:gray;stroke-width:1'/></g></svg>\")");
bar.attr("title", title)
container.append(bar);
}
return container;
}
};
col.styleFilter = function () {
return {
'margin-top': '3px',
'margin-bottom': '0px',
};
}
}
else {
//col.bgFilter = function (item) {
// if (item.ConflictDays > 0)
// return '#c55a11';
//};
col.styleFilter = function (item) {
if (item.ConflictDays > 0)
return {
'color': '#c55a11',
};
};
}
col.alwaysshow = list_columns[hd].alwaysshow;
columns.push(col);
}
grid_allassetdt.canMultiSelect = false;
grid_allassetdt.columns = columns;
grid_allassetdt.init();
grid_allassetdt.rowdblclick = function (rowindex) {
var rowdata = grid_allassetdt.source[rowindex];
if (rowdata) {
}
};
grid_allassetdt.selectedrowchanged = function (rowindex) {
var rowdata = grid_allassetdt.source[rowindex];
if (rowdata) {
}
}
}
function onManageAssets(item, showprenext, index) {
if (showprenext) {
if (!allRequirements || allRequirements.length <= 0)
return;
if (allRequirements.length > 1) {
$('#btnNext').show();
$('#btnPrevious').show();
}
else {
$('#btnNext').hide();
$('#btnPrevious').hide();
}
indexInRequirement = index;
item = allRequirements[indexInRequirement];
}
else {
$('#btnNext').hide();
$('#btnPrevious').hide();
}
if (currentRequirement) {
currentRequirement.Assets = collectAssets();
}
currentRequirement = item;
showmaskbg(true);
$('#span_jobsite').text(item.JobSiteName);
$('#span_assettypes').text(item.AssetTypeName);
$('#span_pointofcontact').text(item.PointOfContact);
$('#span_quantity').text(item.Quantity);
if (addrequirement) {
$('#span_begindate').text(item.BeginDate);
$('#span_enddate').text(item.EndDate);
}
else {
requireid = item.Id;
$('#span_begindate').text(item.BeginDateStr);
$('#span_enddate').text(item.EndDateStr);
}
var title = GetTextByKey("P_JS_MANAGEASSETS", "Manage Assets");
$('#dialog_managemahchine .dialog-title span.title').html(title);
$('#dialog_managemahchine').showDialogAuto(1400);
if (addrequirement)
getAvailableAssets(item);
else
getAvailableAssetsByRequirement();
}
function getAvailableAssets(item) {
$("#dialogmask").show();
var item = {
'AssetType': item.AssetType,
'JobSiteId': item.JobSiteId,
'BeginDate': item.BeginDate,
'EndDate': item.EndDate,
};
var p = htmlencode(JSON.stringify(item));
showAssetList([]);
jobsitequery("GetAvailableAssets", p, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_JS_ERROR", 'Error'));
}
else if (data) {
dispatchAssetsObj = data;
showAssetList(data.DispatchAssets);
}
$("#dialogmask").hide();
}, function (err) {
$("#dialogmask").hide();
});
}
function getAvailableAssetsByRequirement() {
$("#dialogmask").show();
if (!requireid)
return;
showAssetList([]);
jobsitequery("GetAvailableAssetsByRequirement", requireid, function (data) {
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_JS_ERROR", 'Error'));
}
else if (data) {
dispatchAssetsObj = data;
showAssetList(data.DispatchAssets);
}
$("#dialogmask").hide();
}, function (err) {
$("#dialogmask").hide();
});
}
function collectAssets() {
var assets = [];
for (var i = 0; i < grid_assetdt.source.length; i++) {
var ct = grid_assetdt.source[i].Values;
if (ct.Selected) {
var asset = { 'AssetId': ct.AssetId }
if (!addrequirement)
asset.DispatchId = ct.DispatchId;
assets.push(asset);
}
}
return assets;
}
function OnSetMachine() {
if (allRequirements && allRequirements.length > 0) {
for (var i = 0; i < allRequirements.length; i++) {
var req = allRequirements[i];
if (req.Assets)
req.ScheduledQuantity = req.Assets.length;
}
}
if (!checkQuantity()) {
showAlert(GetTextByKey("P_JS_REQUIREMENTIFORASSETSPLEASEREMOVEEXCESSASSETS1", "Requirement is for {0} asset(s), please remove excess asset(s).").replace('{0}', (currentRequirement.Quantity)), GetTextByKey("P_AM_ERROR", 'Error'));
return;
}
var assets = collectAssets();
currentRequirement.Assets = assets;
currentRequirement.ScheduledQuantity = assets.length;
$('#dialog_managemahchine').hide();
showmaskbg(false);
}
function checkQuantity() {
if (currentRequirement) {
var count = 0;
for (var i = 0; i < grid_assetdt.source.length; i++) {
var ct = grid_assetdt.source[i].Values;
if (ct.Selected) count++;
}
return currentRequirement.Quantity >= count;
}
else
return true;
}
function onAddDispatch() {
var assets = [];
for (var i = 0; i < grid_allassetdt.source.length; i++) {
var ct = grid_allassetdt.source[i].Values;
if (ct.Selected) {
var asset = { 'AssetId': ct.AssetId }
assets.push(asset);
}
}
var count = currentRequirement.Quantity - currentRequirement.ScheduledQuantity;
if (assets.length > count) {
showAlert(GetTextByKey("P_JS_REQUIREMENTIFORASSETSPLEASEREMOVEEXCESSASSETS1", "Requirement is for {0} asset(s), please remove excess asset(s).").replace('{0}', (count)), GetTextByKey("P_AM_ERROR", 'Error'));
return;
}
var stdt = new Date(currentRequirement.BeginDate.DisplayValue.replace("-", "/"));
var now = new Date(currentdate);
var time = now.getFullYear() + "/" + ((now.getMonth() + 1) < 10 ? "0" : "") + (now.getMonth() + 1) + "/" + (now.getDate() < 10 ? "0" : "") + now.getDate();
var stime = stdt.getFullYear() + "/" + ((stdt.getMonth() + 1) < 10 ? "0" : "") + (stdt.getMonth() + 1) + "/" + (stdt.getDate() < 10 ? "0" : "") + stdt.getDate();
var daycount = 0;
var days = getDaysBetween(time, stime, true);
if (days > 0 && days < 8) {
daycount++;
}
var alerttitle = GetTextByKey('P_JS_ADDDISPATCH', 'Add Dispatch');
jobsitequery("AddDispatch", requireid + String.fromCharCode(170) + htmlencode(JSON.stringify(assets)), function (data) {
if (typeof (data) === "string") {
showAlert(data, alerttitle);
} else {
_selectdispatchids = data;
$('#dialog_allmahchine').hide();
$("#dialogmask").hide();
if (daycount > 0) {
$('#dialog_managemahchine').hide();
OnRefresh(true);
var msg = GetTextByKey("P_JS_SCHEDULEDREQUIREMENTSTAKEPLACEWITHINTHENEXTDAYSWOULDYOULIKETO", "{0} scheduled requirements take place within the next 7 days. Would you like to:").replace('{0}', 1);
showRequirementConfirm(msg, alerttitle,
function () {
openAssignDispatch(0);
}, function () {
openAssignDispatch(1);
}, function () {
}, function () {
});
}
else
getAvailableAssetsByRequirement();
}
}, function (err) {
$("#dialogmask").hide();
});
}
//function OnExit() {
//}
function onDeleteDispatch() {
var dispatchids = [];
for (var i = 0; i < grid_assetdt.source.length; i++) {
var ct = grid_assetdt.source[i].Values;
if (ct.Selected) {
dispatchids.push(ct.DispatchId);
}
}
if (dispatchids.length == 0)
return;
var item = {
'DispatchId': dispatchids,
'DeleteNotes': ''
};
var p = htmlencode(JSON.stringify(item));
var text = GetTextByKey("P_JS_DELETETHEDISPATCH", "Would you like to delete the dispatch?");
var alerttitle = GetTextByKey("P_JS_DELETEDISPATCH", "Delete Dispatch");
showConfirmIndialog(text, alerttitle, function () {
jobsitequery("DeleteDispatch", p, function (data) {
getAvailableAssetsByRequirement();
}, function (err) {
});
});
}
function OnPrevious() {
if (!checkQuantity()) {
showAlert(GetTextByKey("P_JS_REQUIREMENTIFORASSETSPLEASEREMOVEEXCESSASSETS1", "Requirement is for {0} asset(s), please remove excess asset(s).").replace('{0}', (currentRequirement.Quantity)), GetTextByKey("P_AM_ERROR", 'Error'));
return;
}
if (--indexInRequirement < 0)
indexInRequirement = allRequirements.length - 1;
onManageAssets(allRequirements[indexInRequirement], true, indexInRequirement);
changeGridSelectIndex(indexInRequirement);
}
function OnNext() {
if (!checkQuantity()) {
showAlert(GetTextByKey("P_JS_REQUIREMENTIFORASSETSPLEASEREMOVEEXCESSASSETS1", "Requirement is for {0} asset(s), please remove excess asset(s).").replace('{0}', (currentRequirement.Quantity)), GetTextByKey("P_AM_ERROR", 'Error'));
return;
}
if (++indexInRequirement > allRequirements.length - 1)
indexInRequirement = 0;
onManageAssets(allRequirements[indexInRequirement], true, indexInRequirement);
changeGridSelectIndex(indexInRequirement);
}
function changeGridSelectIndex(index) {
jobsiterequirementCtrl.selectedIndexes = [index];
}
function OnMachineAdd() {
$('#dialogmask').show();
var title = GetTextByKey("P_MA_SELECTASSET", "Select Assets");
$('#dialog_allmahchine .dialog-title span.title').html(title);
$('#dialog_allmahchine').showDialogAuto(1400);
showAllAssetList(alldispatchassets);
}
//*********************************************End Manage Assets***********************************************//