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

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-09-15 14:16:32 +02:00
import Backbone from 'backbone';
import { SettingsStore } from 'comp/settings/settings-store';
2015-10-29 22:20:01 +01:00
2017-01-31 07:50:28 +01:00
const UpdateModel = Backbone.Model.extend({
2015-10-29 22:20:01 +01:00
defaults: {
lastSuccessCheckDate: null,
lastCheckDate: null,
lastVersion: null,
lastVersionReleaseDate: null,
2015-11-13 20:56:22 +01:00
lastCheckError: null,
2016-01-17 21:34:40 +01:00
lastCheckUpdMin: 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
},
2019-08-18 10:17:09 +02:00
initialize() {},
2015-10-29 22:20:01 +01:00
2019-08-18 10:17:09 +02:00
load() {
return SettingsStore.load('update-info').then(data => {
if (data) {
try {
_.each(data, (val, key) => {
if (/Date$/.test(key)) {
data[key] = val ? new Date(val) : null;
}
});
2019-08-16 23:05:39 +02:00
this.set(data, { silent: true });
} catch (e) {
/* failed to load model */
}
}
});
},
2019-08-18 10:17:09 +02:00
save() {
2017-01-31 07:50:28 +01:00
const attr = _.clone(this.attributes);
2016-07-17 13:30:38 +02:00
Object.keys(attr).forEach(key => {
2015-11-14 16:28:36 +01:00
if (key.lastIndexOf('update', 0) === 0) {
delete attr[key];
}
});
2015-12-05 14:57:43 +01:00
SettingsStore.save('update-info', attr);
2015-10-29 22:20:01 +01:00
}
});
UpdateModel.instance = new UpdateModel();
2019-09-15 14:16:32 +02:00
export { UpdateModel };