X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=js%2Fkivi.js;h=31a56a4434df811a1b0e6ad07d5c31c6a57f88f2;hb=57d5d7a285a208e9a24f7cf56ab6eeede95e190c;hp=c6245c8552bf8c799d32657c1a31a27ca027e5a7;hpb=bc1d6d175b170b8b71e16d9fc8d3e2af5be67425;p=kivitendo-erp.git diff --git a/js/kivi.js b/js/kivi.js index c6245c855..31a56a443 100644 --- a/js/kivi.js +++ b/js/kivi.js @@ -676,6 +676,49 @@ namespace("kivi", function(ns) { $input.prop('selectionStart', position); $input.prop('selectionEnd', position); }; + + ns._shell_escape = function(str) { + if (str.match(/^[a-zA-Z0-9.,_=+/-]+$/)) + return str; + + return "'" + str.replace(/'/, "'\\''") + "'"; + }; + + ns.call_as_curl = function(params) { + params = params || {}; + var uri = document.documentURI.replace(/\?.*/, ''); + var command = ['curl', '--user', kivi.myconfig.login + ':SECRET', '--request', params.method || 'POST'] + + $(params.data || []).each(function(idx, elt) { + command = command.concat([ '--form-string', elt.name + '=' + (elt.value || '') ]); + }); + + command.push(uri); + + return $.map(command, function(elt, idx) { + return kivi._shell_escape(elt); + }).join(' '); + }; + + ns.serialize = function(source, target = [], prefix, in_array = false) { + let arr_prefix = first => in_array ? (first ? "[+]" : "[]") : ""; + + if (Array.isArray(source) ) { + source.forEach(( val, i ) => { + ns.serialize(val, target, prefix + arr_prefix(i == 0), true); + }); + } else if (typeof source === "object") { + let first = true; + for (let key in source) { + ns.serialize(source[key], target, (prefix !== undefined ? prefix + arr_prefix(first) + "." : "") + key); + first = false; + } + } else { + target.push({ name: prefix + arr_prefix(false), value: source }); + } + + return target; + }; }); kivi = namespace('kivi');