/** * Displays a modal for confirmation with the "body" modal * body, then executes the given callback on confirmation. * * @param body String * @param callback Function * @param $extraField object Dom object for the extra field to be added * @param auto_close boolean Auto close the modal on clicking confirmation or not * @return void */ function confirmModal(body, callback, $extraField=null, auto_close=false) { const $modal = $('#confirm-modal'); const $apply = $('#confirm-modal-apply'); if ( typeof callback !== 'function' ) return; $modal.find('#confirm-modal-message').text(body); if( $extraField ){ ($modal.find('.L-extra-field-wrapper')).append($extraField); } $modal.modal('show'); $apply.on('click', function () { if(auto_close){ $modal.modal('hide'); } callback(); }); $modal.on('hide.bs.modal', function () { if( $extraField ){ $extraField.remove(); } }); $modal.on('hidden.bs.modal', function () { $apply.off('click'); }); }