Sha256: 6ab22ffcde1b93d681eaf9046b8c2fa8007e1029b1bca366ccbfb4ccc36b4eb1

Contents?: true

Size: 1.31 KB

Versions: 9

Compression:

Stored size: 1.31 KB

Contents

import { Controller } from "stimulus"
import axios from "axios"
import { axiosPostable } from "../lib/utils"

export default class extends Controller {
  initialize() {
    this.axios = axiosPostable(axios)
  }

  async edit(event) {
    event.preventDefault()
    const editPath = event.currentTarget.href

    try {
      const response = await this.axios.get(editPath, {headers: {'Accept': 'text/html'}})
      document.querySelector('#editor-modal-wrapper').innerHTML = response.data
      document.querySelector('#editor-modal input').focus()
    } catch (error) {
      console.log(error)
    }
  }

  async destroy(event) {
    event.preventDefault()
    const deletePath = event.currentTarget.href
    const cardId = this.element.id

    if (confirm("Are you sure you wish to delete this item?")) {
      this.element.classList.add('dimmed')
      try {
        await this.axios.delete(deletePath)
        document.getElementById(cardId).remove()
        this.refreshPublishingMenu()
      } catch (error) {
        console.log(error)
      }
    }
  }

  async refreshPublishingMenu() {
    try {
      let response = null
      response = await this.axios.get(this.data.get('publishing-menu-path'))
      document.getElementById('publishing-menu').innerHTML = response.data
    } catch (error) {
      console.log(error)
    }
  }
}

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
yarii-editor-0.4.8 app/javascript/controllers/card_controller.js
yarii-editor-0.4.7 app/javascript/controllers/card_controller.js
yarii-editor-0.4.6 app/javascript/controllers/card_controller.js
yarii-editor-0.4.5 app/javascript/controllers/card_controller.js
yarii-editor-0.4.4 app/javascript/controllers/card_controller.js
yarii-editor-0.4.3 app/javascript/controllers/card_controller.js
yarii-editor-0.4.2 app/javascript/controllers/card_controller.js
yarii-editor-0.4.1 app/javascript/controllers/card_controller.js
yarii-editor-0.4.0 app/javascript/controllers/card_controller.js