Sha256: 205e9d96561586616a486ab12a6505e121826eec15f3f27a7da82b1ea8242999

Contents?: true

Size: 1.21 KB

Versions: 9

Compression:

Stored size: 1.21 KB

Contents

import { AttributeObserver } from '@stimulus/mutation-observers'
import { Controller } from '@hotwired/stimulus'

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

  target = {}

  enableTarget() {
    if (this.targetIsDisabled(this.target)) {
      this.target.classList.remove('cursor-wait', 'text-gray-500', 'hover:bg-blue-300')
      this.target.classList.add('text-gray-700', 'hover:bg-blue-500')
      this.target.dataset.disabled = false
    }
  }

  disableTarget() {
    this.target.classList.add('cursor-wait', 'text-gray-500', 'hover:bg-blue-300')
    this.target.classList.remove('text-gray-700', 'hover:bg-blue-500')
    this.target.dataset.disabled = true
  }

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

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

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

      return
    }

    this.disableTarget()

    const observer = new AttributeObserver(document.querySelector('turbo-frame#actions_show'), 'busy', {
      elementUnmatchedAttribute: () => {
        this.enableTarget(this.target)
        if (observer) observer.stop()
      },
    })
    observer.start()
  }
}

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
avo-1.25.2 app/javascript/js/controllers/actions_picker_controller.js
avo-1.25.1 app/javascript/js/controllers/actions_picker_controller.js
avo-1.25.0 app/javascript/js/controllers/actions_picker_controller.js
avo-1.24.2 app/javascript/js/controllers/actions_picker_controller.js
avo-1.24.1 app/javascript/js/controllers/actions_picker_controller.js
avo-1.24.0 app/javascript/js/controllers/actions_picker_controller.js
avo-1.23.0 app/javascript/js/controllers/actions_picker_controller.js
avo-1.22.4 app/javascript/js/controllers/actions_picker_controller.js
avo-1.22.3 app/javascript/js/controllers/actions_picker_controller.js