lib/ui5/controller/Cultivar_Create.controller.js in fiveapples-0.0.4 vs lib/ui5/controller/Cultivar_Create.controller.js in fiveapples-0.0.5

- old
+ new

@@ -1,99 +1,110 @@ -sap.ui.define([ - "sap/ui/core/mvc/Controller", +sap.ui.define( + [ + "sap/ui/core/mvc/Controller", "sap/m/MessageToast", - "sap/ui/core/routing/History" -], function (Controller, MessageToast, History) { - "use strict"; - return Controller.extend("vibert.controller.Cultivar_Create", { - onInit: function () { + "sap/ui/core/routing/History" + ], + function(Controller, MessageToast, History) { + "use strict"; + return Controller.extend("fivea.controller.Cultivar_Create", { + onInit: function() { + var oRouter = sap.ui.core.UIComponent.getRouterFor(this); + this._oRouter = oRouter; + + var oView = this.getView(); + var oModel = this.getOwnerComponent().getModel(); + var oContext = oModel.createEntry("/cultivar", {}); + oView.setModel(oModel); + oView.setBindingContext(oContext); + }, - var oRouter = sap.ui.core.UIComponent.getRouterFor(this); - this._oRouter = oRouter; - }, + onCreatePress: function() { + + var oModel = this.getView().getModel(); + var _oRouter = this._oRouter; - onCreatePress: function() { + + function onSuccessHandler(data) { + MessageToast.show("Create success"); + // TODO: isnt this data access OData version dependant? + // OneWay is simply + // var new_entity_tab = data + + // The TwoWay way. No this is not ridiculous. You tell me the better way ? + var new_entity_tab = data["__batchResponses"]["0"].__changeResponses["0"].data; + _oRouter.navTo("cultivar_detail", { id: new_entity_tab["results"][0].id }); + } + function onErrorHandler() { + MessageToast.show("Create failed"); + } + var mParms = {}; + + mParms.success = onSuccessHandler; + mParms.error = onErrorHandler; - var myForm = sap.ui.getCore().byId("cultivar_create_form"); - var sObjectPath = "/cultivar" ; - var oView = this.getView() ; - var oModel = oView.getModel(); + oModel.submitChanges(mParms); + - var oEntry = {}; + }, - oEntry.name = this.byId('name').getValue(); - oEntry.year = this.byId('year').getValue(); - oEntry.breeder_id = this.byId('breeder_id').getValue(); - var _that = this; + onNavBack: function() { + var oHistory = History.getInstance(); + var sPreviousHash = oHistory.getPreviousHash(); - function onSuccessHandler(data){ - oModel.refresh(); - _that.byId('name').setValue(""); - _that.byId('year').setValue(""); - _that.byId('breeder_id').setValue(""); - MessageToast.show("Create success"); - // TODO: isnt this data access OData version dependant? - _that._oRouter.navTo( "cultivar_detail", {id: data["results"]["0"].id} ); - } - function onErrorHandler(){ - MessageToast.show("Create failed"); } + if (sPreviousHash !== undefined) { + window.history.go(-1); + } else { + this._oRouter.navTo("cultivarList", true); + } + }, - oModel.create( sObjectPath, oEntry, - {success: onSuccessHandler, error: onErrorHandler } ); + inputId: "", + inputDescrId: "", - }, + onBreederIdValueHelp: function(oEvent) { + this.inputId = oEvent.getSource().getId(); + this.inputDescrId = this.inputId + "_descr"; + // create value help dialog + if (!this._valueHelpDialog) { + this._valueHelpDialog = sap.ui.xmlfragment( + "fivea.view.BreederOptio", + this + ); - onNavBack: function () { - var oHistory = History.getInstance(); - var sPreviousHash = oHistory.getPreviousHash(); + this.getView().addDependent(this._valueHelpDialog); + } - if (sPreviousHash !== undefined) { - window.history.go(-1); - } else { - this._oRouter.navTo("cultivarList", true); - } - }, + this._valueHelpDialog.open(""); + }, - inputId : "", - inputDescrId: "", + _handleValueHelpSearch: function(evt) { + var sValue = evt.getParameter("value"); + var oFilter = new Filter( + "name", + sap.ui.model.FilterOperator.Contains, + sValue + ); + evt + .getSource() + .getBinding("items") + .filter([oFilter]); + }, - onBreederIdValueHelp : function (oEvent) { + _handleValueHelpClose: function(evt) { + var oSelectedItem = evt.getParameter("selectedItem"); + if (oSelectedItem) { + var IDInput = this.getView().byId(this.inputId); + IDInput.setValue(oSelectedItem.getDescription()); - this.inputId = oEvent.getSource().getId(); - this.inputDescrId = this.inputId + "_descr"; - - // create value help dialog - if (!this._valueHelpDialog) { - this._valueHelpDialog = sap.ui.xmlfragment( - "vibert.view.BreederOptio", this ); - - this.getView().addDependent(this._valueHelpDialog); + var oText = this.getView().byId(this.inputDescrId); + oText.setText(oSelectedItem.getTitle()); + } + evt + .getSource() + .getBinding("items") + .filter([]); } - - this._valueHelpDialog.open( '' ); - }, - - _handleValueHelpSearch : function (evt) { - var sValue = evt.getParameter("value"); - var oFilter = new Filter( "name", - sap.ui.model.FilterOperator.Contains, sValue - ); - evt.getSource().getBinding("items").filter([oFilter]); - }, - - _handleValueHelpClose : function (evt) { - var oSelectedItem = evt.getParameter("selectedItem"); - if (oSelectedItem) { - var IDInput = this.getView().byId(this.inputId); - IDInput.setValue(oSelectedItem.getDescription()); - - var oText = this.getView().byId(this.inputDescrId); - oText.setText(oSelectedItem.getTitle()); - - } - evt.getSource().getBinding("items").filter([]); - - } - - }); -}); + }); + } +);