/**
*@ Value changed for a field. add Inspector ID to array, so we can update all together in SaveAll method.
*/
onFieldValueChange: function(oControlEvent) {
//This code was generated by the layout editor.
var oSelectedItem = oControlEvent.getSource();
var obj = oControlEvent.getSource().getBindingContext().getObject();
//Add Change Inspector to Array
gChangedInspsArr.push(obj.InspId);
},
/**
* Handle Save All Button Event
* Check which records have been changed, and update the Model in batch
* @public
*/
onSaveAll: function() {
var oTable = this.byId("Table");
var oModel = this.getOwnerComponent().getModel();
var oTable = that.getView().byId("Table");
var a = 0;
//Loop through entire table, and add changed records in
oTable.getItems().forEach(function(row) {
var oEntry = {};
var obj = row.getBindingContext().getObject();
if (gChangedInspsArr.indexOf(obj.InspId) > -1) { //If record was changed
var cells = row.getCells();
oEntry.Id = cells[0].getTitle();
oEntry.FieldOne = cells[1].getSelected();
oEntry.FieldTwo = cells[2].getValue();
oEntry.FieldThree = cells[3].getValue();
oModel.update("/ZTABLEENTITY_Set('" + oEntry.Id + "')", oEntry, {
groupId: "updateRecsGrpId",
changeSetId: "InspChangeID"
});
}
});
oModel.submitChanges({
groupId: "updateRecsGrpId",
success: function(oData, oResponse) {
gChangedInspsArr = [];
sap.m.MessageToast.show("Records Updated");
},
error: function(oError) {
sap.m.MessageToast.show("Record Not Updated. Please check with Admin.");
}
});
},
/**
* Event handler for getting 'Add' Dialog started
* @public
*/
handleOpenDialog: function(evt) {
this.getDialogAdd().open(); // get the reference of input fields of fragment and set the values
},
/**
* Event handler for getting 'Add' Dialog started
* @public
*/
getDialogAdd: function() {
if (!this.dialog) {
// This fragment can be instantiated from a controller as follows:
this.dialog = sap.ui.xmlfragment("fragPopupDialog", "Z_UPDATE_TABLE.view.DialogAdd", this);
}
return this.dialog;
},
<core:FragmentDefinition xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:f="sap.ui.layout.form" xmlns:core="sap.ui.core">
<Dialog title="Add Data">
<l:Grid defaultSpan="L12 M12 S12" width="auto" id="idGrid">
<l:content>
<f:SimpleForm id="formAdd" minWidth="1024" maxContainerCols="2" editable="false" layout="ResponsiveGridLayout" title="Data" labelSpanL="3" labelSpanM="3" emptySpanL="4" emptySpanM="4" columnsL="2" columnsM="2">
<f:content>
<Label text="ID"/>
<Input id="i_INSP_ID" type="Number" maxLength="8" editable="true" required="true" showValueHelp="true" valueHelpRequest="handleInspValueHelp"/>
<CheckBox id="i_ COUNT_EXCLUDE" name="WRM_COUNT_EXCLUDE" text="Exclude "/>
<Label text="Field One"/>
<Input id=" i_ FIELD_2" type="Number" maxLength="10"/>
<Label text="Field Two"/>
<Input id=" i_ FIELD_2" type="Number" maxLength="10"/>
<Label text="Field Three"/>
<Input id=" i_ FIELD_3" type="Number" maxLength="10"/>
<Label text="Field Four"/>
<Input id=" i_ FIELD_4" type="Number" maxLength="10"/>
<Label text="Field Five"/>
<Input id=" i_ FIELD_5" type="Number" maxLength="10"/>
<Label text="Description"/>
<Input id="i_DESCRIPTION" maxLength="254"/>
</f:content>
</f:SimpleForm>
</l:content>
</l:Grid>
<buttons>
<Button text="CLOSE" press="closeDialog" type="Reject"/>
<Button text="SAVE" press="onAdd" type="Accept"/>
</buttons>
</Dialog>
</core:FragmentDefinition>
/**
* Handle Save event for New Inspector
* @public
*/
onAdd: function() {
//Start prepairing input Entry
var oEntry = {};
var content = sap.ui.getCore().byId("fragPopupDialog--formAdd").getContent();
oEntry.InspId = sap.ui.getCore().byId("fragPopupDialog--i_INSP_ID").getValue();
//TODO: get values of each field here…
//Get Model
var oModel = this.getOwnerComponent().getModel();
oModel.create("/ZCFG_ENTITYSet", oEntry, {
success: function(oData, oResponse) {
sap.m.MessageToast.show("Record Created");
oModel.updateBindings();
},
error: function(oError) {
sap.m.MessageToast.show(sap.ui.getCore().getMessageManager().getMessageModel().oData[0].message);
oModel.refresh();
}
});
this.closeDialog();
},
<Table id="inspTable" width="auto" items="{ path: '/ZCFG_ENTITYSet', sorter: { path: 'InspId', descending: false } }" delete="onDeletePress" mode="Delete">
/**
* Handle Inspector Delete Event
* Popupp Confirmation
* @public
*/
onDeletePress: function(oEvent) {
//This code was generated by the layout editor.
var oSelectedItem = oEvent.getParameter("listItem");
var sItemName = oSelectedItem.getBindingContext().getProperty("InspId");
gDeleteInspId = sItemName;
sap.ui.commons.MessageBox.confirm("Remove Record for Inspector:" + sItemName + "'?", this.doDelete);
},
This method actually performs the Deletion:
* Perform Deletion of Record
* @public
*/
doDelete: function(sResult) {
if (sResult === true) {
var oModel = that.getOwnerComponent().getModel();
oModel.remove("/ZCFG_ENTITYSet('" + gDeleteInspId + "')", {
success: function(oData, oResponse) {
gDeleteInspId = '';
sap.m.MessageToast.show("Record Deleted...");
oModel.updateBindings();
},
error: function(oError) {
gDeleteInspId = '';
sap.m.MessageToast.show("Record Not Deleted. Please check with Admin.");
oModel.refresh();
}
});
}
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
5 | |
5 | |
5 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 |