Sencha touch list itemtap after view change - extjs

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.

Related

Pass and show data from ListView to TabView Sencha Touch

I have ListView with user list. My controller have event listener on user tap which opens new view (TabView), where I want to show detailed information about user in TabView container template, but it doesn't displays anything.
Controller:
Ext.define('HockeyTeamManagementSystem.controller.Users', {
extend: 'Ext.app.Controller',
config: {
refs: {
UserList: 'userlist',
Users: 'users',
UserDetails: 'userdetailtabs'
},
control: {
"#UserList": {
itemtap: 'onListItemTap'
},
"tabpanel": {
initialize: 'onTabpanelInitialize'
}
}
},
onListItemTap: function(dataview, index, target, record, e, eOpts) {
var user = Ext.create("HockeyTeamManagementSystem.view.UserDetailTabs", {
title: record.data.name +" "+ record.data.lastname,
record: record
});
this.getUsers().push(user).setData(record.data);
},
TabView:
Ext.define('HockeyTeamManagementSystem.view.UserDetailTabs', {
extend: 'Ext.tab.Panel',
alias: 'widget.userdetailtabs',
requires: [
'Ext.tab.Bar',
'Ext.XTemplate'
],
config: {
activeItem: 1,
defaults: {
styleHtmlContent: false
},
tabBar: {
docked: 'bottom',
layout: {
type: 'hbox',
pack: 'center'
}
},
items: [
{
xtype: 'container',
title: 'Information',
iconCls: 'info',
tpl: [
'name: {name}'
]
},
{
xtype: 'container',
title: 'Statistics',
iconCls: 'star'
},
{
xtype: 'container',
title: 'Payments',
iconCls: 'compose'
}
]
}
});
You need to set the data in the container and not in the view itself.
{
xtype: 'container',
title: 'Information',
iconCls: 'info',
name: "info",
tpl: [
'name: {name}'
]
}
In the controller:-
refs: {
infoContainer: 'container[name="info"]'
}
Now set the data:-
onListItemTap: function(dataview, index, target, record, e, eOpts) {
var user = Ext.create("HockeyTeamManagementSystem.view.UserDetailTabs", {
title: record.data.name +" "+ record.data.lastname,
record: record
});
this.getUsers().push(user);
this.getInfoContainer().setData(record.data);
}
Well, after some hours of testing different things I realized that I simply need to set data from onListItemTap function to TabView items:
refs: {
UserInformationTab: '#UserInformationTab'
},
onListItemTap: function(dataview, index, target, record, e, eOpts) {
var user = Ext.create("HockeyTeamManagementSystem.view.UserDetailTabs", {
title: record.data.name +" "+ record.data.lastname,
record: record
});
this.getUsers().push(user);
this.getUserInformationTab().setData(record.data);
}

Sencha Touch 2.3: Pushing data from list view to detail view

So I have made a simple list component view. When I tap a listing's disclosure button, I have a controller that will create a detail view that also pushes data about that respective listing into the detail view for use in a tpl property.
here is my code:
app/view/Main:
Ext.define ('Prac.view.Main', {
extend: 'Ext.Panel',
xtype: 'mainpanel',
requires: ['Prac.store.Names'],
config:{
layout: 'vbox',
items: [
{
xtype: 'titlebar',
docked: 'top',
title: 'Mainpanel',
items: [
{
xtype: 'button',
ui: 'confirm',
iconCls: 'add',
action: 'addName',
align: 'right'
}
]
},
{
xtype: 'list',
flex: 1,
grouped: true,
indexBar: true,
itemTpl: '{firstName} {lastName}',
store: 'Names',
onItemDisclosure: true,
}
]
}
});
app/controller/Main:
Ext.define ('Prac.controller.Main', {
extend: 'Ext.app.Controller',
config: {
refs: {
view: 'viewpanel',
det: 'detail'
},
control: {
'list' : {
disclose: 'showDetail'
}
}
},
showDetail: function(list, record) {
var det = Ext.create('Prac.view.Detail', {
data: record.data
});
Ext.Viewport.setActiveItem(det);
}
});
app/view/Detail:
Ext.define('Prac.view.Detail', {
extend: 'Ext.Panel',
xtype: 'detail',
config: {
items: [
{
xtype: 'titlebar',
title: 'Detail View',
docked: 'top'
},
{
xtype: 'panel',
styleHtmlContent: true,
scrollable: 'vertical',
title: 'Details',
//html: 'Hello, World!'
tpl: 'Hello {firstName} {lastName}',
data: null
}
]
}
});
I think that the issue might be of scope. Since the tpl property is nested inside the 'items' property rather than the config, the component is unable to use the data passed to the detail view from the controller. So I am wondering not just how to push data from one view to another, but how to push data from one view to a specific component in another view.
You are absolutely right. You are not setting data of the nested panel, you are setting the data of the Prac.view.Detail instead.
Data is a config property of a panel. That means sencha will create a setData() method for you. When you use this method internally applyData() or updateData() will be called respectively.
In your case this should work:
Ext.define('Prac.view.Detail', {
extend: 'Ext.Panel',
xtype: 'detail',
config: {
items: [
{
xtype: 'titlebar',
title: 'Detail View',
docked: 'top'
},
{
xtype: 'panel',
styleHtmlContent: true,
scrollable: 'vertical',
title: 'Details',
//html: 'Hello, World!'
tpl: 'Hello {firstName} {lastName}',
data: null
}
]
},
updateData: function ( newData, oldData ) {
var nestedPanel = this.down( 'panel' );
nestedPanel.setData( newData );
},
applyData: function ( newData, oldData ) {
var nestedPanel = this.down( 'panel' );
nestedPanel.setData( newData );
}
});
So when one sets the data of the Prac.view.Detail the applyData method will be called and it grabs the nested panel to set its data instead.

sencha touch 2 how create url dynamic store from item list

I need to pass the value of selected item in the list to a list of detail to load data from a store.
The code view is
Ext.define('App.view.PresidentList', {
extend: 'Ext.List',
xtype: 'presidentlist',
requires: ['App.store.Presidents','Ext.dataview.NestedList','Ext.data.proxy.JsonP'],
config: {
title: 'Events',
iconCls: 'star',
//grouped: true,
itemTpl: '<b>{evento}</b><br>{nombre}',
store: 'Presidents',
onItemDisclosure: true,
}
});
The code controller is
Ext.define('App.controller.Main', {
extend: 'Ext.app.Controller',
config: {
refs: {
main: 'mainpanel'
},
control: {
'presidentlist': {
disclose: 'showDetail'
}
}
},
showDetail: function(list, record) {
var listItems = Ext.create('App.store.ListItems', {newUrl : record.getData()});
listItems.load();
this.getMain().push({
xtype: 'presidentdetail',
title: record.fullName(),
data: record.getData(),
store: listItems
});
}
});
the code view datail is
Ext.define('App.view.PresidentDetail', {
extend: 'Ext.tab.Panel',
xtype: 'presidentdetail',
config: {
title: 'Details',
scrollable: 'vertical',
items:
[
{
extend: 'Ext.List',
xtype: 'presidentlist',
requires: ['App.store.ListItems','Ext.dataview.NestedList','Ext.data.proxy.JsonP'],
config: {
title: 'Events',
iconCls: 'star',
//grouped: true,
itemTpl: '<b>{evento}</b><br>{nombre}',
store: 'ListItems',
onItemDisclosure: true,
}
},
{
xtype: 'nestedlist',
title: 'Contactos',
id: 'panel2',
useToolbar:false,
displayField: 'title',
store: {
type: 'tree',
fields: [
'title','link','author','contentSnippet','content',
{name: 'leaf', defaultValue: true}
],
root: {
leaf: false
},
proxy: {
type: 'jsonp',
url: 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://feeds.feedburner.com/SenchaBlog/',
reader: {
type: 'json',
rootProperty: 'responseData.feed.entries'
}
}
},
detailCard: {
xtype: 'panel',
scrollable: true,
styleHtmlContent: true
},
listeners: {
itemtap: function(nestedList, list, index, element, post) {
this.getDetailCard().setHtml(post.get('content'));
}
}
},
{
xtype: 'panel',
id: 'panel5',
title: 'Costos',
iconCls: 'home'
},
{
xtype: 'panel',
title: 'Otros',
iconCls: 'favorites',
id: 'panel5'
},
]
}
});
and the code store of ListItems is
Ext.define('App.store.ListItems',{
extend: 'Ext.data.Store',
autoLoad: true,
config: {
model: 'App.model.President',
proxy: {
//autoLoad: true,
type: 'ajax',
url:<-------->here comes the url with the variable that is passed from the list
reader: {
type: 'json',
rootProperty: "test"
}
}
}
});
Please collaboration with this issue not to do this. thank you very much.
If you just want to change the url of the proxy on a store, you can do like this
Ext.getStore('YourStoreId').getProxy().setUrl("your_new_url");
Ext.getStore('YourStoreId').load();
You must use estraParams inside the proxy
extraParams:{Parm1:2, Parm2:'eeee'},

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 ?

How to change views when I click a button?

I'm using, or abusing, Sencha Touch for the first time and I just want to push a list view, when i click a button. Here is my view:
Ext.define('TouchNuts.view.Decision', {
extend: 'Ext.Panel',
xtype: 'decision',
config: {
title: 'Decision',
scrollable: true,
styleHtmlContent: true,
styleHtmlCls: 'Decision',
tpl: '<h2>{name}</h2>, <h3>{description}<h3>, <h4>{price:ellipsis(15)}</h4> <h1>you can do this </h1>',
items: [
{
xtype: 'button',
text: 'SEND',
ui: 'confirm',
docked: 'bottom',
action: 'doSomething'
}
]
}
});
Here is the view I'd like to push:
Ext.define('TouchNuts.view.File', {
extend: 'Ext.Panel',
xtype: 'file',
config: {
title: 'File',
iconCls: 'star',
layout: 'fit',
items: [
{
xtype: 'list',
id: 'file',
store: 'TransactionStore',
itemTpl: '<h2>{name:ellipsis(15)}</h2>, <h3>{description:ellipsis(8)}<h3>, <h4>{price:ellipsis(15)}</h4>',
itemCls: 'SummaryItems'
}
]
}
});
And here is my controller:
Ext.define('TouchNuts.controller.doSomething', {
extend: 'Ext.app.Controller',
config: {
refs: {
},
control: {
'button[action=doSomething]' : {
tap: function() {
getMainView('TouchNuts.view.Decision').push('TouchNuts.view.File');
}
}
}
}
});
I'm pretty good with HTML, CSS, and jQuery, but new to JS and totally clueless when it comes to Sencha so any advice is appreciated.
It is good to give your views an itemId inorder to reference them in your controller. So for instance:
TouchNuts.view.Decision can have an itemId:decisionPanel
and
TouchNuts.view.File can have an itemId:filePanel
Now in your Controller you would do this:
...
config: {
refs: {
decisionPanel: {
autocreate: true,
selector: '#decisionPanel',
xtype: 'decision'
},
filePanel: {
autocreate: true,
selector: '#filePanel',
xtype: 'file'
}
},
control: {
'button[action=doSomething]' : {
tap: 'onButtonTap'
}
}
onButtonTap : function(button, e, options) {
var me = this;
Ext.Viewport.setActiveItem(me.getDecisionPanel());
}
...
You will notice that I used getDecisionPanel() to get the decisionPanel view. This is because a getter function is automatically generated for each ref you specify and in order to access it, you new to use get+ the Capitalized ref name.
More info here: http://docs.sencha.com/touch/2-1/#!/api/Ext.app.Controller
Instead of
getMainView('TouchNuts.view.Decision').push('TouchNuts.view.File');
You have to create the view first and then push it to view
getMainView('TouchNuts.view.Decision').push(Ext.create('TouchNuts.view.File'));

Resources