Sha256: 8b21b395c82434509b24d4772bb88f1cfc93c9dc7a9ed0df4d509dc635640a29

Contents?: true

Size: 1.16 KB

Versions: 15

Compression:

Stored size: 1.16 KB

Contents

import { Controller } from "@hotwired/stimulus"
import Sortable from "libraries/sortablejs"

export default class extends Controller {
  static get targets() {
    return [ "collection", "fields" ]
  }
  
  connect() {
    setTimeout(function() {
      this.sortable = Sortable.create(this.collectionTarget, {
        animation: 150
      })
    }.bind(this), 250)
  }
  
  removeImage(event) {
    let id = event.currentTarget.dataset.id
    let image = document.getElementById(id)
    image.parentElement.removeChild(image)
  }
  
  handleDone(event) {
    let html = this.element.dataset.fields
    
    let range = document.createRange()
    range.selectNodeContents(document.body)
    let fragment = range.createContextualFragment(html)
    
    fragment.querySelector(`[data-media-picker-target="signedBlobId"]`).value = event.detail.signedBlobId
    fragment.querySelector(`[data-media-picker-target="filename"]`).value = event.detail.filename
    fragment.querySelector(`[data-media-picker-target="imageId"]`).value = event.detail.imageId
    fragment.querySelector('img').src = event.detail.thumbnail

    // Insert fields
    this.collectionTarget.appendChild(fragment)
  }
  
}

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
spina-2.18.0 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.17.0 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.16.0 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.15.1 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.15.0 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.14.0 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.13.1 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.13.0 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.12.0 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.11.0 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.10.0 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.9.1 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.9.0 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.8.1 app/assets/javascripts/spina/controllers/image_collection_controller.js
spina-2.8.0 app/assets/javascripts/spina/controllers/image_collection_controller.js