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

44 lines
1.1 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';
import { FileInfoModel } from 'models/file-info-model';
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-18 10:17:09 +02:00
initialize() {},
2015-12-06 21:32:41 +01:00
2019-08-18 10:17:09 +02:00
load() {
return SettingsStore.load('file-info').then(data => {
if (data) {
2019-08-16 23:05:39 +02:00
this.reset(data, { silent: true });
}
});
},
2019-08-18 10:17:09 +02:00
save() {
2015-12-06 21:32:41 +01:00
SettingsStore.save('file-info', this.toJSON());
},
2019-08-18 10:17:09 +02:00
getLast() {
2015-12-07 22:20:18 +01:00
return this.first();
2015-12-07 20:07:56 +01:00
},
2019-08-18 10:17:09 +02:00
getMatch(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
},
2019-08-18 10:17:09 +02:00
getByName(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
2019-09-15 14:16:32 +02:00
export { FileInfoCollection };