disallow opening same files twice

This commit is contained in:
Antelle 2015-12-02 23:50:31 +03:00
parent 6779044f13
commit e6f7429213
4 changed files with 17 additions and 3 deletions

View File

@ -16,6 +16,10 @@ var FileCollection = Backbone.Collection.extend({
getByName: function(name) {
return this.find(function(file) { return file.get('name') === name; });
},
getById: function(id) {
return this.find(function(file) { return file.get('id') === id; });
}
});

View File

@ -28,8 +28,13 @@ var AppModel = Backbone.Model.extend({
},
addFile: function(file) {
if (this.files.getById(file.get('id'))) {
return false;
}
this.files.add(file);
file.get('groups').forEach(function(group) { this.menu.groupsSection.addItem(group); }, this);
file.get('groups').forEach(function (group) {
this.menu.groupsSection.addItem(group);
}, this);
this._addTags(file.db);
this._tagsChanged();
this.menu.filesSection.addItem({
@ -39,6 +44,7 @@ var AppModel = Backbone.Model.extend({
file: file
});
this.refresh();
return true;
},
_addTags: function(group) {

View File

@ -13,6 +13,7 @@ var Backbone = require('backbone'),
var FileModel = Backbone.Model.extend({
defaults: {
id: '',
name: '',
keyFileName: '',
passwordLength: 0,
@ -122,7 +123,7 @@ var FileModel = Backbone.Model.extend({
kdbxweb.Kdbx.load(demoFile, credentials, (function(db) {
this.db = db;
this.readModel();
this.setOpenFile({passwordLength: 4, demo: true, name: 'Demo'});
this.setOpenFile({passwordLength: 4, demo: true, name: 'Demo' });
}).bind(this));
},
@ -145,6 +146,7 @@ var FileModel = Backbone.Model.extend({
readModel: function(topGroupTitle) {
var groups = new GroupCollection();
this.set({
id: this.db.getDefaultGroup().uuid.toString(),
groups: groups,
defaultUser: this.db.meta.defaultUser,
recycleBinEnabled: this.db.meta.recycleBinEnabled,

View File

@ -80,7 +80,9 @@ var OpenView = Backbone.View.extend({
},
fileOpenChanged: function() {
this.model.addFile(this.file);
if (!this.model.addFile(this.file)) {
this.trigger('cancel');
}
},
fileOpeningChanged: function() {