1. #1
    Ext GWT Premium Member
    Join Date
    Apr 2010
    Posts
    9
    Vote Rating
    0
    legege is on a distinguished road

      0  

    Question LocalStorage for Application Settings, and remove

    Hi,

    I'm trying to store application settings in a the browser (HTML5 local storage) and I have difficulties to figure out a way to load and save settings without getting more than Store item. What I'm really trying to achieve is to have a single "Account" object, that gets updated with a settings FormPanel (and when the application launches the first time, the user is automatically prompted for settings). I haven't been able to find a way to reuse a Model, so I decided to go with a non-reusable Model: when the user save settings, the app delete the old Model and create a new one. But, for a strange reason, the Model never gets deleted...

    Here is an example. The account object is still in the Local Storage at the end.

    Code:
    Ext.setup({
        icon: 'icon.png',
        tabletStartupScreen: 'tablet_startup.png',
        phoneStartupScreen: 'phone_startup.png',
        glossOnIcon: false,
    
        onReady: function() {
            Ext.regModel('Account', {
                fields: [
                    {name: 'username', type: 'string'},
                    {name: 'password', type: 'password'}
                ],
    
                proxy: {
                    type: 'localstorage',
                    id  : 'testapp-account'
                }
            });
           
            var store = new Ext.data.Store({
                model: "Account"
            });
            store.load();
    
            var account = store.first();
            if (!account) {
              store.add({username: 'test', password: '12345'});
              store.sync();
    
              account = store.first();
            }
    
            store.remove(account);
            store.sync();
       }
    });
    Thanks for your help.

  2. #2
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    692
    Vote Rating
    12
    mrsunshine will become famous soon enough

      0  

    Default

    I did a user setting saving in localstorage in my chat example application. it also shows the settings dialogbif no data is stored.

    me it help you to look n the code of my app

    https://github.com/mrsunshine/Mobile...s---socket.io-

  3. #3
    Ext GWT Premium Member
    Join Date
    Apr 2010
    Posts
    9
    Vote Rating
    0
    legege is on a distinguished road

      0  

    Default

    Thanks for this. I try, but it looks like you have the same problem I have. Removing configuration doesn't work, it looks like a Sencha Touch bug.

    Steps to reproduce with your App:
    1. Clean localstorage, launch app
    2. Save settings
    3. Reload app
    4. Go to settings, change something, save
    5. The localstorage now contains 2 items...

    Code:
    chat-settings-counter: 2
    chat-settings-2: {"server":"localhost","nickname":"test125","email":"me@example.com","gravatar":"..."}
    chat-settings-1: {"server":"localhost","nickname":"test123","email":"me@example.com","gravatar":"..."}
    chat-settings: 1,2

  4. #4
    Sencha User
    Join Date
    Apr 2010
    Posts
    4
    Vote Rating
    0
    chummy is on a distinguished road

      0  

    Default

    It seems you have to add a field with name "id" and type "int" to your model. This field gets populated by sencha touch and from a quick look at the code it seems that the remove function uses this field to identify the model instance to remove.

    Hope it helps.

    Chummy

  5. #5
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    692
    Vote Rating
    12
    mrsunshine will become famous soon enough

      0  

    Default

    Yes, it work, thanks

  6. #6
    Sencha User
    Join Date
    Feb 2012
    Posts
    3
    Vote Rating
    0
    jianbinjblin is on a distinguished road

      0  

    Default Still have problem when update then delete. The data in localstorage can't be load

    1. The localstorage is empty:
    2. Insert 3 records into localstorage:
    3.Update a record, then the "clients" going wrong:
    4.Delete the record updated:
    5.The data in localstorage can't be load automatically.
    l1.jpgl2.jpgl3.jpgl4.jpg
    Last edited by jianbinjblin; 2 Jun 2012 at 3:25 PM. Reason: Images pasted are losted.

Similar Threads

  1. Localstorage help
    By tfrugia in forum Sencha Touch 1.x: Discussion
    Replies: 3
    Last Post: 16 Jun 2011, 9:27 AM
  2. Extjs and localStorage
    By manilodisan in forum Community Discussion
    Replies: 5
    Last Post: 18 Dec 2010, 1:14 AM
  3. Localstorage help
    By tfrugia in forum Sencha Touch 1.x: Discussion
    Replies: 0
    Last Post: 29 Nov 2010, 2:39 PM
  4. how to remove records with localstorage?
    By emm in forum Sencha Touch 1.x: Discussion
    Replies: 4
    Last Post: 3 Sep 2010, 3:20 AM
  5. application settings
    By mnask79 in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 28 Nov 2008, 3:30 PM

Thread Participants: 3

Tags for this Thread