1. #1
    Ext User
    Join Date
    Oct 2010
    Location
    Aachen
    Posts
    18
    Vote Rating
    0
    Applelunatic is on a distinguished road

      0  

    Question Store Applications Settings

    Store Applications Settings


    Hi Experts!

    I want to store this kind of settings on the phone:

    Objecttyp1 = on/off
    Objecttyp2 = on/off
    .
    .

    Code:
    var settingsModel = Ext.regModel('mysettings', {
                fields: [
                    {name: "name", type: 'string'},
                    {name: "state", type: 'boolean'}
                        ]
                });
    In a view I want to change the settings like here:

    Code:
    var settingsFormBase = {
                scroll: 'vertical',
                url   : '<c:url value='/logout.jsp'/>',
                standardSubmit : true,
                floating: true,                
                centered: true,
                modal : true,
                frame: true,
                width: Ext.is.Phone ? 320 : 400,
                height: Ext.is.Phone ? 320 : 400,
                items: [
                    {
                        xtype: 'button',
                        ui  : 'decline',
                        text: 'LOGOUT',
                        handler: function() {
                            settingsForm.submit();
                        }                                       
                    },
                    {
                        xtype: 'fieldset',
                        title: 'Layerauswahl',
                        instructions: 'Aktivierte Layer werden in der Karte dargestellt.',
                        defaults: {
                            required: false,
                            labelAlign: 'left'
                        },
                        items: [
                        {
                            xtype: 'togglefield',
                            name : 'Objecttyp1',
                            label: 'Objecttyp1'
                        },
                        {
                            xtype: 'togglefield',
                            name : 'Objecttyp2',
                            label: 'Objecttyp2'
                        },
                        ]
                    }
                ],    
                dockedItems: [
                    {
                        xtype: 'toolbar',
                        dock: 'bottom',
                        items: [
                            {xtype: 'spacer'},
                            {
                                text: 'Ok',
                                ui: 'confirm',
                                handler: function() {
                                    settingsForm.hide();
                                }
                            }
                        ]
                    }
                ]    
               
            };
    How can I do that smooth? Thanks for help!

  2. #2
    Sencha - Community Support Team jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    you can use cookies or local storage.

  3. #3
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    9
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    Best way is probably something like this:

    Code:
    Ext.regModel('Setting', {
        fields: ['name', 'state'],
        
        proxy: {
            type: 'localstorage',
            id  : 'app-settings'
        }
    });
    
    //store with autoLoad - pulls existing Setting instances out of localStorage
    var store = new Ext.data.Store({
        model: 'Setting',
        autoLoad: {
            callback: function(records) {
                //'records' is now all of the loaded Setting model instances
                console.log(records);
            }
        }
    });
    
    //add new settings
    store.add({name: 'someSetting', state: true});
    
    //saves to localStorage
    store.sync();
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  4. #4
    Ext User
    Join Date
    Oct 2010
    Location
    Aachen
    Posts
    18
    Vote Rating
    0
    Applelunatic is on a distinguished road

      0  

    Default


    @edspancer Thanks for your help and code! This is a good starting point for me. I tried your example, but all my setting records where added to the store like a INCERT statement. Is it possible to update a existing "setting" record in store? The console.log(records); are increase constantly.

    How would you update the togglefields in the "settingsFormBase"? (code above)

  5. #5
    Ext User
    Join Date
    Oct 2010
    Location
    Aachen
    Posts
    18
    Vote Rating
    0
    Applelunatic is on a distinguished road

      0  

    Default


    My code until now, but I get all records, not only the latest updated records.
    PHP Code:
    var records store.getUpdatedRecords();
                
    console.log('logme:'+records);
                for (
    i=0records.length;i++){
                    
                    
    settingsForm.add({xtype'togglefield'name records[i].data.namelabelrecords[i].data.namevalue records[i].data.state});
                };
                
    settingsForm.doLayout();             // refresh the layout 
    I would say there must be something missing like store.update({name: 'someSetting', state: false})).

  6. #6
    Ext JS Premium Member
    Join Date
    Oct 2010
    Posts
    68
    Vote Rating
    0
    iamcam is on a distinguished road

      0  

    Default


    I've run across a bug: when making the Model proxy id 'app-settings', the code will error, however changing the id to 'appsettings' fixes it. A bug report has been submitted, but I'm not sure if it has more to do with Sencha or a webkit local storage naming restriction.

  7. #7
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    9
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    Quote Originally Posted by iamcam View Post
    I've run across a bug: when making the Model proxy id 'app-settings', the code will error, however changing the id to 'appsettings' fixes it. A bug report has been submitted, but I'm not sure if it has more to do with Sencha or a webkit local storage naming restriction.
    Thanks - that seems legitimate
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

Similar Threads

  1. Project settings
    By mic.b in forum Sencha Animator Feature Requests
    Replies: 1
    Last Post: 22 Nov 2010, 1:46 AM
  2. Need Help on reset the settings for singleton GridPanel ColumnModel / Store
    By just_a_kid in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 13 Sep 2010, 7:50 AM
  3. [DEFER-927] Store's api settings.
    By Animal in forum Ext 3.x: Bugs
    Replies: 0
    Last Post: 3 May 2010, 3:04 AM
  4. Calling ext GWT applications from legacy applications
    By mathaj77 in forum Ext GWT: Discussion
    Replies: 3
    Last Post: 14 Aug 2009, 4:15 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