chg: [setting] Slight refactoring of search function
parent
eb0fecc473
commit
7b26d1c676
|
@ -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}`)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue