/* exported showMsg, showAjaxError, showModal */ 'use strict'; /** * Show message to div#msg with level * * @param {string} msg * @param {string} type * @return {void} */ function showMsg(msg, type = 'info') { $('[id=msg]').removeClass().addClass('callout').addClass(`callout-${type}`).html(msg); } /** * Show modal if error occured when sending an ajax request. * * @param {object} json * @return {void} */ function showAjaxError(json) { if (typeof json == 'string') { return console.warn(json); } if (! json.responseText) { return console.warn('Empty Ajax response body.'); } showModal(json.responseText.replace(/\n/g, '
'), trans('general.fatalError'), 'danger'); } function showModal(msg, title = 'Message', type = 'default', options = {}) { let btnType = (type != 'default') ? 'btn-outline' : 'btn-primary'; let onClick = (options.callback === undefined) ? 'data-dismiss="modal"' : `onclick="${options.callback}"`; let dom = ` `; $(dom).modal(options); }