2023-02-16 14:52:05 +01:00
|
|
|
function executePagination(selector, url) {
|
|
|
|
UI.reload(url, $(selector), $(selector).find('table.table'))
|
2020-05-29 13:41:58 +02:00
|
|
|
}
|
2020-06-04 10:05:45 +02:00
|
|
|
|
|
|
|
function executeStateDependencyChecks(dependenceSourceSelector) {
|
|
|
|
if (dependenceSourceSelector === undefined) {
|
|
|
|
var tempSelector = "[data-dependence-source]";
|
|
|
|
} else {
|
|
|
|
var tempSelector = '*[data-dependence-source="' + dependenceSourceSelector + '"]';
|
|
|
|
}
|
|
|
|
$(tempSelector).each(function(index, dependent) {
|
|
|
|
var dependenceSource = $(dependent).data('dependence-source');
|
|
|
|
if ($(dependent).data('dependence-option') === $(dependenceSource).val()) {
|
|
|
|
$(dependent).parent().parent().removeClass('d-none');
|
|
|
|
} else {
|
|
|
|
$(dependent).parent().parent().addClass('d-none');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-12-10 15:18:02 +01:00
|
|
|
|
2021-06-23 11:15:22 +02:00
|
|
|
function toggleAllAttributeCheckboxes(clicked) {
|
|
|
|
let $clicked = $(clicked)
|
|
|
|
let $table = $clicked.closest('table')
|
|
|
|
let $inputs = $table.find('input.selectable_row')
|
|
|
|
$inputs.prop('checked', $clicked.prop('checked'))
|
|
|
|
}
|
|
|
|
|
2021-01-13 14:24:07 +01:00
|
|
|
function testConnection(id) {
|
2021-01-14 12:42:05 +01:00
|
|
|
$container = $(`#connection_test_${id}`)
|
|
|
|
UI.overlayUntilResolve(
|
|
|
|
$container[0],
|
|
|
|
AJAXApi.quickFetchJSON(`/broods/testConnection/${id}`),
|
|
|
|
{text: 'Running test'}
|
|
|
|
).then(result => {
|
|
|
|
const $testResult = attachTestConnectionResultHtml(result, $container)
|
|
|
|
$(`#connection_test_${id}`).append($testResult)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
const $testResult = attachTestConnectionResultHtml(error.message, $container)
|
|
|
|
$(`#connection_test_${id}`).append($testResult)
|
2021-01-13 14:24:07 +01:00
|
|
|
})
|
|
|
|
}
|
2021-01-14 09:15:37 +01:00
|
|
|
|
2021-01-14 12:42:05 +01:00
|
|
|
function attachTestConnectionResultHtml(result, $container) {
|
|
|
|
function getKVHtml(key, value, valueClasses=[], extraValue='') {
|
|
|
|
return $('<div/>').append(
|
|
|
|
$('<strong/>').text(key + ': '),
|
|
|
|
$('<span/>').addClass(valueClasses).text(value),
|
|
|
|
$('<span/>').text(extraValue.length > 0 ? ` (${extraValue})` : '')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
$container.find('div.tester-result').remove()
|
|
|
|
$testResultDiv = $('<div class="tester-result"></div>');
|
|
|
|
if (typeof result !== 'object') {
|
2021-09-17 17:51:45 +02:00
|
|
|
$testResultDiv.append(getKVHtml('Internal error', result, ['text-danger fw-bold']))
|
2021-01-14 12:42:05 +01:00
|
|
|
} else {
|
|
|
|
if (result['error']) {
|
|
|
|
$testResultDiv.append(
|
2023-01-19 10:27:54 +01:00
|
|
|
getKVHtml('Status', `Error: ${result['error']}`, ['text-danger'], (result['ping'] ? `${result['ping']} ms` : '')),
|
2021-01-14 12:42:05 +01:00
|
|
|
getKVHtml('Reason', result['reason'], ['text-danger'])
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
const canSync = result['response']['role']['perm_admin'] || result['response']['role']['perm_sync'];
|
|
|
|
$testResultDiv.append(
|
|
|
|
getKVHtml('Status', 'OK', ['text-success'], `${result['ping']} ms`),
|
|
|
|
getKVHtml('Remote', `${result['response']['application']} v${result['response']['version']}`),
|
|
|
|
getKVHtml('User', result['response']['user'], [], result['response']['role']['name']),
|
|
|
|
getKVHtml('Sync permission', (canSync ? 'Yes' : 'No'), [(canSync ? 'text-success' : 'text-danger')]),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $testResultDiv
|
|
|
|
}
|
|
|
|
|
2021-06-01 07:46:51 +02:00
|
|
|
function syntaxHighlightJson(json, indent) {
|
|
|
|
if (indent === undefined) {
|
|
|
|
indent = 2;
|
|
|
|
}
|
|
|
|
if (typeof json == 'string') {
|
|
|
|
json = JSON.parse(json);
|
|
|
|
}
|
|
|
|
json = JSON.stringify(json, undefined, indent);
|
|
|
|
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/(?:\r\n|\r|\n)/g, '<br>').replace(/ /g, ' ');
|
|
|
|
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
|
|
|
|
var cls = 'text-info';
|
|
|
|
if (/^"/.test(match)) {
|
|
|
|
if (/:$/.test(match)) {
|
|
|
|
cls = 'text-primary';
|
|
|
|
} else {
|
|
|
|
cls = '';
|
|
|
|
}
|
|
|
|
} else if (/true|false/.test(match)) {
|
|
|
|
cls = 'text-info';
|
|
|
|
} else if (/null/.test(match)) {
|
|
|
|
cls = 'text-danger';
|
|
|
|
}
|
|
|
|
return '<span class="' + cls + '">' + match + '</span>';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-24 10:48:53 +02:00
|
|
|
function getTextColour(hex) {
|
|
|
|
if (hex === undefined || hex.length == 0) {
|
|
|
|
return 'black'
|
|
|
|
}
|
|
|
|
hex = hex.slice(1)
|
|
|
|
var r = parseInt(hex.substring(0,2), 16)
|
|
|
|
var g = parseInt(hex.substring(2,4), 16)
|
|
|
|
var b = parseInt(hex.substring(4,6), 16)
|
|
|
|
var avg = ((2 * r) + b + (3 * g))/6
|
|
|
|
if (avg < 128) {
|
|
|
|
return 'white'
|
|
|
|
} else {
|
|
|
|
return 'black'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-10 14:12:19 +02:00
|
|
|
function performGlobalSearch(evt) {
|
2021-09-10 11:55:54 +02:00
|
|
|
const $input = $('#globalSearch')
|
2021-09-10 14:12:19 +02:00
|
|
|
const $resultContainer = $('.global-search-result-container')
|
2021-09-10 11:55:54 +02:00
|
|
|
const value = $input.val()
|
2021-09-13 15:56:51 +02:00
|
|
|
const leftKey = 37,
|
|
|
|
upKey = 38,
|
|
|
|
rightKey = 39,
|
|
|
|
downKey = 40,
|
|
|
|
ingoredKeys = [leftKey, upKey, rightKey, downKey]
|
|
|
|
if (ingoredKeys.indexOf(evt.keyCode) != -1) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-10 14:12:19 +02:00
|
|
|
if (value.length < 3 && evt.keyCode != 13) {
|
2021-09-17 18:53:32 +02:00
|
|
|
bootstrap.Dropdown.getOrCreateInstance('#dropdownMenuSearchAll').hide()
|
2021-09-10 14:12:19 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-09-10 11:55:54 +02:00
|
|
|
const endpoint = '/instance/searchAll'
|
|
|
|
const searchParams = new URLSearchParams({search: value});
|
|
|
|
const url = endpoint + '?' + searchParams
|
|
|
|
const options = {
|
2021-09-17 19:06:56 +02:00
|
|
|
statusNode: $resultContainer.find('.search-results-wrapper')
|
2021-09-10 11:55:54 +02:00
|
|
|
}
|
|
|
|
|
2021-09-17 18:53:32 +02:00
|
|
|
bootstrap.Dropdown.getOrCreateInstance('#dropdownMenuSearchAll').show()
|
2021-09-10 11:55:54 +02:00
|
|
|
AJAXApi.quickFetchURL(url, options).then((theHTML) => {
|
|
|
|
$resultContainer.html(theHTML)
|
|
|
|
})
|
2021-09-13 15:56:51 +02:00
|
|
|
}
|
2021-09-10 11:55:54 +02:00
|
|
|
|
2021-09-13 15:56:51 +02:00
|
|
|
function focusSearchResults(evt) {
|
|
|
|
const upKey = 38,
|
|
|
|
downKey = 40
|
|
|
|
if ([upKey, downKey].indexOf(evt.keyCode) != -1) {
|
|
|
|
$('.global-search-result-container').find('.dropdown-item').first().focus()
|
|
|
|
}
|
2021-09-10 11:55:54 +02:00
|
|
|
}
|
|
|
|
|
2021-10-20 12:21:13 +02:00
|
|
|
function saveSetting(statusNode, settingName, settingValue) {
|
2021-10-20 09:39:12 +02:00
|
|
|
const url = window.saveSettingURL
|
|
|
|
const data = {
|
|
|
|
name: settingName,
|
|
|
|
value: settingValue,
|
|
|
|
}
|
|
|
|
const APIOptions = {
|
|
|
|
statusNode: statusNode,
|
|
|
|
}
|
|
|
|
return AJAXApi.quickFetchAndPostForm(url, data, APIOptions)
|
|
|
|
}
|
|
|
|
|
2021-10-18 13:28:26 +02:00
|
|
|
function openSaveBookmarkModal(bookmark_url = '') {
|
2022-01-26 12:11:44 +01:00
|
|
|
const url = '/user-settings/saveMyBookmark';
|
2021-10-18 13:28:26 +02:00
|
|
|
UI.submissionModal(url).then(([modalFactory, ajaxApi]) => {
|
|
|
|
const $input = modalFactory.$modal.find('input[name="bookmark_url"]')
|
|
|
|
$input.val(bookmark_url)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteBookmark(bookmark, forSidebar=false) {
|
2022-01-26 12:11:44 +01:00
|
|
|
const url = '/user-settings/deleteMyBookmark'
|
2021-10-18 13:28:26 +02:00
|
|
|
AJAXApi.quickFetchAndPostForm(url, {
|
|
|
|
bookmark_name: bookmark.name,
|
|
|
|
bookmark_url: bookmark.url,
|
|
|
|
}, {
|
|
|
|
provideFeedback: true,
|
|
|
|
statusNode: $('.bookmark-table-container'),
|
|
|
|
}).then((apiResult) => {
|
2022-01-26 12:11:44 +01:00
|
|
|
const url = `/userSettings/getMyBookmarks/${forSidebar ? '1' : '0'}`
|
2021-10-18 13:28:26 +02:00
|
|
|
UI.reload(url, $('.bookmark-table-container').parent())
|
|
|
|
const theToast = UI.toast({
|
|
|
|
variant: 'success',
|
|
|
|
title: apiResult.message,
|
|
|
|
bodyHtml: $('<div/>').append(
|
|
|
|
$('<span/>').text('Cancel deletion operation.'),
|
|
|
|
$('<button/>').addClass(['btn', 'btn-primary', 'btn-sm', 'ms-3']).text('Restore bookmark').click(function () {
|
2022-01-26 12:11:44 +01:00
|
|
|
const urlRestore = '/user-settings/saveMyBookmark'
|
2021-10-18 13:28:26 +02:00
|
|
|
AJAXApi.quickFetchAndPostForm(urlRestore, {
|
|
|
|
bookmark_label: bookmark.label,
|
|
|
|
bookmark_name: bookmark.name,
|
|
|
|
bookmark_url: bookmark.url,
|
|
|
|
}, {
|
|
|
|
provideFeedback: true,
|
|
|
|
statusNode: $('.bookmark-table-container')
|
|
|
|
}).then(() => {
|
2022-01-26 12:11:44 +01:00
|
|
|
const url = `/userSettings/getMyBookmarks/${forSidebar ? '1' : '0'}`
|
2021-10-18 13:28:26 +02:00
|
|
|
UI.reload(url, $('.bookmark-table-container').parent())
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
})
|
|
|
|
}).catch((e) => { })
|
|
|
|
}
|
|
|
|
|
2023-11-02 08:08:06 +01:00
|
|
|
function downloadIndexTable(downloadButton, filename, filtered) {
|
2023-02-13 15:29:03 +01:00
|
|
|
const $dropdownMenu = $(downloadButton).closest('.dropdown')
|
|
|
|
const tableRandomValue = $dropdownMenu.attr('data-table-random-value')
|
|
|
|
const $container = $dropdownMenu.closest('div[id^="table-container-"]')
|
|
|
|
const $table = $container.find(`table[data-table-random-value="${tableRandomValue}"]`)
|
|
|
|
const $filterButton = $(`#toggleFilterButton-${tableRandomValue}`)
|
|
|
|
const activeFilters = $filterButton.data('activeFilters')
|
2023-11-02 08:08:06 +01:00
|
|
|
// const additionalUrlParams = $filterButton.data('additionalUrlParams') ? $filterButton.data('additionalUrlParams') : ''
|
|
|
|
// const searchParam = jQuery.param(activeFilters);
|
|
|
|
// const url = $table.data('reload-url') + additionalUrlParams + '?' + searchParam
|
|
|
|
let url = $table.data('reload-url')
|
|
|
|
if (filtered) {
|
|
|
|
url = activeFilters._here
|
|
|
|
}
|
2023-02-13 15:29:03 +01:00
|
|
|
let options = {}
|
2023-11-02 08:08:06 +01:00
|
|
|
let downloadPromise;
|
|
|
|
if (filename.endsWith('.csv')) {
|
|
|
|
downloadPromise = AJAXApi.quickFetchCSV(url, options)
|
|
|
|
} else {
|
|
|
|
downloadPromise = AJAXApi.quickFetchJSON(url, options)
|
|
|
|
}
|
2023-02-13 15:29:03 +01:00
|
|
|
UI.overlayUntilResolve($dropdownMenu, downloadPromise)
|
|
|
|
downloadPromise.then((data) => {
|
2023-11-02 08:08:06 +01:00
|
|
|
if (filename.endsWith('.csv')) {
|
|
|
|
download(filename, data)
|
|
|
|
} else {
|
|
|
|
download(filename, JSON.stringify(data, undefined, 4))
|
|
|
|
}
|
2023-02-13 15:29:03 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-20 09:39:12 +02:00
|
|
|
function overloadBSDropdown() {
|
|
|
|
// Inspired from https://jsfiddle.net/dallaslu/mvk4uhzL/
|
|
|
|
(function ($bs) {
|
|
|
|
const CLASS_NAME_HAS_CHILD = 'has-child-dropdown-show';
|
|
|
|
const CLASS_NAME_KEEP_OPEN = 'keep-dropdown-show';
|
|
|
|
|
|
|
|
$bs.Dropdown.prototype.toggle = function (_orginal) {
|
|
|
|
return function () {
|
|
|
|
document.querySelectorAll('.' + CLASS_NAME_HAS_CHILD).forEach(function (e) {
|
|
|
|
e.classList.remove(CLASS_NAME_HAS_CHILD);
|
|
|
|
});
|
|
|
|
let dd = this._element.closest('.dropdown')
|
|
|
|
if (dd !== null) {
|
|
|
|
dd = dd.parentNode.closest('.dropdown');
|
|
|
|
for (; dd && dd !== document; dd = dd.parentNode.closest('.dropdown')) {
|
|
|
|
dd.classList.add(CLASS_NAME_HAS_CHILD);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._element.classList.contains('open-form')) {
|
|
|
|
const openFormId = this._element.getAttribute('data-open-form-id')
|
|
|
|
document.querySelectorAll('.' + CLASS_NAME_KEEP_OPEN).forEach(function (e) {
|
|
|
|
e.classList.remove(CLASS_NAME_KEEP_OPEN);
|
|
|
|
});
|
|
|
|
let dd = this._element.closest('.dropdown')
|
|
|
|
dd.classList.add(CLASS_NAME_KEEP_OPEN);
|
|
|
|
dd.setAttribute('data-open-form-id', openFormId)
|
|
|
|
dd = dd.parentNode.closest('.dropdown');
|
|
|
|
for (; dd && dd !== document; dd = dd.parentNode.closest('.dropdown')) {
|
|
|
|
dd.setAttribute('data-open-form-id', openFormId)
|
|
|
|
dd.classList.add(CLASS_NAME_KEEP_OPEN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _orginal.call(this);
|
|
|
|
}
|
|
|
|
}($bs.Dropdown.prototype.toggle);
|
2021-10-20 15:41:11 +02:00
|
|
|
})(bootstrap);
|
|
|
|
}
|
2021-10-20 09:39:12 +02:00
|
|
|
|
2021-10-20 15:41:11 +02:00
|
|
|
function addSupportOfNestedDropdown() {
|
|
|
|
const CLASS_NAME_HAS_CHILD = 'has-child-dropdown-show';
|
|
|
|
document.querySelectorAll('.dropdown').forEach(function (dd) {
|
|
|
|
if (dd.getAttribute('data-listener-registered') === null) { // Only add listener once
|
2021-10-20 09:39:12 +02:00
|
|
|
dd.addEventListener('hide.bs.dropdown', function (e) {
|
|
|
|
if (this.classList.contains(CLASS_NAME_HAS_CHILD)) {
|
|
|
|
this.classList.remove(CLASS_NAME_HAS_CHILD);
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e.clickEvent !== undefined) {
|
|
|
|
let dd = e.clickEvent.target.closest('.dropdown')
|
|
|
|
if (dd !== null) {
|
|
|
|
if (dd.classList.contains('keep-dropdown-show')) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e.stopPropagation(); // do not need pop in multi level mode
|
|
|
|
});
|
2021-10-20 15:41:11 +02:00
|
|
|
dd.setAttribute('data-listener-registered', 1)
|
|
|
|
}
|
|
|
|
});
|
2021-10-20 09:39:12 +02:00
|
|
|
}
|
|
|
|
|
2020-12-11 10:38:43 +01:00
|
|
|
var UI
|
2020-12-10 15:18:02 +01:00
|
|
|
$(document).ready(() => {
|
2021-01-11 14:21:46 +01:00
|
|
|
if (typeof UIFactory !== "undefined") {
|
|
|
|
UI = new UIFactory()
|
|
|
|
}
|
2021-10-20 09:39:12 +02:00
|
|
|
overloadBSDropdown();
|
2021-10-20 15:41:11 +02:00
|
|
|
addSupportOfNestedDropdown();
|
2021-09-10 11:55:54 +02:00
|
|
|
|
2021-12-20 15:26:36 +01:00
|
|
|
if (window.debounce) {
|
|
|
|
const debouncedGlobalSearch = debounce(performGlobalSearch, 400)
|
|
|
|
$('#globalSearch')
|
|
|
|
.keydown(debouncedGlobalSearch)
|
|
|
|
.keydown(focusSearchResults);
|
|
|
|
}
|
2021-10-08 16:56:08 +02:00
|
|
|
|
|
|
|
$('.lock-sidebar a.btn-lock-sidebar').click(() => {
|
|
|
|
const $sidebar = $('.sidebar')
|
|
|
|
let expanded = $sidebar.hasClass('expanded');
|
|
|
|
if (expanded) {
|
|
|
|
$sidebar.removeClass('expanded')
|
|
|
|
} else {
|
|
|
|
$sidebar.addClass('expanded')
|
|
|
|
}
|
|
|
|
const settingName = 'ui.sidebar.expanded';
|
2022-01-26 12:11:44 +01:00
|
|
|
const url = `/user-settings/setMySetting/${settingName}`
|
2021-10-08 16:56:08 +02:00
|
|
|
AJAXApi.quickFetchAndPostForm(url, {
|
|
|
|
value: expanded ? 0 : 1
|
|
|
|
}, { provideFeedback: false})
|
|
|
|
})
|
2021-10-08 16:57:38 +02:00
|
|
|
|
|
|
|
$('.sidebar #btn-add-bookmark').click(() => {
|
2021-10-18 13:28:26 +02:00
|
|
|
openSaveBookmarkModal(window.location.pathname)
|
2021-10-08 16:57:38 +02:00
|
|
|
})
|
|
|
|
})
|