Sha256: ccf19247a433cf205e6d8ee7c4a55616a753b68042eca72b8ae43fe56a6f5de9

Contents?: true

Size: 1.13 KB

Versions: 12

Compression:

Stored size: 1.13 KB

Contents

import { Controller } from '@hotwired/stimulus'
import { castBoolean } from '../helpers/cast_boolean'

export default class extends Controller {
  static targets = ['controllerDiv', 'resourceIds', 'form', 'selectedAllQuery']

  connect() {
    this.resourceIdsTarget.value = this.resourceIds

    // This value is picked up from the DOM so we check true/false as strings
    if (this.selectionOptions.itemSelectAllSelectedAllValue === 'true') {
      this.selectedAllQueryTarget.value = this.selectionOptions.itemSelectAllSelectedAllQueryValue
    }

    if (this.noConfirmation) {
      this.formTarget.submit()
    } else {
      this.controllerDivTarget.classList.remove('hidden')
    }
  }

  get noConfirmation() {
    return castBoolean(this.controllerDivTarget.dataset.noConfirmation)
  }

  get resourceName() {
    return this.controllerDivTarget.dataset.resourceName
  }

  get resourceIds() {
    try {
      return JSON.parse(this.selectionOptions.selectedResources)
    } catch (error) {
      return []
    }
  }

  get selectionOptions() {
    return document.querySelector(`[data-selected-resources-name="${this.resourceName}"]`).dataset
  }
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
avo-2.14.3.pre.7.polytranslations1 app/javascript/js/controllers/action_controller.js
avo-2.14.3.pre.6.nosprockets app/javascript/js/controllers/action_controller.js
avo-2.14.3.pre.5.nosprockets app/javascript/js/controllers/action_controller.js
avo-2.14.3.pre.4.tosqlfix app/javascript/js/controllers/action_controller.js
avo-2.14.3.pre.3.jsbundling app/javascript/js/controllers/action_controller.js
avo-2.14.3.pre.2.tailwindcss app/javascript/js/controllers/action_controller.js
avo-2.14.3.pre.1.branding app/javascript/js/controllers/action_controller.js
avo-2.14.2 app/javascript/js/controllers/action_controller.js
avo-2.14.2.pre.1 app/javascript/js/controllers/action_controller.js
avo-2.14.1 app/javascript/js/controllers/action_controller.js
avo-2.14.1.pre.1 app/javascript/js/controllers/action_controller.js
avo-2.14.0 app/javascript/js/controllers/action_controller.js