Titanium - How to close View that is defined in another .js file - titanium

I have one window defined in a FirstView.js and a View defined in Settings.js.
I add the Settings View to the FirstView Window doing this:
var Settings = require('ui/common/Settings');
var Settings = new Settings();
self.add(Settings);
And now, when users press "back" button i need to remove the Settings View from main window.
I know that i could do this with self.remove(Settings) if both codes were in the same .js file.
But, in this case, how can i remove the Settings View from the main FirstView Window?

try to use Application level events.
in Settings.js and when you click on back button
Ti.App.fireEvent("backSetting");
and in FirstView.js
Ti.App.addEventListener("backSetting",function(e){
self.remove(Setting);
};

why not use a container for settings?
e.g:
var FirstView=Ti.UI.createWindow();
var contentSetting=Ti.UI.createView({
height:Ti.UI.SIZE //or Ti.UI.FILL,
width:Ti.UI.SIZE //or Ti.UI.FILL
});
FirstView.add(contentSetting);
var Settings = require('ui/common/Settings');
var Settings = new Settings();
contentSetting.add(Settings);
FirstView.addEventListener('android:back', function(e){
//remove view
$.contentSetting.removeAllChildren();
});

Related

Can a dojo TabContainer be configured to switch by mouse over?

I'm using dojo toolkit dijit.layout.TabContainer to switch 3 tabbed pages.
Right now I click on tabs to switch them, but I want to switch them by mouse over instead.
Can a TabContainer be configured to switch by mouse over, or should I write a code to handle mouse over events to explicitly switch tabs?
I'd appreciate any suggestions!
-Sari
Yes. For this functionality, we need to add the onmouseover event to the tabs label fields. Add this code inside the dojo/ready (or addOnLoad) function.
require(["dojo/ready","dojo/query"], function(ready,query){
ready(function(){
var tabs = dijit.byId("TabContainerID");
query("#TabContainerID.dijitTabInner").onmouseover(function(evt){
var tablabelid = dijit.getEnclosingWidget(evt.target).id;
var currentId = dijit.byId("TabContainerID").selectedChildWidget;
var tabwidid = tablabelid.split("_").pop();
if(tabwidid && currentId!=tabwidid) {
tabs.selectChild(tabwidid);
}
});
});
});

dojo tabbar programatically created but not fixed at the right position

i created a dojo tabbar programmatically and set the fixed:"bottom" attribute but the tabbar is created below the existing document and not fixed at the bottom of the window. After i have done a performeTransition to another view its fixed at bottom correctly.
i did it like this:
function createTabbar() {
var tabBar = new dojox.mobile.TabBar({id:"tabContainer", barType : "tabBar", fixed: "bottom"}).placeAt(dijit.byId("mobileView"));
var tabBarButtonNodes = new dojox.mobile.TabBarButton({label:"Knoten", id:"tabBarButtonNodes", moveTo:"divNodes0", icon1 : "img/nodes_60.png", icon2 : "img/nodes_60.png"}).placeAt(tabBar.domNode);
var tabBarButtonInfo = new dojox.mobile.TabBarButton({label:"Info", id:"tabBarButtonInfo", moveTo:"divInfo", icon1 : "img/info_60.png", icon2 : "img/info_60.png"}).placeAt(tabBar.domNode);
var tabBarButtonLogin = new dojox.mobile.TabBarButton({label:"Login", id:"tabBarButtonLogin", moveTo:"divLogin", icon1 : "img/login_60.png", icon2 : "img/login_60.png"}).placeAt(tabBar.domNode);
var teest = dijit.byId("divInfo");
tabBar.resize();
}
do i have to resize anything else?
As documented, the "fixed" flag matters for dojox/mobile/ScrollableView only. There are two cases: a header/footer at the level of the entire application, and locally at the level of a given ScrollableView. You can find details here:
local view header/footer: https://dojotoolkit.org/reference-guide/1.9/dojox/mobile/ScrollableView.html#view-header-footer-bar-example
global application header/footer: https://dojotoolkit.org/reference-guide/1.9/dojox/mobile/ScrollableView.html#application-header-footer-bar-example
For the local case, you can add the fixed bar using the method ScrollableView.addFixedBar. For an example, see dojox/mobile/tests/test_dynamic-ScrollableView-vh-vf.html.
Hope this helps,
Adrian

Any link for Dojo sliding panel?

Can anyone help me with a link where I find Dojo sliding panel ? I have been searching for it but still didn't got it. I have sliding panel for jQuery, I got it from this link : http://web-kreation.com/all/implement-a-nice-clean-jquery-sliding-panel-in-wordpress-27/
You could make use of the dojo.fx.wipeIn functionality.
http://dojotoolkit.org/reference-guide/1.7/dojo/fx/wipeIn.html
So if you create two divs, one above the other, have the top one with display: none, and the other as the bit that you click to slide the panel down. Then use dojo.connect to link the clicking of the bottom panel to a wipe in of your top panel.
e.g.
// Have your main body content
var mainBody;
// Create top panel
var myPanel = document.createElement("div");
// Set visibility to none
dojo.style(myPanel, "display", "none");
// Create tab to expand your panel (or slide it down)
var expand = document.createElement("div");
expand.innerHTML = "click here to slide down";
mainBody.appendChild(myPanel);
mainBody.appendChild(expand);
var self = this;
dojo.connect(expand, "onclick", this, slidePanel);
Then you'd have your slidePanel function do something like:
// Get reference to your panel
var myPanel;
var wipeArgs = {
node: myPanel
};
// Then just wipe the panel in or out respectively
if (myPanel.style.display == "none") {
dojo.fx.wipeIn(wipeArgs).play();
} else {
dojo.fx.wipeOut(wipeArgs).play();
}

change background image for the main window in Titanium-iphone

I have the following in Titanium:
var imageArray = [];
imageArray[0] = 'photo0.png';
imageArray[1] = 'photo1.png';
....
imageArray[N] = 'photoN.png';
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundImage:imageArray[0],
backgroundColor:'#fff'
});
win1 is my main window and when I click a button I want to change it's backgroundImage without need for recreating the window. Anyone any idea of how could I do that?
Thanks
You can just set the backgroundImage of your window, like this:
win1.backgroundImage = "photo1.png";
It will works to you. But make sure that the image is in the Resources folder.
You have to use Ti.UI.currentWindow just when you are using external windows (with URL parameter in the window, using another JS file).
In the same context, the Ti.UI.currentWindow not works.

Adding buttons in Sencha Touch

I want to update the toolbar's content of the main view from a subview (HotelApp.views.hotelDetail)
This is my toolbar from HotelApp.views.mainView
this.topBar = new Ext.Toolbar({
dock:'top',
id:'main_page_topbar',
title:'H10 Sencha Demo',
items:[this.back,
{xtype: 'spacer'}
]
});
The toolbar already have a back button. The problem is i can see the shape of a button, but no text either ID. What i'm doing wrong??
I use this code:
var toolbar = HotelApp.views.mainView.getDockedItems()[1];
var images = new Ext.Button({
text:'Images',
id:'images',
ui:'drastic'
})
toolbar.setTitle(record.get('nombre'));
toolbar.add({items: images});
toolbar.doLayout();
Thanks!!!
I think that your problem is only that you have to add your button calling
toolbar.add(images);
instead of
toolbar.add({items: images});
I even suggest you to don't use 'id' config for your components but 'itemId'.
In this way you can always get your views components by calling
myView.getComponent('myComponentItemId');
or
myView.getDockedComponent('myComponentItemId');
for DockedComponents like toolbars.
Hope this helps.