migration from vue2 to vue3 #405
2 changed files with 52 additions and 17 deletions
save settings with password confirmation
commit
b98bbd1053
|
|
@ -13,13 +13,14 @@
|
|||
<div
|
||||
v-if="error"
|
||||
id="error"
|
||||
></div>
|
||||
>{{ error }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { NcButton, NcLoadingIcon } from '@nextcloud/vue'
|
||||
import { ref } from 'vue'
|
||||
import { waitPasswordConfirmation } from '../../lib/setting.js'
|
||||
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
|
@ -62,25 +63,33 @@ const save = async () => {
|
|||
}
|
||||
}
|
||||
|
||||
for (let key in data) {
|
||||
let value = data[key]
|
||||
waitPasswordConfirmation()
|
||||
.then(() => {
|
||||
for (let key in data) {
|
||||
let value = data[key]
|
||||
|
||||
if (Array.isArray(value) || typeof value === 'object') {
|
||||
value = JSON.stringify(value)
|
||||
} else if (typeof value === 'boolean') {
|
||||
value = value ? 1 : 0
|
||||
}
|
||||
if (Array.isArray(value) || typeof value === 'object') {
|
||||
value = JSON.stringify(value)
|
||||
} else if (typeof value === 'boolean') {
|
||||
value = value ? 1 : 0
|
||||
}
|
||||
|
||||
OCP.AppConfig.setValue('side_menu', key, value, {
|
||||
success() {
|
||||
update()
|
||||
},
|
||||
error() {
|
||||
error.value = `Error while saving ${key}`
|
||||
update()
|
||||
},
|
||||
OCP.AppConfig.setValue('side_menu', key, value, {
|
||||
success() {
|
||||
update()
|
||||
},
|
||||
error() {
|
||||
error.value = `Error while saving ${key}`
|
||||
update()
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
counter = 0
|
||||
loading.value = false
|
||||
error.value = null
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
26
src/lib/setting.js
Normal file
26
src/lib/setting.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
const waitPasswordConfirmation = async () => {
|
||||
let tries = 0
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const execute = () => {
|
||||
if (!OC.PasswordConfirmation.requiresPasswordConfirmation()) {
|
||||
resolve()
|
||||
return
|
||||
}
|
||||
|
||||
OC.PasswordConfirmation.requirePasswordConfirmation(() => {})
|
||||
|
||||
if (++tries !== 10) {
|
||||
setTimeout(() => {
|
||||
execute()
|
||||
}, 2000)
|
||||
} else {
|
||||
reject()
|
||||
}
|
||||
}
|
||||
|
||||
execute()
|
||||
})
|
||||
}
|
||||
|
||||
export { waitPasswordConfirmation }
|
||||
Loading…
Add table
Add a link
Reference in a new issue