keeweb/app/scripts/models/update-model.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2015-10-29 22:20:01 +01:00
'use strict';
var Backbone = require('backbone');
var UpdateModel = Backbone.Model.extend({
defaults: {
lastSuccessCheckDate: null,
lastCheckDate: null,
lastVersion: null,
lastVersionReleaseDate: null,
2015-11-13 20:56:22 +01:00
lastCheckError: null,
2015-10-29 22:20:01 +01:00
status: null,
updateStatus: null,
2015-11-14 16:28:36 +01:00
updateError: null,
updateManual: false
2015-10-29 22:20:01 +01:00
},
initialize: function() {
},
load: function() {
if (localStorage.updateInfo) {
try {
var data = JSON.parse(localStorage.updateInfo);
_.each(data, function(val, key) {
if (/Date$/.test(key)) {
data[key] = val ? new Date(val) : null;
2015-10-29 22:20:01 +01:00
}
});
this.set(data, { silent: true });
} catch (e) { /* failed to load model */ }
}
},
save: function() {
var attr = _.clone(this.attributes);
2015-11-14 16:28:36 +01:00
Object.keys(attr).forEach(function(key) {
if (key.lastIndexOf('update', 0) === 0) {
delete attr[key];
}
});
2015-10-29 22:20:01 +01:00
localStorage.updateInfo = JSON.stringify(attr);
}
});
UpdateModel.instance = new UpdateModel();
UpdateModel.instance.load();
module.exports = UpdateModel;