Sencha Touch 2 proxy not firing any requests - ajax

I'm trying to just get a list loaded from a proxy that uses rest to get data from the server. I can't figure out what I'm doing wrong, but I don't see any GET requests to /restaurants in Chrome's network call log. Originally I thought maybe the controller wasn't being included, but it's all there and when I add data in the store it populates. This isn't throwing any errors, so I can't debug it. I've gone through every possible tutorial I could find as well as the documentation. Any help or insight is greatly appreciated.
Controller:
Ext.define('Appetize.controller.Restaurants', {
extend: 'Ext.app.Controller',
config: {
models: ['Restaurant'],
views: [
'RestaurantList',
],
refs: {
},
control: { }
}
}
Model:
Ext.define('Appetize.model.Restaurant', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'id'},
{name: 'name'},
{name: 'delivers'},
{name: 'active'}
]
}
});
store:
Ext.define('Appetize.store.Restaurants', {
extend: 'Ext.data.Store',
requires: ['Appetize.model.Restaurant'],
config: {
model: 'Appetize.model.Restaurant',
proxy: {
type: 'rest',
url: '/restaurants',
autoLoad: 'true'
}
}
});
View:
Ext.define('Appetize.view.RestaurantList', {
extend: 'Ext.List',
xtype: 'restaurantListCard',
config: {
iconCls: 'home',
title: 'Restaurants',
id: 'restaurantList',
store: 'Restaurants',
onItemDisclosure: true,
itemTpl: '{name}'
}
});

It turns out I had autoLoad in the wrong place. It shouldn't be within the proxy settings. Instead it should be outside the proxy as part of config.
Ext.define('Appetize.store.Restaurants', {
extend: 'Ext.data.Store',
requires: ['Appetize.model.Restaurant'],
config: {
model: 'Appetize.model.Restaurant',
proxy: {
type: 'rest',
url: '/restaurants',
},
autoLoad: 'true'
}
});

Related

Sencha Touch 2 rendering store data to panel

I am reading data from a JSON feed through a Store. My problem is I am unable to display the data in a View-Panel.
My panel code is as follows:
Ext.define('Layouts.view.Node', {
extend: 'Ext.Panel',
xtype: 'node',
config: {
title: 'Node Data',
styleHtmlContent: true,
scrollable: 'vertical',
tpl: new Ext.XTemplate(
'<div>TITLE: {title}</div>'
),
},
});
The Store code is as follows:
Ext.define('Layouts.store.Node', {
extend: 'Ext.data.Store',
config: {
storeId: 'Node',
autoLoad: true,
model: 'Layouts.model.Node',
proxy: {
type: 'ajax',
url: 'http://178.79.128.76/revivaltimes/app/content/0',
reader: {
type: 'json',
rootProperty: 'JSON',
}
},
},//config
});
And the model code follows:
Ext.define('Layouts.model.Node', {
extend: 'Ext.data.Model',
config: {
fields: [
'title',
'body',
]
},
});
I don't know why my view comes up blank.
Take a look at the DataView component: http://docs.sencha.com/touch/2.3.1/#!/api/Ext.dataview.DataView
The DataView is the proper way to render data from a store. Your view would become something like that (untested code):
Ext.define('Layouts.view.Node', {
extend: 'Ext.dataview.DataView',
xtype: 'node',
config: {
title: 'Node Data',
styleHtmlContent: true,
scrollable: 'vertical',
store: 'Node',
itemTpl: new Ext.XTemplate(
'<div>TITLE: {title}</div>'
),
},
});
Note the use of itemTpl for specifying the item template.

SenchaTouch: Ext.getCmp().setSrc() method is not working

