fix #94: warn user about local files

This commit is contained in:
Antelle 2016-02-23 09:08:57 +03:00
parent d5fedb8d97
commit b577faffdd
4 changed files with 59 additions and 5 deletions

View File

@ -18,7 +18,8 @@ var AppSettingsModel = Backbone.Model.extend({
tableView: false,
colorfulIcons: false,
lockOnMinimize: true,
helpTipCopyShown: false
helpTipCopyShown: false,
skipOpenLocalWarn: false
},
initialize: function() {

View File

@ -101,6 +101,12 @@ var Locale = {
openSelectFile: 'Select a file',
openSelectFileBody: 'Select a file from your Dropbox which you would like to open',
openPassFor: 'Password for',
openRemoveLastQuestion: 'Delete local file?',
openRemoveLastQuestionBody: 'The file you are deleting is stored only in browser. Delete it permanently?',
openLocalFile: 'Local file',
openLocalFileBody: 'You are going to open a local file. Changes you make will not be saved back to file system. ' +
'To get the file with your data, export it from settings.',
openLocalFileDontShow: 'Don\'t show this again',
detAttDownload: 'Shift-click attachment button to download or ',
detAttDelToRemove: 'Delete to remove',

View File

@ -86,9 +86,34 @@ var OpenView = Backbone.View.extend({
Backbone.View.prototype.remove.apply(this, arguments);
},
showLocalFileAlert: function() {
if (this.model.settings.get('skipOpenLocalWarn')) {
return;
}
var that = this;
Alerts.alert({
header: Locale.openLocalFile,
body: Locale.openLocalFileBody,
icon: 'file-text',
buttons: [
{result: 'skip', title: Locale.openLocalFileDontShow, error: true},
{result: 'ok', title: Locale.alertOk}
],
click: '',
esc: '',
enter: '',
success: function(res) {
if (res === 'skip') {
that.model.settings.set('skipOpenLocalWarn', true);
}
}
});
},
fileSelected: function(e) {
var file = e.target.files[0];
if (file) {
this.showLocalFileAlert();
this.processFile(file);
}
},
@ -192,15 +217,35 @@ var OpenView = Backbone.View.extend({
}
var id = $(e.target).closest('.open__last-item').data('id').toString();
if ($(e.target).is('.open__last-item-icon-del')) {
this.model.removeFileInfo(id);
this.$el.find('.open__last-item[data-id="' + id + '"]').remove();
this.initialize();
this.render();
var fileInfo = this.model.fileInfos.get(id);
if (!fileInfo.get('storage')) {
var that = this;
Alerts.yesno({
header: Locale.openRemoveLastQuestion,
body: Locale.openRemoveLastQuestionBody,
buttons: [
{result: 'yes', title: Locale.alertYes},
{result: '', title: Locale.alertNo}
],
success: function() {
that.removeFile(id);
}
});
return;
}
this.removeFile(id);
return;
}
this.showOpenFileInfo(this.model.fileInfos.get(id));
},
removeFile: function(id) {
this.model.removeFileInfo(id);
this.$el.find('.open__last-item[data-id="' + id + '"]').remove();
this.initialize();
this.render();
},
inputKeydown: function(e) {
var code = e.keyCode || e.which;
if (code === Keys.DOM_VK_RETURN) {
@ -255,6 +300,7 @@ var OpenView = Backbone.View.extend({
var dataFile = _.find(files, function(file) { return file.name.split('.').pop().toLowerCase() === 'kdbx'; });
var keyFile = _.find(files, function(file) { return file.name.split('.').pop().toLowerCase() === 'key'; });
if (dataFile) {
this.showLocalFileAlert();
this.setFile(dataFile, keyFile);
}
},

View File

@ -2,6 +2,7 @@ Release notes
-------------
##### v1.0.3 (TBD)
Hotfix
`+` #94: warn user about local files
`-` #92: save files on exit
`-` #95: unlock by opening settings