Работа над BookmarkSettings
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
|
||||
<div class="col row">
|
||||
<div class="left-panel column items-center bg-grey-3">
|
||||
<q-btn class="q-mb-sm" round dense color="blue" icon="la la-edit" @click.stop="editBookmark" size="14px">
|
||||
<q-btn class="q-mb-sm" round dense color="blue" icon="la la-edit" @click.stop="editBookmark" size="14px" :disabled="!selected">
|
||||
<q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">Редактировать закладку</q-tooltip>
|
||||
</q-btn>
|
||||
<q-btn class="q-mb-sm" round dense color="blue" icon="la la-plus" @click.stop="addBookmark" size="14px">
|
||||
@@ -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;
|
||||
|
||||
@@ -68,7 +68,8 @@
|
||||
<template slot="header">
|
||||
<div class="row items-center">
|
||||
<q-icon class="q-mr-sm" name="la la-bookmark" size="28px"></q-icon>
|
||||
Добавить закладку
|
||||
<div v-if="addBookmarkMode == 'edit'">Редактировать закладку</div>
|
||||
<div v-else>Добавить закладку</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -97,7 +98,9 @@
|
||||
</template>
|
||||
</Dialog>
|
||||
</div>
|
||||
<BookmarkSettings v-if="bookmarkSettingsActive" ref="bookmarkSettings" :libs="libs" @do-action="doAction" @close="closeBookmarkSettings"></BookmarkSettings>
|
||||
<BookmarkSettings v-if="bookmarkSettingsActive" ref="bookmarkSettings" :libs="libs" :addBookmarkVisible="addBookmarkVisible"
|
||||
@do-action="doAction" @close="closeBookmarkSettings">
|
||||
</BookmarkSettings>
|
||||
</Window>
|
||||
</template>
|
||||
|
||||
@@ -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(`Такая закладка уже существует с другим описанием<br>` +
|
||||
`Заменить '${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') {
|
||||
|
||||
Reference in New Issue
Block a user