2015-10-17 23:49:24 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var Backbone = require('backbone');
|
|
|
|
|
|
|
|
var AppSettingsModel = Backbone.Model.extend({
|
|
|
|
defaults: {
|
2015-10-19 23:24:32 +02:00
|
|
|
theme: 'd',
|
2015-10-24 21:06:44 +02:00
|
|
|
lastOpenFile: ''
|
2015-10-17 23:49:24 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
initialize: function() {
|
2015-10-24 21:06:44 +02:00
|
|
|
this.listenTo(this, 'change', this.save);
|
2015-10-17 23:49:24 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
load: function() {
|
|
|
|
if (typeof localStorage !== 'undefined' && localStorage.appSettings) {
|
|
|
|
try {
|
|
|
|
var data = JSON.parse(localStorage.appSettings);
|
2015-10-24 21:06:44 +02:00
|
|
|
this.set(data, { silent: true });
|
2015-10-17 23:49:24 +02:00
|
|
|
} catch (e) { /* failed to load settings */ }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
save: function() {
|
|
|
|
if (typeof localStorage !== 'undefined') {
|
|
|
|
localStorage.appSettings = JSON.stringify(this.attributes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AppSettingsModel.instance = new AppSettingsModel();
|
|
|
|
AppSettingsModel.instance.load();
|
|
|
|
|
|
|
|
module.exports = AppSettingsModel;
|