PDA

View Full Version : How to append Url



sharadchandra02
27 Jul 2012, 12:50 AM
Hi,

How to append url in proxy ? My scenario are like below:
I have two variable strUsername and strPassword they contains values strUsername ="Doe" and strPassword "xyz".
url is :-http://10.4.3.199/FineDocsMobileServices/Service1.svc/{0}", "GetGNLogEN?
Now I want to append strUsername and strPassword's values in url
like :
http://10.4.3.199/FineDocsMobileServices/Service1.svc/{0}", "GetGNLogEN?Username="Doe" &Pd=xyz;

my codes are:-


Ext.application({
launch: function () {
Ext.create('Ext.List', {
fullscreen: true,

items: [{
xtype: 'toolbar',
docked: 'top',
title:'List',
//store:'Contacts',
itemTpl: '{Username}' +
'{Password}'

}]
}
);



Ext.define('Contacts', {
extend: 'Ext.data.Model',
config: {
fields: [{
name: 'Username',
type: 'string'
}, {
name: 'Password',
type: 'string'
}]
}
});
var store = Ext.create('Ext.data.Store', {
model:'Contacts',
proxy: {
type: 'jsonp',


url : 'http://localhost:51047/SenchaTest/Default.aspx?',//This is the part where i want to apend url for username and password
callbackKey: 'callback',
reader:{
type:"json",
rootProperty:"contacts"
}

},
autoLoad:true
});
store.load();



}

});

vipsshan
27 Jul 2012, 4:31 AM
Hi,

How to append url in proxy ? My scenario are like below:
I have two variable strUsername and strPassword they contains values strUsername ="Doe" and strPassword "xyz".
url is :-http://10.4.3.199/FineDocsMobileServices/Service1.svc/{0}", "GetGNLogEN?
Now I want to append strUsername and strPassword's values in url
like :
http://10.4.3.199/FineDocsMobileServices/Service1.svc/{0}", "GetGNLogEN?Username="Doe" &Pd=xyz;

my codes are:-


Ext.application({
launch: function () {
Ext.create('Ext.List', {
fullscreen: true,

items: [{
xtype: 'toolbar',
docked: 'top',
title:'List',
//store:'Contacts',
itemTpl: '{Username}' +
'{Password}'

}]
}
);



Ext.define('Contacts', {
extend: 'Ext.data.Model',
config: {
fields: [{
name: 'Username',
type: 'string'
}, {
name: 'Password',
type: 'string'
}]
}
});
var store = Ext.create('Ext.data.Store', {
model:'Contacts',
proxy: {
type: 'jsonp',


url : 'http://localhost:51047/SenchaTest/Default.aspx?',//This is the part where i want to apend url for username and password
callbackKey: 'callback',
reader:{
type:"json",
rootProperty:"contacts"
}

},
autoLoad:true
});
store.load();



}

});

_____________________________________________________________________________

Hi,

I have facing same problem could you please suggest us how to call url with different parameter.

Thanks & Regards
Vipin

gcw07
27 Jul 2012, 1:02 PM
If your store is setup something like this:



Ext.define('App.store.Jobs', {
extend: 'Ext.data.Store',

requires: [
'Ext.data.proxy.JsonP',
],

config: {
model: 'App.model.Job',
autoLoad: false,

proxy: {
type: 'jsonp',
url: 'http://www.someurl.com/jobs',

startParam: '',
pageParam: '',
limitParam: '',

extraParams: {
userName: false,
userPassword: false,
}
}
}
});Notice the extraParams section. That is where the extra variable names are set. Also notice there should be no "?" on the url. That will be added.

Then within your app, do something like this:


var jobsStore = Ext.getStore('Jobs');

// Apply the params to jobs store
jobsStore.getProxy().setExtraParam('userName', 'someusername');
jobsStore.getProxy().setExtraParam('userPassword', 'somepassword');
Then when you call your load method, it will send the information along with the request.

vipsshan
30 Jul 2012, 10:26 PM
Hi gcw07,

Thank you for your valuable solution.
But i have a small problem when i submit the button request data is not updated in first time if i again hit the button then it provides the correct result.

I think data is not updated in first time. please help me if i am missing ...

my store code is

Ext.define("NotesApp.store.Login", {
extend: "Ext.data.Store",
requires: [
'Ext.data.proxy.JsonP', "Ext.data.Model"
],

config: {
model: "NotesApp.model.Login",

proxy:{
type:"jsonp",

url:"http://10.4.3.199/SenchaTest/Default.aspx",
startParam: '',
pageParam: '',
limitParam: '',

extraParams: {
Un: false,
Pd: false

},

reader:{
type:"json",
rootProperty:"res"
}

},
autoLoad:true

}

});

and code of submit button event are:

