lib/ui5/controller/Cultivar_Create.controller.js in fiveapples-0.0.5 vs lib/ui5/controller/Cultivar_Create.controller.js in fiveapples-0.0.6
- old
+ new
@@ -1,110 +1,55 @@
sap.ui.define(
[
"sap/ui/core/mvc/Controller",
"sap/m/MessageToast",
- "sap/ui/core/routing/History"
+ "./Detail",
+ "./Breeder",
+ "./Create"
],
- function(Controller, MessageToast, History) {
+ function(Controller, MessageToast, Detail, Breeder, Create) {
"use strict";
return Controller.extend("fivea.controller.Cultivar_Create", {
onInit: function() {
- var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
- this._oRouter = oRouter;
-
+ this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);
+ this._oRouter
+ .getRoute("cultivar_create")
+ .attachPatternMatched(this.createEntry, this);
+ },
+ createEntry: function(){
var oView = this.getView();
var oModel = this.getOwnerComponent().getModel();
var oContext = oModel.createEntry("/cultivar", {});
oView.setModel(oModel);
- oView.setBindingContext(oContext);
+ oView.setBindingContext(oContext);
},
-
- onCreatePress: function() {
+ onCreatePress: function() {
+ Create.onPress(this);
+ },
+ navToDetail: function(oData){
+ // navigate to detail page but dont keep create
+ // page history (hist. replace)
- var oModel = this.getView().getModel();
- var _oRouter = this._oRouter;
-
-
- 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;
-
- oModel.submitChanges(mParms);
-
-
+ this._oRouter.navTo("cultivar_detail", { id: oData.id }, {}, true);
},
-
+ navToList: function(){
+ this._oRouter.navTo("cultivarList", true);
+ },
onNavBack: function() {
- var oHistory = History.getInstance();
- var sPreviousHash = oHistory.getPreviousHash();
-
- if (sPreviousHash !== undefined) {
- window.history.go(-1);
- } else {
- this._oRouter.navTo("cultivarList", true);
- }
+ Detail.onNavBack(this);
},
-
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
- );
-
- this.getView().addDependent(this._valueHelpDialog);
- }
-
- this._valueHelpDialog.open("");
+ Breeder.onIdValueHelp(this, oEvent);
},
_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]);
+ Breeder._handleValueHelpSearch(evt);
},
_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([]);
+ Breeder._handleValueHelpClose(this, evt);
}
});
}
);