Sha256: 9f0c998f281f6636c8dd393307be4d8f59369a070d31841f6ca135cde3030ddb

Contents?: true

Size: 1.2 KB

Versions: 62

Compression:

Stored size: 1.2 KB

Contents

import { AttributeObserver } from '@stimulus/mutation-observers'
import { Controller } from '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

62 entries across 62 versions & 1 rubygems

Version Path
avo-1.22.2 app/javascript/js/controllers/actions_picker_controller.js
avo-1.22.1 app/javascript/js/controllers/actions_picker_controller.js
avo-1.22.1.pre.2 app/javascript/js/controllers/actions_picker_controller.js
avo-1.22.1.pre.1 app/javascript/js/controllers/actions_picker_controller.js
avo-1.22.0 app/javascript/js/controllers/actions_picker_controller.js
avo-1.22.0.pre.1 app/javascript/js/controllers/actions_picker_controller.js
avo-1.21.1.pre.1 app/javascript/js/controllers/actions_picker_controller.js
avo-1.21.0 app/javascript/js/controllers/actions_picker_controller.js
avo-1.20.2.pre.2 app/javascript/js/controllers/actions_picker_controller.js
avo-1.20.2.pre.1 app/javascript/js/controllers/actions_picker_controller.js
avo-1.21.0.pre.1 app/javascript/js/controllers/actions_picker_controller.js
avo-1.20.1 app/javascript/js/controllers/actions_picker_controller.js
avo-1.19.1.pre.11 app/javascript/js/controllers/actions_picker_controller.js
avo-1.19.1.pre.10 app/javascript/js/controllers/actions_picker_controller.js
avo-1.19.1.pre.9 app/javascript/js/controllers/actions_picker_controller.js
avo-1.19.1.pre.8 app/javascript/js/controllers/actions_picker_controller.js
avo-1.19.1.pre.7 app/javascript/js/controllers/actions_picker_controller.js
avo-1.19.1.pre.6 app/javascript/js/controllers/actions_picker_controller.js
avo-1.19.1.pre.5 app/javascript/js/controllers/actions_picker_controller.js
avo-1.19.1.pre.4 app/javascript/js/controllers/actions_picker_controller.js