Sencha Touch: setting items in panel - hidden view by xtype causes undefined error - sencha-touch-2

I'm building an application with Sencha Touch 2.x. It consists of several screens that may overlap each other.
On app startup I'm loading all screens by adding them as items in my main view (part of the viewport). All of them except the start screen are hidden: true, which is working perfectly fine. I've created a new view and tried adding it the same way I did with the others (it is in fact a copy of another one, just changed names), but on app startup I get:
TypeError: 'undefined' is not an object (evaluating 'firingFn.apply')
When I remove the hidden: true attribute, the view is shown and the app loads. When I create the view with Ext.create(namespace.view.name) it is working fine.
The others views (which are more or less exactly the same) are working!
I've given a unique xtype, specified the path on Ext.define, added the view to app.js.
As I'm able to show it without "hidden: true" the problem shouldn't lie somewhere in there.
Does anybody know about this behavior?
(I know that it is recommended to create and destroy the views once they are needed, but at the moment we're going a different approach. So I'm interested what caused this behavior.)
Here's my Main view:
Ext.define('namespace.view.Main', {
extend: 'Ext.Container',
xtype: 'Main',
config: {
layout: 'hbox',
items: [
//actual necessary screens
{
xtype: 'Start',
showAnimation: {type:'fade', duration: 200, easing: 'easeInOut'}
},
//Preloading all Screens on startup
{
xtype: 'SearchOertlichkeit',
hidden: true
//this is the one causing trouble !
},
{
xtype: 'MeldungNeu',
hidden: true,
showAnimation: {type:'fade', duration: 200, easing: 'easeInOut'}
},
{
xtype: 'MeldungenBearbeiten',
hidden: true,
showAnimation: {type:'fade', duration: 200, easing: 'easeInOut'}
},
{
xtype: 'SearchLocation',
hidden: true
},
{
xtype: 'SearchMieteinheit',
hidden: true
},
{
xtype: 'Menu',
hidden: true
}
]
} //endconfig
});
Here's a part of the view I try to show:
Ext.define('namespace.view.SearchOertlichkeit', {
extend: 'Ext.Container',
xtype: 'SearchOertlichkeit',
config: {
height: '100%',
width: window.innerWidth-300,
padding: 10,
modal: true,
hideOnMaskTap: true,
top: 0,
right: 0,
bottom: 0,
left: 'auto',
enter:'right',
exit: 'right',
showAnimation: {
type: 'slideIn',
direction: 'left',
easing: 'easeInOut'
},
hideAnimation: {
type: 'slideOut',
direction: 'right',
easing: 'easeInOut'
},
items: [
{
//here are some items
},
],
listeners: {
initialize: function(comp , eOpts){
this.element.on('swipe',
function(event, node, options, eOpts) {
namespace.app.getController('Main').onSwipe(event.direction, 'searchOertlichkeit');
}, comp
); //endonswipe
} //endinitialize
} //endlisteners
}, });
I couldn't find any errors with the syntax (using Aptana, doesn't show me any errors too) but when I build for production (sencha cmd is running successful) I get an error once I try to run the prod-app:
Error evaluating http://127.0.0.1:8020/path/production/app.js with message: SyntaxError: Expected token '}'

Check the last line in your main view, the brackets are commented:
} //endconfig });
should be like:
} //endconfig
});

Related

Sencha Touch 2 store doesn't load within floating panel

