1. #31
    Sencha User
    Join Date
    Sep 2011
    Posts
    23
    Vote Rating
    0
    eryx is on a distinguished road

      0  

    Default


    Hi thanks again I think I'm on the right path now. The whole naming thing is not a big deal i just made a model that reflects the names exactly from the xml. Maybe in a later point I can try to figure out how I could change this. For now I made a new model and a store with an xml proxy. I'm able to load the whole data into the store.

    My model
    PHP Code:
    Ext.define('swissunihockey.model.Test', {
        
    extend'Ext.data.Model',

        
    config: {
            
    fields: [
                {
                    
    name'id',// Every model must start with an id of type int
                    
    type'int'
                
    }, {
                    
    name'title',
                    
    type'string'
                
    }, {
                    
    name'link',
                    
    type'string'
                
    }, {
                    
    name'description',
                    
    type'string',
                }, {
                    
    name'pubDate',
                    
    type'int'
                
    }, {
                    
    name'bildgross',
                    
    type'string'
                
    }, {
                    
    name'bildklein',
                    
    type'string'
                
    }
            ]
        }
    }); 
    And my store

    PHP Code:
    Ext.define('swissunihockey.store.Test', {
        
    extend'Ext.data.Store',
        
    requires: [
            
    'swissunihockey.model.Test',
            
    'Ext.data.reader.Xml'
        
    ],
        
    config: {
            
    model'swissunihockey.model.Test',
            
    proxy: {
                
    type'ajax',
                
    url'http://swissunihockey.xservice.ch/xml/newsdata.aspx',
                
    reader: {
                    
    type'xml',
                    
    record'item',
                    
    rootProperty'xml'
                
    }
            }
        }
    }); 
    So now I need to copy this in an store with a model that has the type sqlitestorage?

    Again thank you so much for your help I really appreciate it!

    Greetings eryx

  2. #32
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    502
    Vote Rating
    51
    shepsii has a spectacular aura about shepsii has a spectacular aura about shepsii has a spectacular aura about

      0  

    Default


    Hey eryx, great stuff. I think that mapping would fairly easily deal with the difference but if it's nothing to you it doesn't matter. I think the names look better in german anyway!!

    So now you need to create a new store with the sqlite proxy on it, and copy across the data.

    I've done exactly this in a project myself - I've copied the code below.

    All you need to do is run this code when the XML store has loaded, and you've created the sqlite store (you might be better off giving these stores different names... but whatever).

    The listener here is useful as I don't hide the loading dialog from the user until this listener fires - I don't want them thinking the whole load/save thing has finished before I can guarantee that the data is now in the database.

    Code:
    var writeListener = function(targetStore) {
          sqliteStore.un('write', writeListener, this);
          
          // you can put some code here that you want to run when the sqlite store has saved to the db successfully
        };
        
        sqliteStore.removeAll();
        xmlStore.each(function(record) {
          sqliteStore.add(record);
        });
        
        sqliteStore.on('write', writeListener, this);
        sqliteStore.sync();

  3. #33
    Sencha User
    Join Date
    Sep 2011
    Posts
    23
    Vote Rating
    0
    eryx is on a distinguished road

      0  

    Default


    WoW that was easy! Just used your posted code and now I got the data in the db!
    Will need to clean up my whole code and then I can post the full solution for future questions related to that.
    Thank you so much! Now I'm happy

    greetings Eryx

  4. #34
    Sencha - Services Team Stju's Avatar
    Join Date
    Dec 2008
    Location
    Redwood city, California
    Posts
    290
    Vote Rating
    3
    Stju is on a distinguished road

      0  

    Default


    Found a bug:
    Add new person, click to edit, rename to something else, tap save. data is updated in db, but List is not synced.

  5. #35
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    502
    Vote Rating
    51
    shepsii has a spectacular aura about shepsii has a spectacular aura about shepsii has a spectacular aura about

      0  

    Default


    Which ST2 version is that on?

    A workaround would be to save the phantom record first, and add it to the store after it's been saved. The issue is it's being added to the list before it has an id; when the record is saved to sqlite it's given an id, and then touch tries to update the list, but because there's no id... no match and no update.

    It's an annoying bug... let me have a look into how localstorage deals with this.

    Also, you could just reload the store after every write operation but with large data sets that will come with overhead.

  6. #36
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    502
    Vote Rating
    51
    shepsii has a spectacular aura about shepsii has a spectacular aura about shepsii has a spectacular aura about

      0  

    Default


    So the exact same issue happens if you use the localstorage proxy... the bug here is in the demo app, not the sqlite proxy, and the workaround is simple as explained... just save the record and add it to the store on the save record callback (this is incidentally why the proxy must go on the record - I've encountered this issue before!!)

    No record should ever go into a store unless it has an id, and it just so happens that if Sencha Touch uses IDs related to the local storage protocol (be it web storage or sqlite db) those are not created until the record has been saved. IMO a store should be able to handle phantom records and have some way of updating phantom records that are now saved in the store's dataviews, but that's an issue for the base code.

  7. #37
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    502
    Vote Rating
    51
    shepsii has a spectacular aura about shepsii has a spectacular aura about shepsii has a spectacular aura about

      0  

    Default


    Running into loads of issues trying to build production/testing apps with this thing... will see what solutions I can come up with.

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

      0  

    Default


    Quote Originally Posted by shepsii View Post
    Running into loads of issues trying to build production/testing apps with this thing... will see what solutions I can come up with.
    After you fix the other day to the proxy I had no problems building production and package versions of my app. Now I did have loads of errors trying to build production version of the sqlite demo.

  9. #39
    Sencha User
    Join Date
    Jan 2012
    Location
    London, UK
    Posts
    502
    Vote Rating
    51
    shepsii has a spectacular aura about shepsii has a spectacular aura about shepsii has a spectacular aura about

      0  

    Default


    Hey, which branch from github could you package up without any issues? Very keen to hear! I'll sort this tomorrow. Had one of those days where nothing goes right aggh!

    What errors do you get now? For me (on windows) I get a dom level 18 exception on build.

    *EDIT: bizarrely it does however let me build the demo. IDKWTFIGOH. I just made that up. But the IGOH means is going on here, you should be able to work out the rest ;-)

    Will take another look tomorrow but any help on what works / did work would be great.

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

      0  

    Default


    I unfortunately never had any luck building the demo on any version of it. I just had luck building my own app which uses the sqlite proxy. When trying to build the sqlite demo app I was also getting those DOM 18 errors. I kind of gave up trying to get a build working because I needed to fix other things with my app and phonegap.