chg: [setting] Slight refactoring of search function
parent
eb0fecc473
commit
7b26d1c676
|
@ -174,7 +174,8 @@ function getResolvableID($sectionName, $panelName=false)
|
||||||
handleSettingValueChange($input)
|
handleSettingValueChange($input)
|
||||||
})
|
})
|
||||||
|
|
||||||
redirectToSettingFromURL()
|
const referencedID = window.location.hash
|
||||||
|
redirectToSetting(referencedID)
|
||||||
})
|
})
|
||||||
|
|
||||||
function saveSetting(statusNode, $input, settingName, settingValue) {
|
function saveSetting(statusNode, $input, settingName, settingValue) {
|
||||||
|
@ -262,8 +263,7 @@ function getResolvableID($sectionName, $panelName=false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirectToSettingFromURL() {
|
function redirectToSetting(referencedID) {
|
||||||
const referencedID = window.location.hash
|
|
||||||
const $settingToFocus = $(referencedID)
|
const $settingToFocus = $(referencedID)
|
||||||
const pageNavID = $(referencedID).closest('.tab-pane').attr('aria-labelledby')
|
const pageNavID = $(referencedID).closest('.tab-pane').attr('aria-labelledby')
|
||||||
const $navController = $(`#${pageNavID}`)
|
const $navController = $(`#${pageNavID}`)
|
||||||
|
|
|
@ -26,30 +26,39 @@
|
||||||
.on('select2:select', function (e) {
|
.on('select2:select', function (e) {
|
||||||
const selected = e.params.data
|
const selected = e.params.data
|
||||||
const settingPath = selected.setting['setting-path']
|
const settingPath = selected.setting['setting-path']
|
||||||
let settingPathTokenized = settingPath.split('.')
|
const {tabName, IDtoFocus} = getTabAndSettingIDFromPath(settingPath)
|
||||||
settingPathTokenized = settingPathTokenized.map((elem) => elem.replaceAll(/(\.|\W)/g, '_'))
|
showSetting(selected, tabName, IDtoFocus)
|
||||||
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')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$("#search-settings").val(null).trigger('change.select2');
|
$("#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) {
|
function settingMatcher(params, data) {
|
||||||
if (params.term == null || params.term.trim() === '') {
|
if (params.term == null || params.term.trim() === '') {
|
||||||
return data;
|
return data;
|
||||||
|
|
Loading…
Reference in New Issue