Untitled
unknown
plain_text
a year ago
21 kB
10
Indexable
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
<Dialog stretch="{device>/isPhone}" contentHeight="100%" showHeader="false" contentWidth="90%" id="measuringPointsPopover">
<NavContainer>
<Page id="master" showNavButton="false" title="{EquipmentDesc} - {Equipment}">
<content>
<VBox class="sapUiSmallMargin" alignItems="Stretch" justifyContent="Start">
<Label text="{i18n>WorkOrderDetails-InspectionRoundsPopover-Operation}"/>
<Text text="{Activity} - {Description}" wrapping="true"/>
<Label text="{i18n>WorkOrderDetails-InspectionRoundsPopover-Description}" class="sapUiTinyMarginTop"/>
<Text text="{path: 'LongText', formatter: '.removeNewLine'}" wrapping="true"/>
</VBox>
<Table id="measuringPointsTable" class="workOrderListTableClass sapUiSmallMarginBottom"
items="{path:'OperationMeasPoint', sorter: {path: 'Measpoint', descending: false}}" showSeparators="Inner">
<columns>
<Column>
<Label text="{i18n>WorkOrderDetails-InspectionRoundsPopover-Point}"/>
</Column>
<Column width="6rem" minScreenWidth="tablet" demandPopin="true">
<Label text="{i18n>WorkOrderDetails-InspectionRoundsPopover-LastReading}"/>
</Column>
<Column width="6rem" minScreenWidth="tablet" demandPopin="true">
<Label text="{i18n>WorkOrderDetails-MeasuringPointsBlock-PopOverMeasurementPreviousDifferenceReadingLabel}"/>
</Column>
<Column width="6rem" minScreenWidth="tablet" demandPopin="true" visible="{Complete}">
<Label text="{i18n>WorkOrderDetails-InspectionRoundsPopover-ReadBy}"/>
</Column>
<Column width="4rem" minScreenWidth="tablet" demandPopin="true" hAlign="Center">
<Label text="{i18n>WorkOrderDetails-InspectionRoundsPopover-Counter}"/>
</Column>
<Column width="2rem" minScreenWidth="tablet" demandPopin="true" hAlign="Center" visible="{path: 'Complete', formatter: '.hideInputColumns'}">
<Label text="{i18n>WorkOrderDetails-InspectionRoundsPopover-Note}"/>
</Column>
<Column width="5rem" hAlign="End" minScreenWidth="tablet" demandPopin="true">
<Label text="{i18n>WorkOrderDetails-InspectionRoundsPopover-Threshold}"/>
</Column>
<Column width="8rem" minScreenWidth="tablet" demandPopin="true" visible="{path: 'Complete', formatter: '.hideInputColumns'}">
<Label text="{i18n>WorkOrderDetails-InspectionRoundsPopover-Measurement}"/>
</Column>
</columns>
<items>
<ColumnListItem type="Inactive" vAlign="Middle">
<cells>
<ObjectIdentifier title="{Descriptn}" text="{Measpoint}"/>
<ObjectIdentifier title="{LastReading} {MeasUnit}"
text="{path: 'LastReadingDate', type: 'sap.ui.model.type.Date', formatOptions: {pattern: 'dd.MM.yyyy', strictParsing: true, UTC: true}}"/>
<Text text="{LastDifference}"/>
<Text text="{LastReadingBy}"/>
<Text text="{path: 'Counter', formatter: '.getCounterText'}"/>
<Button icon="{path: 'LongText', formatter: '.getNoteIcon'}" press="openAddNotePopover" type="Transparent"/>
<VBox>
<Label text="{i18n>WorkOrderDetails-MeasuringPointsBlock-PopOverReadingCounterValueInputLabel}"/>
<Input id="readingCounterInput" value="{Value}" enabled="{= ${MeasurementDifference} === ''}" description="{MeasUnit}" fieldWidth="70%"
textAlign="End" type="Number" visible="{path: 'CatalogType', formatter: '.showReadingInput'}"/>
<Label text="{i18n>WorkOrderDetails-MeasuringPointsBlock-PopOverReadingDifferenceValueInputLabel}"/>
<Input type="Text" value="{CodeShortText}" showValueHelp="true" valueHelpRequest="handleValueHelpCodeGroup" valueHelpOnly="false"
visible="{path: 'CatalogType', formatter: '.showSelectCodeGroups'}"/>
<Input id="differenceValueInput" value="{path: 'MeasurementDifference'}" enabled="{= ${Value} === ''}" description="{MeasUnit}"
fieldWidth="70%" textAlign="End" type="Number" visible="{path: 'Counter', formatter: '.showDifferenceReading'}"/>
</VBox>
</cells>
</ColumnListItem>
</items>
</Table>
</content>
<footer>
<OverflowToolbar >
<Button text="{i18n>WorkOrderDetails-InspectionRoundsPopover-CreateNotification}" press="onMeasuringPointsPopoverCreateNotif"/>
<ToolbarSpacer/>
<Button text="{i18n>WorkOrderDetails-InspectionRoundsPopover-Close}" press="onMeasuringPointsPopoverClose" visible="{Complete}"/>
<Button text="{i18n>WorkOrderDetails-InspectionRoundsPopover-Cancel}" press="onMeasuringPointsPopoverClose"
visible="{path: 'Complete', formatter: '.hideInputColumns'}"/>
<Button text="{i18n>WorkOrderDetails-InspectionRoundsPopover-Save}" press="onMeasuringPointsPopoverSave"
visible="{path: 'Complete', formatter: '.hideInputColumns'}">
<layoutData><OverflowToolbarLayoutData priority="NeverOverflow"/></layoutData>
</Button>
<Button type="Emphasized" text="{i18n>WorkOrderDetails-InspectionRoundsPopover-SaveAndComplete}" press="onMeasuringPointsPopoverComplete"
visible="{path: 'Complete', formatter: '.hideInputColumns'}">
<layoutData><OverflowToolbarLayoutData priority="NeverOverflow"/></layoutData>
</Button>
</OverflowToolbar>
</footer>
</Page>
</NavContainer>
</Dialog>
</core:FragmentDefinition>
sap.ui.define([
"com/twobm/mobileworkorder/util/Controller",
"com/twobm/mobileworkorder/components/offline/SyncManager",
"sap/m/MessageBox",
"com/twobm/mobileworkorder/util/Formatter",
"sap/ui/core/format/NumberFormat"
], function (Controller, SyncManager, MessageBox, Formatter, NumberFormat) {
"use strict";
return sap.ui.controller(
"com.twobm.mobileworkorder.HeidelbergWorkOrderExtension.components.workOrderDetails.blocks.InspectionsBlockCustom", {
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf com.twobm.mobileworkorder.HeidelbergWorkOrderExtension.components.workOrderDetails.blocks.InspectionsBlockCustom
*/
onInit: function () {
this.getEventBus().subscribe("showMeasuringPointsPopover", this.openMeasuringPointsPopover, this);
},
onMeasuringPointsPopoverCreateNotif: function () {
this.measuringPointsPopoverCreateNotif(false, true);
},
onMeasuringPointsPopoverCreateNotifWithErrors: function () {
this.measuringPointsPopoverCreateNotif(true, false);
},
openMeasuringPointsPopover: function (oEvent) {
var view = this.getView();
var measuringPointsPopover = view.byId("measuringPointsPopover");
if (!measuringPointsPopover) {
measuringPointsPopover = sap.ui.xmlfragment(view.getId(),
"com.twobm.mobileworkorder.HeidelbergWorkOrderExtension.components.workOrderDetails.fragments.MeasuringPointsPopoverCustom",
this);
view.addDependent(measuringPointsPopover);
}
var newWorkOrderModel = this.getView().getModel("newWorkOrderModel");
var context;
if (newWorkOrderModel.getData().inspectionContext !== undefined) {
context = newWorkOrderModel.getData().inspectionContext;
newWorkOrderModel.getData().inspectionContext = undefined;
newWorkOrderModel.refresh();
} else {
context = oEvent.getSource().getParent().getBindingContext();
}
measuringPointsPopover.setBindingContext(context);
measuringPointsPopover.open();
this.prepareInputFields();
},
prepareInputFields: function () {
// wait for elements to be in the DOM before doing anything
setTimeout(() => {
var allInputs = document.querySelectorAll(`input[id*=measuringPointsTable]`);
allInputs.forEach(input => {
if (input.getAttribute("type") === "text") {
input.addEventListener("keydown", function (e) {
e.preventDefault();
});
}
});
this.getView().byId("measuringPointsTable").setKeyboardMode(sap.m.ListKeyboardMode.Edit);
this.keyDownHandler = function (e) {
var currentInputIndex = parseInt(document.activeElement.id.split("--")[1].split("-")[1]);
var input = document.querySelector(`input[id*=measuringPointsTable-${currentInputIndex + 1}]`);
if (e.key === 'Enter' && input) {
input.focus();
}
}.bind(this);
this.getView().byId("measuringPointsTable").attachBrowserEvent("keydown", this.keyDownHandler);
}, 200);
},
onMeasuringPointsPopoverComplete: function (oEvent) {
this.operationContextPath = oEvent.getSource().getBindingContext().getPath();
var result = this.checkForErrors();
if (result.errors.length > 0 || result.warnings.length > 0) {
this.openMeasurementErrorDialog(result.errors, result.warnings, true);
} else {
this.checkForEmptyFields(true);
}
},
onMeasuringPointsPopoverSave: function (oEvent) {
var operationComplete = this.getView().getModel().setProperty(this.operationContextPath + "/Complete");
if (!operationComplete) {
var result = this.checkForErrors();
if (result.errors.length > 0 || result.warnings.length > 0) {
this.openMeasurementErrorDialog(result.errors, result.warnings, false);
} else {
this.completeOperation(false);
}
}
},
checkForEmptyFields: function () {
if (this.hasEmptyField) {
MessageBox.warning(this.getI18nText("WorkOrderDetails-InspectionRoundsPopover-EmptyFieldsWarning"), {
actions: [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],
onClose: function (action) {
if (action === "YES") {
this.completeOperation(true);
}
}.bind(this)
});
} else {
this.completeOperation(true);
}
},
passToFloatValue: function (value) {
var oNumberFormat = NumberFormat.getFloatInstance({
decimalSeparator: "."
});
return oNumberFormat.parse(value);
},
completeOperation: function (complete) {
// Create each measurement
var pendingChanges = this.getView().getModel().getPendingChanges();
var aPendingChanges = $.map(pendingChanges, function (value, index) {
return [index];
});
aPendingChanges.forEach(function (pendingChange) {
if (pendingChange.toString().startsWith("MeasurementPointsSet")) {
var point = this.getView().getModel().getProperty("/" + pendingChange.toString());
var DifferenceReading = "";
var Recordedval = "";
if (point.MeasurementDifference && this.passToFloatValue(point.MeasurementDifference) > 0) {
DifferenceReading = true;
Recordedval = point.MeasurementDifference;
} else {
DifferenceReading = false;
Recordedval = point.Value;
}
var data = {
properties: {
Measpoint: point.Measpoint,
ReadingDate: new Date(),
LongText: point.LongText,
Orderid: point.Orderid,
Fullname: this.getView().getModel("appInfoModel").getData().UserFullName,
ValuationCode: point.ValuationCode,
CodeGroup: point.CodeGroup,
CodeCatalogue: point.CatalogType,
DifferenceReading: DifferenceReading,
RecordedValue: Recordedval
}
};
// Create measurement doc
this.getView().getModel().resetChanges(["/" + pendingChange.toString()]);
this.getView().getModel().createEntry("/MeasurementDocsSet", data);
// Set last reading and read by on meas point
if (Recordedval) {
this.getView().getModel().setProperty("/" + pendingChange.toString() + "/LastReading", Recordedval);
} else {
this.getView().getModel().setProperty("/" + pendingChange.toString() + "/LastReading", point.ValuationCode);
}
this.getView().getModel().setProperty("/" + pendingChange.toString() + "/LastReadingBy", this.getView().getModel(
"appInfoModel").getData().UserFullName);
}
}.bind(this));
// Set operation to complete
if (complete) {
this.getView().getModel().setProperty(this.operationContextPath + "/Complete", complete);
}
this.getView().getModel().submitChanges({
success: function () {
this.closeMeasurementErrorDialog();
this.onMeasuringPointsPopoverClose();
}.bind(this)
});
},
onMeasuringPointsPopoverClose: function () {
var differenceValueControl = this.getView().byId("differenceValueInput");
var counterValueControl = this.getView().byId("readingCounterInput");
if (this.getView().byId("measuringPointsPopover")) {
this.getView().byId("measuringPointsTable").detachBrowserEvent("keydown", this.keyDownHandler);
// re-enable both counter and difference input fields
differenceValueControl.setEnabled(true);
counterValueControl.setEnabled(true);
this.getView().byId("measuringPointsPopover").close();
}
},
measuringPointsPopoverCreateNotif: function (addLongText, setInspectionContext) {
//Reset create notification model
this.getOwnerComponent().resetNewNotificationModel();
var measuringPoint = this.getView().byId("measuringPointsPopover").getBindingContext().getObject();
var newNotificationModel = this.getView().getModel("newNotificationModel");
newNotificationModel.getData().equipmentNo = measuringPoint.Equipment;
newNotificationModel.getData().equipmentDesc = measuringPoint.EquipmentDesc;
newNotificationModel.getData().functionalLoc = measuringPoint.FunctLoc;
newNotificationModel.getData().funcLocDesc = measuringPoint.FunctLocDesc;
newNotificationModel.getData().fromTechStructure = true;
var newWorkOrderModel = this.getView().getModel("newWorkOrderModel");
if (setInspectionContext) {
newWorkOrderModel.getData().inspectionContext = this.getView().byId("measuringPointsPopover").getBindingContext();
newWorkOrderModel.refresh();
}
var longText = "";
if (addLongText) {
var items = this.getView().byId("measurementErrorDialog").getModel("ViewModel").getData().items;
if (!items.Difference)
items.forEach(function (i) {
if (longText) {
longText = longText + "\n";
}
var minLimit = (+i.MinLimit).toFixed(2);
var maxLimit = (+i.MaxLimit).toFixed(2);
longText = longText + this.getI18nText("WorkOrderDetails-InspectionRoundsPopover-MeasurementPointExceedsThresholdLongTextPart1") +
" (" + i.Measpoint + " - " + i.Descriptn + ") " + this.getI18nText(
"WorkOrderDetails-InspectionRoundsPopover-MeasurementPointExceedsThresholdLongTextPart2") + "." + " " + this.getI18nText(
"WorkOrderDetails-InspectionRoundsPopover-MeasurementPointExceedsThresholdLongTextPart3") + ": " + i.Value + " (" + this.getI18nText(
"WorkOrderDetails-InspectionRoundsPopover-MeasurementPointExceedsThresholdLongTextPart4") + ": " + minLimit + " / " + this.getI18nText(
"WorkOrderDetails-InspectionRoundsPopover-MeasurementPointExceedsThresholdLongTextPart5") + ": " + maxLimit + ")";
}.bind(this));
newNotificationModel.getData().shortText = this.getI18nText(
"WorkOrderDetails-InspectionRoundsPopover-MeasurementPointExceedsThresholdShortText");
newNotificationModel.getData().longText = longText;
}
// Create each measurement
var pendingChanges = this.getView().getModel().getPendingChanges();
var aPendingChanges = $.map(pendingChanges, function (value, index) {
return [index];
});
const found = aPendingChanges.findIndex(function (pendingChange) {
return pendingChange.toString().startsWith("MeasurementPointsSet");
});
if (found > -1) {
sap.m.MessageBox.show(this.getI18nText("WorkOrderDetails-InspectionsBlock-SaveMeasurementMessage"), {
icon: sap.m.MessageBox.Icon.None,
title: this.getI18nText("WorkOrderDetails-InspectionsBlock-SaveMeasurementTitle"),
actions: [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],
defaultAction: sap.m.MessageBox.Action.NO,
onClose: function (oAction, object) {
if (oAction === sap.m.MessageBox.Action.YES) {
aPendingChanges.forEach(function (pendingChange) {
if (pendingChange.toString().startsWith("MeasurementPointsSet")) {
var point = this.getView().getModel().getProperty("/" + pendingChange.toString());
if (point.Value || point.ValuationCode) {
var data = {
properties: {
Measpoint: point.Measpoint,
ReadingDate: new Date(),
RecordedValue: point.Value,
LongText: point.LongText,
Orderid: point.Orderid,
Fullname: this.getView().getModel("appInfoModel").getData().UserFullName,
ValuationCode: point.ValuationCode,
CodeGroup: point.CodeGroup,
CodeCatalogue: point.CatalogType
}
};
// Create measurement doc
this.getView().getModel().resetChanges(["/" + pendingChange.toString()]);
this.getView().getModel().createEntry("/MeasurementDocsSet", data);
// Set last reading and read by on meas point
if (point.Value) {
this.getView().getModel().setProperty("/" + pendingChange.toString() + "/LastReading", point.Value);
} else {
this.getView().getModel().setProperty("/" + pendingChange.toString() + "/LastReading", point.ValuationCode);
}
this.getView().getModel().setProperty("/" + pendingChange.toString() + "/LastReadingBy", this.getView().getModel(
"appInfoModel").getData()
.UserFullName);
}
}
}.bind(this));
this.getView().getModel().submitChanges({
success: function () {
this.closeMeasurementErrorDialog();
this.onMeasuringPointsPopoverClose();
this.getRouter().navTo("notificationCreate", false);
}.bind(this)
});
} else {
aPendingChanges.forEach(function (pendingChange) {
if (pendingChange.toString().startsWith("MeasurementPointsSet")) {
var point = this.getView().getModel().getProperty("/" + pendingChange.toString());
// Create measurement doc
this.getView().getModel().resetChanges(["/" + pendingChange.toString()]);
}
}.bind(this));
this.closeMeasurementErrorDialog();
this.onMeasuringPointsPopoverClose();
this.getRouter().navTo("notificationCreate", false);
}
}.bind(this)
});
} else {
this.closeMeasurementErrorDialog();
this.onMeasuringPointsPopoverClose();
this.getRouter().navTo("notificationCreate", false);
}
},
onOperationItemPress: function (oEvent) {
var oBindingContext = oEvent.getSource().getBindingContext();
var data = {
"block": "operation",
"operationContext": oBindingContext.getPath().substr(1),
"editable": this.getView().getModel("EditModeModel").getData().EditMode
};
this.gotoOperationDetailsPage(data);
},
showDifferenceReading: function (counter, codeGroups) {
return counter == "X" && (codeGroups === undefined || codeGroups.length < 1);
},
isCounterVisible: function (counter) {
return !!counter;
},
onDifferenceLiveChange: function (oEvent) {
var counterValueControl = sap.ui.core.Fragment.byId(view.getId(), 'readingCounterInput');
var value = oEvent.getParameter("value");
if (value.length > 0) {
counterValueControl.setEnabled(false);
} else {
counterValueControl.setEnabled(true);
}
},
onCounterLiveChange: function (oEvent) {
var differenceValueControl = sap.ui.core.Fragment.byId(view.getId(), 'differenceValueInput');
var value = oEvent.getParameter("value");
if (value.length > 0) {
differenceValueControl.setEnabled(false);
} else {
differenceValueControl.setEnabled(true);
}
},
checkForErrors: function () {
var measPoints = this.getView().byId("measuringPointsTable").getItems();
var measObjects = measPoints.map(function (measure) {
return this.getView().getModel().getProperty(measure.getBindingContextPath());
}.bind(this));
var errors = [];
var warnings = [];
this.hasEmptyField = false;
for (var i = 0; i < measObjects.length; i++) {
var point = measObjects[i];
if ((point.ValuationCode && point.ValuationCode !== "") || (point.Value && point.Value !== "")) {
if (point.Value && point.MeasurementDifference) {
errors.push(point);
}
if (point.Counter === "X" && parseInt(point.Value, 10) < parseInt(point.LastReading, 10)) {
errors.push(point);
}
if (point.ValueMinLimit && parseInt(point.Value, 10) < parseInt(point.MinLimit, 10)) {
warnings.push(point);
}
if (point.ValueMaxLimit && parseInt(point.Value, 10) > parseInt(point.MaxLimit, 10)) {
warnings.push(point);
}
} else {
this.hasEmptyField = true;
}
}
return {
errors: errors,
warnings: warnings
};
}
});
});Editor is loading...
Leave a Comment