fixed entry creation on a yubikey

This commit is contained in:
antelle 2020-05-09 23:55:57 +02:00
parent 3cd9bf6505
commit db31e65cdf
No known key found for this signature in database
GPG Key ID: 094A2F2D6136A4EE
6 changed files with 24 additions and 10 deletions

View File

@ -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 };

View File

@ -22,6 +22,7 @@ class ExternalDeviceModel extends Model {
ExternalDeviceModel.defineModelProperties({
id: '',
external: true,
readOnly: true,
active: false,
entries: undefined,
groups: undefined,

View File

@ -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(

View File

@ -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 };

View File

@ -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;

View File

@ -10,7 +10,7 @@
<i class="fa fa-caret-down"></i>
</div>
</div>
<div class="list__search-btn-new" title="{{res 'searchAddNew'}}">
<div class="list__search-btn-new {{#unless canCreate}}hide{{/unless}}" title="{{res 'searchAddNew'}}">
<i class="fa fa-plus"></i>
</div>
<div class="list__search-btn-sort" title="{{res 'searchSort'}}">