lnbits-legend/lnbits/static/js/components/extension-settings.js
dni ⚡ 898f264951
refactor: use <template> for components (#2715)
* refactor: use <template> for components
* fix paymentchart
2024-09-27 12:09:47 +02:00

69 lines
1.7 KiB
JavaScript

window.app.component('lnbits-extension-settings-form', {
name: 'lnbits-extension-settings-form',
template: '#lnbits-extension-settings-form',
props: ['options', 'adminkey', 'endpoint'],
methods: {
async updateSettings() {
if (!this.settings) {
return Quasar.Notify.create({
message: 'No settings to update',
type: 'negative'
})
}
try {
const {data} = await LNbits.api.request(
'PUT',
this.endpoint,
this.adminkey,
this.settings
)
this.settings = data
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
getSettings: async function () {
try {
const {data} = await LNbits.api.request(
'GET',
this.endpoint,
this.adminkey
)
this.settings = data
} catch (error) {
LNbits.utils.notifyApiError(error)
}
},
resetSettings: async function () {
LNbits.utils
.confirmDialog('Are you sure you want to reset the settings?')
.onOk(async () => {
try {
await LNbits.api.request('DELETE', this.endpoint, this.adminkey)
await this.getSettings()
} catch (error) {
LNbits.utils.notifyApiError(error)
}
})
}
},
created: async function () {
await this.getSettings()
},
data: function () {
return {
settings: undefined
}
}
})
window.app.component('lnbits-extension-settings-btn-dialog', {
template: '#lnbits-extension-settings-btn-dialog',
name: 'lnbits-extension-settings-btn-dialog',
props: ['options', 'adminkey', 'endpoint'],
data: function () {
return {
show: false
}
}
})