diff --git a/client/components/ExternalLibs/BookmarkSettings/BookmarkSettings.vue b/client/components/ExternalLibs/BookmarkSettings/BookmarkSettings.vue index 1eeb6f3d..f327c254 100644 --- a/client/components/ExternalLibs/BookmarkSettings/BookmarkSettings.vue +++ b/client/components/ExternalLibs/BookmarkSettings/BookmarkSettings.vue @@ -21,7 +21,7 @@
- + Редактировать закладку @@ -72,6 +72,7 @@ import * as lu from '../linkUtils'; const BookmarkSettingsProps = Vue.extend({ props: { libs: Object, + addBookmarkVisible: Boolean, } }); @@ -91,6 +92,7 @@ class BookmarkSettings extends BookmarkSettingsProps { expanded = []; created() { + this.afterInit = true; } mounted() { @@ -109,7 +111,7 @@ class BookmarkSettings extends BookmarkSettingsProps { this.libs.groups.forEach(group => { const rkey = `${i}`; const g = {label: group.r, key: rkey, children: []}; - this.links[rkey] = group.r; + this.links[rkey] = {l: group.r, c: ''}; let j = 0; group.list.forEach(link => { @@ -119,7 +121,7 @@ class BookmarkSettings extends BookmarkSettingsProps { key }); - this.links[key] = link.l; + this.links[key] = link; if (link.l == this.libs.startLink && expanded.indexOf(rkey) < 0) { expanded.push(rkey); } @@ -131,9 +133,12 @@ class BookmarkSettings extends BookmarkSettingsProps { i++; }); - this.$nextTick(() => { - this.expanded = expanded; - }); + if (this.afterInit) { + this.$nextTick(() => { + this.expanded = expanded; + }); + this.afterInit = false; + } return result; } @@ -147,22 +152,36 @@ class BookmarkSettings extends BookmarkSettingsProps { if (!this.selected) return; if (this.selected.indexOf('-') < 0) {//rootLink - this.$emit('do-action', {action: 'setRootLink', data: this.links[this.selected]}); + this.$emit('do-action', {action: 'setRootLink', data: this.links[this.selected].l}); } else {//selectedLink - this.$emit('do-action', {action: 'setSelectedLink', data: this.links[this.selected]}); + this.$emit('do-action', {action: 'setSelectedLink', data: this.links[this.selected].l}); } - - //this.close(); + this.close(); } openOptions() { } + editBookmark() { + this.$emit('do-action', {action: 'editBookmark', data: {link: this.links[this.selected].l, desc: this.links[this.selected].c}}); + } + + addBookmark() { + this.$emit('do-action', {action: 'addBookmark'}); + } + + delBookmark() { + } + close() { + this.afterInit = false; this.$emit('close'); } keyHook(event) { + if (this.addBookmarkVisible) + return false; + if (event.type == 'keydown' && event.key == 'Escape') { this.close(); return true; diff --git a/client/components/ExternalLibs/ExternalLibs.vue b/client/components/ExternalLibs/ExternalLibs.vue index 463aa6a1..6648032a 100644 --- a/client/components/ExternalLibs/ExternalLibs.vue +++ b/client/components/ExternalLibs/ExternalLibs.vue @@ -68,7 +68,8 @@ @@ -97,7 +98,9 @@
- + + @@ -154,6 +157,7 @@ class ExternalLibs extends Vue { addBookmarkVisible = false; transparentLayoutVisible = false; + addBookmarkMode = ''; bookmarkLink = ''; bookmarkDesc = ''; defaultRootLink = ''; @@ -297,6 +301,8 @@ class ExternalLibs extends Vue { case 'setLibs': this.commitLibs(event.data); break; case 'setRootLink': this.rootLink = event.data; this.rootLinkInput(); break; case 'setSelectedLink': this.selectedLink = event.data; this.selectedLinkInput(); break; + case 'editBookmark': this.addBookmark('edit', event.data.link, event.data.desc); break; + case 'addBookmark': this.addBookmark('add'); break; } } @@ -439,9 +445,17 @@ class ExternalLibs extends Vue { } } - addBookmark() { - this.bookmarkLink = (this.bookUrl ? this.makeProxySubst(lu.addProtocol(this.bookUrl), true) : ''); - this.bookmarkDesc = ''; + addBookmark(mode = 'add', link = '', desc = '') { + + if (mode == 'edit') { + this.editBookmarkLink = this.bookmarkLink = link; + this.editBookmarkDesc = this.bookmarkDesc = desc; + } else { + this.bookmarkLink = (this.bookUrl ? this.makeProxySubst(lu.addProtocol(this.bookUrl), true) : ''); + this.bookmarkDesc = ''; + } + + this.addBookmarkMode = mode; this.addBookmarkVisible = true; this.$nextTick(() => { this.$refs.bookmarkLink.focus(); @@ -474,7 +488,6 @@ class ExternalLibs extends Vue { bookmarkDescKeyDown(event) { if (event.key == 'Enter') { this.okAddBookmark(); - event.preventDefault(); } } @@ -482,7 +495,7 @@ class ExternalLibs extends Vue { if (!this.bookmarkLink) return; - const link = lu.addProtocol(this.bookmarkLink); + const link = (this.addBookmarkMode == 'edit' ? lu.addProtocol(this.editBookmarkLink) : lu.addProtocol(this.bookmarkLink)); let index = -1; try { index = lu.getRootIndexByUrl(this.libs.groups, link); @@ -491,14 +504,25 @@ class ExternalLibs extends Vue { return; } + let libs = _.cloneDeep(this.libs); + + //добавление //есть группа в закладках if (index >= 0) { - const item = lu.getListItemByLink(this.libs.groups[index].list, link); - - if (!item || item.c != this.bookmarkDesc) { - //добавляем - let libs = _.cloneDeep(this.libs); + const item = lu.getListItemByLink(libs.groups[index].list, link); + //редактирование + if (item && this.addBookmarkMode == 'edit') { + if (item) { + //редактируем + item.l = link; + item.c = this.bookmarkDesc; + this.commitLibs(libs); + } else { + await this.$root.stdDialog.alert('Не удалось отредактировать закладку', 'Ошибка'); + } + } else if (!item) { + //добавляем if (libs.groups[index].list.length >= 100) { await this.$root.stdDialog.alert('Достигнут предел количества закладок для этого сайта', 'Ошибка'); return; @@ -506,10 +530,18 @@ class ExternalLibs extends Vue { libs.groups[index].list.push({l: link, c: this.bookmarkDesc}); this.commitLibs(libs); + } else if (item.c != this.bookmarkDesc) { + if (await this.$root.stdDialog.confirm(`Такая закладка уже существует с другим описанием
` + + `Заменить '${this.$sanitize(item.c)}' на '${this.$sanitize(this.bookmarkDesc)}'?`, ' ')) { + item.c = this.bookmarkDesc; + this.commitLibs(libs); + } else + return; + } else { + await this.$root.stdDialog.alert('Такая закладка уже существует', ' '); + return; } } else {//нет группы в закладках - let libs = _.cloneDeep(this.libs); - if (libs.groups.length >= 100) { await this.$root.stdDialog.alert('Достигнут предел количества различных сайтов в закладках', 'Ошибка'); return; @@ -573,10 +605,13 @@ class ExternalLibs extends Vue { keyHook(event) { if (this.$root.rootRoute() == '/external-libs') { + if (this.$root.stdDialog.active) + return false; + if (this.bookmarkSettingsActive && this.$refs.bookmarkSettings.keyHook(event)) return true; - if (this.$refs.dialogAddBookmark.active) + if (this.addBookmarkVisible) return false; if (event.type == 'keydown' && event.key == 'F4') {