-
Notifications
You must be signed in to change notification settings - Fork 158
Allow special characters in auto_accounts by adding data-alias #4673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 14 commits
29ad623
54d03f3
1558604
19fd16e
2ba994d
f7faa06
2b115dc
12944f2
1f7ff22
3dce6cf
5b01748
9760693
c117ec4
bb60e9e
5024d41
2305bba
3ea1700
436cfd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ const setValueLookup = {}; | |
| const hideLookup = {}; | ||
| const labelLookup = {}; | ||
|
|
||
| const aliasLookup = {}; | ||
|
|
||
| // the regular expression for mountain casing | ||
| const mcRex = /[-_]([a-z])|([_-][0-9])|([\/])/g; | ||
|
|
||
|
|
@@ -130,8 +132,10 @@ function makeChangeHandlers(prefix){ | |
| // the variable 'opt' is just a data structure, not a jQuery result. | ||
| // it has no attr, data, show or hide methods so we have to query | ||
| // for it again | ||
| let data = $(`${optionSearch}[value='${opt.value}']`).data(); | ||
| let keys = Object.keys(data); | ||
| let data = $(`${optionSearch}`).filter(function() { | ||
| return (this.value === opt.value); | ||
| }).data(); | ||
| let keys = Object.keys(data).sort(); | ||
| if(keys.length !== 0) { | ||
| keys.forEach((key) => { | ||
| if(key.startsWith('optionFor')) { | ||
|
|
@@ -148,7 +152,8 @@ function makeChangeHandlers(prefix){ | |
| addHideHandler(element['id'], opt.value, key, data[key]); | ||
| } else if(key.startsWith('label')) { | ||
| addLabelHandler(element['id'], opt.value, key, data[key]); | ||
| } | ||
| } else if(key.startsWith('alias')) | ||
| cacheAliases(element['id']); | ||
| }); | ||
| } | ||
| }); | ||
|
|
@@ -167,7 +172,6 @@ function makeChangeHandlers(prefix){ | |
| } | ||
| } | ||
| }); | ||
|
|
||
| initializing = false; | ||
| }; | ||
|
|
||
|
|
@@ -728,6 +732,24 @@ function idFromToken(str) { | |
| } | ||
| } | ||
|
|
||
| function cacheAliases(elementId) { | ||
| // This should only run once on each select with an alias defined | ||
| if (!Object.keys(aliasLookup).includes(elementId)) { | ||
|
||
| aliasLookup[elementId] = {}; | ||
| const options = [...document.querySelectorAll(`#${elementId} option`)]; | ||
| options.forEach(option => { | ||
| const data = option.dataset; | ||
| Object.keys(data).forEach(key => { | ||
| if (key.startsWith('alias')){ | ||
| const alias = key.replace(/^alias/, ''); | ||
| const value = data[key] | ||
| aliasLookup[elementId][value] = alias; | ||
| } | ||
| }) | ||
| }) | ||
|
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extract the option for out of an option for directive. | ||
| * | ||
|
|
@@ -780,22 +802,33 @@ function sharedToggleOptionsFor(_event, elementId, contextStr) { | |
|
|
||
| // it's some other directive type, so just keep going and/or not real | ||
| if(!key.startsWith(contextStr) || optionForId === undefined) { | ||
| continue; | ||
| continue | ||
Bubballoo3 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| const value = document.getElementById(optionForId).value; | ||
| let optionForValue = mountainCaseWords(value); | ||
|
|
||
| let optionForValue = mountainCaseWords(document.getElementById(optionForId).value); | ||
| let optionForAlias = ''; | ||
| if ((elementId in aliasLookup) && (value in aliasLookup[elementId])) { | ||
johrstrom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| optionForAlias = aliasLookup[elementId][value] | ||
| } | ||
| // handle special case where the very first token here is a number. | ||
| // browsers expect a prefix of hyphens as if it's the next token. | ||
| if (optionForValue.match(/^\d/)) { | ||
| optionForValue = `-${optionForValue}`; | ||
| } | ||
|
|
||
| if (contextStr == 'optionFor') { | ||
| hide = option.dataset[`optionFor${optionFor}${optionForValue}`] === 'false'; | ||
| let key = `optionFor${optionFor}${optionForValue}` | ||
| if (!(key in option.dataset)) { | ||
| key = `optionFor${optionFor}${optionForAlias}` | ||
| } | ||
| hide = option.dataset[key] === 'false'; | ||
| } else if (contextStr == 'exclusiveOptionFor') { | ||
| hide = !(option.dataset[`exclusiveOptionFor${optionFor}${optionForValue}`] === 'true') | ||
| let key = `exclusiveOptionFor${optionFor}${optionForValue}` | ||
| if (!(key in option.dataset)){ | ||
| key = `exclusiveOptionFor${optionFor}${optionForAlias}` | ||
| } | ||
| hide = !(option.dataset[key] === 'true') | ||
| } | ||
|
|
||
| if (hide) { | ||
| break; | ||
| } | ||
|
|
@@ -856,7 +889,6 @@ function sharedToggleOptionsFor(_event, elementId, contextStr) { | |
|
|
||
| // get attributes based on widget id | ||
| function getWidgetInfo(id){ | ||
| console.log(id) | ||
| const type = getWidgetType(id) | ||
| const label = $(`label[for="${id}"]`); | ||
| const labelText = label.length ? label.text().trim() : null; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.