|
1 | 1 | <template>
|
2 |
| - <NcAppNavigationSettings :title="t('notes', 'Notes settings')" :class="{ loading: saving }"> |
| 2 | + <NcAppNavigationSettings :title="t('notes', 'Notes settings')" :class="{ loading: saving }" :exclude-click-outside-selectors="['div.oc-dialog']"> |
3 | 3 | <div class="settings-block">
|
4 | 4 | <p class="settings-hint">
|
5 | 5 | <label for="notesPath">{{ t('notes', 'Folder to store your notes') }}</label>
|
6 | 6 | </p>
|
7 |
| - <form @submit.prevent="onChangeSettingsReload"> |
8 |
| - <input id="notesPath" |
9 |
| - v-model="settings.notesPath" |
10 |
| - type="text" |
11 |
| - name="notesPath" |
12 |
| - :placeholder="t('notes', 'Root directory')" |
13 |
| - @change="onChangeSettingsReload" |
14 |
| - ><input type="submit" class="icon-confirm" value=""> |
15 |
| - </form> |
| 7 | + <input id="notesPath" |
| 8 | + v-model="settings.notesPath" |
| 9 | + type="text" |
| 10 | + name="notesPath" |
| 11 | + :placeholder="t('notes', 'Root directory')" |
| 12 | + @click="onChangeNotePath" |
| 13 | + > |
16 | 14 | </div>
|
17 | 15 | <div class="settings-block">
|
18 | 16 | <p class="settings-hint">
|
@@ -51,8 +49,23 @@ import {
|
51 | 49 | } from '@nextcloud/vue'
|
52 | 50 |
|
53 | 51 | import { setSettings } from '../NotesService.js'
|
| 52 | +import { FilePicker, FilePickerType } from '@nextcloud/dialogs' |
54 | 53 | import store from '../store.js'
|
55 | 54 |
|
| 55 | +/* |
| 56 | +* Workaround until excludeClickOutsideSelectors will work and does nott close the menu while |
| 57 | +* clicking in the filePicker |
| 58 | +*/ |
| 59 | +const callback = (mutationList, observer) => { |
| 60 | + for (const mutation of mutationList) { |
| 61 | + if (mutation.target.id === 'app-settings__content' && mutation.type === 'attributes' && mutation.attributeName === 'style') { |
| 62 | + mutation.target.style = 'display: block;' |
| 63 | + document.getElementById('app-settings').classList.add('open') |
| 64 | + observer.disconnect() |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | +
|
56 | 69 | export default {
|
57 | 70 | name: 'AppSettings',
|
58 | 71 |
|
@@ -89,6 +102,30 @@ export default {
|
89 | 102 | },
|
90 | 103 |
|
91 | 104 | methods: {
|
| 105 | + onChangeNotePath(event) { |
| 106 | + // Obeserver for the workaround |
| 107 | + const observer = new MutationObserver(callback) |
| 108 | + observer.observe(document.querySelector('#app-settings__content'), { attributes: true }) |
| 109 | +
|
| 110 | + // Code Example from: https://github.com/nextcloud/text/blob/main/src/components/Menu/ActionInsertLink.vue#L130-L155 |
| 111 | + const filePicker = new FilePicker( |
| 112 | + t('text', 'Select folder to link to'), |
| 113 | + false, // multiselect |
| 114 | + ['text/directory'], // mime filter |
| 115 | + true, // modal |
| 116 | + FilePickerType.Choose, // type |
| 117 | + true, // directories |
| 118 | + event.target.value === '' ? '/' : event.target.value // path |
| 119 | + ) |
| 120 | + filePicker.pick().then((file) => { |
| 121 | + const client = OC.Files.getClient() |
| 122 | + client.getFileInfo(file).then((_status, fileInfo) => { |
| 123 | + this.settings.notesPath = fileInfo.path === '/' ? `/${fileInfo.name}` : `${fileInfo.path}/${fileInfo.name}` |
| 124 | +
|
| 125 | + this.onChangeSettingsReload() |
| 126 | + }) |
| 127 | + }) |
| 128 | + }, |
92 | 129 | onChangeSettings() {
|
93 | 130 | this.saving = true
|
94 | 131 | return setSettings(this.settings)
|
|
0 commit comments