save to dropbox

This commit is contained in:
antelle 2016-03-27 19:38:33 +03:00
parent 131a18aff0
commit cc95625c77
2 changed files with 49 additions and 42 deletions

View File

@ -210,6 +210,17 @@ var StorageDropbox = StorageBase.extend({
callback(null, fileList, dir);
});
});
},
remove: function(path, callback) {
var that = this;
that.logger.debug('Remove', path);
var ts = that.logger.ts();
path = that._toFullPath(path);
DropboxLink.deleteFile(path, function(err) {
that.logger.debug('Removed', path, that.logger.ts(ts));
return callback && callback(err);
}, _.noop);
}
});

View File

@ -9,6 +9,7 @@ var Backbone = require('backbone'),
Links = require('../../const/links'),
Format = require('../../util/format'),
Locale = require('../../util/locale'),
UrlUtil = require('../../util/url-util'),
kdbxweb = require('kdbxweb'),
FileSaver = require('filesaver');
@ -188,7 +189,7 @@ var SettingsFileView = Backbone.View.extend({
},
saveToStorage: function(e) {
if (this.model.get('syncing')) {
if (this.model.get('syncing') || this.model.get('demo')) {
return;
}
var storageName = $(e.target).closest('.settings__file-save-to-storage').data('storage');
@ -196,49 +197,44 @@ var SettingsFileView = Backbone.View.extend({
if (!storage) {
return;
}
Alerts.notImplemented();
var that = this;
if (that.model.get('storage') === storageName) {
that.save();
} else {
if (!storage.list) {
return Alerts.notImplemented();
}
that.model.set('syncing', true);
storage.list(function(err, files) {
that.model.set('syncing', false);
if (err) {
return;
}
var expName = that.model.get('name').toLowerCase();
var existingFile = _.find(files, function(file) {
return UrlUtil.getDataFileName(file.name).toLowerCase() === expName;
});
if (existingFile) {
Alerts.yesno({
header: Locale.setFileAlreadyExists,
body: Locale.setFileAlreadyExistsBody.replace('{}', that.model.escape('name')),
success: function() {
that.model.set('syncing', true);
storage.remove(existingFile.path, function(err) {
that.model.set('syncing', false);
if (!err) {
that.save({storage: storageName});
}
});
}
});
} else {
that.save({storage: storageName});
}
});
}
},
// saveToDropbox: function() {
// var that = this;
// this.model.set('syncing', true);
// DropboxLink.authenticate(function(err) {
// that.model.set('syncing', false);
// if (err) {
// return;
// }
// if (that.model.get('storage') === 'dropbox') {
// that.save();
// } else {
// that.model.set('syncing', true);
// DropboxLink.list('', function(err, files) { // TODO: replace with actual path
// that.model.set('syncing', false);
// if (!files) { return; }
// var expName = that.model.get('name').toLowerCase();
// var existingPath = files.filter(function(f) { return f.toLowerCase().replace('/', '') === expName; })[0];
// if (existingPath) {
// Alerts.yesno({
// icon: 'dropbox',
// header: Locale.setFileAlreadyExists,
// body: Locale.setFileAlreadyExistsBody.replace('{}', that.model.escape('name')),
// success: function() {
// that.model.set('syncing', true);
// DropboxLink.deleteFile(existingPath, function(err) {
// that.model.set('syncing', false);
// if (!err) {
// that.save({storage: 'dropbox'});
// }
// });
// }
// });
// } else {
// that.save({storage: 'dropbox'});
// }
// });
// }
// });
// },
closeFile: function() {
if (this.model.get('modified')) {
var that = this;