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.