I am trying to change the source of an image using setSrc but I get this error:
Uncaught TypeError: Cannot call method 'setSrc' of undefined
Ext.Ajax.request.success Ext.apply.callback Ext.define.onComplete
Ext.define.onStateChange (anonymous function)
This is my source code :
View Page:
Ext.define('MechanicalTerk.view.Picture', {
extend: 'Ext.Container',
xtype: 'Picture',
requires: [
'Ext.data.Store'
],
config: {
layout: 'vbox',
items:
[
{
xtype: 'toolbar',
docked: 'top',
title: 'Requests',
minHeight: '60px',
items: [
{
xtype:'button',
ui:'back button',
id:'backButton',
text:'Back'
},{
xtype: 'button',
id:'logoutButton',
text: 'Logout'
}
],
},
{
xtype:'image',
height:500,
id:'layoutImage'
}
]
}
});
Controller:
Ext.define('MechanicalTerk.controller.PictureController',{
extend:'Ext.app.Controller',
showPicture: function(userID,sentAt){
Ext.Ajax.request({
url:'app/Model/database.php',
params: {
functionID: 3,
userID: userID,
sentAt: sentAt,
},
success: function (response, opts){
Ext.getCmp('layoutImage').setSrc('http://www.sencha.com/img/20110215-feat-perf.png');
Ext.Viewport.setActiveItem(Ext.create('MechanicalTerk.view.Picture'));
}
});
}
});
Any ideas ?
You should consider not using your own id and instead use an itemId. This is probably happening because you are trying to re-use a component that has been destroyed. I would suggest creating a ref to your image in your controller so you can access it.
So I'm thinking:
Ext.define('MechanicalTerk.controller.PictureController',{
extend:'Ext.app.Controller',
config: {
refs : {
myImage : {
autoCreate: true,
selector: '#myimage',//assuming your image's itemId is 'myimage'
xtype: 'image'
}
}
},
showPicture: function(userID,sentAt){
Ext.Ajax.request({
url:'app/Model/database.php',
params: {
functionID: 3,
userID: userID,
sentAt: sentAt,
},
success: function (response, opts){
var me = this;
me.getMyImage().setSrc('http://www.sencha.com/img/20110215-feat-perf.png');
Ext.Viewport.setActiveItem(Ext.create('MechanicalTerk.view.Picture'));
}
});
}
});
PS: Not tested but try that approach.

Extjs mvc add record to grid panel

first I thought it is a simple problem however I could not solve it anyway.
I have a extjs gridpanel, its store and model. From controller, I can insert new records to store, when I use firebug and debug, I can list all the new records in the store (panel.store.data.items) however in the gridview I cannot make it visible.
Could you please tell me where and what I am missing? Why the records are not listed in the grid?
This is my model
Ext.define('BOM.model.PaketModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'seriNo', type: 'string' },
{ name: 'tutar', type: 'string' },
]
});
This is store
Ext.define('BOM.store.PaketStore', {
extend: 'Ext.data.Store',
model: 'BOM.model.PaketModel',
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'data',
},
writer: {
type: 'json',
root: 'data',
},
},
});
This is the method I add new rows
addNew: function () {
this.getPaketWindow().returnRowEdit().cancelEdit();
this.getPaketWindow().getStore().insert(0, new BOM.model.PaketModel());
this.getPaketWindow().returnRowEdit().startEdit(0, 0);
}
UPDATE VIEW
Ext.define('BOM.view.PaketCreate', {
extend: 'Ext.grid.Panel',
alias: 'widget.paketcreate',
bodyPadding: 5,
layout: 'fit',
header:false,
initComponent: function () {
this.columns = [
{ text: 'Seri No', flex: 2, sortable: true, dataIndex: 'seriNo', field: {xtype: 'textfield'} },
{ text: 'Tutar', flex: 2, sortable: true, dataIndex: 'tutar', field: {xtype: 'textfield'} }
];
this.dockedItems = [{
xtype: 'toolbar',
items: [{
text: 'Ekle',
id:'addNewCheck',
iconCls: 'icon-add',
},'-',{
id: 'deleteCheck',
text: 'Sil',
iconCls: 'icon-delete',
disabled: true,
}]
}];
this.store = 'BOM.store.PaketStore';
rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false
});
this.plugins = rowEditing,
this.callParent(arguments);
},
returnRowEdit: function () {
console.log("row editing...");
return rowEditing;
}
});
var rowEditing;
Try:
this.store = Ext.create('BOM.store.PaketStore');
instead of:
this.store = 'BOM.store.PaketStore';
http://jsfiddle.net/qzMb7/1/
It works when I add ".getView()" like
this.getPaketWindow().getView().getStore().insert(0, new BOM.model.PaketModel())
However, I still do not understand. Both reaches the same store when I add records manually I can see them in the store.data but it is visible only if I include .getView() part

