1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-20 06:56:40 +02:00
keeweb/app/scripts/collections/file-info-collection.js
2019-08-18 10:17:09 +02:00

44 lines
1.1 KiB
JavaScript

const Backbone = require('backbone');
const FileInfoModel = require('../models/file-info-model');
const SettingsStore = require('../comp/settings-store');
const FileInfoCollection = Backbone.Collection.extend({
model: FileInfoModel,
initialize() {},
load() {
return SettingsStore.load('file-info').then(data => {
if (data) {
this.reset(data, { silent: true });
}
});
},
save() {
SettingsStore.save('file-info', this.toJSON());
},
getLast() {
return this.first();
},
getMatch(storage, name, path) {
return this.find(fi => {
return (
(fi.get('storage') || '') === (storage || '') &&
(fi.get('name') || '') === (name || '') &&
(fi.get('path') || '') === (path || '')
);
});
},
getByName(name) {
return this.find(file => file.get('name').toLowerCase() === name.toLowerCase());
}
});
FileInfoCollection.instance = new FileInfoCollection();
module.exports = FileInfoCollection;