PDA

View Full Version : Store Applications Settings



Applelunatic
26 Nov 2010, 2:31 AM
Hi Experts!

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

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


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:



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!

jay@moduscreate.com
26 Nov 2010, 7:54 AM
you can use cookies or local storage.

edspencer
26 Nov 2010, 6:24 PM
Best way is probably something like this:



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();

Applelunatic
29 Nov 2010, 2:49 AM
@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)

Applelunatic
30 Nov 2010, 2:30 AM
My code until now, but I get all records, not only the latest updated records.


var records = store.getUpdatedRecords();
console.log('logme:'+records);
for (i=0; i < records.length;i++){

settingsForm.add({xtype: 'togglefield', name : records[i].data.name, label: records[i].data.name, value : records[i].data.state});
};
settingsForm.doLayout(); // refresh the layout

I would say there must be something missing like store.update({name: 'someSetting', state: false})).

iamcam
7 Feb 2011, 12:23 PM
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.

edspencer
7 Feb 2011, 1:55 PM
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