Skip to Content
0
Former Member
Sep 23, 2014 at 07:57 PM

How to avoid spagetti code? - handlers

29 Views

Hi,

because we have to use that ugly language called javascript for SAPUI5 dev. ( I hope typescript or dart will be used in future, because productivity in that language from hell is cca 10% against normal languages - almost no IDE support, have to memorize every method....), I want to write code as much understandable for me.

Now I want to rewrite this:

 var oSelectDialog = new sap.m.SelectDialog({
  title: "Plant Selection",
  noDataText: "No Plant Information Found",
  confirm: function(oEvent) {
     jQuery.sap.require("sap.m.MessageToast");
     var aContexts = oEvent.getParameter("selectedContexts");
     if (aContexts.length) {
       sap.m.MessageToast.show("You have chosen " + aContexts.map(function(oContext) { return oContext.getObject().Name; }).join(", "));
     }
     oEvent.getSource().getBinding("items").filter([]);
   },
  });

to something like this:

 var oSelectDialog = new sap.m.SelectDialog({
  title: "Plant Selection",
  noDataText: "No Plant Information Found",
  confirm : this.handleconfirm(oEvent)
  });

So I will be able to write code for handle confirm event somewhere else than in initialization of SelectDialog.

Many thanks for any solution...