Sencha Touch Ext.TabPanel handler - extjs

I did a lot of reading but i can't figure this out.
This app uses Sencha Touch 2.0
My 'app' has a segmented button
xtype: 'segmentedbutton'
With this item
{
text: 'Blog',
scope: this,
handler: this.makeYqlRequest
}
This is what it does
blog: {
query: "select * from rss where url='http://feeds.feedburner.com/extblog' limit 5",
tpl: Ext.create('Ext.XTemplate', [
'<tpl if="item">',
'<tpl for="item">',
'<div class="blog-post">',
'<h3>{title}</h3>',
'<p>{description}</p>',
'</div>',
'</tpl>',
'</tpl>'
])
}
This works wel but now i want to use the Ext.TabPanel
And i have this item
{
title: 'Blog',
iconCls: 'home',
html: 'Blog Screen'
}
How can i get the handler from the segmented button to work with the Ext.TabPanel?
I played a little with a listener but i can't get it to work.
Can someone explain this a little more to me?
Thank you!

You will need to get a reference to your TabPanel and call the [setActiveItem](http://docs.sencha.com/touch/2-0/#!/api/Ext.Container-method-setActiveItem), passing the view you want to make active, or the index of that view.
Simple example (viewable here):
Ext.setup({
onReady: function() {
var tabPanel = Ext.create('Ext.tab.Panel', {
fullscreen: true,
items: [
{
title: 'Home',
items: [
{
xtype: 'toolbar',
items: [
{
xtype: 'segmentedbutton',
items: [
{
text: 'home'
},
{
text: 'blog',
handler: function() {
// Using an index
tabPanel.setActiveItem(1);
}
},
{
text: 'about',
handler: function() {
// Using a reference
var about = tabPanel.down('#about');
tabPanel.setActiveItem(about);
}
}
]
}
]
},
{
html: 'tap one of the above buttons to change the active tab.'
}
]
},
{
title: 'Blog',
html: 'blog'
},
{
title: 'About',
itemId: 'about',
items: [
{
xtype: 'toolbar',
docked: 'top',
items: [
{
text: 'Go to home',
handler: function() {
// using the index
tabPanel.setActiveItem(0);
}
}
]
}
]
}
]
});
}
});

Related

Why the ext component is not overriden although I did exactly as written in documentation?

I would like to override Ext.ux.LiveSearchGridPanel so that instead of text ‘Search’ some other text appears, for example ‘xyz’.
I have a LiveSearchGridPanel as:
Ext.define('MyApp.view.main.List', {
//extend: 'Ext.grid.Panel',
extend: 'Ext.ux.LiveSearchGridPanel',
xtype: 'mainlist',
requires: [
'MyApp.store.Personnel'
],
title: 'Personnel',
store: {
type: 'personnel'
},
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Email', dataIndex: 'email', flex: 1 },
{ text: 'Phone', dataIndex: 'phone', flex: 1 }
],
listeners: {
select: 'onItemSelected',
afterrender: function() {
console.log('We have been rendered');
}
}
});
I created new file LiveSearchGridPanel123.js in ${app.dir}/overrides directory:
Ext.define('Ext.overrides.LiveSearchGridPanel123', {
override: 'Ext.ux.LiveSearchGridPanel',
initComponent: function () {
var me = this;
console.log(this.self.getName() + ' created 123');
me.tbar = ['XXX', {
xtype: 'textfield',
name: 'searchField',
hideLabel: true,
width: 20,
listeners: {
change: {
fn: me.onTextFieldChange,
scope: this,
buffer: 100
}
}
}, {
xtype: 'button',
text: '<',
tooltip: 'Find Previous Row',
handler: me.onPreviousClick,
scope: me
}, {
xtype: 'button',
text: '>',
tooltip: 'Find Next Row',
handler: me.onNextClick,
scope: me
}
];
me.bbar = Ext.create('Ext.ux.StatusBar', {
defaultText: me.defaultStatusText,
name: 'searchStatusBar'
});
me.callParent(arguments);
}
});
And I added
requires: [
'Ext.overrides.LiveSearchGridPanel123',
],
In app.js.
Then I did sencha app refresh, but component remained the same.
Could you please tell me where the the error is?
screenshot
It's because you call parent this.callParent();.
You can try:
Ext.define(null,{
override:'Ext.ux.LiveSearchGridPanel',
initComponent: function() {
const me = this;
me.tbar = [{
xtype:'textfield'
}];
this.superclass.superclass.initComponent.call(this); //<-- this does the magic
}
});

Sencha touch list itemtap after view change

