chg: [setting] Slight refactoring of search function

pull/70/head
mokaddem 2021-07-30 11:44:53 +02:00
parent eb0fecc473
commit 7b26d1c676
2 changed files with 32 additions and 23 deletions

View File

@ -174,7 +174,8 @@ function getResolvableID($sectionName, $panelName=false)
handleSettingValueChange($input)
})
redirectToSettingFromURL()
const referencedID = window.location.hash
redirectToSetting(referencedID)
})
function saveSetting(statusNode, $input, settingName, settingValue) {
@ -262,8 +263,7 @@ function getResolvableID($sectionName, $panelName=false)
}
}
function redirectToSettingFromURL() {
const referencedID = window.location.hash
function redirectToSetting(referencedID) {
const $settingToFocus = $(referencedID)
const pageNavID = $(referencedID).closest('.tab-pane').attr('aria-labelledby')
const $navController = $(`#${pageNavID}`)

View File

@ -26,30 +26,39 @@
.on('select2:select', function (e) {
const selected = e.params.data
const settingPath = selected.setting['setting-path']
let settingPathTokenized = settingPath.split('.')
settingPathTokenized = settingPathTokenized.map((elem) => elem.replaceAll(/(\.|\W)/g, '_'))
const tabName = settingPathTokenized[0]
const IDtoFocus = 'sp-' + settingPathTokenized.slice(1).join('-')
const $navController = $('.settings-tabs').find('a.nav-link').filter(function() {
return $(this).text() == tabName
})
if ($navController.length == 1) {
$toFocus = $(`#${IDtoFocus}`).parent()
if ($navController.hasClass('active')) {
$toFocus[0].scrollIntoView()
$toFocus.find(`input#${selected.id}, textarea#${selected.id}`).focus()
} else {
$navController.on('shown.bs.tab.after-selection', () => {
$toFocus[0].scrollIntoView()
$toFocus.find(`input#${selected.id}, textarea#${selected.id}`).focus()
$navController.off('shown.bs.tab.after-selection')
}).tab('show')
}
}
const {tabName, IDtoFocus} = getTabAndSettingIDFromPath(settingPath)
showSetting(selected, tabName, IDtoFocus)
$("#search-settings").val(null).trigger('change.select2');
})
})
function getTabAndSettingIDFromPath(settingPath) {
let settingPathTokenized = settingPath.split('.')
settingPathTokenized = settingPathTokenized.map((elem) => elem.replaceAll(/(\.|\W)/g, '_'))
const tabName = settingPathTokenized[0]
const IDtoFocus = 'sp-' + settingPathTokenized.slice(1).join('-')
return {tabName: tabName, IDtoFocus: IDtoFocus}
}
function showSetting(selected, tabName, IDtoFocus) {
const $navController = $('.settings-tabs').find('a.nav-link').filter(function() {
return $(this).text() == tabName
})
if ($navController.length == 1) {
$toFocus = $(`#${IDtoFocus}`).parent()
if ($navController.hasClass('active')) {
$toFocus[0].scrollIntoView()
$toFocus.find(`input#${selected.id}, textarea#${selected.id}`).focus()
} else {
$navController.on('shown.bs.tab.after-selection', () => {
$toFocus[0].scrollIntoView()
$toFocus.find(`input#${selected.id}, textarea#${selected.id}`).focus()
$navController.off('shown.bs.tab.after-selection')
}).tab('show')
}
}
}
function settingMatcher(params, data) {
if (params.term == null || params.term.trim() === '') {
return data;