var loginStore = Ext.getStore('Login');
// Apply the params to login store
loginStore.getProxy().setExtraParam('Un', txt);
loginStore.getProxy().setExtraParam('Pd', pwd);
loginStore.load();


Thanks & Regards
Vipin

gcw07
30 Jul 2012, 11:17 PM
Without seeing more of the code, my guess would be it is caused by your autoload in the store. With autoload set to true, when you call this "var loginStore = Ext.getStore('Login');", it actually is executing the load of the remote server without the extra parameters being set. Then you set the params and execute the load again, this time sending the request with the extra params as it should be. Try setting the autoload to false and see what happens.

vipsshan
31 Jul 2012, 2:16 AM
Hi gcw07,

Thanks for your quick response.
Here is given the detail code:
===================================================================
Store page
===================================================================
Ext.define("NotesApp.store.Login", {
extend: "Ext.data.Store",
requires: [
'Ext.data.proxy.JsonP', "Ext.data.Model"
],

config: {
model: "NotesApp.model.Login",

proxy:{
type:"jsonp",

url:"http://10.4.3.199/SenchaTest/Default.aspx",
startParam: '',
pageParam: '',
limitParam: '',

extraParams: {
Un: false,
Pd: false

},

reader:{
type:"json",
rootProperty:"res"
}

},
autoLoad:true

}

});
===================================================================
Model Page
===================================================================
Ext.define("NotesApp.model.Login", {
extend: "Ext.data.Model",
config: {
// idProperty: 'id',
fields: [
{ name: 'userName', type: 'string' },
{ name: 'userPassword', type: 'string' },
{ name: 'ret', type: 'string' },
{ name: 'UID', type: 'string' },
{ name: 'L', type: 'string' },
{ name: 'OldA', type: 'string' },
{ name: 'Un', type: 'string' },
{ name: 'Pd', type: 'string' }

],
validations: [
{ type: 'presence', field: 'user_name', message:"Please Enter the User Name" },
{ type: 'presence', field: 'password', message:"Please Enter the Password" }

]
}
});
===================================================================
View Page
===================================================================
Ext.define("NotesApp.view.Login", {
extend:"Ext.form.Panel",
requires:"Ext.form.FieldSet",
alias:"widget.login",
id:"userForm",
config:{
scrollable:"vertical"
},
initialize: function(){
this.callParent(arguments);

var toolbar = {
xtype:"toolbar",
title:"Login",
docked:"top",
layout: {
pack: 'center'
}
};
var loginField = {
xtype:"textfield",
//label:"User Name",
placeHolder:"[email protected]",
name:"userName",
id:"txt"
};

var passwordField = {
xtype:"passwordfield",
placeHolder:"password",
// label:"Password",
name:"userPassword",
id:"pwd"
};
var btnSubmit = {
xtype:"button",
text:"Submit",
ui:"confirm",
align:"center",
margin:"0 auto",
width:"90%",
height:"41px",
handler: this.onSubmitTap,
scope: this
};
this.add([toolbar, //loginStore,
{ xtype:"fieldset",
items:[loginField, passwordField]
},

{
xtype:"container",
layout:{
pack:"center"
},
items:[btnSubmit]
}
]);

},
onSubmitTap: function(){
//console.log("rrrrrrrrrr");
this.fireEvent("submitButtonCommand", this);

}

});

===================================================================
Control Page
===================================================================
In control page i am provide the code of submit button event handler


onSubmitButton: function(btn, evt){
// console.log("ssssssssssssss")


var txt = Ext.ComponentQuery.query('#txt')[0].getValue();
console.log(txt);
//
var pwd = Ext.ComponentQuery.query('#pwd')[0].getValue();
console.log(pwd);

var loginStore = Ext.getStore('Login');
// Apply the params to login store
loginStore.getProxy().setExtraParam('Un', txt);
loginStore.getProxy().setExtraParam('Pd', pwd);
loginStore.load();
// var ps=Ext.getStore('Login').getAt(0).get('userPassword');
var nm=Ext.getStore('Login').getAt(0).get('ret');
console.log("return value is="+nm);



//loginStore.load();
// if(txt==nm&&pwd==ps)
if(nm==1)
{

Ext.Msg.alert("Login in Successful");
this.activateLogin();
}
else{
nm = 0
// Ext.Msg.alert("Enter the correct User Name and password");
}
//this.activateLogin();

console.log("return is="+nm);

}


If possible Please help me .

Thanks & Regards
Vipin

gcw07
31 Jul 2012, 5:34 AM
Looking at your code, it appears you are creating a login script. So basically you have a form within the app where the user will type in there username and password then click the login button. It will check against the server logging them in or denying them. Are you controlling the server login script that you are comparing against? If you are, why pass the information via GET? Just seeing if there was a specific reason for that or not. If not I think you might be over complicating this.

vipsshan
1 Aug 2012, 12:28 AM
Hi gcw07,
Thanks for the response,
i also want to know how i replace the coding of proxy from store to controller, store is below:



Ext.define("NotesApp.store.Login", {




extend:"Ext.data.Store",
requires: [
"Ext.data.proxy.JsonP",
"Ext.data.Model"
],
autoLoad:true,
config:{
model:"NotesApp.model.Login",






proxy:{
//type:"ajax",
type:"jsonp",




url:'http://10.4.3.199/SenchaTest/Default.aspx',


startParam: '',
pageParam: '',
limitParam: '',


extraParams: {
Un:false,
Pd:false
},
listeners:{
exception:function(proxy, response, orientation){
console.error('Failure Notification', response.responseText);
Ext.Msg.alert('Loading failed', response.statusText);
}
} ,




reader:{
type:"json",
rootProperty:"res"


}


}




//autoLoad:true




}


});

i want to use the url in my controller in "OnSubmitButton" function.

Below is my controller:


onSubmitButton: function(btn, evt){
// console.log("ssssssssssssss")


var txt = Ext.ComponentQuery.query('#txt')[0].getValue();
console.log(txt);
//
var pwd = Ext.ComponentQuery.query('#pwd')[0].getValue();
console.log(pwd);

var loginStore = Ext.getStore('Login');
// Apply the params to login store
loginStore.getProxy().setExtraParam('Un', txt);
loginStore.getProxy().setExtraParam('Pd', pwd);
loginStore.load();
// var ps=Ext.getStore('Login').getAt(0).get('userPassword');
var nm=Ext.getStore('Login').getAt(0).get('ret');
console.log("return value is="+nm);



//loginStore.load();
// if(txt==nm&&pwd==ps)
if(nm==1)
{

Ext.Msg.alert("Login in Successful");
this.activateLogin();
}
else{
nm = 0
// Ext.Msg.alert("Enter the correct User Name and password");
}
//this.activateLogin();

console.log("return is="+nm);

}



Please suggest me......

Thanks & Regards

gcw07
1 Aug 2012, 7:32 AM
OK, like I said above, I think you are overcomplicating the login. You don't even need a store/model for it because your just sending off the username/password to verify that the data is legit.


onLoginTap: function() {
var values = this.getLoginPanel().getValues();

this.getLoginPanel().submit({
url : 'http://localhost/app/login.php',
waitMsg : {xtype: 'loadmask', message: 'Checking', cls: 'loading'},
success : function(action, response){
this.getLoginPanel().reset();
// response contains the json response from the server. So do something with that response here.
},
failure : function(action, response){
Ext.Msg.alert('Login', response.text, Ext.emptyFn);
},
scope : this
});
},This is all you need to send off a request and get a response from the server on something like login. This would be within a controller. You need to make sure to create refs for the loginPanel and setup the login tap reference and control within the config. The server also needs to set the "success" flag on the returned json response. So if the login info is correct, "success" would be set to true, if it isn't correct, set "success" to false.

gcw07
1 Aug 2012, 7:34 AM
I'm not sure what you are asking on this other one. Can I get a little better explanation of what you are wanting?

vipsshan
2 Aug 2012, 3:28 AM
Hi gcw07,

Thanks for your response.
Actually from the view I am calling the store.load function and in the store I am calling the web service and then based on the result I want to do some processing, It seems that when I am calling the store.load one thread goes there and another thread moves forward and at that point of time store is still having the old values so I can't perform the desired action. This will be more clear from the below piece of code

onSubmitButton: function(btn, evt){

//Getting the value from control to variable
var txt = Ext.ComponentQuery.query('#txt')[0].getValue();
var pwd = Ext.ComponentQuery.query('#pwd')[0].getValue();


//Creating the object of store
var loginStore = Ext.getStore('Login');


//passing the value for parameter
loginStore.getProxy().setExtraParam('Un', txt);
loginStore.getProxy().setExtraParam('Pd', pwd);
//Loading the store
loginStore.load();

//Trying to to get the value which has been returned from web service to store

var nm=Ext.getStore('Login').getAt(0).get('ret');

//Based the value trying to call another page or show error message
if(nm==1)
{
this.activateNotesList();
}
else{
Ext.Msg.alert("Enter the correct User Name and password");
}
},

Here Immediately after load I am not getting the updated value, I need that programm should wait till it got the updated value I tried using IsLoading and IsLoaded function but unable to achieve the desired flow. Please help.....

Regards.

gcw07
2 Aug 2012, 11:34 AM
Not really sure what your asking. Like I previously said, I think your over complicating it. I think all you need is to use the submit and just submit the form to the server and get the response back.

Also remember that loading is asynchronous. So it will send of the request to load, but your script will continue on. So if you don't wait until it is fully loaded, it will not have the values from that loaded store.

vipsshan
2 Aug 2012, 9:48 PM
The wait is my problem, How to wait till I get the result that I don't know can you please help me out on that.