Load another view after login with sencha touch 2.0

I'm having a dumb problem and I would like you to give me a hand.Thanks in advance.
The situatios is as follows: I have 2 wiews (both created with sencha architect 2.0), one for login, and another for general purposes. And I would like to load the second view on successful response when trying to log in, this is, after any successful login. The main problem is that I've tried with Ex.create, Ext.Viewport.add, Ext.Viewport.setActiveItem, but I can't manage to make the second view to appear on screen, the login screen just keeps there and the app does not load the other view. Another thing, I don't have to use a navigation view for this.
Here is the code of my controller, from which I want to load my second view. And as you'll see, I even created a reference of the view, which has autoCreate enabled and has that ID "mainTabPanel":
Ext.define('MyApp.controller.Login', {
extend: 'Ext.app.Controller',
config: {
refs: {
loginButton: {
selector: '#login',
xtype: 'button'
},
username: {
selector: '#user',
xtype: 'textfield'
},
password: {
selector: '#pass',
xtype: 'passwordfield'
},
mainTabPanel: {
selector: '#mainTabPanel',
xtype: 'tabpanel',
autoCreate: true
}
},
control: {
"loginButton": {
tap: 'onLoginButtonTap'
}
}
},
onLoginButtonTap: function(button, e, options) {
Ext.Ajax.request({
url: '../../backend/auth.php',
method: 'POST',
params: {
user: this.getUsername().getValue(),
pass: this.getPassword().getValue()
},
success: function(response) {
var json = Ext.decode(response.responseText);
if (json.type == 'success') {
// LOAD THE DAMN SECOND VIEW HERE!
//var paneltab = Ext.create('MyApp.view.MainTabPanel');
//Ext.Viewport.add(paneltab);
//Ext.Viewport.setActiveItem(this.getMainTabPanel());
} else {
alert(json.value);
}
},
failure: function(response) {
alert('The request failed!');
}
});
}
});
And here is the code of my login view:
Ext.define('MyApp.view.LoginForm', {
extend: 'Ext.form.Panel',
config: {
id: 'loginForm',
ui: 'light',
items: [
{
xtype: 'fieldset',
ui: 'light',
title: 'Log into the system',
items: [
{
xtype: 'textfield',
id: 'user',
label: 'User',
name: 'user'
},
{
xtype: 'passwordfield',
id: 'pass',
label: 'Pass',
name: 'pass'
}
]
},
{
xtype: 'button',
id: 'login',
ui: 'confirm',
text: 'Login'
}
]
}
});
And finally, the code of the view I want to load. This view loads normally if I set it as the Initial View, but does not load when a successful login occurs:
Ext.define('MyApp.view.MainTabPanel', {
extend: 'Ext.tab.Panel',
config: {
id: 'mainTabPanel',
layout: {
animation: 'slide',
type: 'card'
},
items: [
{
xtype: 'container',
layout: {
type: 'vbox'
},
title: 'Tab 1',
iconCls: 'time',
items: [
{
xtype: 'titlebar',
docked: 'top',
title: 'General Report',
items: [
{
xtype: 'button',
iconCls: 'refresh',
iconMask: true,
text: '',
align: 'right'
}
]
},
{
xtype: 'container',
height: 138,
flex: 1,
items: [
{
xtype: 'datepickerfield',
label: 'From',
placeHolder: 'mm/dd/yyyy'
},
{
xtype: 'datepickerfield',
label: 'To',
placeHolder: 'mm/dd/yyyy'
},
{
xtype: 'numberfield',
label: 'Hours'
}
]
},
{
xtype: 'dataview',
ui: 'dark',
itemTpl: [
'<div style="height:50px; background-color: white; margin-bottom: 1px;">',
' <span style="color: #0000FF">{user}</span>',
' <span>{description}</span>',
'</div>'
],
store: 'hoursStore',
flex: 1
}
]
},
{
xtype: 'container',
title: 'Tab 2',
iconCls: 'maps'
},
{
xtype: 'container',
title: 'Tab 3',
iconCls: 'favorites'
}
],
tabBar: {
docked: 'bottom'
}
}
});
Please, I need help... :)
I'm stuck here for like 3 days now and can't figure out what the problem is. Thank you.
Could you post your app.js too?
I'm trying your code here and it load the view as expected. Here is my app.js:
Ext.application({
name: 'MyApp',
requires: [
'Ext.MessageBox'
],
controllers: ['Login'],
views: ['LoginForm','MainTabPanel'],
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('MyApp.view.Main'));
Ext.Viewport.add(Ext.create('MyApp.view.LoginForm'));
},
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();
}
}
);
}
});
Destroy the login panel, You don't really need it anymore...
success: function(response) {
var json = Ext.decode(response.responseText);
if (json.type == 'success') {
// LOAD THE DAMN SECOND VIEW HERE!
var paneltab = Ext.create('MyApp.view.MainTabPanel');
Ext.getCmp('loginForm').destroy();
Ext.Viewport.add(paneltab);
} else {
alert(json.value);
}
},
There are several problems here:
Your autoCreate rule uses an xtype: 'tabpanel' which will only ever create a vanilla Ext.TabPanel with no items in it. You'd need to assign an xtype attribute to your MyApp.view.MainTabPanel like xtype: 'mainTabPanel' and then use that xtype value in your autoCreate rule.
This then explains why this code won't work since this.getMainTabPanel() will return the wrong object. Simpler would be to just use Ext.Viewport.setActiveItem(paneltab).
In general, you usually don't want assign an id to a view (id: 'mainTabPanel'). Safer to just use an xtype to fetch it. Although you don't need it in this case, avoiding global id's allows you to create multiple instances of a view (or any other class type).

