-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI/InputViewControls: JS, move jquerydispatcher to core, externalize …
…VCs JS
- Loading branch information
Showing
15 changed files
with
367 additions
and
83 deletions.
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
15 changes: 15 additions & 0 deletions
15
components/ILIAS/UI/resources/js/Input/ViewControl/dist/input.viewcontrols.min.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
components/ILIAS/UI/resources/js/Input/ViewControl/rollup.config.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,39 @@ | ||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
*/ | ||
|
||
import terser from '@rollup/plugin-terser'; | ||
import copyright from '../../../../../../../scripts/Copyright-Checker/copyright.js'; | ||
import preserveCopyright from '../../../../../../../scripts/Copyright-Checker/preserveCopyright.js'; | ||
|
||
export default { | ||
input: './src/viewcontrols.js', | ||
output: { | ||
file: './dist/input.viewcontrols.min.js', | ||
format: 'iife', | ||
banner: copyright, | ||
plugins: [ | ||
terser({ | ||
format: { | ||
comments: preserveCopyright, | ||
}, | ||
}), | ||
], | ||
globals: { | ||
il: 'il', | ||
jquery: '$', | ||
}, | ||
}, | ||
external: ['il', 'jquery'], | ||
}; |
62 changes: 62 additions & 0 deletions
62
components/ILIAS/UI/resources/js/Input/ViewControl/src/fieldselection.factory.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,62 @@ | ||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
*/ | ||
|
||
export default class FieldSelectionFactory { | ||
/** | ||
* @type {JQueryEventDispatcher} | ||
*/ | ||
#eventDispatcher; | ||
|
||
/** | ||
* @param {JQueryEventDispatcher} eventDispatcher | ||
*/ | ||
constructor(eventDispatcher) { | ||
this.#eventDispatcher = eventDispatcher; | ||
} | ||
|
||
/** | ||
* @param {HTMLElement} component | ||
* @param {string} internalSignal | ||
* @param {string} containerSubmitSignal | ||
* @param {string} componentName | ||
* @return {void} | ||
*/ | ||
init(component, internalSignal, containerSubmitSignal, componentName) { | ||
this.#eventDispatcher.register( | ||
component.ownerDocument, | ||
internalSignal, | ||
(event) => { | ||
const container = event.target.closest('.il-viewcontrol-fieldselection'); | ||
const checkbox = container.querySelectorAll('input[type=checkbox]'); | ||
const valueContainer = container.querySelector('.il-viewcontrol-value'); | ||
const value = Object.values(checkbox).map((o) => (o.checked ? o.value : '')); | ||
|
||
valueContainer.innerHTML = ''; | ||
value.forEach( | ||
(v) => { | ||
const element = component.ownerDocument.createElement('input'); | ||
element.type = 'hidden'; | ||
element.name = `${componentName}[]`; | ||
element.value = v; | ||
valueContainer.appendChild(element); | ||
}, | ||
); | ||
|
||
this.#eventDispatcher.dispatch(event.target, containerSubmitSignal); | ||
return false; | ||
}, | ||
); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
components/ILIAS/UI/resources/js/Input/ViewControl/src/mode.factory.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,52 @@ | ||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
*/ | ||
|
||
export default class ModeFactory { | ||
/** | ||
* @type {JQueryEventDispatcher} | ||
*/ | ||
#eventDispatcher; | ||
|
||
/** | ||
* @param {JQueryEventDispatcher} eventDispatcher | ||
*/ | ||
constructor(eventDispatcher) { | ||
this.#eventDispatcher = eventDispatcher; | ||
} | ||
|
||
/** | ||
* @param {HTMLElement} component | ||
* @param {string} optValue | ||
* @param {string} containerSubmitSignal | ||
* @return {void} | ||
*/ | ||
init(component, optValue, containerSubmitSignal) { | ||
component.addEventListener( | ||
'click', | ||
(event) => { | ||
const btn = event.srcElement; | ||
btn.parentElement.querySelectorAll('button').forEach( | ||
(button) => button.classList.remove('engaged'), | ||
); | ||
btn.classList.add('engaged'); | ||
btn.closest('.il-viewcontrol') | ||
.querySelector('.il-viewcontrol-value > input') | ||
.value = optValue; | ||
this.#eventDispatcher.dispatch(event.target, containerSubmitSignal); | ||
return false; | ||
}, | ||
); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
components/ILIAS/UI/resources/js/Input/ViewControl/src/pagination.factory.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,51 @@ | ||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
*/ | ||
|
||
export default class PaginationFactory { | ||
/** | ||
* @type {JQueryEventDispatcher} | ||
*/ | ||
#eventDispatcher; | ||
|
||
/** | ||
* @param {JQueryEventDispatcher} eventDispatcher | ||
*/ | ||
constructor(eventDispatcher) { | ||
this.#eventDispatcher = eventDispatcher; | ||
} | ||
|
||
/** | ||
* @param {HTMLElement} component | ||
* @param {string} internalSignal | ||
* @param {string} containerSubmitSignal | ||
* @return {void} | ||
*/ | ||
init(component, internalSignal, containerSubmitSignal) { | ||
this.#eventDispatcher.register( | ||
component.ownerDocument, | ||
internalSignal, | ||
(event, signalData) => { | ||
const inputs = event.target | ||
.closest('.il-viewcontrol-pagination') | ||
.querySelectorAll('.il-viewcontrol-value input'); | ||
inputs[0].value = signalData.options.offset; | ||
inputs[1].value = signalData.options.limit; | ||
|
||
this.#eventDispatcher.dispatch(event.target, containerSubmitSignal); | ||
return false; | ||
}, | ||
); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
components/ILIAS/UI/resources/js/Input/ViewControl/src/sortation.factory.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,58 @@ | ||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
*/ | ||
|
||
export default class SortationFactory { | ||
/** | ||
* @type {JQueryEventDispatcher} | ||
*/ | ||
#eventDispatcher; | ||
|
||
/** | ||
* @param {JQueryEventDispatcher} eventDispatcher | ||
*/ | ||
constructor(eventDispatcher) { | ||
this.#eventDispatcher = eventDispatcher; | ||
} | ||
|
||
/** | ||
* @param {HTMLElement} component | ||
* @param {string} internalSignal | ||
* @param {string} containerSubmitSignal | ||
* @return {void} | ||
*/ | ||
init(component, internalSignal, containerSubmitSignal) { | ||
this.#eventDispatcher.register( | ||
component.ownerDocument, | ||
internalSignal, | ||
(event, signalData) => { | ||
let container = event.target.closest('.il-viewcontrol-fieldselection'); | ||
if (signalData.options.parent_container) { | ||
container = component.ownerDocument.querySelector( | ||
`#${signalData.options.parent_container | ||
} .il-viewcontrol-sortation`, | ||
); | ||
} else { | ||
container = event.target.closest('.il-viewcontrol-sortation'); | ||
} | ||
const inputs = container.querySelectorAll('.il-viewcontrol-value > input'); | ||
const val = signalData.options.value.split(':'); | ||
[inputs[0].value, inputs[1].value] = val; | ||
|
||
this.#eventDispatcher.dispatch(event.target, containerSubmitSignal); | ||
return false; | ||
}, | ||
); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
components/ILIAS/UI/resources/js/Input/ViewControl/src/viewcontrols.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,32 @@ | ||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
*/ | ||
|
||
import il from 'il'; | ||
import $ from 'jquery'; | ||
import FieldSelectionFactory from './fieldselection.factory.js'; | ||
import SortationFactory from './sortation.factory.js'; | ||
import PaginationFactory from './pagination.factory.js'; | ||
import ModeFactory from './mode.factory.js'; | ||
import JQueryEventDispatcher from '../../../Core/src/jqueryeventdispatcher.js'; | ||
|
||
const eventDispatcher = new JQueryEventDispatcher($); | ||
|
||
il.UI = il.UI || {}; | ||
il.UI.Input = il.UI.Input || {}; | ||
il.UI.Input.Viewcontrols = il.UI.Input.Viewcontrols || {}; | ||
il.UI.Input.Viewcontrols.FieldSelection = new FieldSelectionFactory(eventDispatcher); | ||
il.UI.Input.Viewcontrols.Sortation = new SortationFactory(eventDispatcher); | ||
il.UI.Input.Viewcontrols.Pagination = new PaginationFactory(eventDispatcher); | ||
il.UI.Input.Viewcontrols.Mode = new ModeFactory(eventDispatcher); |
2 changes: 1 addition & 1 deletion
2
components/ILIAS/UI/resources/js/ViewControl/dist/viewcontrols.min.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.