var clientUUID = ''; var advancedDisplayed = false; var json = {}; var jsonIndex = 0; var host = window.location.protocol + "//" + window.location.hostname + "/mock"; const C_UUID = 'mock-uuid'; const C_ADV = 'advanced-mode'; const color_red = "#ff8f8f"; const color_grey = "#6b6b6b"; const setModified = function(){ setDataModified(); } const getUpdate = function(){ updateData(); } const dataRefresh = function(){ getData(); } /* Listeners segment */ $(document).on('change', '.data-field', setModified); $('#btn-save').click( () => { disableSaveButton(); } ); $('#btn-newRow').click( ()=> { newRowInput(); setDataModified(); } ); $('#btn-copy').click( ()=> { var link = $("#messageLink").html(); navigator.clipboard.writeText(link); } ); /* Functions segment */ function disableSaveButton(){ $('#btn-save').removeClass('active'); $('#btn-save').off(); } function createLink(uuid){ var link = host + '/api/mock/r/'+uuid; return link; } function onLoad(){ loadCookies(); getData(); } function getData(){ $.getJSON(host + '/api/mock/'+clientUUID, function(data) { json = data; loadFetchedMessage(); initializeUUID(); }); } function loadCookies(){ clientUUID = getCookie(C_UUID); advancedDisplayed = getCookie(C_ADV) == 'true'; } function setCookie(){ document.cookie = C_UUID + '=' +clientUUID; document.cookie = C_ADV + '=' + advancedVisibility; } function initializeUUID(){ if(clientUUID == null || clientUUID == undefined || clientUUID == ''){ clientUUID = json.clientUUID; setCookie(); } } function httpStatusInvalid(){ value = $('#httpStatus').val(); return value == ''; } function setDataModified(){ if(httpStatusInvalid()){ $('#btn-save').removeClass('active'); $('#btn-save').off(); document.getElementById("httpStatus").style.backgroundColor = color_red; return; } $('#btn-save').addClass('active'); $('#btn-save').click(getUpdate); document.getElementById("httpStatus").style.backgroundColor = null; } function getCookie(cname) { var name = cname + '='; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i ' + '' + '' + ''; } return '' + '' + '' + '' + '' + ''; } function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } function createRequestBody(){ var newJson = { clientUUID: json.clientUUID, contentType: $('#typeSelector').val(), messageBody: $('#bodyEditor').val(), httpStatus: $('#httpStatus').val(), httpHeaders: {}, }; newJson['httpHeaders'] = convertTableToJson(); json = newJson; return newJson; } function convertTableToJson(){ const rows = $('#headerMapTable').children(); var obj = {}; var key; for(let i=0; i