TrestleAdmin/trestle

View on GitHub
frontend/js/controllers/toggle_attr_controller.js

Summary

Maintainability
A
0 mins
Test Coverage
import ApplicationController from './application_controller'

export default class extends ApplicationController {
  static targets = ["item"]

  static values = {
    attribute: String
  }

  toggle () {
    this.itemTargets.forEach((item) => {
      item[this.attributeValue] = !item[this.attributeValue]
    })
  }

  set () {
    this.itemTargets.forEach((item) => {
      item[this.attributeValue] = true
    })
  }

  unset () {
    this.itemTargets.forEach((item) => {
      item[this.attributeValue] = false
    })
  }
}