function showSchedulerData(data) { if (data) { assetsObj = data; if (assetsObj.HasSchedule) grid_dt.columns[grid_dt.columns.length - 1].width = assetsObj.TotalDays * 5; else grid_dt.columns[grid_dt.columns.length - 1].width = 320; grid_dt.init(); showSchedulerList(data.DispatchAssets); } else { assetsObj = null; grid_dt.columns[grid_dt.columns.length - 1].width = 320; grid_dt.init(); showSchedulerList([]); } } function showSchedulerList(data) { var rows = []; for (var i = 0; i < data.length; i++) { var r = data[i]; var fr = { Values: r }; rows.push(fr); } grid_dt.setData(rows); grid_dt.refresh(); } var grid_dt; function InitGridData() { grid_dt = new GridView('#schedulerlist'); grid_dt.lang = { all: GetTextByKey("P_GRID_ALL", "(All)"), ok: GetTextByKey("P_GRID_OK", "OK"), reset: GetTextByKey("P_GRID_RESET", "Reset") }; var list_columns = [ { name: 'TypeName', caption: GetTextByKey("P_JS_ASSETTYPE", "Asset Type"), valueIndex: 'TypeName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } }, { name: 'MakeName', caption: GetTextByKey("P_PM_MAKE", "Make"), valueIndex: 'MakeName', allowFilter: true, css: { 'width': 100, 'text-align': 'left' } }, { name: 'ModelName', caption: GetTextByKey("P_PM_MODEL", "Model"), valueIndex: 'ModelName', allowFilter: true, css: { 'width': 100, 'text-align': 'left' } }, { name: 'AssetName', caption: GetTextByKey("P_JS_ASSETNAME", "Asset Name"), valueIndex: 'AssetName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } }, { name: 'CurrentJobSite', caption: GetTextByKey("P_JS_CURRJOBSITE", "Current Jobsite"), allowFilter: true, valueIndex: 'CurrentJobSite', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } }, { name: 'AssetGroups', caption: GetTextByKey("P_JS_ASSETGROUP", "Asset Group"), valueIndex: 'AssetGroups', allowFilter: true, 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', allowFilter: true, 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; col.alwaysshow = list_columns[hd].alwaysshow; if (col.name === "Schedules") { var labelCount = 4; col.sortable = false; col.allowHtml = true; col.caption = function () { if (!assetsObj || !assetsObj.HasSchedule) return; var container = $('').css({ position: 'relative', height: '100%', display: 'block' }); var left = 0; for (var i = 0; i < assetsObj.Labels.length; i++) { var label = assetsObj.Labels[i]; var sp = $('').text(label.Key).css({ left: left }); left += parseInt(label.Value) * 5; container.append(sp); } grid_dt.resize(); //var totalDays = (led.getTime() - fbd.getTime()) / (1000 * 60 * 60 * 24); //var interval = parseInt(totalDays / labelCount); //if (totalDays % labelCount != 0) // interval += 1; //var d = new Date(assetsObj.BeginDate); //var w = col.width / labelCount; //for (var i = 0; i < labelCount; i++) { // var label = new DateFormatter().formatDate(d, 'm/d/Y'); // var sp = $('').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 && assetsObj && assetsObj.HasSchedule) { var totalDays = assetsObj.TotalDays; var interval = parseInt(totalDays / labelCount); if (totalDays % labelCount != 0) interval += 1; totalDays = interval * labelCount; var container = $('
').css({ position: 'relative', height: '20px', }); var d = new Date(assetsObj.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; 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 df = new DateFormatter(); var title = df.formatDate(bdate, 'm/d/Y') + " - " + df.formatDate(new Date((edate.getTime() - 1000 * 60 * 60 * 24)), 'm/d/Y') + "\n"; 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 (sp.Schedules[j].PointOfContact) title += "\n " + GetTextByKey("P_JS_CONTACT_COLON", "Contact: ") + " " + sp.Schedules[j].PointOfContact; if (sp.Schedules[j].Creator) title += "\n " + GetTextByKey("P_JS_CREATOR_COLON", "Creator: ") + " " + sp.Schedules[j].Creator; if (j != sp.Schedules.length - 1) title += "\n"; } var bar = $(''); bar.css({ left: l, width: w - 1, 'border-left': '1px solid transparen' }); if (sp.Schedules.length == 1) bar.css("backgroundColor", color); else { //bar.css("background", "url(img/gridline.jpg) repeat 20px 20px"); //bar.css("background", "linear-gradient(45deg," + color + ")"); //bar.css("background-image", "repeating-linear-gradient(45deg,white, white 5px,#ff9900 5px,#ff9900 7px)"); //bar.css("background-image", "repeating-linear-gradient(135deg,blue 1px, transparent 0), repeating-linear-gradient(45deg, red 1px, transparent 0)"); //bar.css("background-size", "5px 5px"); //bar.css("background-image", "url(\"data:image/svg+xml,\")"); bar.css("background-image", "url(\"data:image/svg+xml,\")"); } bar.attr("title", title); if (!IsReadOnly) { bar.dblclick(sp, function (e) { onEditScheduler(item, e.data.Schedules); }); } container.append(bar); } return container; } }; col.styleFilter = function () { return { 'margin-top': '3px', 'margin-bottom': '0px', }; } } columns.push(col); } grid_dt.canMultiSelect = false; grid_dt.columns = columns; grid_dt.init(); grid_dt.celldblclick = function (rowindex, columnIndex) { if (!IsReadOnly) { if (columnIndex != grid_dt.columns.length - 1) { var rowdata = grid_dt.source[rowindex]; if (rowdata) { onEditScheduler(rowdata.Values); } } } } grid_dt.selectedrowchanged = function (rowindex) { var rowdata = grid_dt.source[rowindex]; if (rowdata) { } } } if (typeof jobsiteschedulerCtrl !== 'function') { $jobsiteschedulerCtrl = function jobsiteschedulerCtrl() { this.tmpobj = { }; this.wizardCtrl = null; this.vue = null; }; (function () { 'use strict'; var dataGrid = window.DataGrid || window['g5-datagrid']; $jobsiteschedulerCtrl.prototype.getData = function (/*dataObj, tmpdata*/) { return this.vue.source; }; $jobsiteschedulerCtrl.prototype.setData = function (data) { if (data) { for (var i = 0; i < data.length; i++) { data[i].Selected = false; } } this.vue.source = data ? data : []; this.vue.$refs.grid.resize(); }; $jobsiteschedulerCtrl.prototype.reload = function () { this.vue.$refs.grid.reload() }; $jobsiteschedulerCtrl.prototype.Init = function (parent, newselected) { var ethis = this; //加载子页面模版 parent.load('../template/JobsiteSchedulerCtrl.html?v=8', function () { ethis.vue = new Vue({ el: parent.find('.JobsiteSchedulerCtrl')[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: 'Selected', caption: '', type: dataGrid.COLUMN_TYPE.checkbox, width: 30, align: 'center', sortable: false, orderable: false, resizable: false, allcheck: false, enabled: function (item) { return !item.Completed; } }, { key: 'JobSiteName', caption: GetTextByKey("P_JS_JOBSITE", "Jobsite"), type: dataGrid.COLUMN_TYPE.label, width: 200, orderable: false, resizable: false, enabled: false }, { key: 'BeginDateStr', caption: GetTextByKey("P_JS_BEGINDATE", 'Begin Date'), type: dataGrid.COLUMN_TYPE.datepicker, width: 120, orderable: false, resizable: false, enabled: editable, onchanged: function (item) { item.Changed = true; } }, { key: 'EndDateStr', caption: GetTextByKey("P_JS_ENDDATE", 'End Date'), type: dataGrid.COLUMN_TYPE.datepicker, width: 120, orderable: false, resizable: false, enabled: editable, onchanged: function (item) { item.Changed = true; } }, { key: 'Delete', type: dataGrid.COLUMN_TYPE.link, align: 'center', width: 30, orderable: false, resizable: false, enabled: editable, filter: function (item) { return item.Completed ? '' : '\uf00d'; }, onclick: function (e, item) { onDeleteScheduler(item); }, styleFilter: function (item) { return { 'font-family': 'FontAwesome', 'cursor': 'pointer', 'color': 'rgb(123, 28, 33)' }; }, attrs: { 'title': GetTextByKey("P_JS_DELETE", 'Delete') } } ]; return columns; } }()); } var currentscheduler; var allSchedulers; function onEditScheduler(item, schedules) { allSchedulers = []; currentscheduler = item; if (!schedules || schedules.length == 0) { schedules = item.Schedules; } if (schedules && schedules.length > 0) allSchedulers = schedules; $('#dialog_assetname').text(item.AssetName); $('#dialog_assettype').text(item.TypeName); $('#dialog_make').text(item.MakeName); $('#dialog_model').text(item.ModelName); showmaskbg(true); var title = GetTextByKey("P_JS_MANAGESCHEDULER", "Manage Scheduler"); $('#dialog_managescheduler .dialog-title span.title').html(title); $('#dialog_managescheduler') .attr('init', 1) .css({ 'top': (document.documentElement.clientHeight - $('#dialog_managescheduler').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_managescheduler').width()) / 2 }).showDialogfixed(); if (jobsiteschedulerCtrl) { jobsiteschedulerCtrl.setData(allSchedulers); } } function onDeleteScheduler(item) { var schduler = item; var ids = []; if (schduler) { ids.push(schduler.DispatchId); } else { for (var i = 0; i < jobsiteschedulerCtrl.vue.source.length; i++) { var sch = jobsiteschedulerCtrl.vue.source[i]; if (sch.Selected && !sch.Completed) { ids.push(sch.DispatchId); } } } if (ids.length == 0) return; var text = GetTextByKey("P_JS_WOULDYOULIKETODELETETHESCHEDULERS", "Would you like to delete the scheduler(s)?"); var alerttitle = GetTextByKey("P_JS_DELETESCHEDULER", "Delete Scheduler"); showConfirmIndialog(text, alerttitle, function () { var dispatchids = []; if (schduler) { dispatchids.push(schduler.DispatchId); var index = jobsiteschedulerCtrl.vue.source.indexOf(schduler); jobsiteschedulerCtrl.vue.$refs.grid.deleteRow(index); } else { for (var i = jobsiteschedulerCtrl.vue.source.length - 1; i >= 0; i--) { var sch = jobsiteschedulerCtrl.vue.source[i]; if (sch.Selected && !sch.Completed) { dispatchids.push(sch.DispatchId); jobsiteschedulerCtrl.vue.$refs.grid.deleteRow(i); } } } if (dispatchids.length == 0) return; var item = { 'DispatchId': dispatchids, 'DeleteNotes': '' }; var p = htmlencode(JSON.stringify(item)); jobsitequery("DeleteDispatch", p, function (data) { }, function (err) { }); }); } function checkSchedulerItems(alerttitle) { var items = []; for (var i = 0; i < jobsiteschedulerCtrl.vue.source.length; i++) { var sch = jobsiteschedulerCtrl.vue.source[i]; if (sch.Changed) { var item = { 'DispatchId': sch.DispatchId, 'MoveDate': sch.MoveDate, 'BeginDate': sch.BeginDateStr, 'EndDate': sch.EndDateStr, 'Notes': sch.Notes }; if (!item.BeginDate) { showAlert(GetTextByKey("P_JS_PLEASEENTERTHEBEGINDATE", "Please enter the Begin Date."), alerttitle); return false; } if (!checkDate(item.BeginDate)) { showAlert(GetTextByKey("P_JS_BEGINDATEFORMATERROR", "Begin Date format error."), alerttitle); return false; } if (!item.EndDate) { showAlert(GetTextByKey("P_JS_PLEASEENTERTHEENDDATE", "Please enter the End Date."), alerttitle); return false; } if (!checkDate(item.EndDate)) { showAlert(GetTextByKey("P_JS_ENDDATEFORMATERROR", "End Date format error."), alerttitle); return false; } 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 (stdt < nowdt) { // showAlert(GetTextByKey("P_JS_BEGINDATESHOULDBENOEARLIERTHANTODAYSDATE", "Begin Date should be no earlier than today’s date. Please select another date."), alerttitle); // return false; //} //if (etdt < nowdt) { // showAlert(GetTextByKey("P_JS_ENDDATEMUSTBELATERTHANBEGINDATE1", "End Date must be later than Begin Date. Please select another date range."), alerttitle); // return false; //} if (stdt > etdt) { showAlert(GetTextByKey("P_JS_ENDDATEMUSTBELATERTHANBEGINDATE", "End Date must be later than Begin Date."), alerttitle); return false; } items.push(item); } } return items; } function onUpdateScheduler() { if (jobsiteschedulerCtrl.vue.source.length == 0) { $('#dialog_managescheduler').hide(); $('#mask_bg').hide(); OnRefresh(); return; } var alerttitle = GetTextByKey("P_JS_MANAGESCHEDULER", "Manage Scheduler"); var items = checkSchedulerItems(alerttitle); if (!items) return; if (items.length == 0) { $('#dialog_managescheduler').hide(); $('#dialogmask').hide(); OnRefresh(); return; } showloading(true); var param = JSON.stringify(items); param = htmlencode(param); jobsitequery("UpdateDispatch", param, function (data) { showloading(false); if (data !== "OK") { showAlert(data, GetTextByKey("P_AM_ERROR", 'Error')); } $('#dialog_managescheduler').hide(); $('#dialogmask').hide(); OnRefresh(); }, function (err) { console.log(err); showloading(false); showAlert(GetTextByKey("P_JS_FAILEDTOSAVE", "Failed to save jobsite."), alerttitle); }); } function openAddScheduler() { showmaskbg(true); $('#dialogmask').show(); $('#dialog_addjobsite').val(''); $('#dialog_addbegindate').val(''); $('#dialog_addenddate').val(''); $('#dialog_addnotes').val(''); $('#dialog_pointofcontact').val(''); var title = GetTextByKey("P_JS_ADDSCHEDULER", "Add Scheduler"); $('#dialog_addscheduler .dialog-title span.title').html(title); $('#dialog_addscheduler') .attr('init', 1) .css({ 'top': (document.documentElement.clientHeight - $('#dialog_addscheduler').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_addscheduler').width()) / 2 }).showDialogfixed(); } function onAddScheduler(ignorebeginpast) { var alerttitle = GetTextByKey("P_JS_ADDSCHEDULER", "Add Scheduler"); var item = { 'JobSiteId': $('#dialog_addjobsite').find("option:selected").val(), 'JobSiteName': $("#dialog_addjobsite").find("option:selected").text(), 'BeginDate': $.trim($('#dialog_addbegindate').val()), 'EndDate': $.trim($('#dialog_addenddate').val()), 'Quantity': 1, 'Notes': $('#dialog_addnotes').val(), 'PointOfContact': $('#dialog_pointofcontact').val() }; item.AssetType = currentscheduler.TypeId; var assets = []; var asset = { 'AssetId': currentscheduler.AssetId, 'BeginDate': item.BeginDate, 'EndDate': item.EndDate }; assets.push(asset); item.Assets = assets; if (item.BeginDate.length === 0) { 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.length === 0) { 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?") showConfirm(msg, alerttitle, function () { onAddScheduler(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; } $('#dialogmask1').show(); var param = JSON.stringify(item); param = htmlencode(param); jobsitequery("CreateNewRequirment", param, function (data) { if (typeof (data) === "string") { showAlert(data, alerttitle); $('#dialogmask1').hide(); } else { $('#dialog_addscheduler').hide(); $('#dialogmask').hide(); $('#dialogmask1').hide(); var scheduleritem = item; scheduleritem.DispatchId = data[0]; scheduleritem.BeginDateStr = item.BeginDate; scheduleritem.EndDateStr = item.EndDate; allSchedulers.push(scheduleritem); } }, function (err) { console.log(err); showAlert(GetTextByKey("P_JS_FAILEDTOSAVESCHEDULER", "Failed to save scheduler."), alerttitle); $('#dialogmask1').hide(); }); }