How to add a form xtype sencha touch 2.0

Currently I am teaching myself Sencha Touch 2.0 and I am encountering a problem with adding a xtype called test to my viewport.
The test class is extending "Ext.form.Panel'" the problem is that no form shows up in my view and sencha also doesn't give any errors. When I extend "Ext.Panel" and set a html attribute this does show up. Can someone tell me what i am doing wrong ?
Viewport file
Ext.define('App.view.Viewport', {
extend: 'Ext.viewport.Default',
config: {
scrollable: true,
fullscreen:true,
items:[
{
xtype: "panel",
items: [
{
xtype:"toolbar",
title:"Test App"
},
{
xtype:"panel",
items: [
{
xtype:"test"
}
]
}
]
}
]
}
});
Controller file
//Define controller name
Ext.define('App.controller.User', {
//Extend the controller class
extend: 'Ext.app.Controller',
//define associated views with this controller
views: ['user.Test'],
init: function()
{
//do something and setup listeners
//setup listeners
}
});
View File
Ext.define('App.view.user.Test', {
extend: 'Ext.form.Panel',
alias: 'widget.test',
config: {
items: [
{
xtype: 'textfield',
name: 'name',
label: 'Name'
},
{
xtype: 'emailfield',
name: 'email',
label: 'Email'
},
{
xtype: 'passwordfield',
name: 'password',
label: 'Password'
}
]
},
initialize: function() {
console.log('initialize home view');
this.callParent();
}
});
Simply specify
xtype: 'test'
in your App.view.user.Test definition
I have got it sorted. Have a look at:
http://www.sencha.com/forum/showthread.php?191765-My-Ext.form.Panel-object-does-not-want-to-show&p=767689#post767689

Resources