Skip to content

Commit

Permalink
use data- attributes to pass data
Browse files Browse the repository at this point in the history
  • Loading branch information
HesterG committed Apr 20, 2023
1 parent 5f92db8 commit f9430f7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
4 changes: 2 additions & 2 deletions templates/base/page_dimmer_buttons.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="actions">
<button class="ui red cancel button">
<button class="ui red cancel button cancel-button">
{{svg "octicon-x"}}
{{if .ModalNoText}}{{.ModalNoText}}{{else}}{{.locale.Tr "modal.no"}}{{end}}
</button>
<button class="ui green ok button{{if .ExtendedClasses}} {{.ExtendedClasses}}{{end}}" {{if .DataUrl}}data-url="{{.DataUrl}}"{{end}}>
<button class="ui green ok button confirm-button">
{{svg "octicon-check"}}
{{if .ModalYesText}}{{.ModalYesText}}{{else}}{{.locale.Tr "modal.yes"}}{{end}}
</button>
Expand Down
14 changes: 7 additions & 7 deletions templates/projects/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@
{{$.locale.Tr "repo.projects.column.unset_default"}}
</a>
{{end}}
<a class="item show-modal button" data-modal="#delete-board-modal-{{.ID}}">
<a class="item show-modal button show-delete-column-modal"
data-modal="#delete-board-modal-{{.ID}}"
data-url="{{$.Link}}/{{.ID}}"
>
{{svg "octicon-trash"}}
{{$.locale.Tr "repo.projects.column.delete"}}
</a>
Expand Down Expand Up @@ -171,12 +174,9 @@
{{$.locale.Tr "repo.projects.column.deletion_desc"}}
</label>
</div>
<div class="text right actions">
{{$DataUrl := printf "%s/%d" $.Link .ID}}
{{$ModalNoText := $.locale.Tr "settings.cancel"}}
{{$ModalYesText := $.locale.Tr "repo.projects.column.delete"}}
{{template "base/page_dimmer_buttons" (dict "." $ "ExtendedClasses" "delete-project-board" "DataUrl" $DataUrl "ModalNoText" $ModalNoText "ModalYesText" $ModalYesText)}}
</div>
{{$ModalNoText := $.locale.Tr "settings.cancel"}}
{{$ModalYesText := $.locale.Tr "repo.projects.column.delete"}}
{{template "base/page_dimmer_buttons" (dict "." $ "ModalNoText" $ModalNoText "ModalYesText" $ModalYesText)}}
</div>
</div>
</div>
Expand Down
14 changes: 7 additions & 7 deletions templates/repo/projects/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@
{{$.locale.Tr "repo.projects.column.unset_default"}}
</a>
{{end}}
<a class="item show-modal button" data-modal="#delete-board-modal-{{.ID}}">
<a class="item show-modal button show-delete-column-modal"
data-modal="#delete-board-modal-{{.ID}}"
data-url="{{$.RepoLink}}/projects/{{$.Project.ID}}/{{.ID}}"
>
{{svg "octicon-trash"}}
{{$.locale.Tr "repo.projects.column.delete"}}
</a>
Expand Down Expand Up @@ -177,12 +180,9 @@
{{$.locale.Tr "repo.projects.column.deletion_desc"}}
</label>
</div>
<div class="text right actions">
{{$DataUrl := printf "%s/projects/%d/%d" $.RepoLink $.Project.ID .ID}}
{{$ModalNoText := $.locale.Tr "settings.cancel"}}
{{$ModalYesText := $.locale.Tr "repo.projects.column.delete"}}
{{template "base/page_dimmer_buttons" (dict "." $ "ExtendedClasses" "delete-project-board" "DataUrl" $DataUrl "ModalNoText" $ModalNoText "ModalYesText" $ModalYesText)}}
</div>
{{$ModalNoText := $.locale.Tr "settings.cancel"}}
{{$ModalYesText := $.locale.Tr "repo.projects.column.delete"}}
{{template "base/page_dimmer_buttons" (dict "." $ "ModalNoText" $ModalNoText "ModalYesText" $ModalYesText)}}
</div>
</div>
</div>
Expand Down
12 changes: 8 additions & 4 deletions web_src/js/features/repo-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,16 @@ export function initRepoProject() {
});
});

$('.delete-project-board').each(function () {
$(this).click(function (e) {
$('.show-delete-column-modal').each(function () {
const deleteColumnModal = $(`${$(this).attr('data-modal')}`);
const deleteColumnButton = deleteColumnModal.find('.confirm-button');
const deleteUrl = $(this).attr('data-url');

deleteColumnButton.on('click', function (e) {
e.preventDefault();

$.ajax({
url: $(this).data('url'),
url: deleteUrl,
headers: {
'X-Csrf-Token': csrfToken,
},
Expand All @@ -162,7 +166,7 @@ export function initRepoProject() {
window.location.reload();
});
});
});
})

$('#new_board_submit').click(function (e) {
e.preventDefault();
Expand Down

0 comments on commit f9430f7

Please sign in to comment.