/************************************* * SPDX-FileCopyrightText: 2009-2020 Vtenext S.r.l. * SPDX-License-Identifier: AGPL-3.0-only ************************************/ /* crmv@146670 crmv@146671 */ var ExtWSConfig = { busy: false, showBusy: function() { var me = this; me.busy = true; jQuery('#extws_busy').show(); }, hideBusy: function() { var me = this; me.busy = false; jQuery('#extws_busy').hide(); }, createNew: function() { if (this.busy) return; this.showBusy(); location.href = 'index.php?module=Settings&action=ExtWSConfig&parentTab=Settings&mode=create'; }, editWS: function(wsid) { if (this.busy) return; this.showBusy(); location.href = 'index.php?module=Settings&action=ExtWSConfig&parentTab=Settings&mode=edit&extwsid='+wsid; }, testWS: function(wsid) { var me = this; if (me.busy) return; me.prepareFieldForSave(); if (!me.validate(false)) return false; // crmv@147433 var formval = jQuery('#extws_form').serializeArray(), params = {}; jQuery.each(formval, function(idx, el) { params[el.name] = el.value; }); params[extwsid] = wsid; me.ajaxCall('test_ws', params, function(data) { // populate the popup var result = data.result; if (result) { me.populateTestResult(result); me.gotoTestTab('result'); showFloatingDiv('TestWSWindow'); } }); }, populateTestResult: function(result) { var me = this; jQuery('#wstest_status').removeClass('text-success text-danger').addClass(result.success ? 'text-success' : 'text-danger') .text(result.success ? alert_arr.SUCCESS : alert_arr.ERROR); jQuery('#wstest_code').text(result.code +' '+result.message); if (result.headers) { var htext = ""; for (var key in result.headers) { var val = result.headers[key]; htext += key+': '+val+"\r\n"; } if (!me.headers_code) { me.headers_code = CodeMirror.fromTextArea(jQuery('#wstest_headers')[0], { mode: 'http', readOnly: true, theme: 'eclipse', lineWrapping: false, indentUnit: 4, tabSize: 4, indentWithTabs: true, }); } me.headers_code.setValue(htext); } me.body_response = null; if (result.body) { if (!me.body_code) { me.body_code = CodeMirror.fromTextArea(jQuery('#wstest_body')[0], { mode: null, readOnly: true, theme: 'eclipse', lineWrapping: true, maxHighlightLength: 50000, }); } me.body_code.setValue(result.body); // now detect the format of the response var beginBody = result.body.substring(0, 5), format = 'raw'; if (beginBody == ' span').text(); // check emptyness if (!wsname) return me.displayError(alert_arr.CANNOT_BE_EMPTY.replace('%s', alert_arr.LBL_NAME)); if (!wsurl) return me.displayError(alert_arr.CANNOT_BE_EMPTY.replace('%s', wsurl_label)); // check results if (checkResults) { var table = jQuery('#results_table'); var fields = JSON.parse(jQuery('#extws_results').val()) || []; if (table.find('tr').length <= 2 || fields.length == 0) { return me.displayError(alert_arr.LBL_EXTWS_NO_RETURN_FIELDS); } // check for resultswith same name var names = jQuery.map(fields, function(o) { return o["name"]; }); var dup = false; for (var i=0; i