Pass and show data from ListView to TabView Sencha Touch - extjs

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);
}

Related

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.

Sencha Touch: How Can I pass Data from a view to Controller and Controller to Next View

I want to pass the an ID from a Tabview (myView1) to a Controller(theController) then after that I want that Controller class to pass data to another Tabview (myView2) at the same Panel. Anyone has any Idea, how can I do this?
You can do like this
in your controller:
config:{
refs:{
myView1: "myView1Ref",
myView2: "myView2Ref"
},
controls:{
myView1:{
idgiven: "onIdGiven"
}
}
},
onIdGiven: function(id){
this.getMyView2().setData(yourData);
}
in MyView1, when you want to give the id, just do
this.fireEvent(yourId);
This is my Tab Panel View class (MyTabPanel)
Ext.define('MyApp.view.MyTabPanel', {
extend: 'Ext.tab.Panel',
config: {
items: [
{
xtype: 'container',
title: 'Tab 1',
id: 'tab1',
items: [
{
xtype: 'textfield',
label: 'User'
},
{
xtype: 'container',
height: 46,
margin: '5px',
items: [
{
xtype: 'button',
ui: 'action',
width: 173,
text: 'Send Data'
}
]
}
]
},
{
xtype: 'container',
title: 'Tab 2',
id: 'tab2',
tpl: [
'{id}'
]
},
{
xtype: 'container',
title: 'Tab 3',
id: 'tab3'
}
]
}
});
This is my Controller :
Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',
config: {
refs: {
Tab1: '#tab1',
Tab2: '#tab2',
Tab3: '#tab3'
},
control: {
"Tab2": {
activate: 'onTabpanelActivate1'
}
}
},
onTabpanelActivate1: function(newActiveItem, container, oldActiveItem, eOpts) {
var Rec = [{id:1}]; // this should come from my #tab1 tab and set to #tab2 tab
this.getTab2().setRecord(Rec); // So this is the problem I am facing
}
});
Ext.define('myapp.controller.theController', {
extend: 'Ext.app.Controller',
config: {
refs: {
views: [
'myapp.view.myView1',
'myapp.view.myView2',
],
refMyView1: 'myView1',
refMyView2: 'myView2',
},
control: {
'button[action=submit]':{ // on tab of submit button
tap: 'submitTapHandler'
},
},
},
submitTapHandler: function(){
var view1data = this.getRefMyView1().getValues(); // view1data contain all field data of view1 in record form
//controller to view pass data
var myView2 = Ext.create('myapp.view.myView2');
// create a record that key value have name of fields and value to pass to that field
var record;
// set record key value
myView2.setRecord(record);
}
})

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 ?

Sencha touch 2: Set button handler parameter to lunch javascript function

I am using the sencha touch o'really example. Is a conference that have sessions and speakers associated. Imagine that I have a session list that when is tapped the view change to the session details.
I have a view like this:
Ext.define('MyApp.view.session.Detail', {
extend: 'Ext.Container',
xtype: 'session',
config: {
layout: 'vbox',
title: '',
items: [
{
flex: 1,
layout: 'fit',
scrollable: 'vertical',
xtype: 'sessionInfo'
},
{
flex: 2,
xtype: 'speakers',
store: 'SessionSpeakers',
items: [
{
xtype: 'listitemheader',
cls: 'dark',
html: 'Speakers'
}
]
},
{
flex: 1,
xtype: 'button',
text: "Decline Button" ,
handler: function () {
/*HERE I WANT TO PUT SOME DATA FROM THE SESSION OBJECT. FOR EXAMPLE */
alert({title});
alert({start_date});
alert({location});
}
}
]
}
});
So, I want to replace the {title} {start_date} {location} for the corresponding values of the current session.
By the way in the controller I have this:
onSessionTap: function(list, idx, el, record) {
var speakerStore = Ext.getStore('SessionSpeakers'),
speakerIds = record.get('speakerIds');
speakerStore.clearFilter();
speakerStore.filterBy(function(speaker) {
return Ext.Array.contains(speakerIds, speaker.get('id'));
});
if (!this.session) {
this.session = Ext.widget('session');
}
this.session.setTitle(record.get('title'));
this.getSessionContainer().push(this.session);
this.getSessionInfo().setRecord(record);
},
Thanks!!
I could resolve it.
I had to create the button on runtime.
:
In Session view:
Ext.define('MyApp.view.session.Detail', {
extend: 'Ext.Container',
xtype: 'session',
config: {
layout: 'vbox',
title: '',
items: [
{
flex: 1,
layout: 'fit',
scrollable: 'vertical',
xtype: 'sessionInfo'
},
{
flex: 2,
xtype: 'speakers',
store: 'SessionSpeakers',
items: [
{
xtype: 'listitemheader',
cls: 'dark',
html: 'Speakers'
}
]
}
]
}
});
In Session controller:
onSessionTap: function(list, idx, el, record) {
var speakerStore = Ext.getStore('SessionSpeakers'),
speakerIds = record.get('speakerIds');
speakerStore.clearFilter();
speakerStore.filterBy(function(speaker) {
return Ext.Array.contains(speakerIds, speaker.get('id'));
});
if (!this.session) {
this.session = Ext.widget('session');
}
else{
//To avoid multiple buttons
this.session.removeAt(2);
}
this.session.setTitle(record.get('title'));
this.session.add(
Ext.Button.create({
flex: 1,
xtype: 'button',
text:'My button' ,
handler: function () {
alert(record.get('title'));
alert(record.get('start_date'));
} })
);
this.getSessionContainer().push(this.session);
this.getSessionInfo().setRecord(record);
},

show window in tabpanel

I am working on extjs4, my case is:
Extjs mvc is used to build my application, viewport is the toppest container of my application, west region is a tree, center region is a tabpage container, when click the tree item, a new page with certain content will be created. then in this page, I popup a model window, this model window just mask the page, not the whole viewport, so that I can still click the tree item to open another new page.
I have achieved this, but there is a problem, if I have already open a model window in a tab, and I switch to a another tab then return back, the model window is hidden, but I still want that window to show if I haven't closed it. Can anyone help me, is there a better way except using ifram in tabpage?
app.js:
Ext.application({
name: 'SysOpv',
appFolder: '/Js/AppSysOpv/app',
autoCreateViewport: true,
controllers: [
'Category',
'Band'
]
});
Viewport:
Ext.define('SysOpv.view.Viewport', {
extend: 'Ext.container.Viewport',
layout: 'fit',
initComponent: function() {
this.items = {
dockedItems: [{
dock: 'top',
xtype: 'toolbar',
height: 80,
items: [
{ xtype: 'component', html: 'setup' }
]
}],
layout: {
type: 'hbox',
align: 'stretch'
},
items: [{
width: 250,
xtype: 'categorytree'
}, {
id: 'maintabpanel',
flex: 1,
xtype: 'tabpanel'
}]
};
this.callParent(arguments);
}
});
Tree View:
Ext.define('SysOpv.view.category.Tree', {
extend: 'Ext.tree.Panel',
alias: 'widget.categorytree',
title: 'setup',
rootVisible: false,
useArrows: true,
hideHeaders: true,
columns: [{
flex: 1,
xtype: 'treecolumn',
text: 'Name',
dataIndex: 'name'
}],
store: 'Category',
initComponent: function() {
this.callParent(arguments);
}
});
Window View:
Ext.define('SysOpv.view.edit.Band', {
extend: 'Ext.window.Window',
alias: 'widget.editband',
title: 'Setup',
layout: 'fit',
constrain: true,
modal: true,
initComponent: function() {
this.items = [{
xtype: 'form',
bodyPadding: 10,
items: [{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name'
}]
}];
this.buttons = [{
text: 'Save',
action: 'save'
}, {
text: 'Cancel',
scope: this,
handler: this.close
}];
this.callParent(arguments);
}
});
Tree Controller:
Ext.define('SysOpv.controller.Category', {
extend: 'Ext.app.Controller',
models: [ 'Category' ],
stores: [ 'Category' ],
views: [ 'category.Tree' ],
init: function() {
this.control({
'categorytree': {
itemdblclick: this.onTreeItemdblclick
}
});
},
onTreeItemdblclick: function (tree, record, item, index, e, eOpts) {
var mainTabs = Ext.getCmp('maintabpanel');
var tabId = record.get('id');
if (mainTabs) {
var checkTab = mainTabs.getComponent(tabId);
if (checkTab) {
mainTabs.setActiveTab(checkTab);
} else {
var controller;
var list;
switch (tabId) {
case '0101':
list = Ext.widget('listband');
break;
}
if (list)
{
var tabPage = mainTabs.add({
id: record.get('id'),
title: record.get('name'),
closable: true,
layout: 'fit',
items: [ list ]
});
mainTabs.setActiveTab(tabPage);
}
}
}
}
});
Module Controller:
Ext.define('SysOpv.controller.Band', {
extend: 'Ext.app.Controller',
models: [ 'Band' ],
stores: [ 'Band' ],
views: [ 'list.Band', 'edit.Band' ],
init: function() {
this.control({
'listband button[action=edit]': {
click: this.onEdit
}
});
},
onEdit: function(button, e, eOpts) {
var edit = Ext.widget('editband');
var list = button.up('gridpanel');
if (list.getSelectionModel().hasSelection()) {
var record = list.getSelectionModel().getLastSelected();
// I use renderTo here but have no effect,
// so I search in the google find a way to show the window in tab,
// and not mask all the viewport.
button.up('#0101').add(edit);
edit.down('form').loadRecord(record);
edit.show();
} else {
console.log('Not selected');
}
}
});
Below is example solution:
Ext.create('Ext.TabPanel', {
renderTo: 'container',
items: [
{
title: 'Tab 1',
itemId: 'tab1',
items: [
{ xtype: 'button', text: 'Show window', handler: function(){
var tab = this.up('#tab1'); // Find tab
var win = Ext.widget('editband'); // Find window
this.up('tabpanel').showWindow(tab, win);
} }
]
},
],
showWindow: function(tab, w){
tab.add(w);
tab.popup = w;
w.on('close', function() { // clean up after window close
delete this.popup;
}, tab, { single: true });
w.show();
},
listeners: {
tabchange: function(panel, tab) {
if (tab.popup !== undefined) { // show window after tab change
tab.popup.show();
}
}
}
});
Basically I've created event handler for tabchange event in which I re-show window.
Working sample: http://jsfiddle.net/aCxYU/1/

Resources