window.utils = Utils = {}; Utils.pushWaterfallPayload = function(data) { return (cb) => cb(null, data); }; Utils.waterfallWithHooks = function(opts, cb) { cb = cb || function(){}; opts = Object.assign({ pre: [], post: [], data: {}, action: (payload, cb) => cb(null, payload) }, opts); async.waterfall([ // Yield the data to pre hooks Utils.pushWaterfallPayload(opts.data), // Perform pre hooks ...opts.pre, // Perform the create request opts.action, // Perform post hooks ...opts.post ], cb); }; Utils.request = function(opts, cb) { opts = Object.assign({ url: '/', type: 'POST', data: '{}', dataType: 'json', contentType: 'application/json; charset=utf-8', ignoreErrors: false }, opts || {}, { success: (result) => cb(null, result) }); errCb = (err) => cb(err); if (opts.ignoreErrors) { errCb = (err) => cb(null, err); } $.ajax(opts).fail(errCb); }; Utils.escape = function(str) { return str.replace(/&/g, "&") .replace(//g, ">"); }; Utils.prepareOutput = function(output) { try { if (typeof output !== 'object') { output = JSON.parse(output); } output = JSON.stringify(output, null, 2); } catch { } return window.utils.escape(output); }; Utils.clipboardButton = function(id) { id = id || 'data'; return ` Copy result to clipboard `; }; Utils.clipboardBadge = function(id) { id = id || 'data'; return ` `; }; Utils.card = function(opts) { opts = Object.assign({ id: 'details', icon: 'fa-asterisk', title: 'Details', body: '' }, opts || {}); return `
${opts.body}
`; };