var myconfirm=function(opts) { BootstrapDialog.show({ title: opts.title || 'Confirmation', message: opts.question || 'Confirmez-vous ?', autodestroy: true, cssClass: opts.css_class || 'modal-warning', type: opts.type || 'type-default', data: { oncancel: opts.oncancel, onconfirm: opts.onconfirm, data: opts.data, confirm: false, }, buttons: [ { label: opts.cancel_label || 'Annuler', action: function(dialog) { dialog.close(); } }, { label: opts.confirm_label || 'Valider', cssClass: 'btn-danger', action: function(dialog) { dialog.setData('confirm',true); dialog.close(); } } ], onhidden: function(dialog) { if (dialog.getData('confirm')) { if (jQuery.type(dialog.getData('onconfirm')) == 'function') { dialog.getData('onconfirm')(dialog.getData('data')); } } else { if (jQuery.type(dialog.getData('oncancel')) == 'function') { dialog.getData('oncancel')(dialog.getData('data')); } } } }); } var myalert=function(title,msg,opts) { if ($.type(opts) != "object") { opts={}; } BootstrapDialog.show({ title: title || opts.title || 'Erreur', message: msg, autodestroy: true, type: opts.type || 'type-danger', size: opts.size || 'size-normal', data: { data: opts.data, onclose: opts.onclose, }, buttons: [ { label: opts.btnLabel || 'OK', cssClass: opts.btnCssClass ||'btn-primary', action: function(dialog) { dialog.close(); } }, ], onhidden: function(dialog) { if ($.type(dialog.getData('onclose')) == 'function') { dialog.getData('onclose')(dialog.getData('data')); } } }); } var myprompt=function(opts) { if ($.type(opts) != "object") { opts={}; } var onSubmitBtnClick = function(dialog) { dialog.setData('submited',true); var val = dialog.getModalBody().find('input').val(); if (jQuery.type(dialog.getData('onsubmit')) == 'function') { if (!dialog.getData('onsubmit')(val, dialog.getData('data'))) { if (jQuery.type(dialog.getData('onerror')) == 'function') { dialog.getData('onerror')(val, dialog.getData('data')); } if (!dialog.getData('closeonerror')) { return false; } } } dialog.close(); }; BootstrapDialog.show({ title: opts.title || 'Question', message: "", autodestroy: true, type: opts.type || 'type-info', size: opts.size || 'size-normal', data: { oncancel: opts.oncancel, onsubmit: opts.onsubmit, onerror: opts.onerror, closeonerror: opts.closeonerror || false, default_answer: opts.default_answer, onSubmitBtnClick: onSubmitBtnClick, data: opts.data, submited: false, }, buttons: [ { label: opts.cancel_label || 'Annuler', action: function(dialog) { dialog.close(); } }, { label: opts.submit_label || 'Valider', cssClass: 'btn-danger', action: onSubmitBtnClick } ], onshow: function(dialog) { var input = dialog.getModalBody().find('input'); input.on('keyup', function (e) { if (e.keyCode == 13) { dialog.getData('onSubmitBtnClick')(dialog); } }); if (dialog.getData('default_answer')) { input.val(dialog.getData('default_answer')); } }, onhidden: function(dialog) { if (!dialog.getData('submited') && jQuery.type(dialog.getData('oncancel')) == 'function') { dialog.getData('oncancel')(dialog.getData('data')); } } }); } var myloadingalert=function(msg,opts) { if ($.type(opts) != "object") { opts={}; } BootstrapDialog.show({ title: opts.title || 'Merci de patienter', message: msg, autodestroy: true, type: opts.type || 'type-info', size: opts.size || 'size-normal', closable: opts.closable || false, }); }; $( document ).ready(function () { // Manage .myconfirm-link $('.myconfirm-link').click(function(event) { event.preventDefault(); myconfirm({ title: $(this).data("myconfirm-title") || "Confirmation", question: "
"+($(this).data("myconfirm-question") || "Êtes-vous sûre ?")+"
", onconfirm: function(data) { window.location = data.confirm_url; }, data: { confirm_url: $(this).data('myconfirm-url') } }); }); // Manage .myconfirm-btn $('.myconfirm-btn').click(function(event) { if ($(this).data('myconfirm-btn-confirmed') == '1') { $(this).data('myconfirm-btn-confirmed', ''); return true; } event.preventDefault(); myconfirm({ title: $(this).data("myconfirm-title") || "Confirmation", question: ""+($(this).data("myconfirm-question") || "Êtes-vous sûre ?")+"
", onconfirm: function(data) { data.btn.data('myconfirm-btn-confirmed', 1); data.btn.click(); }, data: { btn: $(this) } }); }); });