sul-dlss/argo

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

Summary

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

// This handles the "Register APO" as well as "Edit APO" forms
// This controller should be on a <form> node
export default class extends Controller {
  static targets = ['selectCollectionFields', 'createCollectionFields', 'catalogRecordIdFields']

  connect () {
    this.sharing = new Sharing(this.element.querySelector('sharing'))
    this.sharing.start()
  }

  submit () {
    this.sharing.serialize(this.element)
  }

  hideCollection () {
    this.selectCollectionFieldsTarget.hidden = true
    this.createCollectionFieldsTarget.hidden = true
    this.catalogRecordIdFieldsTarget.hidden = true
  }

  revealCreateCollection () {
    this.hideCollection()
    this.createCollectionFieldsTarget.hidden = false
  }

  revealCreateCollectionCatalogRecordId () {
    this.hideCollection()
    this.catalogRecordIdFieldsTarget.hidden = false
  }

  revealSelectCollection () {
    this.hideCollection()
    this.selectCollectionFieldsTarget.hidden = false
  }
}