Skip to content

Commit c0aaf79

Browse files
ycerutojaviereguiluz
authored andcommitted
confirmation message using bootstrap modal
1 parent a41db16 commit c0aaf79

File tree

9 files changed

+101
-13
lines changed

9 files changed

+101
-13
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of the Symfony package.
3+
*
4+
* (c) Fabien Potencier <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
/**
11+
* jQuery plugin for a modal confirmation message.
12+
*
13+
* @author Yonel Ceruto <[email protected]>
14+
*/
15+
(function ($) {
16+
$(document).on('submit', 'form[data-confirmation]', function (event) {
17+
var $form = $(this),
18+
$confirm = $('#confirmationModal');
19+
20+
if ($confirm.data('result') !== 'yes') {
21+
//cancel submit event
22+
event.preventDefault();
23+
24+
$confirm
25+
.off('click', '#btnYes')
26+
.on('click', '#btnYes', function () {
27+
$confirm.data('result', 'yes');
28+
$form.submit();
29+
})
30+
.modal('show');
31+
}
32+
});
33+
})(window.jQuery);

app/Resources/assets/scss/main.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ footer {
136136
}
137137
}
138138

139+
// Confirmation Modal Window
140+
#confirmationModal {
141+
.modal-dialog {
142+
width: 500px;
143+
}
144+
145+
.modal-footer {
146+
button {
147+
min-width: 75px;
148+
}
149+
}
150+
}
151+
139152
//
140153
// Forms
141154
// --------------------------------------------------

app/Resources/translations/messages.en.xliff

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@
8484
<source>action.delete_post_confirmation</source>
8585
<target>Are you sure you want to delete this post?</target>
8686
</trans-unit>
87+
<trans-unit id="title.confirmation_modal">
88+
<source>title.confirmation_modal</source>
89+
<target>Confirmation</target>
90+
</trans-unit>
91+
<trans-unit id="label.yes">
92+
<source>label.yes</source>
93+
<target>Yes</target>
94+
</trans-unit>
95+
<trans-unit id="label.no">
96+
<source>label.no</source>
97+
<target>No</target>
98+
</trans-unit>
8799
<trans-unit id="action.create_post">
88100
<source>action.create_post</source>
89101
<target>Create a new post</target>

app/Resources/translations/messages.es.xliff

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@
8888
<source>action.delete_post_confirmation</source>
8989
<target>¿Está seguro que quiere eliminar este artículo?</target>
9090
</trans-unit>
91+
<trans-unit id="title.confirmation_modal">
92+
<source>title.confirmation_modal</source>
93+
<target>Confirmación</target>
94+
</trans-unit>
95+
<trans-unit id="label.yes">
96+
<source>label.yes</source>
97+
<target>Sí</target>
98+
</trans-unit>
99+
<trans-unit id="label.no">
100+
<source>label.no</source>
101+
<target>No</target>
102+
</trans-unit>
91103
<trans-unit id="action.create_post">
92104
<source>action.create_post</source>
93105
<target>Crear un nuevo artículo</target>

app/Resources/views/admin/blog/_form.html.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#}
88

99
{% if show_confirmation|default(false) %}
10-
{% set attr = {'data-confirmation-message': 'action.delete_post_confirmation'|trans} %}
10+
{% set attr = {'data-confirmation': 'true'} %}
11+
{{ include('default/_confirmation_modal.html.twig', {'message': 'action.delete_post_confirmation'|trans}) }}
1112
{% endif %}
1213

1314
{{ form_start(form, { attr: attr|default({}) }) }}

app/Resources/views/base.html.twig

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@
144144
{% javascripts filter="?jsqueeze" output="js/app.js"
145145
"%kernel.root_dir%/Resources/assets/js/jquery-2.1.4.js"
146146
"%kernel.root_dir%/Resources/assets/js/bootstrap-3.3.4.js"
147-
"%kernel.root_dir%/Resources/assets/js/highlight.pack.js" %}
147+
"%kernel.root_dir%/Resources/assets/js/highlight.pack.js"
148+
"%kernel.root_dir%/Resources/assets/js/jquery.confirm_modal.js" %}
148149
<script src="{{ asset_url }}"></script>
149150
{% endjavascripts %}
150151
#}
@@ -155,15 +156,6 @@
155156
$(document).ready(function() {
156157
hljs.initHighlightingOnLoad();
157158
});
158-
159-
$(document).on('submit', 'form[data-confirmation-message]', function (event) {
160-
var message = $(this).data('confirmation-message');
161-
162-
if (confirm(message) === false) {
163-
//cancel the event
164-
event.preventDefault();
165-
}
166-
});
167159
</script>
168160
{% endblock %}
169161

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{# Bootstrap modal, see http://getbootstrap.com/javascript/#modals #}
2+
<div class="modal fade" id="confirmationModal" tabindex="-1">
3+
<div class="modal-dialog">
4+
<div class="modal-content">
5+
<div class="modal-header">
6+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
7+
<span aria-hidden="true">&times;</span>
8+
</button>
9+
<h4 class="modal-title">{{ 'title.confirmation_modal'|trans }}</h4>
10+
</div>
11+
<div class="modal-body">
12+
{{ message }}
13+
</div>
14+
<div class="modal-footer">
15+
<button type="button" class="btn btn-danger" id="btnYes" data-dismiss="modal">
16+
{{ 'label.yes'|trans }}
17+
</button>
18+
<button type="button" class="btn btn-default" id="btnNo" data-dismiss="modal">
19+
{{ 'label.no'|trans }}
20+
</button>
21+
</div>
22+
</div>
23+
</div>
24+
</div>

web/css/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)