fix #157: option to disable storage providers

This commit is contained in:
Antelle 2016-03-13 20:33:25 +03:00
parent 4d4b0b3fab
commit c18539833b
8 changed files with 63 additions and 4 deletions

View File

@ -25,7 +25,10 @@ var AppSettingsModel = Backbone.Model.extend({
hideEmptyFields: false,
skipHttpsWarning: false,
demoOpened: false,
dropboxAppKey: null
dropbox: true,
webdav: true,
gdrive: false,
onedrive: false
},
initialize: function() {

View File

@ -1,6 +1,7 @@
'use strict';
var Launcher = require('../comp/launcher');
var Launcher = require('../comp/launcher'),
AppSettingsModel = require('../models/app-settings-model');
var Storage = {
file: require('./storage-file'),
@ -11,4 +12,13 @@ var Storage = {
cache: Launcher ? require('./storage-file-cache') : require('./storage-cache')
};
_.forEach(Storage, function(prv, name) {
if (!prv.system) {
var enabled = AppSettingsModel.instance.get(name);
if (typeof enabled === 'boolean') {
prv.enabled = enabled;
}
}
});
module.exports = Storage;

View File

@ -111,6 +111,7 @@ var Locale = {
openNew: 'New',
openMore: 'More',
openDemo: 'Demo',
openSettings: 'Settings',
openCaps: 'Caps Lock is on',
openKeyFile: 'key file',
openKeyFileDropbox: '(from dropbox)',
@ -259,6 +260,7 @@ var Locale = {
setGenMinInstead: 'Minimize app instead of close',
setGenLockMinimize: 'Auto-lock on minimize',
setGenLockCopy: 'Auto-lock on password copy',
setGenStorage: 'Storage',
setGenAdvanced: 'Advanced',
setGenDevTools: 'Show dev tools',

View File

@ -25,6 +25,7 @@ var OpenView = Backbone.View.extend({
'click .open__icon-demo': 'createDemo',
'click .open__icon-more': 'toggleMore',
'click .open__icon-storage': 'openStorage',
'click .open__icon-settings': 'openSettings',
'click .open__pass-input[readonly]': 'openFile',
'input .open__pass-input': 'inputInput',
'keydown .open__pass-input': 'inputKeydown',
@ -472,6 +473,10 @@ var OpenView = Backbone.View.extend({
this.$el.find('.open__icons--lower').toggleClass('hide');
},
openSettings: function() {
Backbone.trigger('toggle-settings');
},
openStorage: function(e) {
if (this.busy) {
return;

View File

@ -7,6 +7,7 @@ var Backbone = require('backbone'),
AppSettingsModel = require('../../models/app-settings-model'),
UpdateModel = require('../../models/update-model'),
RuntimeInfo = require('../../comp/runtime-info'),
Storage = require('../../storage'),
FeatureDetector = require('../../util/feature-detector'),
Locale = require('../../util/locale'),
Links = require('../../const/links');
@ -31,6 +32,7 @@ var SettingsGeneralView = Backbone.View.extend({
'click .settings__general-restart-btn': 'restartApp',
'click .settings__general-download-update-btn': 'downloadUpdate',
'click .settings__general-update-found-btn': 'installFoundUpdate',
'change .settings__general-prv-check': 'changeStorageEnabled',
'click .settings__general-dev-tools-link': 'openDevTools'
},
@ -75,7 +77,8 @@ var SettingsGeneralView = Backbone.View.extend({
updateFound: updateFound,
updateManual: updateManual,
releaseNotesLink: Links.ReleaseNotes,
colorfulIcons: AppSettingsModel.instance.get('colorfulIcons')
colorfulIcons: AppSettingsModel.instance.get('colorfulIcons'),
storageProviders: this.getStorageProviders()
});
},
@ -116,6 +119,23 @@ var SettingsGeneralView = Backbone.View.extend({
}
},
getStorageProviders: function() {
var storageProviders = [];
Object.keys(Storage).forEach(function(name) {
var prv = Storage[name];
if (!prv.system) {
storageProviders.push(prv);
}
});
storageProviders.sort(function(x, y) { return (x.uipos || Infinity) - (y.uipos || Infinity); });
return storageProviders.map(function(sp) {
return {
name: sp.name,
enabled: sp.enabled
};
});
},
changeTheme: function(e) {
var theme = e.target.value;
AppSettingsModel.instance.set('theme', theme);
@ -207,6 +227,14 @@ var SettingsGeneralView = Backbone.View.extend({
Backbone.trigger('refresh');
},
changeStorageEnabled: function(e) {
var storage = Storage[$(e.target).data('storage')];
if (storage) {
storage.enabled = e.target.checked;
AppSettingsModel.instance.set(storage.name, storage.enabled);
}
},
openDevTools: function() {
if (Launcher) {
Launcher.openDevTools();

View File

@ -50,7 +50,7 @@ var SettingsView = Backbone.View.extend({
},
returnToApp: function() {
Backbone.trigger('toggle-settings');
Backbone.trigger('toggle-settings', false);
}
});

View File

@ -38,6 +38,10 @@
<div class="open__icon-text">{{res 'openDemo'}}</div>
</div>
{{/if}}
<div class="open__icon open__icon-settings">
<i class="fa fa-cog open__icon-i"></i>
<div class="open__icon-text">{{res 'openSettings'}}</div>
</div>
</div>
<div class="open__pass-area">
<div class="open__pass-warn-wrap">

View File

@ -111,6 +111,13 @@
<label for="settings__general-lock-on-copy">{{res 'setGenLockCopy'}}</label>
</div>
<h2>{{res 'setGenStorage'}}</h2>
{{#each storageProviders as |prv|}}
<h3><input type="checkbox" id="settings__general-prv-check-{{prv.name}}" class="settings__general-prv-check"
data-storage="{{prv.name}}" {{#if prv.enabled}}checked{{/if}}
/><label for="settings__general-prv-check-{{prv.name}}">{{res prv.name}}</label></h3>
{{/each}}
{{#if devTools}}
<h2>{{res 'setGenAdvanced'}}</h2>
<a class="settings__general-dev-tools-link">{{res 'setGenDevTools'}}</a>