1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    7
    Vote Rating
    0
    sharadchandra02 is on a distinguished road

      0  

    Default How to append Url

    How to append Url


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



    }

    });

  2. #2
    Sencha User
    Join Date
    Apr 2012
    Posts
    13
    Vote Rating
    0
    vipsshan is on a distinguished road

      0  

    Default


    Quote Originally Posted by sharadchandra02 View Post
    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

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    28
    Vote Rating
    0
    gcw07 is on a distinguished road

      0  

    Default


    If your store is setup something like this:

    Code:
    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:

    Code:
    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.

  4. #4
    Sencha User
    Join Date
    Apr 2012
    Posts
    13
    Vote Rating
    0
    vipsshan is on a distinguished road

      0  

    Default


    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

  5. #5
    Sencha User
    Join Date
    Mar 2012
    Posts
    28
    Vote Rating
    0
    gcw07 is on a distinguished road

      0  

    Default


    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.

  6. #6
    Sencha User
    Join Date
    Apr 2012
    Posts
    13
    Vote Rating
    0
    vipsshan is on a distinguished road

      0  

    Default


    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:"User@domain.com",
    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

  7. #7
    Sencha User
    Join Date
    Mar 2012
    Posts
    28
    Vote Rating
    0
    gcw07 is on a distinguished road

      0  

    Default


    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.

  8. #8
    Sencha User
    Join Date
    Apr 2012
    Posts
    13
    Vote Rating
    0
    vipsshan is on a distinguished road

      0  

    Default


    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

  9. #9
    Sencha User
    Join Date
    Mar 2012
    Posts
    28
    Vote Rating
    0
    gcw07 is on a distinguished road

      0  

    Default


    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.

    Code:
        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.

  10. #10
    Sencha User
    Join Date
    Mar 2012
    Posts
    28
    Vote Rating
    0
    gcw07 is on a distinguished road

      0  

    Default


    I'm not sure what you are asking on this other one. Can I get a little better explanation of what you are wanting?

Thread Participants: 2