* add servicesDisabled field for groups and for global configuration * fixup! add servicesDisabled field for groups and for global configuration * comment libcurl upgrade to fix ci temporarly * upgrade caddy version * review * fix test * feat: add paying membership option (#714) * feat: add paying membership option * fix: ci * fix: phpstan + review * fix: eslint ci
36 lines
1 KiB
JavaScript
36 lines
1 KiB
JavaScript
import { Controller} from '@hotwired/stimulus'
|
|
|
|
export default class extends Controller {
|
|
static targets = ['servicesEnabledField', 'parentField']
|
|
|
|
connect() {
|
|
}
|
|
|
|
updateParentOptions() {
|
|
const userId = this.servicesEnabledFieldTarget.getAttribute('data-user-id')
|
|
const servicesEnabled = this.servicesEnabledFieldTarget.checked
|
|
|
|
const url = `/api/groups?user=${userId}&services_enabled=${servicesEnabled}`
|
|
this.addGroupsWithEnabledServices(url)
|
|
}
|
|
|
|
async addGroupsWithEnabledServices(url) {
|
|
const response = await fetch(url, { method: 'GET' })
|
|
if (!response.ok) {
|
|
return
|
|
}
|
|
const data = await response.json()
|
|
const groups = data['hydra:member']
|
|
|
|
// Remove options and set a default value
|
|
Array.from(this.parentFieldTarget.options).map((group) => {
|
|
this.parentFieldTarget.remove(group)
|
|
})
|
|
this.parentFieldTarget.add(new Option())
|
|
|
|
// Populate with new options
|
|
groups.map(group => {
|
|
this.parentFieldTarget.add(new Option(group.name, group.id))
|
|
})
|
|
}
|
|
}
|