diff --git a/app/scripts/models/app-model.js b/app/scripts/models/app-model.js index 42119675..b2945a7f 100644 --- a/app/scripts/models/app-model.js +++ b/app/scripts/models/app-model.js @@ -340,7 +340,7 @@ class AppModel { return filter; } - getFirstSelectedGroup() { + getFirstSelectedGroupForCreation() { const selGroupId = this.filter.group; let file, group; if (selGroupId) { @@ -351,7 +351,7 @@ class AppModel { }); } if (!group) { - file = this.files[0]; + file = this.files.find(f => f.active && !f.readOnly); group = file.groups[0]; } return { group, file }; @@ -391,7 +391,7 @@ class AppModel { } createNewEntry(args) { - const sel = this.getFirstSelectedGroup(); + const sel = this.getFirstSelectedGroupForCreation(); if (args && args.template) { if (sel.file !== args.template.file) { sel.file = args.template.file; @@ -409,12 +409,12 @@ class AppModel { } createNewGroup() { - const sel = this.getFirstSelectedGroup(); + const sel = this.getFirstSelectedGroupForCreation(); return GroupModel.newGroup(sel.group, sel.file); } createNewTemplateEntry() { - const file = this.getFirstSelectedGroup().file; + const file = this.getFirstSelectedGroupForCreation().file; const group = file.getEntryTemplatesGroup() || file.createEntryTemplatesGroup(); return EntryModel.newEntry(group, file); } @@ -1184,6 +1184,10 @@ class AppModel { }); return device; } + + canCreateEntries() { + return this.files.some(f => f.active && !f.readOnly); + } } export { AppModel }; diff --git a/app/scripts/models/external/external-device-model.js b/app/scripts/models/external/external-device-model.js index 3a251352..871699b8 100644 --- a/app/scripts/models/external/external-device-model.js +++ b/app/scripts/models/external/external-device-model.js @@ -22,6 +22,7 @@ class ExternalDeviceModel extends Model { ExternalDeviceModel.defineModelProperties({ id: '', external: true, + readOnly: true, active: false, entries: undefined, groups: undefined, diff --git a/app/scripts/views/details/details-fields.js b/app/scripts/views/details/details-fields.js index 98e9e7f7..4270e397 100644 --- a/app/scripts/views/details/details-fields.js +++ b/app/scripts/views/details/details-fields.js @@ -55,8 +55,11 @@ function createDetailsFields(detailsView) { }) ); } else { - if (model.isJustCreated && AppModel.instance.files.length > 1) { - const fileNames = AppModel.instance.files.map(file => { + const writeableFiles = AppModel.instance.files.filter( + file => file.active && !file.readOnly + ); + if (model.isJustCreated && writeableFiles.length > 1) { + const fileNames = writeableFiles.map(file => { return { id: file.id, value: file.name, selected: file === model.file }; }); fieldViews.push( diff --git a/app/scripts/views/list-search-view.js b/app/scripts/views/list-search-view.js index b07828a9..68a34a08 100644 --- a/app/scripts/views/list-search-view.js +++ b/app/scripts/views/list-search-view.js @@ -127,6 +127,7 @@ class ListSearchView extends View { this.listenTo(Events, 'filter', this.filterChanged); this.listenTo(Events, 'set-locale', this.setLocale); this.listenTo(Events, 'page-blur', this.pageBlur); + this.listenTo(this.model.files, 'change', this.fileListUpdated); this.once('remove', () => { this.removeKeypressHandler(); @@ -176,7 +177,8 @@ class ListSearchView extends View { } super.render({ adv: this.advancedSearch, - advEnabled: this.advancedSearchEnabled + advEnabled: this.advancedSearchEnabled, + canCreate: this.model.canCreateEntries() }); this.inputEl = this.$el.find('.list__search-field'); if (searchVal) { @@ -422,6 +424,10 @@ class ListSearchView extends View { addArrow(str) { return str.replace('{}', '→'); } + + fileListUpdated() { + this.render(); + } } export { ListSearchView }; diff --git a/app/styles/areas/_list.scss b/app/styles/areas/_list.scss index ceb963d0..1f767b4c 100644 --- a/app/styles/areas/_list.scss +++ b/app/styles/areas/_list.scss @@ -45,6 +45,7 @@ &-field-wrap { flex: 1; position: relative; + margin-right: $small-spacing; } &-field { width: 100%; @@ -72,7 +73,6 @@ } &-btn-new { @include icon-btn; - margin-left: $small-spacing; } &-btn-sort { @include icon-btn; diff --git a/app/templates/list-search.hbs b/app/templates/list-search.hbs index 0d07b750..768ce2df 100644 --- a/app/templates/list-search.hbs +++ b/app/templates/list-search.hbs @@ -10,7 +10,7 @@ -
+