Sha256: 055dc804f7be996370c3d1cfcded4b8122a1039ecb49bc04f114160a9ef5ad96

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

import { Controller } from '@hotwired/stimulus'
import * as bootstrap from 'bootstrap'

export default class extends Controller {
  static outlets = ['asociable']
  static targets = ['response']

  modalPuntero = null

  connect (e) {
    this.modalPuntero = new bootstrap.Modal(this.element)
    if (this.element.dataset.removeOnHide) {
      this.element.addEventListener('hidden.bs.modal', (e) => {
        this.element.remove()
        // FIXME: handlear mejor
        window.Stimulus.controllers.map((c) => { return c.calendar })
          .filter((e) => { return e })
          .forEach((c) => { c.refetchEvents() })
      })
    }
    this.modalPuntero.show()
    document.addEventListener('turbo:before-cache', () => {
      this.element.remove()
    }, { once: true })
  }

  responseTargetConnected (e) {
    const newObject = JSON.parse(e.dataset.response)
    this.asociableOutlet.completarCampo(newObject)
    this.element.remove()
  }

  openModal () {
    this.modalPuntero.show()
  }

  disconnect (e) {
    this.modalPuntero.hide()
    this.modalPuntero.dispose()
  }
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pg_rails-7.1.12 pg_associable/app/javascript/modal_controller.js