cancel
Showing results for 
Search instead for 
Did you mean: 

How to avoid spagetti code? - handlers

Former Member
0 Kudos

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...

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Got it:


   var oSelectDialog = new sap.m.SelectDialog({

  title: "Plant Selection",

  noDataText: "No Plant Information Found",

  confirm: [this.handleClosePlantDialog, this]

 

  });

Answers (1)

Answers (1)

former_member189945
Contributor
0 Kudos

Hi Jiri,

You can pass functions as any other variable. So handler can be defined like this:


var oSelectDialog = new sap.m.SelectDialog({ 

      title: "Plant Selection", 

      noDataText: "No Plant Information Found", 

      confirm : this.handleconfirm 

});

function handleconfirm(oEvent) {

}

Regards,

Kimmo