1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-27 07:45:08 +02:00
keeweb/app/scripts/models/update-model.js
Alex Shpak a9d3b08c49 Finished with async settings store,
Removed cloud drives from cordova
2017-02-04 19:31:26 +01:00

55 lines
1.4 KiB
JavaScript

'use strict';
const Backbone = require('backbone');
const SettingsStore = require('../comp/settings-store');
const UpdateModel = Backbone.Model.extend({
defaults: {
lastSuccessCheckDate: null,
lastCheckDate: null,
lastVersion: null,
lastVersionReleaseDate: null,
lastCheckError: null,
lastCheckUpdMin: null,
status: null,
updateStatus: null,
updateError: null,
updateManual: false
},
initialize: function() {
},
load: function() {
SettingsStore.load('update-info', this.onLoaded.bind(this));
},
onLoaded: function(data) {
if (data) {
try {
_.each(data, (val, key) => {
if (/Date$/.test(key)) {
data[key] = val ? new Date(val) : null;
}
});
this.set(data, { silent: true });
} catch (e) { /* failed to load model */ }
}
},
save: function() {
const attr = _.clone(this.attributes);
Object.keys(attr).forEach(key => {
if (key.lastIndexOf('update', 0) === 0) {
delete attr[key];
}
});
SettingsStore.save('update-info', attr);
}
});
UpdateModel.instance = new UpdateModel();
UpdateModel.instance.load();
module.exports = UpdateModel;