-
Notifications
You must be signed in to change notification settings - Fork 13
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
[EDMTP-281] DependsOn: add fill-select option #282
Open
nattallius
wants to merge
6
commits into
develop
Choose a base branch
from
feature/EDMTP-281
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
16245f5
[EDMTP-281] DependsOn: add fill-select option
nattallius b7e91cf
[EDMTP-281] lint fixes
nattallius 9af474f
[EDMTP-281] lint fixes
nattallius 68945f5
[EDMTP-281] documentation updates
nattallius 06fafa2
[EDMTP-281] lint fixes
nattallius 0dedeb3
[EDMTP-281] add dependsOnSelectUtils.js & dependsOnCoralSelectAction.…
nattallius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../jcr_root/apps/etoolbox-authoring-kit/depends-on/js/actions/dependsOnCoralSelectAction.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @author Natasha Gorshunova | ||
* | ||
* DependsOn Coral 3 Select Action. | ||
* | ||
* A simple action to fill select with options with provided values | ||
* | ||
* Action callback params: | ||
* {Array<{value:string, text:string}>} options | ||
* {string} config.selected - a dependsOn query, whose evaluation result should be a value or an array of selected values | ||
*/ | ||
(function (Granite, $, DependsOn) { | ||
'use strict'; | ||
|
||
const ACTION_NAME = 'fill-select'; | ||
|
||
DependsOn.ActionRegistry.register(ACTION_NAME, function (options, { selected }) { | ||
if (!options || !options.length) { | ||
return; | ||
} | ||
|
||
const $select = this.$el; | ||
const selectedValue = selected ? DependsOn.QueryProcessor.calculateQuery(selected, $select) : ''; | ||
|
||
DependsOn.SelectUtils.setOptions($select, options, selectedValue); | ||
setTimeout(() => $select.trigger('change.dependsOn')); | ||
}); | ||
})(Granite, Granite.$, Granite.DependsOnPlugin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../content/jcr_root/apps/etoolbox-authoring-kit/depends-on/js/utils/dependsOnSelectUtils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/*** | ||
* Coral 3 Select Utils | ||
* */ | ||
(function (Granite, $, DependsOn) { | ||
'use strict'; | ||
|
||
class SelectUtils { | ||
/** | ||
* Creates a new Granite option | ||
* | ||
* @param option - an option object | ||
* @param {string} option.text - text to display | ||
* @param {string} option.value - actual value of an option | ||
* @param selectedValue - value or array of values to trigger 'selected' state of the option | ||
*/ | ||
static createOption(option, selectedValue) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return { | ||
value: option.value, | ||
content: { | ||
textContent: option.text | ||
}, | ||
selected: (!selectedValue && !option.value) || selectedValue === option.value || (Array.isArray(selectedValue) && selectedValue.includes(option.value)) | ||
}; | ||
} | ||
|
||
/** | ||
* Sets a new option set to the Granite Select component | ||
* | ||
* @param {JQuery} $select - Select widget to set options for | ||
* @param {Array} options - new option set, represented by "raw" (non-Granite) entities | ||
* @param selectedValue - the value to mark as selected in the option set | ||
*/ | ||
static setOptions($select, options, selectedValue) { | ||
const itemCollection = $select.get(0).items; | ||
itemCollection.clear(); | ||
options.map(option => SelectUtils.createOption(option, selectedValue)).forEach(option => itemCollection.add(option)); | ||
} | ||
} | ||
|
||
DependsOn.SelectUtils = SelectUtils; | ||
})(Granite, Granite.$, Granite.DependsOnPlugin); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A question is:
Are we always going to fill only selects? No raidoGroups/ buttonGroups / autocompletes? May it be, we would want to give a more generic name, kind of "fill-options"?