Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rails-ujs instead of jquery_ujs #2619

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/assets/javascripts/alchemy/admin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Alchemy CMS Sprockets Manifest
// ------------------------------
//= require jquery2
//= require jquery_ujs
//= require jquery-ui/widgets/draggable
//= require jquery-ui/widgets/sortable
//= require tinymce/tinymce.min
Expand Down
24 changes: 15 additions & 9 deletions app/assets/javascripts/alchemy/alchemy.dialog.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,23 @@ class window.Alchemy.Dialog
# Watches ajax requests inside of dialog body and replaces the content accordingly
watch_remote_forms: ->
form = $('[data-remote="true"]', @dialog_body)
form.bind "ajax:complete", (e, xhr, status) =>
content_type = xhr.getResponseHeader('Content-Type')
form.bind "ajax:complete", () =>
Alchemy.Buttons.enable(@dialog_body)
if status == 'success'
if content_type.match(/javascript/)
return
else
@dialog_body.html(xhr.responseText)
@init()
return
form.bind "ajax:success", (event) =>
xhr = event.detail[2]
content_type = xhr.getResponseHeader('Content-Type')
if content_type.match(/javascript/)
return
else
@show_error(xhr, status)
@dialog_body.html(xhr.responseText)
@init()
return
form.bind "ajax:error", (event, b, c) =>
statusText = event.detail[1]
xhr = event.detail[2]
@show_error(xhr, statusText)
return

# Displays an error message
show_error: (xhr, status_message, $container = @dialog_body) ->
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/alchemy_admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "@hotwired/turbo-rails"
import Rails from "@rails/ujs"

import Buttons from "alchemy_admin/buttons"
import GUI from "alchemy_admin/gui"
Expand Down Expand Up @@ -57,4 +58,6 @@ Object.assign(Alchemy, {
PagePublicationFields
})

Rails.start()

$(document).on("turbo:load", Initializer)
1 change: 1 addition & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
pin "@shoelace/tab", to: "https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.9.0/cdn/components/tab/tab.js", preload: true
pin "@shoelace/tab-group", to: "https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.9.0/cdn/components/tab-group/tab-group.js", preload: true
pin "@shoelace/tab-panel", to: "https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.9.0/cdn/components/tab-panel/tab-panel.js", preload: true
pin "@rails/ujs", to: "https://ga.jspm.io/npm:@rails/ujs@7.1.2/app/assets/javascripts/rails-ujs.esm.js"

pin "alchemy_admin", to: "alchemy_admin.js", preload: true
pin_all_from File.expand_path("../app/javascript/alchemy_admin", __dir__), under: "alchemy_admin"
Loading