diff --git a/client/components/ExternalLibs/ExternalLibs.vue b/client/components/ExternalLibs/ExternalLibs.vue index 3b4a9243..caa375c6 100644 --- a/client/components/ExternalLibs/ExternalLibs.vue +++ b/client/components/ExternalLibs/ExternalLibs.vue @@ -19,10 +19,10 @@ rounded outlined dense emit-value map-options display-value-sanitize options-sanitize > @@ -34,6 +34,7 @@ dropdown-icon="la la-angle-down la-sm" rounded outlined dense emit-value map-options hide-selected display-value-sanitize options-sanitize > + Закладки @@ -62,6 +97,8 @@ import Component from 'vue-class-component'; import _ from 'lodash'; import Window from '../share/Window.vue'; +import Dialog from '../share/Dialog.vue'; +import rstore from '../../store/modules/reader'; import * as utils from '../../share/utils'; const proxySubst = { @@ -70,7 +107,8 @@ const proxySubst = { export default @Component({ components: { - Window + Window, + Dialog }, watch: { libs: function() { @@ -82,6 +120,9 @@ export default @Component({ }, selectedLink: function() { this.updateStartLink(); + }, + defaultRootLink: function() { + this.updateBookmarkLink(); } } }) @@ -95,6 +136,11 @@ class ExternalLibs extends Vue { bookUrl = ''; libs = {}; fullScreenActive = false; + addBookmarkVisible = false; + + bookmarkLink = ''; + bookmarkDesc = ''; + defaultRootLink = ''; created() { this.$root.addKeyHook(this.keyHook); @@ -199,7 +245,7 @@ class ExternalLibs extends Vue { updateSelectedLink() { if (!this.ready) return; - const index = this.getRootIndexByUrl(this.rootLink); + const index = this.getRootIndexByUrl(this.libs.groups, this.rootLink); if (index >= 0) this.selectedLink = this.libs.groups[index].s; } @@ -207,7 +253,7 @@ class ExternalLibs extends Vue { updateStartLink() { if (!this.ready) return; - const index = this.getRootIndexByUrl(this.rootLink); + const index = this.getRootIndexByUrl(this.libs.groups, this.rootLink); if (index >= 0) { let libs = _.cloneDeep(this.libs); libs.groups[index].s = this.selectedLink; @@ -230,12 +276,22 @@ class ExternalLibs extends Vue { return result; } + get defaultRootLinkOptions() { + let result = []; + + rstore.libsDefaults.groups.forEach(group => { + result.push({label: this.removeProtocol(group.r), value: group.r}); + }); + + return result; + } + get selectedLinkOptions() { let result = []; if (!this.ready) return result; - const index = this.getRootIndexByUrl(this.rootLink); + const index = this.getRootIndexByUrl(this.libs.groups, this.rootLink); if (index >= 0) { this.libs.groups[index].list.forEach(link => { result.push({label: (link.c ? link.c + ' ': '') + this.removeOrigin(link.l), value: link.l}); @@ -282,11 +338,10 @@ class ExternalLibs extends Vue { return (result ? result : '/'); } - getRootIndexByUrl(url) { + getRootIndexByUrl(groups, url) { if (!this.ready) return -1; const origin = this.getOrigin(url); - const groups = this.libs.groups; for (let i = 0; i < groups.length; i++) { if (groups[i].r == origin) return i; @@ -314,8 +369,8 @@ class ExternalLibs extends Vue { return url; } - onInputFocus() { - this.$refs.input.select(); + onInputFocus(event) { + event.target.select(); } submitUrl() { @@ -331,6 +386,26 @@ class ExternalLibs extends Vue { } addBookmark() { + this.addBookmarkVisible = true; + this.$nextTick(() => { + this.$refs.bookmarkLink.focus(); + }); + } + + updateBookmarkLink() { + this.bookmarkLink = this.defaultRootLink; + const index = this.getRootIndexByUrl(rstore.libsDefaults.groups, this.bookmarkLink); + if (index >= 0) { + this.bookmarkDesc = this.getCommentByLink(rstore.libsDefaults.groups[index].list, this.bookmarkLink); + } else { + this.bookmarkDesc = ''; + } + } + + okAddBookmark() { + } + + bookmarkSettings() { } fullScreenToggle() { @@ -347,17 +422,23 @@ class ExternalLibs extends Vue { } keyHook() { - //недостатки сторонних ui - const input = this.$refs.input.$refs.input; - if (document.activeElement === input && event.type == 'keydown' && event.code == 'Enter') { - this.submitUrl(); + if (this.$root.rootRoute() == '/external-libs') { + if (this.$refs.dialogAddBookmark.active) + return false; + + //недостатки сторонних ui + const input = this.$refs.input.$refs.input; + if (document.activeElement === input && event.type == 'keydown' && event.code == 'Enter') { + this.submitUrl(); + return true; + } + + if (event.type == 'keydown' && (event.code == 'Escape')) { + this.close(); + } return true; } - - if (event.type == 'keydown' && (event.code == 'Escape')) { - this.close(); - } - return true; + return false; } } diff --git a/client/store/modules/reader.js b/client/store/modules/reader.js index 3db50b94..b9be276e 100644 --- a/client/store/modules/reader.js +++ b/client/store/modules/reader.js @@ -266,7 +266,11 @@ const libsDefaults = { ]}, {r: 'http://lib.ru', s: 'http://lib.ru', list: [ {l: 'http://lib.ru', c: 'Библиотека Максима Мошкова'}, - ]}, + ]}, + {r: 'https://aldebaran.ru', s: 'https://aldebaran.ru', list: [ + {l: 'https://aldebaran.ru', c: 'АЛЬДЕБАРАН | Электронная библиотека книг'}, + ]}, + ] };