initEmpModel : function (){
this._oEmpModel = new sap.ui.model.json.JSONModel();
this._oEmpModel.setData({
columns : ["Empcd","Cnum"],
rows : new Array()
});
const oSchema = this.getView().getModel().getServiceMetadata()
.dataServices.schema.find(
e => e.namespace == "Z_GW_CERTEMP_SRV");
const oProperty = oSchema.entityType.find(
e => e.name == "ZEMPCERT").property;
const oTable = this.byId("idEmpTable");
oTable.setModel(this._oEmpModel);
oTable.bindColumns("/columns", function(sId, oContext){
const sColumnName = oContext.getObject();
return new sap.ui.table.Column({
label : oProperty.find(e => e.name == sColumnName)
.extensions.find(e => e.name == "label").value,
template : sColumnName
});
});
oTable.bindRows("/rows");
this.byId("idEmpSmartForm").bindElement(this.getView().getModel()
.createEntry("ZEMPCERTSet").getPath());
},
onTableEmpCellClick : function(oEvent){
if(this.getView().getModel("viewConfig").getProperty("/isEdit") == false)
return;
this._iEmpModelIndex = oEvent.mParameters.rowIndex;
const oEntry = this._oEmpModel.oData.rows[this._iEmpModelIndex];
const sPath = this.byId("idEmpSmartForm").getBindingContext().getPath();
const oModel = this.getView().getModel();
$.each(Object.keys(oEntry), function(){
if(this == "__metadata")
return;
oModel.setProperty(sPath + "/" + this, oEntry[this]);
});
this.byId("idDialog").open();
},
onSaveButtonEmpPress : function(){
const oEmp = this.byId("idEmpSmartForm");
if(oEmp.check().length > 0)
return;
const oEmpInfo = oEmp.getBindingContext().getObject();
if(this._iEmpModelIndex == -1)
this._oEmpModel.oData.rows.push(oEmpInfo);
else{
this._oEmpModel.oData.rows[this._iEmpModelIndex] = oEmpInfo;
this._iEmpModelIndex = -1;
}
this._oEmpModel.refresh();
this.byId("idEmpTable").clearSelection();
this.onCancelButtonEmpPress();
},
onDialogBeforeClose : function(){
const oEmpForm = this.byId("idEmpSmartForm");
oEmpForm.unbindElement();
oEmpForm.bindElement(this.getView().getModel()
.createEntry("ZEMPCERTSet").getPath());
},
onCancelButtonEmpPress : function(){
this.byId("idDialog").close();
},
onAddButtonPress : function(){
this.byId("idDialog").open();
},
onDelButtonPress : function(){
const oTable = this.byId("idEmpTable");
const aSelectedIndices = oTable.getSelectedIndices();
const aTempArray = new Array();
$.each(this._oEmpModel.oData.rows, function(idx, row){
if(aSelectedIndices.indexOf(idx) > -1)
return;
aTempArray.push(row);
});
this._oEmpModel.oData.rows = aTempArray;
this._oEmpModel.refresh();
oTable.clearSelection();
},
onSaveButtonPress : function(oEvent, sUpdkz){
const oCertForm = this.byId("SF1");
if(oCertForm.check().length > 0)
return;
const oDeepEntity = oCertForm.getBindingContext().getObject();
oDeepEntity.Updkz = sUpdkz;
oDeepEntity.CertInfoToEmpcert = this._oEmpModel.oData.rows;
this.getView().getModel().create("/ZCERTINFOSet", oDeepEntity, {
success : function(oData, oResponse){
MessageToast.show("저장 성공적으로 저장되었습니다.");
this.getRouter().navTo("RouteListView");
}.bind(this),
error : function(oError){
var oMsg = JSON.parse(oError.responseText);
MessageBox.error(oMsg.error.message.value);
}
});
}