tpl inside combined items - sencha-touch

I want a carousel panel in the detailview of a list. I put the carousel with a flex 3 inside a panel. With this code I make sure the tpl inside the panel items will work. But I don't know how to fix the problem with the carousel.
Code for tpl inside panel items:
updateData: function(newData, oldData) {
this.down('component').setData(newData);
this.getAt(0).setData(newData); this.getAt(1).setData(newData);
}
complete code of my WorkDetail.js
Ext.define('Portfolio.view.WorkDetail', {
extend: 'Ext.Panel',
xtype: 'workdetail',
requires: [
'Ext.carousel.Carousel'
],
config: {
xtype: 'panel',
layout: 'hbox',
align: 'stretch',
styleHtmlContent: true,
scrollable: null,
items: [
{
flex:3,
xtype: 'carousel',
// HERE THE TLP WORKS
// tpl: '<img src="{bigImage1}"></img>',
// style: 'background-color: #456370;',
items: [
{
// TPL DON'T WORK
tpl: '<img src="{bigImage1}"></img>',
style: 'background-color: #E84F17;'
},
{
// TPL DON'T WORK
tpl: '<img src="{bigImage2}"></img>',
style: 'background-color: #4DBAB6;'
},
{
// TPL DON'T WORK
tpl: '<img src="{bigImage3}"></img>',
style: 'background-color: #BBB399;',
}
]
},
{
// HERE THE TLP WORKS
flex:1,
tpl: '<p>{workDiscriptionLarge}</p> <p>{workDate}</P> Bekijk de website'
}
]
},
updateData: function(newData, oldData) {
this.down('component').setData(newData);
this.getAt(0).setData(newData);
this.getAt(1).setData(newData);
}
});

this.down('component').setData(newData);
this.getAt(0).setData(newData);
These two lines will target your Carousel item and so won't populate the templates of the sub-items.
this.getAt(1).setData(newData);
This line will target the second item where you see the template working.
You will need to target each of the Carousel items individually and call the setData method of each for the templates to be populated.
// untested :)
var components = this.getAt(0).query('component');
for(var i = 0; i < components.length; i++){
components[i].setData(newData);
}

Related

Sencha Touch 2 painted event not firing

