mirror of https://github.com/keeweb/keeweb.git
file save view
This commit is contained in:
parent
60dd443117
commit
5d823b959c
|
@ -355,6 +355,12 @@ var AppModel = Backbone.Model.extend({
|
|||
Storage.cache.remove(id);
|
||||
this.fileInfos.remove(id);
|
||||
this.fileInfos.save();
|
||||
},
|
||||
|
||||
syncFile: function(file, options, callback) {
|
||||
if (file.get('syncing')) {
|
||||
return callback('Sync in progress');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -216,26 +216,6 @@ var FileModel = Backbone.Model.extend({
|
|||
}
|
||||
},
|
||||
|
||||
autoSave: function(complete) {
|
||||
var that = this;
|
||||
that.set('syncing', true);
|
||||
var storage = Storage[that.get('storage')];
|
||||
if (storage) {
|
||||
that.getData(function(data) {
|
||||
storage.save(that.get('path'), data, function (err) {
|
||||
if (err) {
|
||||
that.set('syncing', false);
|
||||
} else {
|
||||
that.saved(that.get('path'), that.get('storage'));
|
||||
}
|
||||
if (complete) { complete(err); }
|
||||
});
|
||||
});
|
||||
} else {
|
||||
throw 'Unknown storage; cannot auto save';
|
||||
}
|
||||
},
|
||||
|
||||
getData: function(cb) {
|
||||
this.db.cleanup({
|
||||
historyRules: true,
|
||||
|
@ -255,7 +235,6 @@ var FileModel = Backbone.Model.extend({
|
|||
this.forEachEntry({}, function(entry) {
|
||||
entry.unsaved = false;
|
||||
});
|
||||
this.addToLastOpenFiles();
|
||||
},
|
||||
|
||||
setPassword: function(password) {
|
||||
|
|
|
@ -368,13 +368,14 @@ var OpenView = Backbone.View.extend({
|
|||
},
|
||||
|
||||
openDb: function() {
|
||||
if (!this.busy) {
|
||||
this.$el.toggleClass('open--opening', true);
|
||||
this.inputEl.attr('disabled', 'disabled');
|
||||
this.busy = true;
|
||||
this.params.password = this.passwordInput.value;
|
||||
this.afterPaint(this.model.openFile.bind(this.model, this.params, this.openDbComplete.bind(this)));
|
||||
if (this.busy || !this.params.name) {
|
||||
return;
|
||||
}
|
||||
this.$el.toggleClass('open--opening', true);
|
||||
this.inputEl.attr('disabled', 'disabled');
|
||||
this.busy = true;
|
||||
this.params.password = this.passwordInput.value;
|
||||
this.afterPaint(this.model.openFile.bind(this.model, this.params, this.openDbComplete.bind(this)));
|
||||
},
|
||||
|
||||
openDbComplete: function(err) {
|
||||
|
@ -382,6 +383,7 @@ var OpenView = Backbone.View.extend({
|
|||
this.$el.toggleClass('open--opening', false);
|
||||
this.inputEl.removeAttr('disabled').toggleClass('input--error', !!err);
|
||||
if (err) {
|
||||
console.error('Error opening file', err);
|
||||
this.inputEl.focus();
|
||||
this.inputEl[0].selectionStart = 0;
|
||||
this.inputEl[0].selectionEnd = this.inputEl.val().length;
|
||||
|
|
|
@ -18,7 +18,7 @@ var SettingsAboutView = Backbone.View.extend({
|
|||
'click .settings__file-button-save-default': 'saveDefault',
|
||||
'click .settings__file-button-save-file': 'saveToFile',
|
||||
'click .settings__file-button-export-xml': 'exportAsXml',
|
||||
'click .settings__file-button-save-dropbox': 'saveToDropboxClick',
|
||||
'click .settings__file-button-save-dropbox': 'saveToDropbox',
|
||||
'click .settings__file-button-close': 'closeFile',
|
||||
'change #settings__file-key-file': 'keyFileChange',
|
||||
'mousedown #settings__file-file-select-link': 'triggerSelectFile',
|
||||
|
@ -104,10 +104,33 @@ var SettingsAboutView = Backbone.View.extend({
|
|||
return true;
|
||||
},
|
||||
|
||||
save: function(arg) {
|
||||
var that = this;
|
||||
if (!arg) {
|
||||
arg = {};
|
||||
}
|
||||
arg.startedByUser = true;
|
||||
if (!arg.skipValidation) {
|
||||
var isValid = this.validatePassword(function() {
|
||||
arg.skipValidation = true;
|
||||
that.save(arg);
|
||||
});
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.appModel.syncFile(this.model, arg, function(err) {
|
||||
if (err) {
|
||||
console.error('Error saving file', err);
|
||||
} else {
|
||||
that.passwordChanged = false;
|
||||
}
|
||||
that.render();
|
||||
});
|
||||
},
|
||||
|
||||
saveDefault: function() {
|
||||
// TODO: save
|
||||
//that.passwordChanged = false;
|
||||
//that.model.saved(path, 'file');
|
||||
this.save();
|
||||
},
|
||||
|
||||
saveToFile: function(skipValidation) {
|
||||
|
@ -145,58 +168,14 @@ var SettingsAboutView = Backbone.View.extend({
|
|||
}).bind(this));
|
||||
},
|
||||
|
||||
saveToDropboxClick: function() {
|
||||
var nameChanged = this.model.get('path') !== this.model.get('name') + '.kdbx',
|
||||
canOverwrite = !nameChanged;
|
||||
this.saveToDropbox(canOverwrite);
|
||||
},
|
||||
|
||||
saveToDropbox: function(overwrite) {
|
||||
if (this.model.get('syncing') || !this.validatePassword()) {
|
||||
return;
|
||||
}
|
||||
saveToDropbox: function() {
|
||||
var that = this;
|
||||
this.model.getData(function(data) {
|
||||
var fileName = that.model.get('name') + '.kdbx';
|
||||
that.model.set('syncing', true);
|
||||
that.render();
|
||||
DropboxLink.authenticate(function(err) {
|
||||
if (err) {
|
||||
that.model.set('syncing', false);
|
||||
that.render();
|
||||
return;
|
||||
}
|
||||
DropboxLink.saveFile(fileName, data, overwrite, function (err) {
|
||||
if (err) {
|
||||
that.model.set('syncing', false);
|
||||
that.render();
|
||||
if (err.exists) {
|
||||
Alerts.alert({
|
||||
header: 'Already exists',
|
||||
body: 'File ' + fileName + ' already exists in your Dropbox.',
|
||||
icon: 'question',
|
||||
buttons: [{result: 'yes', title: 'Overwrite it'}, {result: '', title: 'I\'ll choose another name'}],
|
||||
esc: '',
|
||||
click: '',
|
||||
enter: 'yes',
|
||||
success: that.saveToDropbox.bind(that, true),
|
||||
cancel: function () {
|
||||
that.$el.find('#settings__file-name').focus();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Alerts.error({
|
||||
header: 'Save error',
|
||||
body: 'Error saving to Dropbox: \n' + err
|
||||
});
|
||||
}
|
||||
} else {
|
||||
that.passwordChanged = false;
|
||||
that.model.saved(fileName, 'dropbox');
|
||||
that.render();
|
||||
}
|
||||
});
|
||||
});
|
||||
DropboxLink.authenticate(function(err) {
|
||||
if (err) {
|
||||
that.render();
|
||||
return;
|
||||
}
|
||||
this.save({ storage: 'dropbox' });
|
||||
});
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue