1. #1
    Sencha User
    Join Date
    Mar 2012
    Location
    Tunisia
    Posts
    74
    Vote Rating
    0
    zied jouini is on a distinguished road

      0  

    Default Unanswered: Add in Local Storage

    Unanswered: Add in Local Storage


    SALAM
    I try to use local storge of sencha touch from many days but i don't find a solution.
    here is my store:

    Code:
    Ext.regStore('NotesStore', {
        model: 'NoteModel',
        sorters: [{
            property: 'date',
            direction: 'DESC'
        }],
        proxy: {
            type: 'localstorage',
            id: 'notes-app-store'
        },
        getGroupString: function (record) {
            if (record && record.data.date) {
                return record.get('date').toDateString();
            } else {
                return '';
            }
        }
    });
    App.stores.notesStore = Ext.StoreMgr.get('NotesStore');
    and my model:
    Code:
    Ext.regModel('NoteModel', {
        idProperty: 'id',
        fields: [
            { name: 'id', type: 'int' },
            { name: 'date', type: 'date', dateFormat: 'c' },
            { name: 'title', type: 'string' },
            { name: 'narrative', type: 'string' }
        ],
        validations: [
            { type: 'presence', field: 'id' },
            { type: 'presence', field: 'title', message: 'Please enter a title for this note.' }
        ]
    });
    and my view:

    Code:
    App.views.NoteEditorView = Ext.extend(Ext.form.FormPanel, {
    
    
        items: [{
            xtype: 'textfield',
            name: 'title',
            label: 'Title',
            required: true
        }, {
            xtype: 'textareafield',
            name: 'narrative',
            label: 'Narrative'
        }]
    });
    Ext.reg('NoteEditorView', App.views.NoteEditorView);
    and in my controller file i add:
    Code:
    // editer action
    editer: function()
    {
        
            this.editerView = this.render({
                xtype: 'NoteEditorView',
            });
    
    
    var backBtn = this.application.viewport.query('#backBtn')[0];
    backBtn.show(); 
    backBtn.setHandler(function(){
         Ext.dispatch({
            controller: 'Home',
            action: 'list',
            historyUrl: 'Home/list',
           animation: {
            type: 'slide',
            reverse: true,
        },
    
    
        });
    });
    
    
    var nouv = this.application.viewport.query('#nouv')[0];
    nouv.hide();
    
    
    var save = this.application.viewport.query('#save')[0];
    save.show();
    save.setHandler(function(){
    alert ("add begin");
    var currentNote = App.views.NoteEditorView.getRecord();
    App.views.NoteEditorView.updateRecord(currentNote);
    var errors = currentNote.validate();
            if (!errors.isValid()) {
    			currentNote.reject();
                Ext.Msg.alert('Wait!', errors.getByField('title')[0].message, Ext.emptyFn);
                return;
            }
    
    
            if (null == App.stores.notesStore.findRecord('id', currentNote.data.id)) {
                App.stores.notesStore.add(currentNote);
               
            } else {
                 currentNote.setDirty();
            }
    
    
            App.stores.notesStore.sync();
             alert ("add done");
            App.stores.notesStore.sort([{ property: 'date', direction: 'DESC'}]);
    
    
            App.views.NoteList.refreshList();
    
    
    
    
         Ext.dispatch({
            controller: 'Home',
            action: 'list',
            historyUrl: 'Home/list',
           animation: {
            type: 'slide',
            reverse: true,
                       },
    
    
                     });
    
    
    
    
    });
    
    
    
    
    
    
        this.application.viewport.setActiveItem(this.editerView);
    },
    when i execute this code the first alert appear:
    alert ("add begin");
    but the second aler don't appear
    alert ("add done");
    I think that my call to the store is wrong, but i don't know how correct it
    how can i fix it please
    thank you.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    34,107
    Vote Rating
    453
    Answers
    3155
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    Have any errors?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Location
    Tunisia
    Posts
    74
    Vote Rating
    0
    zied jouini is on a distinguished road

      0  

    Default


    SALAM
    No i haven't any error. i work with notepad it don't show me any message. my call to Stor is it correct ? or what kind of modification have i to do ?