I have very simple view index.xml
<Alloy>
<Window id="byFav">
<TableView id="tableByFav" />
</Window>
<Alloy>
in this program I want to open webView and use this instead of tableByFav View
when you click tableByFav.
I am not sure how to describe this process in xml.
So I write code in index.js like this.
$.tableByFav.addEventlistener('click',function(e){
entryWindow = Titanium.UI.createWindow({
title: "window"
});
entryView = Titanium.UI.createWebView({
url: "google.com"
});
entryWindow.add( entryView );
$.byFav.open( entryWindow );
}
However I am not sure it is obeying the concept of alloy.
I am trying to understand the concept of alloy.
You are opening the wrong window, try this instead:
$.tableByFav.addEventlistener('click',function(e){
var entryWindow = Titanium.UI.createWindow({
title: "window"
});
var entryView = Titanium.UI.createWebView({
url: "http://www.google.com"
});
entryWindow.add( entryView );
// Call open on the entry window itself
entryWindow.open({
modal : true // Set to true if you want an opening animation
});
}
To do this with Alloy, you can create a controller for the webview named (entryWindow.xml) like this:
<Alloy>
<Window id="entryWindow">
<WebView id="entryView" />
</Window>
<Alloy>
And the in controller (entryWindow.js) you can set the url from the supplied arguments:
$.entryView.url = arguments[0].url;
Now in your index controller, you would open the webview like this:
$.tableByFav.addEventlistener('click',function(e){
// Create a controller, pass url argument
var controller = Alloy.createController('entryWindow', {url: "http://www.google.com"});
// Get the controller's view (a window) and open it
controller.getView().open({
modal : true // Set to true if you want an opening animation
});
}
Related
I have following code (index.js) :
<Alloy>
<Window id="home" >
<View id="formulaire">
<Require type="view" id="etape_1_form" src="form/etape_1" />
</View>
</Window>
</Alloy>
On etape_1_form.xml i have to use a picker widget from : danielhanold.pickerwidget
here is a simple method to use this widget inside etape_1_form.js (the controller) :
Alloy.createWidget('danielhanold.pickerWidget', {
id: 'mySingleColumn',
outerView: $.home,
hideNavBar: false,
type: 'single-column',
selectedValues: [20],
pickerValues: [{10: 'Auburn', 20: 'Bald', 30: 'Black', 40: 'Blond', 50: 'Brown'}],
onDone: function(e) {
// Do something
},
});
$.form_win.open();
Now instead of opening a picker, this throw an error because i cannot access the current window from this line :
outerView: $.home
The error : "undefined is not an object (evaluating 'outerView.add')
When i move the picker to the index.js (main controller) the picker works, but i have many required forms and want to organise my code, so i like put each form js code inside it's controller file.
So how i can access $.home window from required view? thank you for your help.
No, you can't directly.
But you can easily avoid this using "globals".
On index.js:
Alloy.Globals.indexController = $;
On etape_1_form.js
outerView: Alloy.Globals.indexController.home
I'm creating a custom menu with background images, styling, etc. so I created a separate menuTile view and controller and send it the background, title, and callback. If I add multiple menuTiles using the Require tag, all tiles fire the callback of the last menuTile instead of their own individual one. I'm confident there is no bug/typo in my code so maybe it's a misunderstanding of the Require tag or callbacks. Please assist.
Menu.xml, Menu.js...
<View id="vwBody">
<Require src="menuTile" id="menuTile1" />
<Require src="menuTile" id="menuTile2" />
<Require src="menuTile" id="menuTile3" />
</View>
function initializeMenuTiles() {
$.menuTile1.initialize({
backgroundImage: 'img1.jpg',
title: 'Menu Tile 1',
callback: btnMenuTile1Click,
});
$.menuTile2.initialize({
backgroundImage: 'img2.jpg',
title: 'Menu Tile 2',
callback: btnMenuTile2Click,
});
$.menuTile3.initialize({
backgroundImage: 'img3.jpg',
title: 'Menu Tile 3',
callback: btnMenuTile3Click,
});
}
MenuTile.js...
$.initialize = function(args) {
$.btnMenuTile.backgroundImage = '/images/' + args.backgroundImage;
$.btnMenuTileLabel.text = args.title;
if (args.callback) {
btnMenuTileClicked_callback = args.callback;
}
};
function btnMenuTileClick() {
if (btnMenuTileClicked_callback) {
btnMenuTileClicked_callback();
}
}
So no matter what menuTile I click, btnMenuTile3Click will always fire. If I don't provide a callback for menuTile3, then btnMenuTile2Click will always fire.
I don't see where you define btnMenuTileClicked_callback so it will then be in the module's global scope, which is shared between all instances.
Simply add this before the $.initialize... line:
var btnMenuTileClicked_callback;
I want to to send data from one window to another.
Example:
I have a text field and a button on first window. When click on window I need to send text field value to the second window?
I found a tutorial, but it's not in MVC.
I have created a new alloy controller (left click in your project and then new) and here is how i am passing parameters to the next view.
The new controller is called CallBack and the first controller is called index.
In CallBack.xml i have:
<Alloy>
<View class="container">
</View>
</Alloy>
In CallBack.tss i have:
".container": {
backgroundColor: "black"
}
In CallBack.js i have:
var args = arguments[0] || {};
//here you can do whatever you want to your parameter, i just show the value.
alert(args.textField);
And finally in index.js this is how i am passing the parameters of my textField:
//with a button i can open a new view in my current window
$.btnNext.addEventListener('click',function(e){
//tfInsert is the id of my textfield in index.xml file and with .value i can access to whatever it contains
//the "?" operator is like an if
var textField = $.tfInsert.value != "" ? textField = $.tfInsert.value : textField = "Hello";
var nextView = Alloy.createController('/CallBack', {
textField: textField
}).getView();
//this is how i add a new view to my current window
$.window.add(nextView);
});
Hope this helps.
In controller.js (from where we are passing Data)
function createController(win)
{
//title is the data to pass
var platform = Ti.Platform.osname;
var calledWindow = require('/ui/' + platform + '/addProductWindow').createCalledWindow(title);
calledWindow.open();
};
In calledWindowController.js
function createController(win){
//Do whatever control you want
};
In calledWindow.js
exports.createCalledWindow = function(title)
{
//Do whatever UI you want
Ti.include('/Controllers/calledWindowController.js');
var controller = createController(win);
return win;
};
i developing sample android application in Titanium. on home window(app.js) it has some buttons ,now what i want is on the click of each button app.js(home window) must call another javascript file (they will create new window of their own.
but.addEventListener('click', function(e){
call another .js file which will open new window
})
will appreciate some guidance
that's not so hard. Incl. params.
First create your other .js file and create a function as follows.
Another .js File:
exports.createNewWindow(params) {
var window = Ti.UI.createWindow ({
// ... Your stuff with your params
});
return window;
}
Than you can call this function as follows:
First .js File
var window = require("pathToYouAnotherFile.js").createNewWindow({title:"xyz"});
window.open();
If you want you can call the window.open() in the "another.js" file.
Have fun.
You should learn Alloy. It will help you properly structure your app, as you have asked.
http://projects.appcelerator.com/alloy/docs/Alloy-bootstrap/index.html
I handled this by raising an event from one JS file to another. Take a look at Ti.App.fireEvent('event',data) to fire the event and Ti.App.addEventListener to receive the event.
but.addEventListener('click', function(e){
var newwin=Ti.UI.createWindow({url:'another.js'});
newwin.open();
});
Its a simple event handler in which we are creating and opening a windows and opening after that.Url is the file to the desired window.
Simple.Cheers!!
var All = require('ui/common/All');
Tree = require('ui/common/Tree');
EBOM = require('ui/common/E-BOM');
MBOM = require('ui/common/M-BOM');
SBOM = require('ui/common/S-BOM');
//create object instance
var self = Ti.UI.createWindow({
title:'Products',
exitOnClose:true,
navBarHidden:true,
backgroundColor:'#ffffff',
/////////////////////////////////////////////////////////////////////////////
activity: {
onCreateOptionsMenu: function(e) {
var menu = e.menu;
var menuItem = menu.add({ title: "C-BOM", icon: 'Arrow-Hover.jpg' });
//menuItem.setIcon("Arrow-Hover.jpg");
menuItem.addEventListener("click", function(e) {
var all = new All();
self.add(all);
});
......................
.....................
..........................
I have a ContentPane defined as follows:
<div id="searchResultsContentPane" data-dojo-type="dijit.layout.ContentPane" data-dojo-props='splitter:false, region:"center"'></div>
I am trying to dynamically set the href when a button in another ContentPane is pressed:
var searchResultsContentPane = dijit.byId("searchResultsContentPane");
searchResultsContentPane.set("href", "modules/content_panes/callrecords.php");
For some reason this doesn't seem to be working. The content pane flashes loading then goes back to white and FireBug doesn't give me usable info. This is all it shows:
If you cant read that it says in red:
GET http://cdr.homelinux.net:10001/Mike/modules/content_panes/callrecords.php
callrecords.php loads just fine if I set it with html as a data-dojo-props property.
Thanks
Page was refreshing. Used the following code to properly load the content pane.
function sendSearchForm() {
// format taken from http://dojotoolkit.org/reference-guide/1.7/dojo/xhrPost.html
var form = dojo.byId("search_form");
dojo.connect(form, "onsubmit", function(event) {
dojo.stopEvent(event);
var xhrArgs = {
form: dojo.byId("search_form"),
handleAs: "text",
load: function(data){
loadAdvancedSearchResultsTable();
//var searchResultsContentPane = dijit.byId("searchResultsContentPane");
//searchResultsContentPane.set("href", "modules/content_panes/test_module.html");
},
error: function(error){
// TODO Handle errors
}
}
// Call the asynchronous xhrPost
//dojo.byId("response").innerHTML = "Form being sent..."
var deferred = dojo.xhrPost(xhrArgs);
});
}
dojo.ready(sendSearchForm);