4

I'm working on a TideSDK project and I want to create a configuration settings window for my application, but I haven't seen any documentation on how to do anything like that on the website or any of the accompanying documentation.

I'm familiar with web development and in a browser I would use a target=new (or something like that) to flag that I want the url to open in a new window, but I haven't seen anything like that in tide.

I've also tried to use the tide dialog functions, but it looks like the windows will only pertain to html files that are located within the applications directory (meaning it won't be built in or packaged with the application).

Is this functionality available in tidsdk, or will I have to find an alternate way to make a settings/configuration window?

mikeyGlitz
  • 423
  • 3
  • 13
  • I'm not sure exactly what your problem is... you can just create a html document for your settings window (in the Resource directory), and then create a new window with it: `Ti.UI.createWindow("app://settings.html");`. – Alex Feb 10 '13 at 23:14

1 Answers1

5

I looked into the dialog functions, and found a way to do exactly what you want! The API documentation isn't very clear about this, I had to try around...

Example code

In the main window:

//Example function to apply configuration
function applyConfig(configObject){
    setSomething(configObject.field);
    ...
}
//Create a dialog, and give it the above function as an `onclose` callback:
var dialog=Ti.UI.showDialog({url:"app://config.html",onclose:applyConfig});

In config.html:

//An example of an object that could hold your config data
var config={field:0,example:"hello",...};
//Function to call in order to pass that object back to the main window callback:
Ti.UI.getCurrentWindow().close(config);

Explanation

So... In your main window, you create a dialog window with Ti.UI.showDialog and pass it a callback (params.onclose, see above). In the dialog window, once the user has set his configuration options through the html interface, you can just save the configuration data in an object, and pass it to the window's close method, and it will be passed to the callback in the main window.

Notes

Ti.UI.showDialog actually calls Ti.UI.createWindow, and returns a Ti.UI.UserWindow object, with some added fields and methods related to the dialog's parameters, result, and onclose callback.

Dialog parameters passed with Ti.UI.showDialog({url:"...",parameters:{...}}) can be accessed from inside the dialog window using Ti.UI.getCurrentWindow().getDialogParameter("name") or Ti.UI.getCurrentWindow()._dialogParameters["name"].

Alex
  • 1,157
  • 3
  • 11
  • 25
  • Might want to know that if you open the dialog, make sure you are aware that any scripts you include will be run all over again, say your application.js. – Automatico Mar 07 '14 at 00:01