From 8093279b957369ae5999029d35586915f3cba011 Mon Sep 17 00:00:00 2001 From: antelle Date: Sun, 31 Jul 2016 10:47:56 +0300 Subject: [PATCH] allow to add multiple files --- app/scripts/models/app-model.js | 24 +++++++++++++----------- app/scripts/util/locale.js | 1 + app/scripts/views/open-view.js | 3 +++ util/config-example.json | 4 ++-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/scripts/models/app-model.js b/app/scripts/models/app-model.js index e71257de..a9bcb890 100644 --- a/app/scripts/models/app-model.js +++ b/app/scripts/models/app-model.js @@ -72,17 +72,19 @@ var AppModel = Backbone.Model.extend({ applyUserConfig(config) { this.settings.set(config.settings); - if (config.file && config.file.storage && config.file.name && config.file.path) { - if (!this.fileInfos.getMatch(config.file.storage, config.file.name, config.file.path)) { - var fileInfo = new FileInfoModel({ + if (config.files) { + config.files + .filter(file => file && file.storage && file.name && file.path && + !this.fileInfos.getMatch(file.storage, file.name, file.path)) + .map(file => new FileInfoModel({ id: IdGenerator.uuid(), - name: config.file.name, - storage: config.file.storage, - path: config.file.path, - opts: config.file.options - }); - this.fileInfos.unshift(fileInfo); - } + name: file.name, + storage: file.storage, + path: file.path, + opts: file.options + })) + .reverse() + .forEach(fi => this.fileInfos.unshift(fi)); } }, @@ -358,7 +360,7 @@ var AppModel = Backbone.Model.extend({ logger.info('Load from storage'); storage.load(params.path, params.opts, (err, data, stat) => { if (err) { - if (fileInfo) { + if (fileInfo && fileInfo.openDate) { logger.info('Open file from cache because of storage load error', err); that.openFileFromCache(params, callback, fileInfo); } else { diff --git a/app/scripts/util/locale.js b/app/scripts/util/locale.js index fe769eb6..1ef5c7db 100644 --- a/app/scripts/util/locale.js +++ b/app/scripts/util/locale.js @@ -169,6 +169,7 @@ var Locale = { openConfigErrorNotFound: 'File not found', openError: 'Error', openErrorDescription: 'There was an error opening file', + openErrorFileNotFound: 'File not found', detAttDownload: 'Shift-click attachment button to download or ', detAttDelToRemove: 'Delete to remove', diff --git a/app/scripts/views/open-view.js b/app/scripts/views/open-view.js index c54deff4..ca39b1a5 100644 --- a/app/scripts/views/open-view.js +++ b/app/scripts/views/open-view.js @@ -471,6 +471,9 @@ var OpenView = Backbone.View.extend({ this.inputEl[0].selectionStart = 0; this.inputEl[0].selectionEnd = this.inputEl.val().length; if (err.code !== 'InvalidKey') { + if (err.notFound) { + err = Locale.openErrorFileNotFound; + } Alerts.error({ header: Locale.openError, body: Locale.openErrorDescription + '' diff --git a/util/config-example.json b/util/config-example.json index f0fff109..a1b690a8 100644 --- a/util/config-example.json +++ b/util/config-example.json @@ -35,10 +35,10 @@ "onedrive": true, "onedriveClientId": null }, - "file": { + "files": [{ "storage": "webdav", "name": "", "path": "", "options": { "user": "", "password": "" } - } + }] }