Sha256: 39ed465373d6aaf724a267bbfb53787cd2dac538fda97bf5d836ac699354fcbd

Contents?: true

Size: 1.14 KB

Versions: 76

Compression:

Stored size: 1.14 KB

Contents

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

export default class extends Controller {
  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

76 entries across 76 versions & 1 rubygems

Version Path
avo-1.0.0 app/packs/js/controllers/actions_picker_controller.js
avo-0.5.0.beta15 app/packs/js/controllers/actions_picker_controller.js
avo-0.5.0.beta14 app/packs/js/controllers/actions_picker_controller.js
avo-0.5.0.beta13 app/packs/js/controllers/actions_picker_controller.js
avo-0.5.0.beta12 app/packs/js/controllers/actions_picker_controller.js
avo-0.5.0.beta11 app/packs/js/controllers/actions_picker_controller.js
avo-0.5.0.beta10 app/packs/js/controllers/actions_picker_controller.js
avo-0.5.0.beta9 app/packs/js/controllers/actions_picker_controller.js
avo-0.5.0.beta8 app/packs/js/controllers/actions_picker_controller.js
avo-0.5.0.beta7 app/frontend/js/controllers/actions_picker_controller.js
avo-0.5.0.beta6 app/frontend/js/controllers/actions_picker_controller.js
avo-0.5.0.beta5 app/frontend/js/controllers/actions_picker_controller.js
avo-0.5.0.beta4 app/frontend/js/controllers/actions_picker_controller.js
avo-0.5.0.beta3 app/frontend/js/controllers/actions_picker_controller.js
avo-0.5.0.beta2 app/frontend/js/controllers/actions_picker_controller.js
avo-0.5.0.beta1 app/frontend/js/controllers/actions_picker_controller.js