Sha256: 99cba960129ce8b19ed7fc0b5d93191bb3cbcc9fc4e6951d46d9725cd26a5d31

Contents?: true

Size: 1.2 KB

Versions: 30

Compression:

Stored size: 1.2 KB

Contents

import { Controller } from "@hotwired/stimulus"
import { FetchRequest } from '@rails/request.js'


// Base class for controllers that reload form content from the server
export default class extends Controller {
  connect() {
    this.state.finishUpdate()
  }

  get state() {
    let currentElement = this.element

    while(currentElement !== document.body) {
      if (currentElement.matches('[data-controller~="refine--state"]'))
        return this.application.getControllerForElementAndIdentifier(currentElement, 'refine--state')
      else {
        currentElement = currentElement.parentNode
      }
    }

    return null
  }

  async refreshFromServer(options = {}) {
    const { includeErrors } = options
    this.state.startUpdate()
    const request = new FetchRequest(
      "GET",
      this.state.refreshUrlValue,
      {
        responseKind: "turbo-stream",
        query: {
          "refine_filters_builder[filter_class]": this.state.filterName,
          "refine_filters_builder[blueprint_json]": JSON.stringify(this.state.blueprint),
          "refine_filters_builder[client_id]": this.state.clientIdValue,
          include_errors: !!includeErrors
        }
      }
    )
    await request.perform()
  }
}

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
refine-rails-2.12.0 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.12 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.11 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.10 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.9 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.8 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.6 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.5 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.4 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.3 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.2 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.1 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.11.0 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.10.1 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.10.0 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.9.14 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.9.13 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.9.12 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.9.11 app/javascript/controllers/refine/server-refresh-controller.js
refine-rails-2.9.10 app/javascript/controllers/refine/server-refresh-controller.js