I have a rest api and for user authentication, the rest url is:
https://api.abc.com/user/{username}/{password}. So I need to set two parameters for the rest proxy. Can any one please help me?
Here is my User model:
Ext.define('NCAPP.model.User', {
extend:'Ext.data.Model',
config:{
fields:[
{ name:'id', type: 'int'},
{ name: 'username', type: 'string'},
{ name: 'netshop_id', type:'int'},
{ name: 'firstname', type: 'string'},
{ name: 'lastname', type: 'string'},
{ name: 'address', type: 'string'},
{ name:'password', type:'string'},
],
proxy: {
type:'rest',
url:https://api.abc.com/user/',
noCache: false,
reader: {
type:'json',
rootProperty:'user'
}
}
}
});
And here is my LoginController on loginbuttion tap function:
onLoginButtonTap:function(){
var values=this.getLoginForm().getValues();
Ext.ModelMgr.getModel('NCAPP.model.User').load(values.username,{
success: function(user){
if(user==null)
{
Ext.Msg.alert('NCAPP',"Invalid username or password!");
}
else
{
Ext.Msg.alert('NCAPP','Welcome! '+user.get('username'));
//do after login implementation
}
},
failure: function(user){
console.log("Uff, Something went worng!");
}
});
},
In the following line, i want to pass user name and password:
Ext.ModelMgr.getModel('NCAPP.model.User').load(values.username, values.password, {.....
Can anyone help me achieving this goal?
You can use the method "setProxy" to add dynamically a proxy to your model/Store.
var values = this.getLoginForm().getValues();
YOURMODEL.setProxy({
proxy: {
type: 'rest',
url: 'https://api.abc.com/user/'+ values.username +'/'+ values.password,
noCache: false,
reader: {
type: 'json',
rootProperty: 'user'
}
}
});
Related
In my model, I have the following code:
Ext.define('Proximity.model.CandidateblocklistModel', {
extend: 'Ext.data.Model',
requires: ['Ext.data.proxy.LocalStorage'],
config: {
store:'Proximity.store.CandidateblockStore',
fields: [
{ name: 'id', type: 'id' },
{ name: 'name', type: 'string' },
{ name: 'img', type: 'string' },
{ name: 'designation', type: 'string' },
{ name: 'summary', type: 'string' },
{ name: 'experience', type: 'string' },
{ name: 'industry', type: 'string' },
{ name: 'functionnml', type: 'string' },
{ name: 'role', type: 'string' }
],
proxy : {
type : 'ajax',
url : Proximity.util.Config.getBaseUrl() + '/index.php/candidate/getcandidateblock',
withCredentials: false,
useDefaultXhrHeader: false,
extraParams: {
"id": localStorage.getItem('id')
},
reader : {
filters: [
Ext.create('Ext.util.Filter', {
property: 'name'
})
]
}
}
}
});
The id in the local storage is already set before calling this model. I can see the id in localStorage by inspect element in Chrome, and I did get the value of it in other section. But I only can't get it in my model when I am trying to use it in proxy. I want to get data from my web service based on the value of the localStorage.
Code in my proxy:
extraParams: {
"id": localStorage.getItem('id')
},
I want to get the id from localStorage here.
Please help me.
I think the following code works
proxy : {
type : 'ajax',
url : Proximity.util.Config.getBaseUrl() + '/index.php/candidate/getcandidatebest',
withCredentials: false,
useDefaultXhrHeader: false,
extraParams: {
id: localStorage.getItem('id')
},
reader : {
filters: [
Ext.create('Ext.util.Filter', {
property: 'ind_id',
property: 'fun_id',
property: 'role_id',
property: 'id'
})
]
}
}
and then use the filtering facility of store to pass the localstorage value. To do that give filter permission remoteFilter: true, this.
Ahh i found an awesome trick. Instate of setting extraParams in your Model, set it in the store of the same model.
My new code is as follows.
Ext.define('Proximity.model.RecruiterbestlistModel', {
extend: 'Ext.data.Model',
config: {
store:'Proximity.store.RecruiterbestStore',
fields: [
{ name: 'id', type: 'int' },
{ name: 'name', type: 'string' },
{ name: 'img', type: 'string' },
{ name: 'company', type: 'string' },
{ name: 'summary', type: 'string' },
{ name: 'address', type: 'string' },
{ name: 'industry', type: 'string' },
{ name: 'functionnml', type: 'string' },
{ name: 'role', type: 'string' }
],
proxy : {
type : 'ajax',
url : Proximity.util.Config.getBaseUrl() + '/index.php/recruiter/getrecruiterbest/',
withCredentials: false,
useDefaultXhrHeader: false,
reader : {
filters: [
Ext.create('Ext.util.Filter', {
property: 'ind_id',
property: 'fun_id',
property: 'role_id'
})
]
}
}
}
});
Look i have removed the code
extraParams: {
"id": localStorage.getItem('id')
},
from Model. And in my store i have added
listeners: {
beforeload: function(store){
this.getProxy().setExtraParams({
id: localStorage.getItem('id')
});
return true;
},
So my new store code is as follows
Ext.define('Proximity.store.RecruiterbestStore', {
extend: 'Ext.data.Store',
alias: 'store.recruiterbeststore',
config: {
model: 'Proximity.model.RecruiterbestlistModel',
autoLoad: true,
remoteFilter: true,
storeId: 'recruiterbeststore'
},
listeners: {
beforeload: function(store){
this.getProxy().setExtraParams({
id: localStorage.getItem('id')
});
return true;
}
}
});
And its solved my problem.
But now i am having another issue. after running sencha app build native(using cordova bild), again i am having same issue, the extraParam are not added to proxy request.
Please help me to solve this.
Who knows how to filter the Store right?
I tried to do it in listener of leafItemTap of Nested List, but my leaf items not tapping now. Massage in console: "Uncaught TypeError: Cannot call method 'filter' of undefined "
Here is Nested list, where Store must be filtered:
Ext.define('Application.view.SplitView', {
extend: 'Ext.Container',
xtype: 'splitview',
config: {
layout: 'card',
store: null
},
initialize: function() {
this.nestedList = Ext.create('Ext.NestedList', {
title : 'Рецепты',
detailCard: Ext.create('Application.view.MainDetail'),
store: this.getStore(),
listeners: {
scope: this,
leafitemtap: this.onLeafItemTap
}
});
this.setItems([this.nestedList]);
},
updateStore: function(newStore) {
if (this.nestedList) {
this.nestedList.setStore(newStore);
}
},
onLeafItemTap: function(nestedList, list, index, node, record, e) {
var psn = record.get('text');
console.log(psn);
var detailCard = nestedList.getDetailCard();
var store = Ext.getStore('Application.store.DetailStore');
store.filter('title', 'Brownies');
console.log(store);
}
});
This is my Store, which I want to filter:
Ext.define('Application.store.DetailStore', {
extend: 'Ext.data.Store',
config: {
model: 'Application.model.DetailModel',
autoLoad :true,
sorters: 'title',
grouper : function(record) {
return record.get('title')[0];
},
proxy: {
type: 'ajax',
url : '/data/data1.php',
reader: {
type: 'json',
rootProperty:'recipes'}
}
}
});
And Store's model:
Ext.define('Application.model.DetailModel', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'title', type: 'string'},
{name: 'serves', type: 'string'},
{name: 'cooktime', type: 'string'},
{name: 'ingridients', type: 'string'},
{name: 'picture', type: 'string'},
{name: 'kitchen', type: 'string'},
{name: 'category', type: 'string'},
{name: 'instructions', type: 'string'}
]
},
fullName: function() {
var d = this.data,
names = [
d.title
];
return names.join(" ");
}
});
I'm new in Sencha and every advice will be useful
The following error means the object which you're calling the filter function on is undefined
"Uncaught TypeError: Cannot call method 'filter' of undefined "
In your case, the store is undefined.
Try to get it by doing :
var store = Ext.getStore('DetailStore');
Also, you could check what stores are in the StoreManager by doing :
console.log(Ext.data.StoreManager.all);
Hope this helps
My problem is... I have a list who is completed by a store and this store comes from a proxy (json). When i clik in a item of the list i need a detail information, and this detail information comes from anothe json.
For example:
ArtistList and ArtistDetail
When i click in an item of artistList i need a call to
http://localhost/json-detail/45
if i click in another item...
http://localhost/json-detail/50 etc...
My problem is that i can't send the parameter to the other view... or maybe the error is in my concept of lists... :S
This is my list view:
var listaArtistas = {
xtype: 'list',
title: 'Artistas',
height: 240,
store: {
autoLoad: true,
fields: ['node'],
proxy: {
type: 'ajax',
url: 'http://localhost/json-artistas',
reader: {
type: 'json',
rootProperty: 'nodes'
}
}
},
listeners: {
itemtap: function(lista,index,target,record,e,eOpts)
{
var artistDetail = new Ext.create('app.view.ArtistDetail');
artistDetail.setArtistID('45');
panelHomeNav.push(artistDetail);
}
},
itemTpl: tpl
};
This is my detail:
Ext.define('app.view.ArtistDetail',{
extend: 'Ext.Panel',
xtype: 'artistdetail',
style: "background-image:url('/resources/images/fondoartista.png');",
config:{
title: 'Artistas',
iconCls: 'star',
ArtistID: '',
items:
{
title: 'Artistas',
items: [artistDetailPanelContenedor]
}
}});
And need something like this
var listaEspectaculo = {
xtype: 'list',
title: 'Artistas',
store:
{
autoLoad: true,
fields: ['node'],
proxy: {
type: 'ajax',
url: 'http://localhost/json-artistasdetail/'+getArtistID, <<<<<<<<<<------ PROBLEM
reader: {
type: 'json',
rootProperty: 'nodes'
}
}
},
listeners: {
itemtap: function(lista,index,target,record,e,eOpts)
{
var eventDetail = new Ext.create('app.view.EventDetail');
panelHomeNav.push(eventDetail);
}
},
itemTpl: tplEspectaculo
};
THx for help !!!
Maybe this could help:
How to pass value from controller to data store in sencha touch
handler: function () {
Ext.dispatch({
controller: MyApp.controllers.controller,
action: 'myActionOnController',
id: e.get{'id'}
});
}
You can call ext.dispatch from your "itemtap", then in the controller you can call a new view with you parameters, remember use something like this:
myActionOnController: function (options) {
var city = options.id; //if you want to use your parameters
var newView = Ext.create('MyApp.view.viewOfSomething');
this.getMain().push(newView);
},
how I add querystring in sencha touch?
?name=jake as
localhost/JSONDemo/XMLToJson.aspx?name=jake
My code is
Ext.regStore('NewsItems', {
model: 'NewsItem',
proxy: {
type: 'ajax',
url: 'XMLToJson.aspx',
reader: {
type: 'json',
root: 'liste.dokuman'
}
},
autoLoad: true
});
You can pass additional parameters using the extraParams property available with your proxy object. Here is an example:
Ext.regStore('NewsItems', {
model: 'NewsItem',
proxy: {
type: 'ajax',
url: 'XMLToJson.aspx',
extraParams: {
name: 'jack'
},
reader: {
type: 'json',
root: 'liste.dokuman'
}
},
autoLoad: true
});
I want to make a simple request like Ext.Ajax.request and display it in a list. But it does not work.
I have a URL like this
http://server/GetContacts.aspx?CustAccount=10019
Can someone tell me exactly how it works and what I should consider?
This is an example of what I get back.
{
"HasError": false,
"ErrorString": "",
"Data": [
{"ContactPersonId":"","Name":"","FirstName":"","MiddleName":"","LastName":"","Phone":"","CellularPhone":"","Telefax":"","Email":"","Url":"","Address":"","ZipCode":"","City":"","Street":"","Country":"","Function":""}
]
}
Ext.regModel('kunden', {
idProperty: 'id',
fields: [
{ name: 'ContactPersonId', type: 'string' },
.
.
.
{ name: 'Function', type: 'string' }
]
});
Ext.regStore('kundenStore', {
model: 'kunden',
sorters: [{
property: 'LastName'
}],
proxy: {
type: 'ajax',
url: 'http://server/GetContacts.aspx?CustAccount=10019'
},
reader: {
type: 'json',
root: 'Data'
}
});
NotesApp.views.kundenList = new Ext.List({
id: 'kundenList',
store: 'kundenStore',
grouped: true,
indexBar : true,
itemTpl: '<div class="list-item-title">{firstname} {lastname}</div>' +'<div class="list-item-narrative">{email}</div>',
listeners: {}
}
});
It can be so easily XP