Skip to Content
0

Open function at start app

Mar 05 at 02:20 PM

50

avatar image

Hello community, i have a question how can i open a dialog in the moment that i open my app? i have a view with a table and a button, that button opens a dialog

		oDialog : function () {
	         var oView = this.getView();
	         var oDialog = oView.byId("userDialog");
	         // create dialog lazily
	         if (!oDialog) {
	            // create dialog via fragment factory
	            oDialog = sap.ui.xmlfragment(oView.getId(), "Calendario.app.view.Popup_usuario", this);
	            oView.addDependent(oDialog);
	         }

	  oDialog.open(); // Abrimos el dialogo
	      },
		onCloseDialog : function () {
		this.getView().byId("userDialog").close();
		}

so i want to open this dialog with the button and in the moment that my app is opened (i thought to play with the cicle of life of my app especificly in my component but i don't know if this is possible and how), the other part if you have any idea is can i send data from this dialog to an odata the flow of the program it's like i open my app , a dialog is't opened, i introduce an user , consume an odata filtering with that id and show the results in the table

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Nicholas Owen O’Malley Mar 06 at 06:37 AM
1

In the controller you can add a onInit function. That will whatever inside it. Then you can cal oDialog like this

onInit: function(){ 
    this.oDialog();
}


if you want to pas data from one controller to another you can use the router or the eventBuss

On the receiver side:

var eventBus = sap.ui.getCore().getEventBus();  
eventBus.subscribe("someTasks", "dataSuccess", this.functionName, this);

On the sender side


sap.ui.getCore().getEventBus().publish("someTasks", "dataSuccess", oData);
Show 6 Share
10 |10000 characters needed characters left characters exceeded

Thanks! Nicholas Owen O’Malley i thought that i need to do something else and i din't try the oninit function :D do you have any example for calling an odata after passing a parameter with a dialog

0

How are you passing the parameter? Are you in the same controller?

0
Nicholas Owen O’Malley

i'm searching how to, yes it's same controller. this is how i want my app works, open app> appears a dialog, you put an user > should call the odata and searh with that user passed > return the data to a table > the dialog is closed , if you want a new search there's a botton to open the dialog but i don't know hoy to pass the parameter to the odata

0

Hello Naoto Amari

In the same controller it is not to much work :)

Controller:

onInit: function(){
    this.getView().byId('dialog').open();
},
getText: function(){
	//Get the text
	var text = this.getView().byId("input").getValue();
	//Do something with the text
	console.log(text);
        //Make a request
        this.makeRequest(text).then(function(oData){
            console.log(oData)
        });
	//Close
	this.getView().byId('dialog').close();
},
closeDialog: function(){
	this.getView().byId('dialog').close();
},
makeRequest: function(sText){
return new Promise(function(resolve, reject) {
    var oModel = new sap.ui.model.odata.ODataModel({
	serviceUrl: "/sap/opu/odata/sap/SERVICE_NAME",
        json: true
    });
    var sPath = "/ENDPOINT?filter=search eq " + sText;
    oModel.read(sPath, null, null, true
       function(oData) {
	  resolve(oData);
       },
       function(oError) {
	  reject(oError);
	});
});
}

Dialog:

<Dialog id="dialog" title="Dialog">
	<content>
	    <Input id="input" type="Text" />
	</content>
	<beginButton>
		<Button type="Accept" text="OK" press="getText"/>
	</beginButton>
	<endButton>
		<Button text="Close" press="closeDialog"/>
	</endButton>
</Dialog>
1

really thanks! do you have a repository so i could check ? :D when i grow i want to be like you xD

this is very helpful can you explain a little more this and the model that i'm going to use in my table to show data will be oModel ???:

makeRequest: function(sText){
return new Promise(function(resolve, reject) {
    var oModel = new sap.ui.model.odata.ODataModel({
serviceUrl: "/sap/opu/odata/sap/SERVICE_NAME",
        json: true
    });
    var sPath = "/ENDPOINT?filter=search eq " + sText;
    oModel.read(sPath, null, null, true
       function(oData) {
  resolve(oData);
       },
       function(oError) {
  reject(oError);
});
});
0

Thank you Naoto Amari that is nice to hear :). Most of what i code is in private repos :'( But this is my github: https://github.com/aiopa

the result from makeRequest will contain a oData object. So in the function getText

this.makeRequest(text).then(function(oData){
   var someModel = new sap.ui.model.json.JSONModel();
   someModel.setData(oData);
this.getView().setModel(someModel, "modelName");
});

Then you can use modelName

1