-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.0] Com_association js cleanup, fixes #21176
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
Changes from 7 commits
1e0d4a6
39f6129
082e54a
60687a7
43c84b0
64365ce
d09db13
8502b13
92a08ec
911b15f
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /** | ||
| * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
| Joomla.submitbutton = (pressbutton) => { | ||
|
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. Expected to return a value at the end of arrow function consistent-return |
||
| if (pressbutton === 'associations.purge') { | ||
| // eslint-disable-next-line no-restricted-globals | ||
| if (confirm(Joomla.JText._('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT'))) { | ||
|
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. Unexpected use of 'confirm' no-restricted-globals |
||
| Joomla.submitform(pressbutton); | ||
| } else { | ||
| return false; | ||
| } | ||
| } else { | ||
| Joomla.submitform(pressbutton); | ||
| } | ||
|
|
||
| return true; | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,23 @@ | ||
| /** | ||
|
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. Expected space or tab before '*/' in comment spaced-comment |
||
| * PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION. | ||
| * OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD. | ||
| **/ | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
| Joomla.submitbutton = function(pressbutton) { | ||
| if (pressbutton == 'associations.purge') { | ||
| if (confirm(Joomla.JText._('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT'))) { | ||
| Joomla.submitform(pressbutton); | ||
| } else { | ||
| return false; | ||
| } | ||
| } else { | ||
| Joomla.submitform(pressbutton); | ||
| } | ||
| Joomla.submitbutton = function (pressbutton) { | ||
|
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. Expected to return a value at the end of function consistent-return |
||
| if (pressbutton === 'associations.purge') { | ||
| // eslint-disable-next-line no-restricted-globals | ||
| if (confirm(Joomla.JText._('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT'))) { | ||
|
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. Unexpected use of 'confirm' no-restricted-globals |
||
| Joomla.submitform(pressbutton); | ||
| } else { | ||
| return false; | ||
| } | ||
| } else { | ||
| Joomla.submitform(pressbutton); | ||
| } | ||
|
|
||
| return true; | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
| Joomla = window.Joomla || {}; | ||
|
|
||
| ((Joomla, document) => { | ||
| 'use strict'; | ||
|
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. Expected newline after "use strict" directive lines-around-directive |
||
|
|
||
| document.addEventListener('DOMContentLoaded', () => { | ||
|
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. Block must not be padded by blank lines padded-blocks |
||
| const target = window.parent.document.getElementById("target-association"); | ||
|
||
| const links = [].slice.call(document.querySelectorAll('.select-link')); | ||
|
|
||
| links.forEach((item) => { | ||
| item.addEventListener('click', (event) => { | ||
| target.src = target.getAttribute("data-editurl") + '"&task="' + target.getAttribute("data-item") + ".edit" + "&id=" + parseInt(event.target.getAttribute('data-id'), 10); | ||
|
||
| window.parent.Joomla.Modal.getCurrent().close(); | ||
| }); | ||
| }); | ||
| }); | ||
| })(Joomla, document); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,26 @@ | ||
| /** | ||
|
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. Expected space or tab before '*/' in comment spaced-comment |
||
| * PLEASE DO NOT MODIFY THIS FILE. WORK ON THE ES6 VERSION. | ||
| * OTHERWISE YOUR CHANGES WILL BE REPLACED ON THE NEXT BUILD. | ||
| **/ | ||
|
|
||
| /** | ||
| * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| Joomla = window.Joomla || {}; | ||
|
|
||
| (function( Joomla, document ) { | ||
| 'use strict'; | ||
| (function (Joomla, document) { | ||
|
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. Move the invocation into the parens that contain the function wrap-iife |
||
| 'use strict'; | ||
|
|
||
| document.addEventListener('DOMContentLoaded', function() { | ||
|
|
||
| if (Joomla.getOptions('modal-associations')) { | ||
| var fnName = Joomla.getOptions('modal-associations').func, | ||
| links = [].slice.call(document.querySelectorAll('.select-link')); | ||
| document.addEventListener('DOMContentLoaded', function () { | ||
|
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. Unexpected function expression prefer-arrow-callback |
||
| var target = window.parent.document.getElementById("target-association"); | ||
| var links = [].slice.call(document.querySelectorAll('.select-link')); | ||
|
|
||
| links.forEach(function (item) { | ||
| item.addEventListener('click', function (event) { | ||
| if (self != top) { | ||
| // Run function on parent window. | ||
| window.parent[fnName](event.target.getAttribute('data-id')); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| }); | ||
| })(); | ||
| links.forEach(function (item) { | ||
| item.addEventListener('click', function (event) { | ||
| target.src = target.getAttribute("data-editurl") + '"&task="' + target.getAttribute("data-item") + ".edit" + "&id=" + parseInt(event.target.getAttribute('data-id'), 10); | ||
| window.parent.Joomla.Modal.getCurrent().close(); | ||
| }); | ||
| }); | ||
| }); | ||
| })(Joomla, document); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /** | ||
| * @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
| Joomla = window.Joomla || {}; | ||
|
|
||
| ((Joomla, document) => { | ||
| 'use strict'; | ||
|
|
||
| Joomla.hideAssociation = (formControl, languageCode) => { | ||
| const controlGroup = [].slice.call(document.querySelectorAll('#associations .control-group')); | ||
|
|
||
| controlGroup.forEach((element) => { | ||
| // Current selected language. Hide it | ||
| const el = element.querySelector('.control-label label'); | ||
|
|
||
| if (el) { | ||
| const attribute = el.getAttribute('for'); | ||
|
|
||
| if (attribute.replace('_id', '') === `${formControl}_associations_${languageCode.replace('-', '_')}`) { | ||
| element.style.display = 'none'; | ||
| } | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| Joomla.showAssociationMessage = () => { | ||
| const controlGroup = [].slice.call(document.querySelectorAll('#associations .control-group')); | ||
|
|
||
| controlGroup.forEach((element) => { | ||
| element.style.display = 'none'; | ||
|
|
||
| const associations = document.getElementById('associations'); | ||
|
|
||
| if (associations) { | ||
| const html = document.createElement('div'); | ||
| html.classList.add('alert'); | ||
| html.classList.add('alert-info'); | ||
| html.id = 'associations-notice'; | ||
| html.innerHTML = Joomla.JText._('JGLOBAL_ASSOC_NOT_POSSIBLE'); | ||
|
|
||
| associations.insertAdjacentElement('afterbegin', html); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| document.addEventListener('DOMContentLoaded', () => { | ||
| const associationsEditOptions = Joomla.getOptions('system.associations.edit'); | ||
| const formControl = associationsEditOptions.formControl || 'jform'; | ||
| const formControlLanguage = document.getElementById(`${formControl}_language`); | ||
|
|
||
| // Hide the associations tab if needed | ||
| if (parseInt(associationsEditOptions.hidden, 10) === 1) { | ||
| Joomla.showAssociationMessage(); | ||
| } else if (formControlLanguage) { | ||
| // Hide only the associations for the current language | ||
| Joomla.hideAssociation(formControl, formControlLanguage.value); | ||
| } | ||
|
|
||
| // When changing the language | ||
| if (formControlLanguage) { | ||
| formControlLanguage.addEventListener('change', (event) => { | ||
| // Remove message if any | ||
| Joomla.removeMessages(); | ||
|
|
||
| let existsAssociations = false; | ||
|
|
||
| /** For each language, remove the associations, ie, | ||
| * empty the associations fields and reset the buttons to Select/Create | ||
| */ | ||
| const controlGroup = [].slice.call(document.querySelectorAll('#associations .control-group')); | ||
|
|
||
| controlGroup.forEach((element) => { | ||
| const attribute = element.querySelector('.control-label label').getAttribute('for'); | ||
| const languageCode = attribute.replace('_id', '').replace('jform_associations_', ''); | ||
|
|
||
| // Show the association fields | ||
| element.style.display = 'block'; | ||
|
|
||
| // Check if there was an association selected for this language | ||
| if (!existsAssociations && document.getElementById(`${formControl}_associations_${languageCode}_id`).value !== '') { | ||
| existsAssociations = true; | ||
| } | ||
|
|
||
| // Call the modal clear button | ||
| const clear = document.getElementById(`${formControl}_associations_${languageCode}_clear`); | ||
|
|
||
| if (clear.onclick) { | ||
| clear.onclick(); | ||
| } else if (clear.click) { | ||
| clear.click(); | ||
| } | ||
| }); | ||
|
|
||
| // If associations existed, send a warning to the user | ||
| if (existsAssociations) { | ||
| Joomla.renderMessages({ warning: [Joomla.JText._('JGLOBAL_ASSOCIATIONS_RESET_WARNING')] }); | ||
| } | ||
|
|
||
| // If the selected language is All hide the fields and add a message | ||
| const selectedLanguage = event.target.value; | ||
|
|
||
| if (selectedLanguage === '*') { | ||
| Joomla.showAssociationMessage(); | ||
| } else { | ||
| // Else show the associations fields/buttons and hide the current selected language | ||
| Joomla.hideAssociation(formControl, selectedLanguage); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| })(Joomla, document); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Expected to return a value at the end of arrow function consistent-return