[enh] Implements bootstrap modal as confirm dialog.

This commit is contained in:
opi 2014-11-17 13:59:28 +01:00
parent 79542a4b13
commit d1433ab4b6
6 changed files with 97 additions and 12 deletions

View file

@ -209,24 +209,51 @@ body {
*
*/
#popup {
#modal {
.modal;
.fade;
overflow-y: auto;
& > div {
.modal-dialog;
.modal-dialog;
& > div {
.modal-content;
}
}
#popup-title {
.modal-header;
header {
.modal-header;
.title {
.modal-title;
font-weight: bold;
text-transform: uppercase;
margin: 0;
}
}
#popup-body {
.modal-body;
&.no-title header {display: none;}
.content {
.modal-body;
}
footer {
.modal-footer;
button {
.btn;
&#modal-cancel {.btn-link;}
&#modal-confirm {.btn-primary;}
}
}
}
@media (min-width: 768px) {
#modal > div > div {
width: 600px;
margin: 30px auto;
}
}
/*
* Various styles

4
css/style.min.css vendored

File diff suppressed because one or more lines are too long

View file

@ -40,10 +40,23 @@
</div>
<div id="popup" role="dialog"><div>
<h2 id="popup-title"></h2>
<div id="popup-body"></div>
</div></div>
<div id="modal" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<div><div>
<header>
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">&times;</span>
<span class="sr-only" data-y18n="close">Close</span>
</button>
<h4 class="title" id="modalLabel"></h4>
</header>
<div class="content"></div>
<footer>
<button type="button" id="modal-cancel" data-action="cancel" data-y18n="cancel">Cancel</button>
<button type="button" id="modal-confirm" data-action="confirm" data-y18n="ok">OK</button>
</footer>
</div></div>
</div>
<script type="text/javascript" src="js/vendor/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="js/vendor/handlebars-v1.3.0.js"></script>

View file

@ -228,6 +228,7 @@ app = Sammy('#main', function (sam) {
loaded = true;
$('div.loader').remove();
$('#modal').modal('hide');
if (enableSlide) {
function leSwap() {
@ -279,6 +280,48 @@ app = Sammy('#main', function (sam) {
}
},
confirm: function(title, content, confirmCallback, cancelCallback) {
// Default callbacks
confirmCallback = typeof confirmCallback !== 'undefined' ? confirmCallback : function() {};
cancelCallback = typeof cancelCallback !== 'undefined' ? cancelCallback : function() {};
// Get modal element
box = $('#modal');
// Modal title
if (typeof title === 'string' && title.length) {
$('.title', box).html(title);
}
else {
box.addClass('no-title');
}
// Modal content
$('.content', box).html(content);
// Handle buttons
$('footer button', box)
.click(function(e){
e.preventDefault();
// Reset & Hide modal
box
.removeClass('no-title')
.modal('hide');
// Do corresponding callback
if ($(this).data('action') == 'confirm') {
confirmCallback();
}
else {
cancelCallback();
}
});
// Show modal
return box.modal('show');
},
arraySortById: function(arr) {
arr.sort(function(a, b){
if (a.id > b.id) {

View file

@ -37,6 +37,7 @@
"both" : "Both",
"home" : "Home",
"read_more" : "Read more",
"cancel" : "Cancel",
"installing" : "Installing",
"installed" : "Installed",

View file

@ -37,6 +37,7 @@
"both" : "Les deux",
"home" : "Accueil",
"read_more" : "En savoir plus",
"cancel" : "Annuler",
"installing" : "Installation",
"installed" : "Installé",