Results 1 to 10 of 10

Thread: baseUrl with selection in util.config

  1. #1
    Sencha User
    Join Date
    Nov 2014
    Posts
    47

    Default baseUrl with selection in util.config

    Under app.util.Config

    How can I use 2 different url for baseUrl? Is it possible to make it editable?

  2. #2
    Sencha Premium User
    Join Date
    May 2011
    Location
    Gainesville, FL
    Posts
    227

    Default

    Not sure what you're talking about.

  3. #3
    Sencha User
    Join Date
    Feb 2011
    Location
    Düsseldorf, Germany
    Posts
    599

    Default

    Sounds like you implemented a folder "util" inside the "app" folder and you added a file Config.js inside.
    Most likely this is a singleton.

    Can you post the code of that file, so that we can help?

  4. #4
    Sencha User
    Join Date
    Nov 2014
    Posts
    47

    Default

    Yes, that is what I want to do. In case of I want to use the same application but run at different network. If at home, use this url-a. When at another place, use this url-b.


    app/util/Config.json


    Code:
    Ext.define('app.util.Config', {
        singleton : true,
        config : {
    		baseUrl: 'http://website.com' <---need this url to be editable
        },
        constructor: function(config) {
            this.initConfig(config);
            this.callParent([config]);		
        }
    });
    Store/localstorage to keep url-a and url-b


    Code:
    Ext.define('app.store.UrlSetting', {
        extend: 'Ext.data.Store',
    	alias: 'store.UrlSetting',
    	
        requires: [
    		'app.model.UrlSetting'
        ],
        config: {	
            storeId: 'UrlSetting',
    		model: 'app.model.UrlSetting',
            autoLoad: true,
    		//localstorage proxy
    		proxy: {
    			type: 'localstorage',
    			id: 'urlsetting'
            }
        }
    });
    model:


    Code:
    Ext.define('app.model.UrlSetting', {
        extend: 'Ext.data.Model',
    	alias: 'model.UrlSetting',
    	
        config: {
               fields: [
               {
                  name: 'urlexternal'
               },
    		   {
                  name: 'urlinternal'
               }
               ]
         }
    });
    A view to edit/save both urls:


    Code:
    Ext.define('app.view.EditAddress', {
        extend: 'Ext.form.Panel',
    	//extend: 'Ext.Container',
    	alias: 'widget.editaddress',
    	
    	requires: [
            'Ext.dataview.List',
    		'Ext.form.Panel'
        ],
    	
        config: {
            itemId: 'editaddress',
    		title: 'Address Settings',
                    items: [
                        {
    							xtype: 'fieldset',
    							docked: 'top',
    							items: [
    								{
    									xtype: 'urlfield',
    									label: 'Url External',
    									labelWrap: true,
    									name: 'urlexternal',
    									placeHolder: 'http://example.com'
    								},
    								{
    									xtype: 'urlfield',
    									label: 'Url Internal',
    									labelWrap: true,
    									name: 'urlinternal',
    									placeHolder: 'http://example.com'
    								}								
    							]						
                        },
    					{
    						xtype: 'button',
    						itemId: 'save',
    						width: '30%',
    						text: 'Save'
    					}
                    ],
    				listeners: [
    					{
    					fn: 'onFormSave',
    					event: 'tap',
    					delegate: '#save'
    					}
    				]
        },
    	
    	onFormSave: function(button,e,options){
     
    		var formObj = button.up('editaddress');
    		var formData = formObj.getValues();
    		 
    		var usr = Ext.create('app.model.UrlSetting',{
    			 urlexternal:formData.urlexternal,
    			 urlinternal:formData.urlinternal
    		});
    		 
    		var errs = usr.validate();
    		var msg = '';
    		 
    		if (!errs.isValid()) {
    		   errs.each(function (err) {
    		   msg += err.getField() + ' : ' + err.getMessage() + '<br/>';
    		   });
    		 
    		   Ext.Msg.alert('ERROR', msg);
    		 
    		} else {
    			 var UrlSetting = Ext.getStore('UrlSetting');
    			 UrlSetting.add(usr);
    			 UrlSetting.sync();
    			  Ext.Msg.alert('SUCCESS', 'Data Saved Successfully');
    		}
     
    	}
    });


    This way, I can save both url in localstorage:


    Code:
    {"urlexternal":"http://url-a","urlinternal":"http://url-b","id":"ext-record-16"}
    Now, back to app/util/Config.json


    What to do next with this line???:


    Code:
    baseUrl: 'http://website.com' <---need this url to be editable
    How to refer it to data in localstorage? Please advice.

  5. #5
    Sencha User
    Join Date
    Feb 2011
    Location
    Düsseldorf, Germany
    Posts
    599

    Default

    You could use


    Code:
    Ext.define('app.util.Config', {
        singleton : true,
        alternateClassName: 'app.Config',
    
        config : {
            baseUrl: 'http://website.com',
            homeUrl: 'http://webiteAtHome.com',
            awayUrl: 'http://awayUrl.com'
        },
    
        constructor: function(config) {
            this.initConfig(config);
        },
    
        setUrl: function(isAtHome){
            this.setBaseUrl(isAtHome ? this.getHomeUrl() : this.getAwayUrl());
        }
    });
    Now, based on the location (which you need to grab from any LBS you could set the baseUrl using

    Code:
    app.Config.setUrl(true);

  6. #6
    Sencha User
    Join Date
    Nov 2014
    Posts
    47

    Default

    I did think of that way. That will mean a whole bunch of urls involve. And it is hardcoded.
    When url is changing, need to rebuild that app again.

    I am looking for a way that global url for references is customizeable. Meaning that only need to compile one app to cover a lot of locations. Just need to key in the url, then it is my baseUrl. Any idea?

  7. #7
    Sencha User
    Join Date
    Feb 2011
    Location
    Düsseldorf, Germany
    Posts
    599

    Default

    You would need to save a json file and grab that with an ajax call

    url.json
    Code:
    {
         "url": "myHomeUrl"
    }
    ajax call
    Code:
    Ext.Ajax.request({
        url: 'url.json',
    
        success: function (response) {
            var returnUrl = JSON.parse(response.responseText).url;
    
            app.Config.setBaseUrl(returnUrl);
        }
    });

  8. #8
    Sencha User
    Join Date
    Nov 2014
    Posts
    47

    Default

    Good idea.

    I think this might be a way to save a file:

    https://druckit.wordpress.com/2014/0...onegapcordova/

    http://blog.figleaf.com/2014/06/senc...nd-saving.html

    Any other sample code I can refer?

  9. #9
    Sencha User
    Join Date
    Feb 2011
    Location
    Düsseldorf, Germany
    Posts
    599

    Default

    If you just need to save the data, you can always go with localStorage too.Still I do not understand why you would like to write this to a file and where the problem is.On the first run you can initialize the value for the localStorage.You could grab the data from the server (Ajax call) and update the localStorage.Or the user enters an URL or you grab it from a web page, rss feed, what ever you like.

  10. #10
    Sencha User
    Join Date
    Nov 2014
    Posts
    47

    Default

    It is not just to save data. If it is, I already provide solution on my second post.
    I created a view and did store the url into localstorage.

    This is the data now in my localstorage:

    {"urlexternal":"http://url-a","urlinternal":"http://url-b","id":"ext-record-16"}

    The question is now how to put it in config?


    Ext.define('app.util.Config', { singleton : true, config : { baseUrl: 'How to call url I store in localstorage here????' <---need this url to be editable }, constructor: function(config) { this.initConfig(config); this.callParent([config]); }});

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •