Sha256: 6495cf24ae538385e82329670aba7d351552c42d82f947d98572769291a568d0

Contents?: true

Size: 1.07 KB

Versions: 214

Compression:

Stored size: 1.07 KB

Contents

import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  static targets = ['resourceAction', 'standaloneAction']

  static classes = ['enabled', 'disabled']

  target = {}

  get targetIsDisabled() {
    return this.target.dataset.disabled === 'true'
  }

  get actionsShowTurboFrame() {
    return document.querySelector('turbo-frame#actions_show')
  }

  enableTarget() {
    if (this.targetIsDisabled) {
      this.target.classList.remove(...this.disabledClasses)
      this.target.classList.add(...this.enabledClasses)
      this.target.dataset.disabled = false
    }
  }

  disableTarget() {
    this.target.classList.remove(...this.enabledClasses)
    this.target.classList.add(...this.disabledClasses)
    this.target.dataset.disabled = true
  }

  visitAction(event) {
    this.target = event.target

    if (this.targetIsDisabled) {
      event.preventDefault()

      return
    }

    this.disableTarget()
    const that = this
    setTimeout(() => {
      this.actionsShowTurboFrame.loaded.then(() => that.enableTarget(that.target))
    }, 1)
  }
}

Version data entries

214 entries across 214 versions & 1 rubygems

Version Path
avo-2.53.0 app/javascript/js/controllers/actions_picker_controller.js
avo-3.12.0 app/javascript/js/controllers/actions_picker_controller.js
avo-3.11.10 app/javascript/js/controllers/actions_picker_controller.js
avo-3.11.9 app/javascript/js/controllers/actions_picker_controller.js
avo-3.11.8 app/javascript/js/controllers/actions_picker_controller.js
avo-3.11.7 app/javascript/js/controllers/actions_picker_controller.js
avo-3.11.6 app/javascript/js/controllers/actions_picker_controller.js
avo-3.11.5 app/javascript/js/controllers/actions_picker_controller.js
avo-3.11.4 app/javascript/js/controllers/actions_picker_controller.js
avo-3.11.3 app/javascript/js/controllers/actions_picker_controller.js
avo-3.11.2 app/javascript/js/controllers/actions_picker_controller.js
avo-3.11.1 app/javascript/js/controllers/actions_picker_controller.js
avo-3.11.0 app/javascript/js/controllers/actions_picker_controller.js
avo-2.52.0 app/javascript/js/controllers/actions_picker_controller.js
avo-3.10.10 app/javascript/js/controllers/actions_picker_controller.js
avo-3.10.9 app/javascript/js/controllers/actions_picker_controller.js
avo-3.10.8 app/javascript/js/controllers/actions_picker_controller.js
avo-3.10.7 app/javascript/js/controllers/actions_picker_controller.js
avo-3.10.6 app/javascript/js/controllers/actions_picker_controller.js
avo-3.10.5 app/javascript/js/controllers/actions_picker_controller.js