Skip to content

Commit a060898

Browse files
committed
fix/Use new modal format for all modals
1 parent ba638de commit a060898

File tree

4 files changed

+43
-44
lines changed

4 files changed

+43
-44
lines changed

app/javascript/controllers/modal_controller.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ export default class extends Controller {
88
this.element[this.identifier] = this
99
}
1010

11-
present(url, opts = {}) {
12-
event.preventDefault()
13-
11+
present(url) {
1412
axios.get(url)
1513
.then(res => {
1614
this.bodyTarget.insertAdjacentHTML('afterbegin', res.data);
17-
if (opts.callback) { opts.callback() }
1815
this.modalTarget.classList.remove('hidden')
1916
})
2017
.catch(console.error)
@@ -24,8 +21,4 @@ export default class extends Controller {
2421
this.modalTarget.classList.add('hidden')
2522
this.bodyTarget.innerHTML = ''
2623
}
27-
28-
get url() {
29-
return this.data.get('url')
30-
}
3124
}

app/javascript/controllers/popover_controller.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export default class extends Controller {
3535
event.preventDefault();
3636
}
3737

38+
presentModal(event) {
39+
this.modal.present(event.currentTarget.dataset.modalUrl)
40+
}
41+
3842
disconnect() {
3943
if (this.hasPopoverTarget) { this.popoverTarget.remove() }
4044
}
@@ -52,4 +56,8 @@ export default class extends Controller {
5256
get confirmText() {
5357
return this.data.get('confirm')
5458
}
59+
60+
get modal() {
61+
return document.getElementById('modal').modal
62+
}
5563
}

app/views/shared/_popover.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<% else %>
1717
<div
1818
data-controller="modal"
19-
data-action="click->modal#present"
19+
data-action="click->popover#presentModal"
2020
data-modal-url="<%= option[:url] %>"
2121
class="popover--item"
2222
>
Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
1-
<%= render 'shared/modal', header: @header do %>
2-
<div
3-
data-controller="snippets"
4-
data-snippets-selected-folder-id="<%= @current_folder_id %>"
5-
data-snippets-original-folder-id="<%= @current_folder_id %>"
6-
data-snippets-confirm-path="<%= file_snippet_path(@snippet) %>"
7-
>
8-
<input data-action="keyup->snippets#modal_search" class="move-snippet--search" type="search" placeholder="Find a folder...">
9-
<div class="move-snippet--list" data-target="snippets.list">
10-
<% @folders.each do |folder| %>
11-
<div
12-
data-action="click->snippets#select_folder"
13-
data-folder-id="<%= folder.id %>"
14-
data-target="snippets.listItem"
15-
data-filter-key="<%= folder.name %>"
16-
class="<%= folder.id == @current_folder_id ? 'move-snippet--item-selected' : 'move-snippet--item' %>"
17-
>
18-
<span><%= folder.name %></span>
19-
<% if folder.id == @current_folder_id %>
20-
<img id="selected-checkmark" src="/icons/checked.svg" width="14">
21-
<% end %>
22-
</div>
23-
<% end %>
24-
</div>
25-
<div class="move-snippet--buttons">
26-
<button data-action="click->modal#close" class="button--cta-cancel">CANCEL</button>
27-
<button
28-
data-action="click->snippets#file"
29-
data-target="snippets.moveButton"
30-
class="button--cta-disabled"
31-
disabled
1+
<div
2+
data-controller="snippets"
3+
data-snippets-selected-folder-id="<%= @current_folder_id %>"
4+
data-snippets-original-folder-id="<%= @current_folder_id %>"
5+
data-snippets-confirm-path="<%= file_snippet_path(@snippet) %>"
6+
>
7+
<input data-action="keyup->snippets#modal_search" class="move-snippet--search" type="search" placeholder="Find a folder...">
8+
<div class="move-snippet--list" data-target="snippets.list">
9+
<% @folders.each do |folder| %>
10+
<div
11+
data-action="click->snippets#select_folder"
12+
data-folder-id="<%= folder.id %>"
13+
data-target="snippets.listItem"
14+
data-filter-key="<%= folder.name %>"
15+
class="<%= folder.id == @current_folder_id ? 'move-snippet--item-selected' : 'move-snippet--item' %>"
3216
>
33-
<%= @header.upcase %>
34-
</button>
35-
</div>
17+
<span><%= folder.name %></span>
18+
<% if folder.id == @current_folder_id %>
19+
<img id="selected-checkmark" src="/icons/checked.svg" width="14">
20+
<% end %>
21+
</div>
22+
<% end %>
3623
</div>
37-
<% end %>
24+
<div class="move-snippet--buttons">
25+
<button data-action="click->modal#close" class="button--cta-cancel">CANCEL</button>
26+
<button
27+
data-action="click->snippets#file"
28+
data-target="snippets.moveButton"
29+
class="button--cta-disabled"
30+
disabled
31+
>
32+
<%= @header.upcase %>
33+
</button>
34+
</div>
35+
</div>

0 commit comments

Comments
 (0)