In sencha touch application I got views, one of them contains a list.
If I switch from the view which contains the list to another view and back, the list itemtap event not fires again.
My view with the list:
Ext.define('app.view.ItemList', {
extend: 'Ext.navigation.View',
xtype: 'listitems',
config: {
title: 'List',
items: [
{
xtype: 'toolbar',
ui: 'light',
docked: 'top',
title: 'List',
items: [
{
xtype: 'button',
text: 'Back',
ui: 'back',
handler: function() {
Ext.Viewport.animateActiveItem({xtype:'main'}, {type:'slide'});
}
},
]
},
{
xtype: 'list',
itemTpl: '{"name"}',
store: {
autoLoad: true,
fields: ['name', 'email'],
proxy: {
type: 'rest',
url: 'data/data.json',
reader: {
type: 'json'
}
}
}
}]
},
initialize: function() {
this.callParent();
}
})
Controller for this:
Ext.define('app.controller.Main', {
extend: 'Ext.app.Controller',
config: {
refs: {
listitems: 'listitems'
},
control: {
'listitems list': {
itemtap: 'showItem',
}
}
},
showItem: function(list, index, element, record) {
this.getItemlist().push({
xtype: 'panel',
title: record.get('name'),
html: [
"<b>Name:</b> " + record.get('name') +
"<b>Email:</b> " + record.get('email')
],
scrollable: true,
styleHtmlContent: true
})
}
})
I tried it also with id, itemId, nothing worked.
How could I solve this?
Please try sth like this:
this.getItemlist().push(
Ext.create('Ext.panel.Panel,{
title: record.get('name'),
html: [
"<b>Name:</b> " + record.get('name') +
"<b>Email:</b> " + record.get('email')
],
scrollable: true,
styleHtmlContent: true
})
)
and don't forget to use getItemlist().pop() when back button is clicked! In my app, the back button did not (or not always) remove the view on top of the stack. It gets even worse when adding loadmasks and ActionSheets.

Tab Panel Listener not working

When try to call the function method in tab panel on click, method is calling in listener. Here my code,
var homepnl=Ext.create('Ext.TabPanel', {
id:'homepnl',
width:'100%',
height:'100%',
tabBarPosition: 'bottom',
defaults: {
styleHtmlContent: true
},
items: [
{
title: 'My Items',
iconCls: 'star',
id:'divtab1',
items: [myitemspnl]
},
{
title: 'Add Items',
iconCls: 'compose',
id:'divtab2',
items: [additemspnl]
},
{
title: 'Friend List',
iconCls: 'team',
//id:'friendsid',
id:'divtab3',
items:[friendslistpnl],
},
{
title: 'Search',
iconCls: 'search',
items: [searchpnl]
},
{
title: 'Settings',
iconCls: 'settings',
items: [settingspnl]
}
],
listeners: {
tabchange: function (homepnl, tab) {
alert(homepnl.id);// No alert is coming here
}
}
});
What the problem with my code here? Please help me to solve
I am looking at Sench touch documentation, there is no event tabchange. See documentation.
You can use activeitemchange event.
Use below code in listeners :
listeners: {
activeitemchange: function (homepnl, value, oldValue) {
alert(homepnl.id);
}
}

Sencha Touch detailed page view into items with buttons

