sul-dlss/argo

View on GitHub
app/javascript/controllers/content_type_controller.js

Summary

Maintainability
A
0 mins
Test Coverage
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  static targets = ['direction', 'directionRow', 'contentType']

  connect () {
    this.render()
  }

  render () {
    switch (this.currentType()) {
      case 'https://cocina.sul.stanford.edu/models/image':
      case 'https://cocina.sul.stanford.edu/models/book':
        this.showDirection()
        break
      default:
        this.hideDirection()
    }
  }

  currentType () {
    return this.contentTypeTarget.selectedOptions[0].value
  }

  hideDirection () {
    this.directionRowTarget.hidden = true
    this.directionTarget.disabled = true
  }

  showDirection () {
    this.directionRowTarget.hidden = false
    this.directionTarget.disabled = false
  }
}