Sha256: cf1d157caf7bffea6eee05b8a4b32584943e55a65ac761102c53b847928aa920

Contents?: true

Size: 1.55 KB

Versions: 9

Compression:

Stored size: 1.55 KB

Contents

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

export default class extends Controller {
  static targets = [ "status" ]
  
  initialize() {
    this.axios = axiosPostable(axios)
  }

  connect() {
    // We'll handle saving ourselves. Disable normal form operation
    this.element.querySelector('.modal-card-body > form').addEventListener('submit', event => {
      event.preventDefault()
    })
  }
  async commit() {
    const form = this.element.querySelector('.modal-card-body > form');
    const data = new FormData(form);

    this.element.querySelector('.modal-card-body > form').classList.add('dimmed')
    this.element.querySelector('button[data-action="commit-modal#commit"]').classList.add('is-loading')
    this.statusTarget.classList.add('in-progress')
    this.statusTarget.innerHTML = "Pushing Updates…"

    try {
      let response = null
      response = await this.axios.post(this.data.get('path'), data)
      this.refreshPublishingMenu()
      this.closeModal()
    } catch (error) {
      alert("I'm sorry, I ran into trouble communicating with the server. Try pushing again in a moment.")
      console.log(error)
    }
  }

  cancel() {
    this.closeModal()
  }

  closeModal() {
    this.element.remove()
  }

  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/commit_modal_controller.js
yarii-editor-0.4.7 app/javascript/controllers/commit_modal_controller.js
yarii-editor-0.4.6 app/javascript/controllers/commit_modal_controller.js
yarii-editor-0.4.5 app/javascript/controllers/commit_modal_controller.js
yarii-editor-0.4.4 app/javascript/controllers/commit_modal_controller.js
yarii-editor-0.4.3 app/javascript/controllers/commit_modal_controller.js
yarii-editor-0.4.2 app/javascript/controllers/commit_modal_controller.js
yarii-editor-0.4.1 app/javascript/controllers/commit_modal_controller.js
yarii-editor-0.4.0 app/javascript/controllers/commit_modal_controller.js