I'm trying to load a list within a floating panel. It works with static values but it doesn't load using a json file.
If I tried this and it works:
var panel = Ext.create('Ext.Panel', {
left: 0,
padding: 10,
width: 300,
height: 300,
modal: true,
hideOnMaskTap: true,
layout: 'fit',
items: [
{
xtype: 'list',
scrollable: true,
ui: 'round',
height: '100%',
store: {
fields: ['name'],
data: [
{name: 'Cowper'},
{name: 'Everett'},
{name: 'University'},
{name: 'Forest'}
]
},
itemTpl: '{name}'
}
]
});
But when I try to call a Json file, it doesn't work. This is the panel:
var panel = Ext.create('Ext.Panel', {
left: 0,
padding: 10,
width: 300,
height: 300,
modal: true,
hideOnMaskTap: true,
layout: 'fit',
items: [
{
xtype: 'list',
scrollable: true,
ui: 'round',
height: '100%',
store: 'storeCardStatus',
itemTpl: '{Card_Status}'
}
]
});
This is the store:
Ext.define('MyApp.store.storeCardStatus',{
extend: 'Ext.data.Store',
config: {
model: 'MyApp.model.modelCardStatus',
autoLoad: true,
proxy: {
type: 'ajax',
url : 'card_status.json',
reader: 'json'
}
}
});
This is the model:
Ext.define('MyApp.model.modelCardStatus', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'Card_Status', type: 'string'}
]
}
});
This is the Json file:
[
{"Card_Status": "Completed"},
{"Card_Status": "Issued"},
{"Card_Status": "In Use"}
]
This has nothing to do with local data vs JSON file. You simply aren't setting the predefined store correctly on the list view. You want to add an alias to the store definition, and define the store as an object with type of your store alias (minus the prefix). Here is a fiddle:
https://fiddle.sencha.com/#fiddle/2bh
(Look specifically at Line #3, and #45)
I would recommend always creating stores via alias like this, it easier allows for management and destruction, and each store created will always be a new instance. Creating stores ahead of time (for example, via Ext.create) and then assigning them to components introduces a huge risk of tying the same store to 2+ dataviews inadvertently.

Button Event not getting fired when put inside Tab Panel in Sencha Touch 2

I have put two buttons inside a tab Panel in Sencha Touch 2 application. The code is given below:
var btnAttendance = Ext.create('Ext.Button', {
text: 'Take Attendance',
padding: 10,
width: 200,
handler: function () {
alert('a');
}
});
var btnAddUser = Ext.create('Ext.Button', {
text: 'Add User',
padding: 10,
width: 200,
handler: function () {
alert('a');
}
});
var buttonContainer = Ext.create('Ext.Panel', {
fullscreen: true,
title: 'Home',
defaults: {
margin: 5
},
layout: {
type: 'vbox',
align: 'center'
},
padding: 10,
items: [
btnAttendance,
btnAddUser
]
});
Ext.application({
requires: [
'Ext.tab.Panel'
],
launch: function () {
Ext.Viewport.add({
xtype: 'tabpanel',
items: [
buttonContainer,
{
title: 'Present',
items: {
html: '2',
centered: true
},
cls: 'present'
},
{
title: 'Absent',
items: {
html: '3',
centered: true
},
cls: 'absent'
}
]
});
}
});
I have tried modifying the handler function as:
handler: function (button, event)
But this also doesn't work.
Thanks,
Nitin
You need to put all your code inside Ext.application... and launch:function(){...}.... Your code is working fine. See demonstration here.
But then again, buttonContainer is not really being added to any tab panel. If you change the tab, you can see buttonContainer is gone once to change the tabs. If you want to add it inside any tab do this-
First -
Set fullscreen:false to you buttonContainer panel.
var buttonContainer = Ext.create('Ext.Panel', {
fullscreen: false,
....... //rest of the code.
And suppose you want to add those buttons in Present tab. You can do this with following--
Ext.Viewport.add({
xtype: 'tabpanel',
items: [
{
title: 'Present',
cls: 'present',
items: [
{
html: '2',
centered: true
},
buttonContainer
]
},
{
title: 'Absent',
items: {
html: '3',
centered: true
},
cls: 'absent'
}
]
});
Here, buttonContainer is added as an item inside present tab only. You can switch the tabs and can see buttons there with correct event handler.
See this demo here
If you follow MVC architecture, your job becomes much easier writing application having multiple views and user interactions. ST is all about MVC and it's good practice to follow it.

After taking picture how to set that picture in the layout in Sencha Touch?

I am trying to take a picture using camera API and display this in the screen. I am able to take the picture. But not getting how to display it in my screen. For this i wrote the below code:
Ext.define('MyApp.view.CameraPanel', { extend: 'Ext.Panel',
config: {
ui: 'light',
layout: {
type: 'card'
},
items: [
{
xtype: 'button',
handler: function(button, event) {
Ext.device.Camera.capture({
source: 'camera',
destination: 'data',
success: function(image) {
takenimage.setSrc(image);
},
failure: function() {
Ext.Msg.alert('Error', 'There was an error when acquiring the picture.');
},
scope: this
});
},
height: 33,
left: 60,
top: 400,
ui: 'decline-round',
width: 200,
text: 'Take a Photo'
},
{
xtype: 'image',
itemId: 'takenimage',
src: 'image'
}
]
}
});
I am new to this sencha platform. Please help.
THANKS
Using html tag, i am able to fix this issue..

extjs 4 dynamically enable an actioncolumn item

Using 4.0.6 I have a gridpanel with an actioncolumn that has two items, a delete button and and view button. The delete button is disabled but there are some circumstances where it needs to be enabled (if a user is an admin). So I am trying to enable it in code.
Here's the view:
Ext.define('PP.view.person.List', {
extend: 'Ext.grid.Panel',
alias: 'widget.personlist',
title: 'Current people',
store: 'People',
columnLines: true,
initComponent: function () {
this.columns = [
{ header: 'Id', dataIndex: 'personId', flex: 1, sortable: true },
{ header: 'Title', dataIndex: 'title', flex: 1 },
{ header: 'Name', dataIndex: 'name', flex: 1},
{ xtype:'actioncolumn',
items:[
{icon:'cross.gif',disabled:true,handler:function(){alert('delete pressed');}},
{icon:'tick.gif',handler:function(){alert('view pressed');}}
]
}
];
this.callParent(arguments);
}
});
and the controller function I'm using to enable:
enableDel: function () {
var view = Ext.widget('personlist');
view.down('actioncolumn').enableAction(0);
}
but I am getting an error inside the extjs enableAction function on the line that starts
me.up('tablepanel').el.select
the el is undefined. The column doesn't get enabled either. Can anyone tell me what I'm doing wrong or post an example that works? If I specify
renderTo: Ext.getBody()
in the view I don't get the error any more but the column still doesn't enable. So I think it must be something to do with rendering but I'm so new to this I haven't a clue where to start.
Generally when el is undefined it means that you are attempting to access it before the component is rendered. When does your enableDel function get called? You might want to try putting it in an afterrender listener.

Sencha Touch TabBar + page navigation. Why it's breaking?

I'm a newbie to SenchaTouch. I have started working on an App and the results are this until now: http://mobz.com.br:86. (based on the Sencha-Touch-tabs-and-toolbars-demo)
Now I started playing with it and I have difficulties to set things strait in my head.
I have lot of JQuery experience, but regarding the design of this library, the coin haven't dropped yet.
I got a TabPanel with 5 sections. I will focus only in one section cause there where my problem is.
The Problem
As you can see in my app, when one clicks an item of ingressos (tickets in English), the app loads the second panel, but load it with bugs.
It loads it without the title bar, without the Back button, and also add an empty sixth button on the right.
But if I load the second panel first, when the page loads, it loads without any UI issues.
My Code
First I declare my ViewPort
Mobz.views.Viewport = Ext.extend(Ext.TabPanel, {
fullscreen: true,
initComponent: function() {
Ext.apply(this, {
tabBar: {
dock: 'bottom',
layout: {
pack: 'center'
}
},
items: [
{ xtype: 'destaques', id: 'home' },
{ xtype: 'ingressos' },
{ xtype: 'mobilizacoes' },
{ xtype: 'locais' },
{ xtype: 'minhaconta' }
]
});
Mobz.views.Viewport.superclass.initComponent.apply(this, arguments);
}
});
Than after, at the ingressos.js file, I define the tab.
First I got the panel that will load the items into it.
Mobz.views.Ingressos = Ext.extend(Ext.Panel, {
id: "ingressos",
title: "Ingressos", //title of the page
iconCls: "arrow_right", // icon of the tab at the bottom
styleHtmlContent: true,
fullscreen: true,
layout: 'card',
initComponent: function () {
Ext.apply(this, {
dockedItems: [{
xtype: "toolbar",
title: "Ingressos"
}],
items: [Mobz.views.IngressosList]
});
Mobz.views.Ingressos.superclass.initComponent.apply(this, arguments);
}
});
Ext.reg('ingressos', Mobz.views.Ingressos);
This is the initial item that load into the panel.
Mobz.views.IngressosList = new Ext.List({
id: 'ingressoslist',
itemTpl: IngressosList_Template,
store: Mobz.stores.IngressosStore,
onItemTap: function (subIdx) {
//Mobz.views.IngressoCinemaList.update(subIdx);
Mobz.views.viewport.setActiveItem(Mobz.views.IngressoCinemaList, { type: 'slide', direction: 'left' });
}
});
And that's the second panel.
The panel where the first panel goes to.
Mobz.views.IngressoTitle = new Ext.Panel({
id: 'ingressotitle',
tpl: IngressoTitle_Template,
data: Mobz.stores.IngressoTitle_Store
});
Mobz.views.IngressoCinemaList = new Ext.List({
id: 'ingressocinemalist',
itemTpl: IngressoCinemaList_Template,
store: Mobz.stores.IngressoCinemaListStore,
flex: 1, grouped: true,
dockedItems: [{
xtype: 'toolbar',
items: [{
text: 'Back',
ui: 'back',
handler: function () {
Mobz.views.viewport.setActiveItem(Mobz.ingressos, { type: 'slide', direction: 'right' });
}
}]
}
],
onItemDisclosure: function () {
app.views.viewport.setActiveItem(Mobz.views.IngressosHorario, { type: 'slide', direction: 'left' });
}
});
Mobz.views.Ingresso = new Ext.Panel({
id: 'ingresso',
layout: {
type: 'vbox',
align: 'fit'
},
items: [Mobz.views.IngressoHorario_IngressoECinemaTitles, Mobz.views.IngressoCinemaList]
});
That's it.
I hope some of you guys will have the patient to read all my code examples. I'll appreciate any help.
Shlomi.
First, you must understand the logic about the panels.
You have an TabPanel and you have 5 panel in it. If you run your code when you click a ticket as you described in problem, your code added a new pane to TabPanel. But you need to set active item of Ingression panel(second panel which is in tabPanel).
Now start the solution;
The second tab has a panel(I will say senchaTabItem) whose layout is card layout. And this panel has a panel in it with list of Ingressos. We want to remove this panel and replace the new panel so we should not call the tabPanel's method, we must call to senchaTabItem's method.
So if you replace below code
Mobz.views.viewport.setActiveItem(Mobz.views.IngressoCinemaList, { type: 'slide', direction: 'left' });
with working code(below code).
Mobz.views.viewport.getActiveItem().setActiveItem(Mobz.views.IngressoCinemaList, { type: 'slide', direction: 'left' });
In your site; it is at line 170 in ingressos.js
I tried and it works, I hope it helps