ebs/assets/controllers/parentgroup_controller.js
Sarahshr b9a87a420b
Feat/disable services option for groups (#711)
* 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
2024-10-08 09:40:23 +02:00

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))
})
}
}