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.9.0 app/packs/js/controllers/actions_picker_controller.js
avo-1.8.4 app/packs/js/controllers/actions_picker_controller.js
avo-1.8.3 app/packs/js/controllers/actions_picker_controller.js
avo-1.8.2 app/packs/js/controllers/actions_picker_controller.js
avo-1.8.1 app/packs/js/controllers/actions_picker_controller.js
avo-1.8.0 app/packs/js/controllers/actions_picker_controller.js
avo-1.7.3 app/packs/js/controllers/actions_picker_controller.js
avo-1.7.3.pre.1 app/packs/js/controllers/actions_picker_controller.js
avo-1.7.2 app/packs/js/controllers/actions_picker_controller.js
avo-1.7.1 app/packs/js/controllers/actions_picker_controller.js
avo-1.7.0 app/packs/js/controllers/actions_picker_controller.js
avo-1.6.4.pre.1 app/packs/js/controllers/actions_picker_controller.js
avo-1.6.3.pre.3 app/packs/js/controllers/actions_picker_controller.js
avo-1.6.3.pre.2 app/packs/js/controllers/actions_picker_controller.js
avo-1.6.3.pre.1 app/packs/js/controllers/actions_picker_controller.js
avo-1.6.2.pre.1 app/packs/js/controllers/actions_picker_controller.js
avo-1.6.1 app/packs/js/controllers/actions_picker_controller.js
avo-1.6.0 app/packs/js/controllers/actions_picker_controller.js
avo-1.5.5 app/packs/js/controllers/actions_picker_controller.js
avo-1.5.4 app/packs/js/controllers/actions_picker_controller.js