I built a view and I want to do some manipulation of the elements, after the view has been painted.
I am trying to use the "painted" event with no avail.
Any ideas why?
Ext.define('TestApp.view.phone.RegisterViewPhone', {
extend: 'Ext.Panel',
xtype: 'RegisterViewPhone',
config: {
items: [
{
xtype: 'Header'
},{
xtype: 'panel',
itemId: 'thePanel',
html: 'THIS WILL HOLD THE VIEWS CONTENT'
},{
xtype: 'Footer'
}
],
listeners: [
{
delegate: '#thePanel',
event: 'painted',
fn: 'onPainted'
}
]
},
onPainted: function () {
alert('hey!');
}
});
You can attach listeners to that particular element like
{
xtype: 'panel',
itemId: 'thePanel',
html: 'THIS WILL HOLD THE VIEWS CONTENT',
listeners: {
painted: function(){
alert('hey!');
}
}
}
As painted is not dependent on individual element and it acts on page scope also U can write it in views directly
items: [
],
listeners: {
painted: function () {
alert('hey!');
}

Referencing the HTML objects inside a Sencha Touch Container

I'm using Sencha Touch 2.0.1. I'm trying to get a reference to some HTML in a Container. (My objective is to read the width of the object, and shrink the font size if necessary so it fits nicely).
Here's my code:
Ext.define("SFCT.view.Flashcard", {
extend: 'Ext.Container',
xtype: 'flashcardpanel',
requires: [
'Ext.TitleBar'
],
config: {
itemId: 'mainScreen',
title: 'Flashcards',
layout: 'fit',
items: [
{
xtype: 'container',
layout: {
type: 'vbox',
pack: 'center'
},
items: [
{
xtype: 'container',
itemId: 'wordContainer'
}
],
style: 'text-align: center'
},
{
xtype: 'button',
docked: 'right',
text: 'Next',
action: 'next'
}
]
},
updateWord: function(newWord) {
var s = '<div style="font-size: 72px">' + newWord+ '</div>';
var c = Ext.ComponentQuery.query('#wordContainer')[0];
console.log(c.getHtml());
c.setHtml(s);
}
});
If I use Ext.Container.getHtml() as shown above, it returns the HTML as a string. But I'm looking for a reference to the div element itself, so that I can get its width.
Any ideas how I can do that?
Thanks.
If I'm not mistaken
c.element
Should get you a reference to the wrapped element.

sencha touch 2: card layout within one of the panel of a carousel

What I'm trying to do here is to use a card layout within the panel of a carousel. But it seems impossible that it's not common to create a card layout and the carousel is actually one of the card-layout-like container. So I wonder if it can be achieved in Sencha Touch 2.
Here is my main view, a plain carousel container:
Ext.define("myapp.view.Main", {
extend: 'Ext.carousel.Carousel',
config: {
defaults: {
styleHtmlContent : true
},
activeItem: 0,
items: [
{
xtype: 'firstview'
},
{
xtype: 'secondview'
},
{
xtype: 'thirdview'
}
]
}
});
and here is my 'firstview', which extends the Ext.Panel as part of the carousel container:
Ext.define("myapp.view.Compose", {
extend: 'Ext.Panel',
xtype: 'firstview',
requires: [
'Ext.form.FieldSet',
'Ext.TitleBar',
'Ext.form.Text',
'Ext.Button'
],
config: {
styleHtmlContent: true,
scrollable: true,
layout: 'vbox',
items: [
{ // title bar
xtype: 'titlebar',
docked: 'top',
title: 'a Title here'
},
{
xtype: 'toolbar',
docked: 'top',
layout: {
type: 'vbox',
align: 'center',
pack: 'center'
},
items: [
{ // controll button set - to change view for composing different kinds of messages
xtype: 'segmentedbutton',
allowDepress: true,
allowMultiple: false,
items: [
{
text: 'subview-1',
pressed: true
},
{
text: 'subview-2'
},
{
text: 'subview-3'
}
]
}
]
},
{
xtype: 'container',
id: 'id_compose_card',
layout: {
type: 'card',
align: 'center',
pack: 'top'
},
config: {
height: '100%',
items: [
{
html: 'card 1'
},
{
html: 'card 2'
}
]
}
}
]
}
});
as you can see, there is a card layout within this panel. But as a matter of fact nothing is not going to display.
Of course, I can find another way out to achieve some thing similar here, but I just want to know is it impossible to embed a card container into a card-layout-like container, for example, 'tabPanel' or 'carousel' in sencha touch 2?
Hey in the Compose widget replace the the part with id:'id_compose_card'
with this
{
xtype: 'container',
id: 'id_compose_card',
layout: {
type: 'card',
align: 'center',
pack: 'top'
},
flex: 1,
items: [
{
html: 'card 1'
},
{
html: 'card 2'
}
]
}
I just took out the parts inside the config object and put them outside. Im getting this feeling that u cant nest a config inside another config object for a class definition. A lot of people are having issue and this seems to be the problem. You might want to confirm this on their forum.
Then I also replaced the attribute
height: '100%',
with this
flex:1
This will tell the vbox layout to make your component fill the remaining space.

How to handle Orientation Change in Sencha Touch V2

I've got a Panel that needs to execute some Javascript if the orientation changes. How do I handle the Orientation Change in sencha-touch-2?
This is basically the key line I'm trying to get to work
this.on('orientationchange', 'handleOrientationChange', this, {buffer: 50 });
Here's the context.
Ext.define('rpc.view.home.indexView', {
extend: 'Ext.Panel',
alias: 'widget.home-indexView',
config: {
scrollable: true,
items: [{
xtype: 'toolbar',
title: 'RockPointe Mobile',
docked: 'top'
}, {
xtype: 'panel',
items: [{
xtype: 'panel',
style:'border:1px solid #c4c4c4 !important; border-left:none;border-right:none;',
items: [{
html: '<div style="width:100%; height:150px;"><ol id="AN-sObj-parentOl"><li id="AN-sObj-scene-0"><div class="AN-sObj-stage" id="ext-gen5089"><div class="AN-Object" id="AN-sObj-60"><div id="AN-sObj-val-60"><img src="img/banner-3.jpg" /></div></div><div id="AN-sObj-61"><span>Relentlessly Focused On The Lost</span></div><div id="AN-sObj-62"><span>Passionately Devoted To God</span></div><div id="AN-sObj-63"><span>Deeply Committed To One Another</span></div></div></li></div>'
}]
}, {
xtype: 'container',
layout: {
type: 'hbox',
pack: 'center'
},
defaults: {
xtype: 'button',
ui: 'plain',
style: 'margin-top: 5px;',
pressedCls: 'x-button-rpc-pressed'
},
items: [{
text: 'Videos',
cls: 'x-button-rpc',
flex: 1
}, {
xtype: 'container',
cls: 'x-button-rpc-spacer'
}, {
text: 'Calendar',
cls: 'x-button-rpc',
flex: 1
}, {xtype: 'container',
cls: 'x-button-rpc-spacer'
}, {
text: 'Sites',
cls: 'x-button-rpc',
flex: 1
}]
}, {
xtype: 'panel',
cls: 'x-panel-rpc',
items: [{
html: 'body content'
}]
}, {
xtype: 'panel',
items: [{
html: '<div style="text-align: right; width:100%; padding-right: 5px;"><img src="/img/facebook.png" /><img src="/img/twitter.png" /></div>'
}]
}]
}]
},
initialize: function () {
console.log('rpc.view.home.indexView ~ initialize');
this.on('painted', 'handlePainted', this, { buffer : 50 });
// HOW TO HANDLE ORIENTATION CHANGE
this.on('orientationchange', 'handleOrientationChange', this, {buffer: 50 });
this.callParent(arguments);
},
handlePainted: function() {
console.log('rpc.view.home.indexView ~ handlePainted');
loadHomeBanner();
},
handleOrientationChange: function(){
console.log('rpc.view.home.indexView ~ handleOrientationChange');
loadHomeBanner();
}
});
Orientation change is handled by the Viewport. Here's the working snippet
Ext.Viewport.on('orientationchange', 'handleOrientationChange', this, {buffer: 50 });
Essentially, on the initialization of a Panel, you add a listener (where on is an alias for addListner) to the panel. From there, you create a new method called 'handleOrientationChange` (or whatever you want to call it) that will execute when the Viewport Orientation Changed
Ext.define('app.view.home.indexView', {
extend: 'Ext.Panel',
alias: 'widget.home-indexView',
config: {
//...
},
// Fires when the Panel is initialized
initialize: function () {
console.log('app.view.home.indexView ~ initialize');
// Add a Listener. Listen for [Viewport ~ Orientation] Change.
Ext.Viewport.on('orientationchange', 'handleOrientationChange', this, {buffer: 50 });
this.callParent(arguments);
},
handleOrientationChange: function(){
console.log('rpc.view.home.indexView ~ handleOrientationChange');
// Execute the code that needs to fire on Orientation Change.
}
};
To add to Chase's solution, the orientationchange event can provide four parameters as follows:
handleOrientationChange: function(viewport, orientation, width, height){
console.log('rpc.view.home.indexView ~ handleOrientationChange');
// Execute the code that needs to fire on Orientation Change.
alert('o:' + orientation + ' w:' + width + ' h:' + height);
}

Sencha touch Panel inside panel not showing up

I have a panel inside a panel as an item, along with other docked items.
For some reason it is not showing up.
These are stuffs to add to main panel:
MarketMakerApp.views.businessInfo = new Ext.Panel({
id: 'businessInfo',
layout: 'fit',
html: '<br /><br /><br /><div>{ id } </div>' + '<div>{ title }</div>'
//html: 'This is the business info view'
});
MarketMakerApp.views.businessTabbar = new Ext.TabBar({
dock: 'bottom',
ui: 'dark',
items: [
{
text: '1',
iconCls: 'info',
hander: function() {
MarketMakerApp.views.viewport.setActiveItem('businessInfo', {type: 'slide', direction: 'left' });
}
},
{
text: '2',
iconCls: 'star',
hander: function() {
this.add( MarketMakerApp.views.businessInfo);
this.setActiveItem(2);
}
},
{
text: '3',
iconCls: 'map',
hander: function() {
}
}
]
});
And the main panel is this:
MarketMakerApp.views.businessContainer = new Ext.Panel({
id: 'businessContainer',
layout: 'fit',
dockedItems: [
MarketMakerApp.views.businessTypeListToolbar,
MarketMakerApp.views.businessTabbar
],
items: [ MarketMakerApp.views.businessInfo]
});
The tabbar and toolbar are showing up fine, but I can't see the businessInfo panel.
Any suggestions would be appreciated.
p.s. I struggled with Tabpanel far too long to give up and just using tabbar now.
I haven't had any success in creating Panels (or whatever your view is) programmatically like that. Here's some code that does work w/that approach though.
Add an initComponent function to your businessContainer like the following instead of setting the items on the businessContainer panel:
initComponent: function(){
Ext.apply(this, {
items: [
MarketMakerApp.views.businessInfo
]
});
MarketMakerApp.views.businessContainer.superclass.initComponent.apply(this, arguments);
}