1.Could please anybody help me with this issue?
1.After clicking on data detail I need see something as bellow (NotesApp.view.NoteEditor):
1.button_1
1.html + {title} + html
1.button_2
1.html + {narrative} + html
app.js
Ext.application({
name: "NotesApp",
models: ["Note"],
stores: ["Notes"],
controllers: ["Notes"],
views: ["NotesList", "NoteEditor"],
launch: function () {
var notesListView = {
xtype: "noteslistview"
};
var noteEditorView = {
xtype: "noteeditorview"
};
Ext.Viewport.add([notesListView, noteEditorView]);
}
});
NotesApp.model.Note
Ext.define("NotesApp.model.Note", {
extend: "Ext.data.Model",
config: {
idProperty: 'id',
fields: [
{ name: 'id', type: 'int' },
{ name: 'title', type: 'string' },
{ name: 'narrative', type: 'string' }
]
}
});
NotesApp.store.Notes
Ext.define("NotesApp.store.Notes", {
extend: "Ext.data.Store",
config: {
model: "NotesApp.model.Note",
data: [
{ title: "Ibuprofen STDATA 200", narrative: "LIEK"},
{ title: "Ibuprofen STDATA 450", narrative: "LIEK"},
{ title: "IbuprofANIN", narrative: "LATKA"}
]
}
});
NotesApp.controller.Notes
Ext.define("NotesApp.controller.Notes", {
extend: "Ext.app.Controller",
config: {
refs: {
notesListView: "noteslistview",
noteEditorView: "noteeditorview",
notesList: "#notesList"
},
control: {
notesListView: {
editNoteCommand: "onEditNoteCommand"
},
noteEditorView: {
backToHomeCommand: "onBackToHomeCommand"
}
}
},
slideLeftTransition: { type: 'slide', direction: 'left' },
slideRightTransition: { type: 'slide', direction: 'right' },
activateNoteEditor: function (record) {
var noteEditorView = this.getNoteEditorView();
noteEditorView.setRecord(record);
Ext.Viewport.animateActiveItem(noteEditorView, this.slideLeftTransition);
},
activateNotesList: function () {
Ext.Viewport.animateActiveItem(this.getNotesListView(), this.slideRightTransition);
},
onEditNoteCommand: function (list, record) {
this.activateNoteEditor(record);
},
launch: function () {
this.callParent(arguments);
var notesStore = Ext.getStore("Notes");
notesStore.load();
},
init: function () {
this.callParent(arguments);
}
});
NotesApp.view.NotesList
Ext.define("NotesApp.view.NotesList", {
extend: "Ext.Container",
requires:"Ext.dataview.List",
alias: "widget.noteslistview",
config: {
layout: {
type: 'fit'
},
items: [{
xtype: "toolbar",
title: "Liek",
docked: "top",
}, {
xtype: "list",
store: "Notes",
itemId:"notesList",
onItemDisclosure: true,
itemTpl: "<div>{title}</div><div>{narrative}</div>"
}],
listeners: [ {
delegate: "#notesList",
event: "disclose",
fn: "onNotesListDisclose"
}]
},
onNotesListDisclose: function (list, record, target, index, evt, options) {
console.log("editNoteCommand");
this.fireEvent('editNoteCommand', this, record);
}
});
NotesApp.view.NoteEditor
Ext.define("NotesApp.view.NoteEditor", {
extend: "Ext.Container",
requires:"Ext.dataview.List",
alias: "widget.noteeditorview",
initialize: function () {
this.callParent(arguments);
},
config: {
// this is working !!!
// tpl: [
// '<div><p>Info about: {title} </p></div>'
// ],
items: [
{
xtype: "button",
text: '<div style="text-align:left;">button 1<div>',
ui: "action",
id:"button_1"
},
{
xtype: 'list',
itemTpl: [
'<div>title: {title} </div>' // working not !!!
]
},
{
xtype: "button",
text: '<div style="text-align:left;">button 2<div>',
ui: "action",
id:"button_2"
},
{
xtype: 'list',
itemTpl: [
'<div>title: {narrative} </div>' // working not !!!
]
}
]
},
});
in your controller, you attach the onEditNoteCommand handler to the editNoteCommand. This is not a valid event (and is never triggered) of the Ext.dataview.List object as you can see in the Sencha documentation.
You have to attach the handler to an existing event, in this case to the itemtap one:
control: {
notesListView: {
itemtap: "onEditNoteCommand"
},
...
Problem
You created NotesApp.view.NoteEditor as list, within that list you have two separate list for title and narrative and But in controller you setting data only for NoteEditor list, not for two list within NoteEditor, so that two list will not show any data because they didn't get data.
Can do like this
In view
Give itemId for that two list.
{
xtype: 'list',
itemId : 'title',
itemTpl: [
'<div>title: {title} </div>' // working not !!!
]
},
{
xtype: "button",
text: '<div style="text-align:left;">button 2<div>',
ui: "action",
id:"button_2"
},
{
xtype: 'list',
itemId : 'narrative',
itemTpl: [
'<div>title: {narrative} </div>' // working not !!!
]
}
In controller
activateNoteEditor: function (record) {
var noteEditorView = this.getNoteEditorView();
noteEditorView.getComponent('title').setData(record.getData().title);
noteEditorView.getComponent('narrative').setData(record.getData().narrative);
Ext.Viewport.animateActiveItem(noteEditorView, this.slideLeftTransition);
},
What you trying to do ?
First of all NotesApp.view.NoteEditor is to edit note with two fields for title and narrative.
Why you have two list for title and narrative ?
What is the purpose of that list in edit screen ?

switching between views in sencha touch

I have the following view code in sencha touch 2
Ext.define('WL.view.Categories', {
extend: 'Ext.Container',
requires: [
'Ext.SegmentedButton',
'WL.view.movie.List',
'Ext.form.Panel',
'Ext.plugin.ListPaging',
'Ext.TitleBar',
'WL.view.movie.SortBar',
'WL.view.movie.SearchBar'
],
xtype: 'categories',
config: {
layout: {
type: 'card',
animation: {
type: 'fade'
}
},
items: [
{
docked: 'top',
xtype: 'toolbar',
cls: 'small withBg',
title: 'Merchants',
items: [
/* {
xtype: 'segmentedbutton',
allowDepress: false,
items: [
/*
{
cls: 'movies',
iconCls: 'movies',
pressed: true
},
{
xtype: 'button',
cls: 'friends',
iconCls: 'friends'
}
]
},
*/
{ xtype: 'spacer' },
{
xtype: 'button',
cls: 'searchBtn',
iconCls: 'search',
align: 'right'
},
{
xtype: 'button',
cls: 'backBtn',
id: 'movieBackButton',
align: 'left'
}
/*
{
xtype: 'component',
cls: 'fbProfilePic',
id: 'fbProfilePic',
tpl: '<img src="https://graph.facebook.com/{profileId}/picture?type=square" />' // the img source can be later changed
}
*/
]
},
{
xtype:'list',
store: 'Merchants',
plugins: [
{ xclass: 'Ext.plugin.ListPaging' }
],
itemCls: 'expandedMovie',
itemHeight:114,
items: [
{ xtype: 'movieSortBar' , docked:'top'},
{ xtype: 'movieSearchBar' , docked:'top' , hidden:true},
{
xtype: 'container',
cls: 'promo',
itemId:'promo-container',
docked:'bottom',
html: '<span class="logo"></span>Brought to you by Sencha Touch 2.1 <button>Learn More</button>'
}
],
loadingText: null,
listeners: {
order: 'before',
select: function() {
return false;
},
itemtap: function(dataview, index, target, record, evt) {
var el = Ext.get(evt.target),
fireEvent;
if (el.dom.nodeName == 'B') el = el.parent();
WL.currentMovie = record;
if (el.hasCls('seen')) {
fireEvent = el.hasCls('selected') ? 'unSeen' : 'seen';
el.toggleCls('selected');
} else if (el.hasCls('want')) {
fireEvent = el.hasCls('selected') ? 'unWantToSee' : 'wantToSee';
el.toggleCls('selected');
} else if (el.hasCls('thumb') && el.hasCls('up')) {
fireEvent = el.hasCls('selected') ? 'unLike' : 'like';
el.toggleCls('selected');
} else if (el.hasCls('thumb') && el.hasCls('down')) {
fireEvent = el.hasCls('selected') ? 'unDislike' : 'dislike';
el.toggleCls('selected');
} else {
fireEvent = 'tapMovie';
}
if (fireEvent) {
this.fireEvent(fireEvent, record, el);
}
}
},
itemTpl: Ext.create('Ext.XTemplate',
'<div class="moreArrow"></div>',
'<div class="img"><img src="http://localhost/WL2/assets/rest/{image}" /></div>',
'<div class="meta">',
'<h3>{merchName}</h3>',
'<div class="actions">',
//'<div class="rating"><span>{% if (values.criticRating >= 0) { %}{criticRating}%{% } else { %}?{% } %}</span></div>',
'<button class="seen{[values.seen ? " selected" : ""]}">{action}</button>',
'{% if (values.seen) { %}',
'<button class="thumb up{[values.like ? " selected" : ""]}"><b></b></button>',
'<button class="thumb down{[values.dislike ? " selected" : ""]}"><b></b></button>',
'{% } else { %}',
'<button class="want{[values.wantToSee ? " selected" : ""]}">Want to Go There</button>',
'{% } %}',
'</div>',
'</div>'
)
} // end of the categories list
]
},
initialize: function() {
this.callParent();
// Enable the Tap event on the profile picture in the toolbar, so we can show a logout button
var profilePic = Ext.getCmp('fbProfilePic');
if (profilePic) {
profilePic.element.on('tap', function(e) {
profilePic.fireEvent('tap', profilePic, e);
});
}
}
});
I have defined xtype to my view, so I can reference it in my controller code
this is my controller code
Ext.define('WL.controller.Categories', {
extend: 'Ext.app.Controller',
config: {
refs: {
categories: 'categories',
List: 'list'
},
control: {
list: {
tapMovie: 'onMovieTap' // the function that will be created when a movie is tapped
}
}
},
slideLeftTransition: { type: 'slide', direction: 'left' },
slideRightTransition: { type: 'slide', direction: 'right' },
onMovieTap: function () {
Ext.Viewport.animateActiveItem(this.getCategories(),this.slideRightTransition);
}
});
my main problem is that the get function getCategories() in the controller doesn't work so I can navigate to my view with slide right effect, I think that my problem is in definin the xtype, can you give me a clue on defining the correct xtype, giving that I tried using alias:widget.categories but it didnt work as well.
Your config should look like this:
config: {
refs : {
categories : {
autoCreate: true,
selector: '#categories_itemId',
xtype: 'categories'
},
List : {
// do the same thing for 'List'
}
},
control: {
...
},
...
},
...
Notice that the selector is the itemIdof your view so give your categories view an itemId (you can see I just made one up).

Resources