I am new to sencha touch. I am beginning with MVC pattern. I want to navigate from one page to another. In my controller i have wriiten a tap function. The alert box inside works when tapped but it is not moving to the next screen. I don't know where have i gone wrong. Please do help.
My app.js looks like this:
//<debug>
Ext.Loader.setPath({
'Ext': 'sdk/src'
});
//</debug>
Ext.application({
name: 'iPolis',
requires: [
'Ext.MessageBox'
],
views: ['Main','mainmenu','journalsearch'],
controllers: [
'mainmenu'
],
icon: {
57: 'resources/icons/Icon.png',
72: 'resources/icons/Icon~ipad.png',
114: 'resources/icons/Icon#2x.png',
144: 'resources/icons/Icon~ipad#2x.png'
},
phoneStartupScreen: 'resources/loading/Homescreen.jpg',
tabletStartupScreen: 'resources/loading/Homescreen~ipad.jpg',
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
// Initialize the main view
Ext.Viewport.add(Ext.create('iPolis.view.Main'));
Ext.Viewport.add(Ext.create('iPolis.view.journalsearch'));
},
onUpdated: function() {
Ext.Msg.confirm(
"Application Update",
"This application has just successfully been updated to the latest version. Reload now?",
function() {
window.location.reload();
}
);
}
});
mainmenu.js:
Ext.define("iPolis.view.mainmenu", {
extend: 'Ext.form.Panel',
requires: ['Ext.TitleBar','Ext.form.FieldSet'],
id:'menuPanel',
config: {
fullscreen:true,
items: [
{
xtype: 'toolbar',
docked: 'top',
title: 'iPolis',
items: [
{
//text:'Back',
ui:'back',
icon: 'home',
iconCls: 'home',
iconMask: true,
handler: function() {
iPolis.Viewport.setActiveItem('menuPanel', {type:'slide', direction:'right'});
}
}]
},
{
xtype: 'fieldset',
title: 'Menu',
items: [
{
xtype: 'button',
text: '<div class="journal">Journal</div>',
labelWidth: '100%',
name: '',
id:'journal',
handler: function() {
// iPolis.Viewport.setActiveItem('journalPanel', {type:'slide', direction:'left'});
}
}
]
}
]
}
});
Journalsearch.js :
Ext.define("iPolis.view.journalsearch", {
extend: 'Ext.form.Panel',
requires: ['iPolis.view.mainmenu','Ext.TitleBar','Ext.form.Panel','Ext.form.FieldSet','Ext.Button'],
id:'journalPanel',
config: {
// tabBarPosition: 'bottom',
layout: {
// type: 'card',
animation: {
type: 'flip'
}
},
items: [
{
xtype: 'toolbar',
docked: 'top',
title: 'iPolis',
items: [
{
//text:'Back',
ui:'back',
icon: 'home',
iconCls: 'home',
iconMask: true,
handler: function() {
}
}]
}
]
}
});
the controller mainmenu.js:
Ext.define('iPolis.controller.mainmenu', {
extend: 'Ext.app.Controller',
requires: [''],
config: {
control: {
'#journal': {
tap: 'onJournalTap'
}
}
},
init: function() {
},
onJournalTap: function() {
alert('i am clicked');
var a = Ext.getCmp('menuPanel');
a.setActiveItem(Ext.getCmp('journalPanel'));
}
});
In this function:
onJournalTap: function() {
alert('i am clicked');
var a = Ext.getCmp('menuPanel');
a.setActiveItem(Ext.getCmp('journalPanel'));
}
Try using this command: console.log(a), and show what it logs, I will help you.
PS: basically that's what Ext.NavigationView is designed for. If you have many views and just want to set one ACTIVE view at one time, let's include them all in your container and later show them using setActiveItem(index of that view)
Related
I want my view access a function was defined in my controller.
If i define a function out of define in controller the code works if not i get the error 'Uncaught ReferenceError: refreshSelection is not defined'
Whats is wrong?
View
initComponent: function() {
this.dockedItems = [
{
xtype: 'toolbar',
items: [
{
text: 'Importar',
action: 'selimp',
tooltip: 'Importar TXT'
},{
text: 'Excluir',
action: 'delete',
tooltip: 'Deletar Registros'
},{
text: 'Excluir Todos',
action: 'deleteAll',
tooltip: 'Deletar todos os Registros'
},{
text: 'Transferir Dados',
action: 'transfDados',
tooltip: 'Transferencia de registros'
}
]
},{
xtype: 'pagingtoolbar',
dock: 'bottom',
store: 'GridStore',
displayInfo: true,
emptyMsg: "Nenhum registro encontrado."
}
];
this.callParent(arguments);
this.getView().on('refresh', refreshSelection , this);
this.selModel.on('select', selectRow , this);
this.selModel.on('deselect', deselectRow , this);
}
Controller
Ext.define('ImpPdf.controller.GridControl', {
extend: 'Ext.app.Controller',
stores: ['GridStore'],
models: ['Espelho'],
views: ['GridView'],
refs: [ {ref: 'GridV',selector: 'grid'} ],
init: function() {
//declaracao dos controles dos botoes
this.control({
'gridV': {
deselect: this.deselectRow
},
'gridV': {
select: this.selectRow
},
'gridV': {
refresh: this.refreshSelection
}
});
},
selectRow: function(){
console.log('selectRow-1');
},
deselectRow: function(){
console.log('deselectRow-1');
},
refreshSelection: function(){
console.log('refreshSelection-1');
},
........
Man you're doing it wrong!
You can't use the Controller Reference to place a controller action.
Instead use the same CSS-like selector of your grid.
All functionality must be in your controller. The controler action (this.Control) will bind the function with the event.
Your controller must look like this:
Ext.define('ImpPdf.controller.GridControl', {
extend: 'Ext.app.Controller',
refs: [
{
ref: 'GridV',
selector: 'grid'
}
],
selectRow: function(rowmodel, record, index, eOpts) {
console.log('Foo');
},
init: function(application) {
this.control({
"grid": {
select: this.selectRow
}
});
}
});
In your view just eliminate the business code.
Ext.define('ImpPdf.view.MyViewport', {
extend: 'Ext.container.Viewport',
requires: [
'Ext.grid.Panel',
'Ext.grid.column.Number',
'Ext.grid.column.Date',
'Ext.grid.column.Boolean',
'Ext.grid.View',
'Ext.toolbar.Paging'
],
initComponent: function() {
var me = this;
Ext.applyIf(me, {
items: [
{
xtype: 'gridpanel',
title: 'My Grid Panel',
store: 'GridStore',
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'string',
text: 'String'
},
{
xtype: 'numbercolumn',
dataIndex: 'number',
text: 'Number'
},
{
xtype: 'datecolumn',
dataIndex: 'date',
text: 'Date'
},
{
xtype: 'booleancolumn',
dataIndex: 'bool',
text: 'Boolean'
}
],
dockedItems: [
{
xtype: 'pagingtoolbar',
dock: 'bottom',
width: 360,
displayInfo: true,
store: 'GridStore'
}
]
}
]
});
me.callParent(arguments);
}
});
I'm writing a Sencha Touch 2 application and I've got a problem with switching views. I've got two views (LoginPanel and RegisterPanel) and I want to switch from LoginPanel to RegisterPanel by clicking a button. I want to use "makeAccount" button to go to the RegisterPanel View. I've tried many tricks, but alas no one work. Here's my codes:
app.js
Ext.application({
name: 'kody2',
requires: [
'Ext.MessageBox'
],
controllers: [
'Main'
],
views: [
'HomeContainer',
'LoginPanel',
'Produkty',
'Start',
'SkanujKod',
'Opcje',
'KatalogPDF',
'RegisterPanel',
'SimpleProduct',
'ForgotPassword'
],
viewport: {
layout: {
type: 'card',
animation: {
type: 'fade',
direction: 'left',
duration: 300
}
}
},
icon: {
'57': 'resources/icons/Icon.png',
'72': 'resources/icons/Icon~ipad.png',
'114': 'resources/icons/Icon#2x.png',
'144': 'resources/icons/Icon~ipad#2x.png'
},
isIconPrecomposed: true,
startupImage: {
'320x460': 'resources/startup/320x460.jpg',
'640x920': 'resources/startup/640x920.png',
'768x1004': 'resources/startup/768x1004.png',
'748x1024': 'resources/startup/748x1024.png',
'1536x2008': 'resources/startup/1536x2008.png',
'1496x2048': 'resources/startup/1496x2048.png'
},
launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
// Initialize the main view
Ext.Viewport.add(Ext.create('kody2.view.HomeContainer'));
},
onUpdated: function() {
Ext.Msg.confirm(
"Application Update",
"This application has just successfully been updated to the latest version. Reload now?",
function(buttonId) {
if (buttonId === 'yes') {
window.location.reload();
}
}
);
}
});
LoginPanel.js
Ext.define('kody2.view.LoginPanel', {
extend: 'Ext.Panel',
xtype: 'loginpanel',
config: {
title: 'Twoje konto',
iconCls: 'user2',
styleHtmlContent: true,
scrollable: true,
items: [
{
xtype: 'fieldset',
id: 'formContent',
title: 'Zaloguj się',
items: [
{
xtype: 'emailfield',
name: 'login',
id: 'email_login',
label: 'Login'
},
{
xtype: 'passwordfield',
name: 'password',
id: 'form_password',
label: 'Hasło'
},
{
xtype: 'button',
text: 'Załóż konto',
id: 'makeAccount',
action: 'register'
},
{
xtype: 'button',
text: 'Zapomniałem hasło',
id: 'forgotPassword'
},
{
xtype: 'button',
text: 'Zaloguj',
id: 'logowanie'
}
]
}
]
}
});
and the Controller:
Ext.define('kody2.controller.Main', {
extend: 'Ext.app.Controller',
config: {
control: {
'button[action=register]': {
tap: 'myFunction'
}
}
},
myFunction: function() {
Ext.Viewport.add({
xtype: 'register'
});
}
});
Thanks for all help!
You just adding register view in viewport, But not setting it as active item.
Ext.Viewport.setActiveItem({xtype:'register'});
Above line will add register view in viewport and also sets as ActiveItem.
Update
Ext.define('kody2.controller.Main', {
extend: 'Ext.app.Controller',
config: {
control: {
'button[action=register]': {
tap: 'myFunction'
}
}
},
myFunction: function() {
Ext.Viewport.setActiveItem({ xtype: 'register' });
console.log(Ext.Viewport.getActiveItem().xtype);
}
});
I have a button at the top right of every page that I want to link to a certain page within my application. Is there a way to give each instance of this button the same behaviour? and if so where would the code sit so that it affects every page? Many thanks in advance.
View:
items: [
{
title: '<span class="logo"></span>',
xtype: 'titlebar',
docked: 'top',
items: [
{
xtype: 'button',
align: 'right',
iconAlign: 'right',
id: 'buytickets',
text: 'Buy Tickets'
}
]
}
]
Controller (specific to one page):
config: {
refs: {
main: 'ListNav'
},
control: {
"button#buytickets": {
tap: 'buytickets'
}
}
},
buytickets: function(button, e, eOpts) {
this.getMain().push({
xtype: 'buyticketspanel'
});
},
You could just put the button at the top of your Viewport, in the app.js file:
Ext.application({
name: 'MyApp',
requires: [],
views: [/*Views*/],
controllers: [/*Controllers*/],
viewport: {
layout: 'vbox'
},
launch: function() {
var me = this;
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();
// Initialize the main view
Ext.Viewport.add([
{
title: '<span class="logo"/>',
xtype: 'titlebar',
docked: 'top',
items: [
{
xtype: 'button',
align: 'right',
iconAlign: 'right',
id: 'buytickets',
text: 'Buy Tickets',
handler: me.doBuyTickets
}
]
},
Ext.create('MyApp.view.Main', {flex: 1})
]);
},
doBuyTickets: function() {
//do stuff
}
});
****EDIT****:
However, you won't be able to re-purpose that bar as the title bar for a NestedView. If you need to have that, then you might be best served with a utils file that has a method to add a button to a toolbar, and just reuse that in the init function of any NestedView components.
Utils.js:
Ext.define("MyApp.util.Utils", {
singleton: true,
addBuyButton: function(toolbar)
{
toolbar.add({
text: 'Buy Tickets',
align: 'right',
handler: function() {
//do stuff
}
});
}
});
Controller:
Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',
config: {
refs: {
nestedList: 'nestedlist'
},
control: {
app-page: {
initialize: 'initAppPage'
}
}
},
initAppPage: function()
{
MyApp.utils.addBuyButton(this.getNestedList().getNavigationBar());
}
});
I have a tabpanel which should always be shown at the bottom of the page.
This tabpanel (main.js) has 3 tabs (home, persoon and todo).
These tabs are "panels" (home.js, persoon.js, todo.js).
Every tab has multiple panels:
Home tab --> home.js, homeOver.js, homeReset.js
Persoon tab --> person.js, personAdd.js, personDetail.js
Todo tab --> todo.js, todoAdd.js, todoDetail.js
When I click at a tab, the correct page will be shown.
When I click at lets say the home tab, the home panel will be shown. When I click within this panel at a button to show another panel within the same tab (home), the tabpanel disappears.
How can I resolve this?
I change the page with the following function:
Ext.Viewport.animateActiveItem( { xtype : 'homeovercard'}, {type: 'slide', direction: 'left'});
Here is my complete code:
app.js:
Ext.application({
name: 'app',
controllers: ['HomeController', 'PersoonController'],
views: ['Main'],
launch: function() {
Ext.Viewport.add({
xclass: 'app.view.Main'
});
}
});
app.view.Main.js:
Ext.define('app.view.Main', {
extend:'Ext.TabPanel',
xtype: 'maincard',
requires: [
'app.view.Home',
'app.view.Persoon',
'app.view.Todo',
'app.view.HomeOver',
'app.view.HomeReset'
],
config: {
tabBar: {
docked: 'bottom',
layout: {
pack: 'center'
}
},
items: [
{ xtype: 'homecard' },
{ xtype: 'persooncard' },
{ xtype: 'todocard' }
]
}
});
app.view.Home.js:
Ext.define('app.view.Home', {
extend: 'Ext.Panel',
alias: "widget.homePage",
xtype: 'homecard',
config: {
iconCls: 'home',
title: 'Home',
html: 'Dit is de home pagina',
styleHtmlContent: true,
items: [{
docked: 'top',
xtype: 'toolbar',
title: 'Home',
items: [
{
xtype: "button",
text: 'Over',
action: 'ButtonHomeOverClicked'
},
{
xtype: "spacer"
},
{
xtype: "button",
text: 'Reset',
action: 'ButtonHomeResetClicked'
//action:
}
]
}
]
}
});
app.view.HomeOver.js:
Ext.define('app.view.HomeOver', {
extend: 'Ext.Panel',
alias: "widget.homeover",
xtype: 'homeovercard',
requires: [
'app.view.Home',
'app.view.Persoon',
'app.view.Todo'
],
config: {
iconCls: 'home',
title: 'Home',
html: 'Dit is de home over pagina',
styleHtmlContent: true,
items: [
{
docked: 'top',
xtype: 'toolbar',
title: 'Over pagina',
items: [
{
xtype: "button",
ui: "back",
text: "Terug",
action: "ButtonBackHome"
}
]
}
]
}
});
app.controller.HomeController:
Ext.define("app.controller.HomeController", {
extend: "Ext.app.Controller",
config: {
refs: {
// We're going to lookup our views by xtype.
overButton: "button[action=ButtonHomeOverClicked]",
resetButton: "button[action=ButtonHomeResetClicked]",
backButton: "button[action=ButtonBackHome]"
},
control: {
overButton: {
// The commands fired by the notes list container.
tap: "onOverCommand"
},
resetButton: {
// The commands fired by the notes list container.
tap: "onResetCommand"
},
backButton: {
tap: "onBackCommand"
}
}
},
onOverCommand: function () {
console.log("Op home over knop gedrukt");
this.changeScreenToOverPage();
},
onResetCommand: function () {
console.log("Op home reset knop gedrukt");
this.changeScreenToResetPage();
},
onBackCommand: function () {
console.log("Op back knop gedrukt");
this.changeScreenToHomePage();
},
changeScreenToOverPage: function () {
console.log("Verander screen!");
Ext.Viewport.animateActiveItem( { xtype : 'homeovercard'}, {type: 'slide', direction: 'left'});
},
changeScreenToResetPage: function () {
console.log("Verander screen!");
Ext.Viewport.animateActiveItem( { xtype : 'homeresetcard'}, {type: 'slide', direction: 'left'});
},
changeScreenToHomePage: function () {
console.log("Verander screen!");
Ext.Viewport.animateActiveItem( { xtype : 'maincard'}, {type: 'slide', direction: 'right'});
},
// Base Class functions.
launch: function () {
this.callParent(arguments);
// Ext.getStore("Notes").load();
console.log("launch");
},
init: function () {
this.callParent(arguments);
console.log("init");
//this.onOverCommand();
}
});
I hope my question is clear.
Thanks in advance for your help.
UPDATE
Here is some code that should get the right component:
changeScreenToOverPage: function (button, e, eOpts) {
var maincard = Ext.Viewport.getComponent(0).animateActiveItem( { xtype : 'homeovercard'}, {type: 'slide', direction: 'left'});
console.log("Verander screen!");
}
The problem is that you are calling animateActiveItem on the viewport, you need to call it on the tabpanel which is your maincard xtype that sits in the viewport
I started to use the Sencha Touch 2 MVC, but I can't overcome the problem below.
I have an Ext.application code:
Ext.application({
name: 'ProjectName',
appFolder: APP_URL + "app",
enableQuickTips: true,
extend: 'Ext.app.Controller',
phoneStartupScreen: 'LOGO.png',
controllers: ['Site'],
views: ['Viewport_login', 'Viewport_reg'],
layout: 'vbox',
launch: function() {
//bootstrap
Ext.create("Ext.Container", {
requires: [
],
items: [
Ext.create("ProjectName.view.Viewport_login", {}),
Ext.create("ProjectName.view.Viewport_reg", {})
]
});
return true;
}
});
view 'Viewport_login' code:
Ext.define('ProjectName.view.Viewport_login', {
extend: 'Ext.Panel',
requires: [
'ProjectName.view.Login',
'ProjectName.view.Header'
],
fullscreen: true,
initialize: function() {
console.log("init viewpor_login");
Ext.create("Ext.Container", {
//fullscreen: true,
style: 'background-color: white;',
layout: 'vbox',
fullscreen: true,
scrollable: true,
items: [
{
xtype: 'Bheader'
},
Ext.create("widget.login")
]
});
this.callParent();
}
});
View 'Viewpoer_reg' code:
Ext.define('ProjectName.view.Viewport_reg', {
extend: 'Ext.Panel',
requires: [
'ProjectName.view.Reg',
'ProjectName.view.Header'
],
fullscreen: true,
initialize: function() {
console.log("init viewpor_reg");
Ext.create("Ext.Container", {
//fullscreen: true,
style: 'background-color: white;',
layout: 'vbox',
fullscreen: true,
scrollable: true,
items: [
{
xtype: 'Bheader'
},
Ext.create("widget.reg")
]
});
this.callParent();
}
});
view 'Header' code:
Ext.define('ProjectName.view.Header', {
extend: 'Ext.Panel',
alias: 'Bheader',
xtype: 'Bheader',
requires: [
'Ext.Img'
],
initialize: function() {
console.log("header inited");
},
config: {
cls: 'bg-holder',
items: [
Ext.create("Ext.Img", {
src: BASE_URL + 'assets/images/header3.png',
height: 35,
width: "100%",
style: "background-position: center 0px; "
})
]
}
});
And finally the 'Site' controller's code:
Ext.define('ProjectName.controller.Site', {
extend: 'Ext.app.Controller',
config: {
views: ['Viewport_login', 'Viewport_reg']
},
init: function() {
console.log('Init site controller');
// Start listening for events on views
this.control({
// example of listening to *all* button taps
'#login_button': {
tap: function () {
// HOW CAN I SWITCH TO 'VIEWPORT_REG' VIEW?
}
}
});
},
renderRegFOrm: function() {
},
onLaunch: function() {
console.log('onLaunch site controller');
},
});
First, I have a problem right now: The 'Header' does'nt appear if I load both views ('Viewport_login', 'Viewport_reg') in Container which created in Ext.application launch function. Can anyone help me, why?
Second, in the Controller code you can see the this.control(... section. How can I switch to other view in here?
From looking at your code, it appears that you only want one of login and register to appear at one time. I would recommend looking at the setActiveItem method for containers and switching views in this way.
I didn't understand your first question. Also, didn't understand why you have widget.login and widget.reg classes when you already have views called login and reg (can't you just use those?)