keeweb/app/scripts/collections/file-info-collection.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-01-31 07:50:28 +01:00
const Backbone = require('backbone');
const FileInfoModel = require('../models/file-info-model');
const SettingsStore = require('../comp/settings-store');
2015-12-06 21:32:41 +01:00
2017-01-31 07:50:28 +01:00
const FileInfoCollection = Backbone.Collection.extend({
2015-12-06 21:32:41 +01:00
model: FileInfoModel,
2019-08-16 23:05:39 +02:00
initialize: function() {},
2015-12-06 21:32:41 +01:00
2019-08-16 23:05:39 +02:00
load: function() {
return SettingsStore.load('file-info').then(data => {
if (data) {
2019-08-16 23:05:39 +02:00
this.reset(data, { silent: true });
}
});
},
2019-08-16 23:05:39 +02:00
save: function() {
2015-12-06 21:32:41 +01:00
SettingsStore.save('file-info', this.toJSON());
},
2019-08-16 23:05:39 +02:00
getLast: function() {
2015-12-07 22:20:18 +01:00
return this.first();
2015-12-07 20:07:56 +01:00
},
2019-08-16 23:05:39 +02:00
getMatch: function(storage, name, path) {
2016-07-17 13:30:38 +02:00
return this.find(fi => {
2019-08-16 23:05:39 +02:00
return (
(fi.get('storage') || '') === (storage || '') &&
2015-12-07 20:07:56 +01:00
(fi.get('name') || '') === (name || '') &&
2019-08-16 23:05:39 +02:00
(fi.get('path') || '') === (path || '')
);
2015-12-07 20:07:56 +01:00
});
2015-12-10 22:31:47 +01:00
},
2015-12-13 15:59:41 +01:00
getByName: function(name) {
2016-07-17 13:30:38 +02:00
return this.find(file => file.get('name').toLowerCase() === name.toLowerCase());
2015-12-06 21:32:41 +01:00
}
});
2017-02-05 20:28:17 +01:00
FileInfoCollection.instance = new FileInfoCollection();
2015-12-06 21:32:41 +01:00
module.exports = FileInfoCollection;