Skip to content

Commit 28908df

Browse files
committed
define arbre dialog component
1 parent f46a1db commit 28908df

File tree

5 files changed

+49
-33
lines changed

5 files changed

+49
-33
lines changed

app/admin/components/dialog.rb

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Admin
2+
module Components
3+
class Header < Arbre::HTML::Tag
4+
builder_method :html5_header
5+
end
6+
7+
class Dialog < Arbre::HTML::Tag
8+
builder_method :dialog
9+
attr_accessor :inner_content
10+
11+
def build(attributes = {})
12+
title = attributes[:title]
13+
super(attributes.except(:title))
14+
html5_header do
15+
strong title if title.present?
16+
button "X", title: "Close", class: "button close-dialog-button"
17+
end
18+
@inner_content = div
19+
end
20+
21+
def add_child(child)
22+
if @inner_content
23+
@inner_content.add_child child
24+
else
25+
super
26+
end
27+
end
28+
29+
def children?
30+
@inner_content.children?
31+
end
32+
end
33+
end
34+
end

app/admin/fmu.rb

+4-16
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,14 @@ def download_shapefiles(fmus)
117117
end
118118
if resource.geojson
119119
row(:geojson) do
120-
dialog id: "geojson_modal" do
121-
html5_header do
122-
strong Fmu.human_attribute_name(:geojson)
123-
button "Close", class: "button close-dialog-button"
124-
end
125-
div do
126-
resource.geojson
127-
end
120+
dialog id: "geojson_modal", title: Fmu.human_attribute_name(:geojson) do
121+
resource.geojson
128122
end
129123
link_to t("active_admin.view"), "javascript:void(0)", onclick: "document.querySelector('#geojson_modal').showModal()"
130124
end
131125
row(:properties) do
132-
dialog id: "properties_modal" do
133-
html5_header do
134-
strong Fmu.human_attribute_name(:properties)
135-
button "Close", class: "button close-dialog-button"
136-
end
137-
div do
138-
resource.properties
139-
end
126+
dialog id: "properties_modal", title: Fmu.human_attribute_name(:properties) do
127+
resource.properties
140128
end
141129
link_to t("active_admin.view"), "javascript:void(0)", onclick: "document.querySelector('#properties_modal').showModal()"
142130
end

app/assets/javascripts/dialog.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ function initializeDialog() {
1414
}
1515
});
1616

17-
dialog.querySelector(".close-dialog-button").addEventListener("click", () => {
18-
dialog.close();
17+
dialog.querySelectorAll(".close-dialog-button").forEach((button) => {
18+
button.addEventListener("click", () => {
19+
dialog.close();
20+
});
1921
});
2022
});
2123
}

app/assets/stylesheets/active_admin.scss

+7-3
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,15 @@ dialog {
229229
justify-content: space-between;
230230
align-items: center;
231231
padding: 10px;
232-
border-bottom: 1px solid #ccc;
233232

234-
.close-dialog {
233+
> strong {
234+
font-size: 1.2em;
235+
}
236+
237+
.close-dialog-button {
235238
cursor: pointer;
236-
font-size: 1.5em;
239+
padding: 10px 15px;
240+
margin-left: auto;
237241
}
238242
}
239243

config/initializers/active_admin.rb

-12
Original file line numberDiff line numberDiff line change
@@ -369,18 +369,6 @@ def set_admin_locale
369369
app.view_factory.register header: CustomAdminHeader
370370
end
371371

372-
module Arbre
373-
module HTML
374-
class Dialog < Tag
375-
builder_method :dialog
376-
end
377-
378-
class Header < Tag
379-
builder_method :html5_header
380-
end
381-
end
382-
end
383-
384372
# activeadmin_addons update in 1.10 introduced a bug where it raises Formtastic::UnsupportedEnumCollection for multiple selects with enum values
385373
# not sure why it should be raising not supported but it works so for me it's supported just fine
386374
# https://github.com/platanus/activeadmin_addons/pull/442/files#diff-811ca221eee9c4866653114961ac21bcd0398557bb402c60f149be506c385a8eR3

0 commit comments

Comments
 (0)