// @require variables: if ('undefined' === typeof JS_FUNCTION_NAME) throw "Missing JS_FUNCTION_NAME"; if ('undefined' === typeof URL_GET_TABLE_TOOLS) throw "Missing URL_GET_TABLE_TOOLS"; function toggleTableTools(n) { var $n = jQuery(n); var $ul = $n.next(); if ($n.data('fetched')) return false; function renderTableToolsData(tableTools) { var procesInitMapHtml = ''; if (!tableTools) { return '
  • ' + "Brak danych" + '
  • '; } else if (!tableTools.length) { return '
  • ' + "Brak narzędzi dla tej tabeli" + '
  • '; } else { return tableTools.map(function (tool) { return '
  • ' + tool.label + '
  • '; }) } return procesInitMapHtml; } window.fetch(URL_GET_TABLE_TOOLS, { method: 'GET', credentials: 'same-origin', }).then(function (response) { return response.json() }).then(function (data) { var type = data.type || null var msg = data.msg || "Error" var tableTools = (data.body && data.body.tableTools) ? data.body.tableTools : null if (type) { if ('success' == type) { $ul.html(renderTableToolsData(tableTools)); } else if ('error' == type) { $ul.html('
  • ' + msg + '
  • '); } else { $ul.html('
  • Wystapił błąd podczas pobierania listy narzędzi
  • '); } } else { $ul.html('
  • Wystapił błąd podczas pobierania listy narzędzi
  • '); } $n.data('fetched', true); }).catch(function (e) { console.warn(e) }) return false; } global[JS_FUNCTION_NAME] = toggleTableTools