first commit
This commit is contained in:
92
media/com_associations/css/sidebyside.css
Normal file
92
media/com_associations/css/sidebyside.css
Normal file
@ -0,0 +1,92 @@
|
||||
/**
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
.sidebyside .outer-panel {
|
||||
float: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
.sidebyside #left-panel .inner-panel {
|
||||
padding-inline-end: 10px;
|
||||
}
|
||||
|
||||
.sidebyside #right-panel .inner-panel {
|
||||
padding-inline-end: 10px;
|
||||
}
|
||||
|
||||
.sidebyside .full-width {
|
||||
float: none !important;
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
.sidebyside .full-width .inner-panel {
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
#reference-association, #target-association {
|
||||
width: 100%;
|
||||
height: 1500px;
|
||||
overflow-y: auto;
|
||||
border: 0 !important;
|
||||
}
|
||||
|
||||
.sidebyside .langtarget {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.sidebyside .modaltarget {
|
||||
float: left;
|
||||
margin-inline-start: .5rem;
|
||||
}
|
||||
|
||||
.sidebyside #target-association {
|
||||
margin-top: .5rem;
|
||||
}
|
||||
|
||||
.sidebyside #reference-association {
|
||||
margin-top: 3.35rem;
|
||||
}
|
||||
|
||||
.target-text {
|
||||
float: left;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
/* RTL overrides */
|
||||
[dir=rtl] .sidebyside .outer-panel {
|
||||
float: right;
|
||||
}
|
||||
|
||||
[dir=rtl] .sidebyside .langtarget {
|
||||
float: right;
|
||||
}
|
||||
|
||||
[dir=rtl] .sidebyside .modaltarget {
|
||||
float: right;
|
||||
}
|
||||
|
||||
[dir=rtl] .target-text {
|
||||
float: right;
|
||||
}
|
||||
|
||||
/* Responsive layout */
|
||||
@media (max-width: 767.98px) {
|
||||
.sidebyside .outer-panel {
|
||||
float: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.sidebyside #reference-association {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.sidebyside #left-panel .inner-panel {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.sidebyside #right-panel .inner-panel {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
1
media/com_associations/css/sidebyside.min.css
vendored
Normal file
1
media/com_associations/css/sidebyside.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.sidebyside .outer-panel{float:left;width:50%}.sidebyside #left-panel .inner-panel,.sidebyside #right-panel .inner-panel{-webkit-padding-end:10px;padding-inline-end:10px}.sidebyside .full-width{float:none!important;width:100%!important}.sidebyside .full-width .inner-panel{padding:0!important}#reference-association,#target-association{border:0!important;height:1500px;overflow-y:auto;width:100%}.sidebyside .langtarget{float:left}.sidebyside .modaltarget{-webkit-margin-start:.5rem;float:left;margin-inline-start:.5rem}.sidebyside #target-association{margin-top:.5rem}.sidebyside #reference-association{margin-top:3.35rem}.target-text{float:left;width:auto}[dir=rtl] .sidebyside .langtarget,[dir=rtl] .sidebyside .modaltarget,[dir=rtl] .sidebyside .outer-panel,[dir=rtl] .target-text{float:right}@media (max-width:767.98px){.sidebyside .outer-panel{float:none;width:100%}.sidebyside #reference-association{margin-top:0}.sidebyside #left-panel .inner-panel,.sidebyside #right-panel .inner-panel{padding:0}}
|
||||
BIN
media/com_associations/css/sidebyside.min.css.gz
Normal file
BIN
media/com_associations/css/sidebyside.min.css.gz
Normal file
Binary file not shown.
73
media/com_associations/joomla.asset.json
Normal file
73
media/com_associations/joomla.asset.json
Normal file
@ -0,0 +1,73 @@
|
||||
{
|
||||
"$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json",
|
||||
"name": "com_associations",
|
||||
"version": "4.0.0",
|
||||
"description": "Joomla CMS",
|
||||
"license": "GPL-2.0-or-later",
|
||||
"assets": [
|
||||
{
|
||||
"name": "com_associations.sidebyside",
|
||||
"type": "preset",
|
||||
"dependencies": [
|
||||
"com_associations.sidebyside#style",
|
||||
"com_associations.sidebyside#script"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "com_associations.admin-associations-default",
|
||||
"type": "script",
|
||||
"uri": "com_associations/admin-associations-default.min.js",
|
||||
"dependencies": [
|
||||
"core"
|
||||
],
|
||||
"attributes": {
|
||||
"type": "module"
|
||||
},
|
||||
"version": "da8949"
|
||||
},
|
||||
{
|
||||
"name": "com_associations.admin-associations-modal",
|
||||
"type": "script",
|
||||
"uri": "com_associations/admin-associations-modal.min.js",
|
||||
"dependencies": [
|
||||
"core"
|
||||
],
|
||||
"attributes": {
|
||||
"type": "module"
|
||||
},
|
||||
"version": "684ed0"
|
||||
},
|
||||
{
|
||||
"name": "com_associations.associations-edit",
|
||||
"type": "script",
|
||||
"uri": "com_associations/associations-edit.min.js",
|
||||
"dependencies": [
|
||||
"core"
|
||||
],
|
||||
"attributes": {
|
||||
"type": "module",
|
||||
"defer": true
|
||||
},
|
||||
"version": "375be7"
|
||||
},
|
||||
{
|
||||
"name": "com_associations.sidebyside",
|
||||
"type": "style",
|
||||
"uri": "com_associations/sidebyside.min.css",
|
||||
"version": "de6649"
|
||||
},
|
||||
{
|
||||
"name": "com_associations.sidebyside",
|
||||
"type": "script",
|
||||
"uri": "com_associations/sidebyside.min.js",
|
||||
"dependencies": [
|
||||
"core",
|
||||
"jquery"
|
||||
],
|
||||
"attributes": {
|
||||
"defer": true
|
||||
},
|
||||
"version": "c267f6"
|
||||
}
|
||||
]
|
||||
}
|
||||
17
media/com_associations/js/admin-associations-default.js
Normal file
17
media/com_associations/js/admin-associations-default.js
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
Joomla.submitbutton = pressbutton => {
|
||||
if (pressbutton === 'associations.purge') {
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
if (confirm(Joomla.Text._('COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT'))) {
|
||||
Joomla.submitform(pressbutton);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
Joomla.submitform(pressbutton);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
1
media/com_associations/js/admin-associations-default.min.js
vendored
Normal file
1
media/com_associations/js/admin-associations-default.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
Joomla.submitbutton=o=>{if("associations.purge"===o){if(!confirm(Joomla.Text._("COM_ASSOCIATIONS_PURGE_CONFIRM_PROMPT")))return!1;Joomla.submitform(o)}else Joomla.submitform(o);return!0};
|
||||
BIN
media/com_associations/js/admin-associations-default.min.js.gz
Normal file
BIN
media/com_associations/js/admin-associations-default.min.js.gz
Normal file
Binary file not shown.
20
media/com_associations/js/admin-associations-modal.js
Normal file
20
media/com_associations/js/admin-associations-modal.js
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
Joomla = window.Joomla || {};
|
||||
((Joomla, document) => {
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const targetAssociation = window.parent.document.getElementById('target-association');
|
||||
const links = [].slice.call(document.querySelectorAll('.select-link'));
|
||||
links.forEach(item => {
|
||||
item.addEventListener('click', ({
|
||||
target
|
||||
}) => {
|
||||
targetAssociation.src = `${targetAssociation.getAttribute('data-editurl')}&task=${targetAssociation.getAttribute('data-item')}.edit&id=${parseInt(target.getAttribute('data-id'), 10)}`;
|
||||
window.parent.Joomla.Modal.getCurrent().close();
|
||||
});
|
||||
});
|
||||
});
|
||||
})(Joomla, document);
|
||||
1
media/com_associations/js/admin-associations-modal.min.js
vendored
Normal file
1
media/com_associations/js/admin-associations-modal.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
Joomla=window.Joomla||{},((t,e)=>{e.addEventListener("DOMContentLoaded",(()=>{const t=window.parent.document.getElementById("target-association");[].slice.call(e.querySelectorAll(".select-link")).forEach((e=>{e.addEventListener("click",(({target:e})=>{t.src=`${t.getAttribute("data-editurl")}&task=${t.getAttribute("data-item")}.edit&id=${parseInt(e.getAttribute("data-id"),10)}`,window.parent.Joomla.Modal.getCurrent().close()}))}))}))})(Joomla,document);
|
||||
BIN
media/com_associations/js/admin-associations-modal.min.js.gz
Normal file
BIN
media/com_associations/js/admin-associations-modal.min.js.gz
Normal file
Binary file not shown.
205
media/com_associations/js/associations-edit.js
Normal file
205
media/com_associations/js/associations-edit.js
Normal file
@ -0,0 +1,205 @@
|
||||
/**
|
||||
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
Joomla = window.Joomla || {};
|
||||
((Joomla, document) => {
|
||||
|
||||
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(/_name$/, '') === `${formControl}_associations_${languageCode.replace('-', '_')}`) {
|
||||
element.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
Joomla.showAssociationMessage = () => {
|
||||
const controlGroup = [].slice.call(document.querySelectorAll('#associations .control-group'));
|
||||
const associations = document.getElementById('associations');
|
||||
if (associations) {
|
||||
const html = document.createElement('joomla-alert');
|
||||
html.innerText = Joomla.Text._('JGLOBAL_ASSOC_NOT_POSSIBLE');
|
||||
associations.insertAdjacentElement('afterbegin', html);
|
||||
}
|
||||
controlGroup.forEach(element => {
|
||||
element.classList.add('hidden');
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Inject associations into other association fields
|
||||
*
|
||||
* This function is called whenever the Ajax request within propagateAssociation() completes
|
||||
* successfully.
|
||||
* Its purpose is to inject the associations which have been returned in the Ajax response into
|
||||
* the other association fields in the form.
|
||||
* It does this by invoking the various callback functions of those association fields (i.e. the
|
||||
* function which gets called whenever the administrator selects an association via the modal),
|
||||
* and passing the appropriate associated record details.
|
||||
*
|
||||
* @param result The response from the Ajax request.
|
||||
* Its structure is that generated by the JResponseJson class,
|
||||
* with the data field containing the associations
|
||||
* @param callbackFunctionPrefix The name of the callback function which the modal window uses
|
||||
* to set the selected item as the association, but minus the
|
||||
* language tag at the end
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 3.9.0
|
||||
*/
|
||||
Joomla.injectAssociations = (result, callbackFunctionPrefix) => {
|
||||
let functionName;
|
||||
if (result.success) {
|
||||
if (result.data.length !== 0) {
|
||||
[].slice.call(Object.keys(result.data)).forEach(lang => {
|
||||
functionName = callbackFunctionPrefix + lang.replace('-', '_');
|
||||
window[functionName](result.data[lang].id, result.data[lang].title, result.data[lang].catid, null, null, lang);
|
||||
});
|
||||
}
|
||||
if (result.message) {
|
||||
Joomla.renderMessages({
|
||||
notice: [result.message]
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Joomla.renderMessages({
|
||||
warning: [Joomla.Text._('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED')]
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Propagate associations from this field into other association fields
|
||||
*
|
||||
* This function is called whenever an administrator populates an association (in the association
|
||||
* modal field) and then clicks on the Propagate button.
|
||||
* The purpose of this function is to find what other records (if any) are associated with the
|
||||
* one which the administrator has selected, and populate the other association fields with these
|
||||
* records. (Otherwise, if the administrator just clicks on Save without clicking on Propagate,
|
||||
* those other associations will be deleted). It does this by finding the id of the selected
|
||||
* associated record (from a hidden field) and makes an Ajax call to the server to find the other
|
||||
* associations, also passing up the language of the record currently being edited, as it should
|
||||
* be excluded. Once it has received from the server the other associations it calls
|
||||
* injectAssociations to inject them into the other association fields within the form.
|
||||
*
|
||||
* @param fieldPrefix The stem of the html ids for the elements comprising the
|
||||
* modal field
|
||||
* @param callbackFunctionPrefix The name of the callback function which the modal window uses
|
||||
* to set the selected item as the association, but minus the
|
||||
* language tag at the end
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 3.9.0
|
||||
*/
|
||||
Joomla.propagateAssociation = (fieldPrefix, callbackFunctionPrefix) => {
|
||||
// Find the id of the record which has been set as an association
|
||||
const assocId = document.getElementById(`${fieldPrefix}_id`).value;
|
||||
|
||||
// Find the language of the record being edited
|
||||
const languageField = document.getElementById('jform_language');
|
||||
const currentLang = languageField.options[languageField.selectedIndex].value;
|
||||
const data = {
|
||||
task: 'ajax.fetchAssociations',
|
||||
format: 'json',
|
||||
assocId,
|
||||
excludeLang: currentLang
|
||||
};
|
||||
data[Joomla.getOptions('csrf.token', '')] = 1;
|
||||
const queryString = Object.keys(data).reduce((a, k) => {
|
||||
a.push(`${k}=${encodeURIComponent(data[k])}`);
|
||||
return a;
|
||||
}, []).join('&');
|
||||
const url = `${document.forms.adminForm.action}&${queryString}`;
|
||||
Joomla.request({
|
||||
// Find the action url associated with the form - we need to add the token to this
|
||||
url,
|
||||
method: 'GET',
|
||||
data: JSON.stringify(data),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
onSuccess: response => {
|
||||
Joomla.injectAssociations(JSON.parse(response), callbackFunctionPrefix);
|
||||
},
|
||||
onError: () => {
|
||||
Joomla.renderMessages({
|
||||
warning: [Joomla.Text._('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED')]
|
||||
});
|
||||
}
|
||||
});
|
||||
return false;
|
||||
};
|
||||
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', ({
|
||||
target
|
||||
}) => {
|
||||
// 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('_name', '').replace('jform_associations_', '');
|
||||
|
||||
// Show the association fields
|
||||
element.classList.remove('hidden');
|
||||
|
||||
// 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
|
||||
let clear = document.getElementById(`${formControl}_associations_${languageCode}_clear`);
|
||||
clear = clear || element.querySelector('[data-button-action="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.Text._('JGLOBAL_ASSOCIATIONS_RESET_WARNING')]
|
||||
});
|
||||
}
|
||||
|
||||
// If the selected language is All hide the fields and add a message
|
||||
const selectedLanguage = 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);
|
||||
1
media/com_associations/js/associations-edit.min.js
vendored
Normal file
1
media/com_associations/js/associations-edit.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
Joomla=window.Joomla||{},((e,s)=>{e.hideAssociation=(e,t)=>{[].slice.call(s.querySelectorAll("#associations .control-group")).forEach((s=>{const o=s.querySelector(".control-label label");if(o){o.getAttribute("for").replace(/_name$/,"")===`${e}_associations_${t.replace("-","_")}`&&s.classList.add("hidden")}}))},e.showAssociationMessage=()=>{const t=[].slice.call(s.querySelectorAll("#associations .control-group")),o=s.getElementById("associations");if(o){const t=s.createElement("joomla-alert");t.innerText=e.Text._("JGLOBAL_ASSOC_NOT_POSSIBLE"),o.insertAdjacentElement("afterbegin",t)}t.forEach((e=>{e.classList.add("hidden")}))},e.injectAssociations=(s,t)=>{let o;s.success?(0!==s.data.length&&[].slice.call(Object.keys(s.data)).forEach((e=>{o=t+e.replace("-","_"),window[o](s.data[e].id,s.data[e].title,s.data[e].catid,null,null,e)})),s.message&&e.renderMessages({notice:[s.message]})):e.renderMessages({warning:[e.Text._("JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED")]})},e.propagateAssociation=(t,o)=>{const a=s.getElementById(`${t}_id`).value,n=s.getElementById("jform_language"),c={task:"ajax.fetchAssociations",format:"json",assocId:a,excludeLang:n.options[n.selectedIndex].value};c[e.getOptions("csrf.token","")]=1;const i=Object.keys(c).reduce(((e,s)=>(e.push(`${s}=${encodeURIComponent(c[s])}`),e)),[]).join("&"),l=`${s.forms.adminForm.action}&${i}`;return e.request({url:l,method:"GET",data:JSON.stringify(c),headers:{"Content-Type":"application/json"},onSuccess:s=>{e.injectAssociations(JSON.parse(s),o)},onError:()=>{e.renderMessages({warning:[e.Text._("JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED")]})}}),!1},s.addEventListener("DOMContentLoaded",(()=>{const t=e.getOptions("system.associations.edit"),o=t.formControl||"jform",a=s.getElementById(`${o}_language`);1===parseInt(t.hidden,10)?e.showAssociationMessage():a&&e.hideAssociation(o,a.value),a&&a.addEventListener("change",(({target:t})=>{e.removeMessages();let a=!1;[].slice.call(s.querySelectorAll("#associations .control-group")).forEach((e=>{const t=e.querySelector(".control-label label").getAttribute("for").replace("_name","").replace("jform_associations_","");e.classList.remove("hidden"),a||""===s.getElementById(`${o}_associations_${t}_id`).value||(a=!0);let n=s.getElementById(`${o}_associations_${t}_clear`);n=n||e.querySelector('[data-button-action="clear"]'),n.onclick?n.onclick():n.click&&n.click()})),a&&e.renderMessages({warning:[e.Text._("JGLOBAL_ASSOCIATIONS_RESET_WARNING")]});const n=t.value;"*"===n?e.showAssociationMessage():e.hideAssociation(o,n)}))}))})(Joomla,document);
|
||||
BIN
media/com_associations/js/associations-edit.min.js.gz
Normal file
BIN
media/com_associations/js/associations-edit.min.js.gz
Normal file
Binary file not shown.
304
media/com_associations/js/sidebyside.js
Normal file
304
media/com_associations/js/sidebyside.js
Normal file
@ -0,0 +1,304 @@
|
||||
/**
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
// @TODO remove jQuery dependency
|
||||
jQuery(document).ready(function($) {
|
||||
$('#toolbar-target').hide();
|
||||
$('#toolbar-copy').hide();
|
||||
|
||||
// Save button actions, replacing the default Joomla.submitbutton() with custom function.
|
||||
Joomla.submitbutton = function(task) {
|
||||
// Using close button, normal joomla submit.
|
||||
if (task === 'association.cancel') {
|
||||
Joomla.submitform(task);
|
||||
} else if(task === 'copy') {
|
||||
document.body.appendChild(document.createElement('joomla-core-loader'));
|
||||
|
||||
var targetLang = document.getElementById('target-association').getAttribute('data-language'),
|
||||
referlangInput = window.frames['reference-association'].document.getElementById('jform_language');
|
||||
|
||||
// Set target language, to get correct content language in the copy
|
||||
referlangInput.removeAttribute('disabled');
|
||||
referlangInput.value = targetLang;
|
||||
|
||||
window.frames['reference-association'].Joomla.submitbutton(document.getElementById('adminForm').getAttribute('data-associatedview') + '.save2copy');
|
||||
} else if (task === 'undo-association') { // Undo association
|
||||
var reference = document.getElementById('reference-association');
|
||||
var target = document.getElementById('target-association');
|
||||
var referenceId = reference.getAttribute('data-id');
|
||||
var referenceLang = reference.getAttribute('data-language').replace(/-/,'_');
|
||||
var targetId = target.getAttribute('data-id');
|
||||
var targetLang = target.getAttribute('data-language').replace(/-/,'_');
|
||||
reference = $(reference).contents();
|
||||
target = $(target).contents();
|
||||
|
||||
// Remove it on the reference
|
||||
// - For modal association selectors.
|
||||
reference.find('#jform_associations_' + targetLang + '_id').val('');
|
||||
reference.find('#jform_associations_' + targetLang + '_name').val('');
|
||||
|
||||
// - For chosen association selectors (menus).
|
||||
reference.find('#jform_associations_' + targetLang).val('');
|
||||
|
||||
var lang = '';
|
||||
|
||||
// Remove it on the target
|
||||
$('#jform_itemlanguage option').each(function()
|
||||
{
|
||||
lang = $(this).val().split(':')[0];
|
||||
|
||||
if (lang) {
|
||||
lang = lang.replace(/-/,'_');
|
||||
|
||||
// - For modal association selectors.
|
||||
target.find('#jform_associations_' + lang + '_id').val('');
|
||||
// - For chosen association selectors (menus).
|
||||
target.find('#jform_associations_' + lang).val('');
|
||||
}
|
||||
});
|
||||
|
||||
// Same as above but reference language is not in the selector
|
||||
// - For modal association selectors.
|
||||
target.find('#jform_associations_' + referenceLang + '_id').val('');
|
||||
target.find('#jform_associations_' + referenceLang + '_name').val('');
|
||||
|
||||
// - For chosen association selectors (menus).
|
||||
target.find('#jform_associations_' + referenceLang).val('');
|
||||
|
||||
// Reset switcher after removing association
|
||||
var currentLangSelect = $('#jform_itemlanguage');
|
||||
var currentSwitcher = currentLangSelect.val();
|
||||
var currentLang = targetLang.replace(/_/,'-');
|
||||
$('#jform_itemlanguage option[value=\"' + currentSwitcher + '\"]').val(currentLang + ':0:add');
|
||||
currentLangSelect.val('');
|
||||
currentLangSelect[0].dispatchEvent(new CustomEvent('change', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}));
|
||||
|
||||
// Save one of the items to confirm action
|
||||
Joomla.submitbutton('reference');
|
||||
} else {
|
||||
// Saving target or reference, send the save action to the target/reference iframe.
|
||||
// We need to re-enable the language field to save.
|
||||
$('#' + task + '-association').contents().find('#jform_language').attr('disabled', false);
|
||||
window.frames[task + '-association'].Joomla.submitbutton(document.getElementById('adminForm').getAttribute('data-associatedview') + '.apply');
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// Attach behaviour to toggle button.
|
||||
$(document).on('click', '#toggle-left-panel', function() {
|
||||
var referenceHide = this.getAttribute('data-hide-reference');
|
||||
var referenceShow = this.getAttribute('data-show-reference');
|
||||
|
||||
if ($(this).text() === referenceHide) {
|
||||
$(this).text(referenceShow);
|
||||
} else {
|
||||
$(this).text(referenceHide);
|
||||
}
|
||||
|
||||
$('#left-panel').toggle();
|
||||
$('#right-panel').toggleClass('full-width');
|
||||
});
|
||||
|
||||
// Attach behaviour to language selector change event.
|
||||
$(document).on('change', '#jform_itemlanguage', function() {
|
||||
var target = document.getElementById('target-association');
|
||||
var selected = $(this).val();
|
||||
|
||||
// Populate the data attributes and load the the edit page in target frame.
|
||||
if (selected !== '' && typeof selected !== 'undefined') {
|
||||
target.setAttribute('data-action', selected.split(':')[2]);
|
||||
target.setAttribute('data-id', selected.split(':')[1]);
|
||||
target.setAttribute('data-language', selected.split(':')[0]);
|
||||
|
||||
// Iframe load start, show Joomla loading layer.
|
||||
document.body.appendChild(document.createElement('joomla-core-loader'));
|
||||
|
||||
// Load the target frame.
|
||||
target.src = target.getAttribute('data-editurl') + '&task=' + target.getAttribute('data-item') + '.' + target.getAttribute('data-action') + '&id=' + target.getAttribute('data-id');
|
||||
} else {
|
||||
// Reset the data attributes and no item to load.
|
||||
$('#toolbar-target').hide();
|
||||
$('#toolbar-copy').hide();
|
||||
$('#select-change').addClass("hidden");
|
||||
$('#remove-assoc').addClass("hidden");
|
||||
|
||||
target.setAttribute('data-action', '');
|
||||
target.setAttribute('data-id', '0');
|
||||
target.setAttribute('data-language', '');
|
||||
target.src = '';
|
||||
}
|
||||
});
|
||||
|
||||
// Attach behaviour to reference frame load event.
|
||||
$('#reference-association').on('load', function() {
|
||||
// Waiting until the reference has loaded before loading the target to avoid race conditions
|
||||
var targetURL = Joomla.getOptions('targetSrc', false);
|
||||
|
||||
if (targetURL)
|
||||
{
|
||||
targetURL = targetURL.split('&').join('&');
|
||||
document.getElementById('target-association').setAttribute('src', targetURL);
|
||||
Joomla.loadOptions({'targetSrc': false});
|
||||
return;
|
||||
}
|
||||
|
||||
// Load Target Pane AFTER reference pane has loaded to prevent session conflict with checkout
|
||||
document.getElementById('target-association').setAttribute('src', document.getElementById('target-association').getAttribute('src'));
|
||||
|
||||
// If copy button used
|
||||
if ($(this).contents().find('#jform_id').val() !== this.getAttribute('data-id')) {
|
||||
var target = document.getElementById('target-association');
|
||||
target.src = target.getAttribute('data-editurl') + '&task=' + target.getAttribute('data-item') + '.edit' + '&id=' + $(this).contents().find('#jform_id').val();
|
||||
this.src = this.getAttribute('data-editurl') + '&task=' + this.getAttribute('data-item') + '.edit' + '&id=' + this.getAttribute('data-id');
|
||||
}
|
||||
|
||||
var reference = $(this).contents();
|
||||
|
||||
// Disable language field.
|
||||
reference.find('#jform_language').attr('disabled', '');
|
||||
|
||||
// Remove modal buttons on the reference
|
||||
reference.find('#associations').find('.btn').remove();
|
||||
|
||||
var parse = '';
|
||||
|
||||
$('#jform_itemlanguage option').each(function() {
|
||||
parse = $(this).val().split(':');
|
||||
|
||||
if (typeof parse[0] !== 'undefined') {
|
||||
// - For modal association selectors.
|
||||
var langAssociation = parse[0].replace(/-/,'_');
|
||||
|
||||
if (reference.find('#jform_associations_' + langAssociation + '_id').val() == '') {
|
||||
reference.find('#jform_associations_' + langAssociation + '_name')
|
||||
.val(document.getElementById('reference-association').getAttribute('data-no-assoc'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Iframe load finished, hide Joomla loading layer.
|
||||
var spinner = document.querySelector('joomla-core-loader');
|
||||
if (spinner) {
|
||||
spinner.parentNode.removeChild(spinner);
|
||||
}
|
||||
});
|
||||
|
||||
// Attach behaviour to target frame load event.
|
||||
$('#target-association').on('load', function() {
|
||||
// We need to check if we are not loading a blank iframe.
|
||||
if (this.getAttribute('src') != '') {
|
||||
$('#toolbar-target').show();
|
||||
$('#toolbar-copy').show();
|
||||
$('#select-change').removeClass("hidden");
|
||||
|
||||
var targetLanguage = this.getAttribute('data-language');
|
||||
var targetId = this.getAttribute('data-id');
|
||||
var targetLoadedId = $(this).contents().find('#jform_id').val() || '0';
|
||||
|
||||
// Remove modal buttons on the target
|
||||
$(this).contents().find('a[href=\"#associations\"]').parent().find('.btn').remove();
|
||||
$(this).contents().find('#associations').find('.btn').remove();
|
||||
|
||||
// Always show General tab first if associations tab is selected on the reference
|
||||
if ($(this).contents().find('#associations').hasClass('active')) {
|
||||
$(this).contents().find('a[href=\"#associations\"]').parent().removeClass('active');
|
||||
$(this).contents().find('#associations').removeClass('active');
|
||||
|
||||
$(this).contents().find('.nav-tabs').find('li').first().addClass('active');
|
||||
$(this).contents().find('.tab-content').find('.tab-pane').first().addClass('active');
|
||||
}
|
||||
|
||||
// Update language field with the selected language and them disable it.
|
||||
$(this).contents().find('#jform_language').val(targetLanguage).attr('disabled', '');
|
||||
|
||||
// If we are creating a new association (before save) we need to add the new association.
|
||||
if (targetLoadedId == '0')
|
||||
{
|
||||
document.getElementById('select-change-text').innerHTML = Joomla.sanitizeHtml(document.getElementById('select-change').getAttribute('data-select'));
|
||||
}
|
||||
// If we are editing an association.
|
||||
else
|
||||
{
|
||||
// Show change language button
|
||||
document.getElementById('select-change-text').innerHTML = Joomla.sanitizeHtml(document.getElementById('select-change').getAttribute('data-change'));
|
||||
$('#remove-assoc').removeClass("hidden");
|
||||
$('#toolbar-copy').hide();
|
||||
|
||||
// Add the id to list of items to check in on close.
|
||||
var currentIdList = document.getElementById('target-id').value;
|
||||
var updatedList = currentIdList == '' ? targetLoadedId : currentIdList + ',' + targetLoadedId;
|
||||
document.getElementById('target-id').value = updatedList;
|
||||
|
||||
// If we created a new association (after save).
|
||||
if (targetLoadedId != targetId) {
|
||||
// Refresh the language selector with the new id (used after save).
|
||||
$('#jform_itemlanguage option[value^=\"' + targetLanguage + ':' + targetId + ':add\"]').val(targetLanguage + ':' + targetLoadedId + ':edit');
|
||||
|
||||
// Update main frame data-id attribute (used after save).
|
||||
this.setAttribute('data-id', targetLoadedId);
|
||||
this.setAttribute('data-action', 'edit');
|
||||
}
|
||||
|
||||
// Update the reference item associations tab.
|
||||
var reference = document.getElementById('reference-association');
|
||||
var languageCode = targetLanguage.replace(/-/, '_');
|
||||
var referenceTitle = reference.getAttribute('data-title');
|
||||
var title = $(this).contents().find('#jform_' + referenceTitle).val();
|
||||
|
||||
// - For modal association selectors.
|
||||
$(reference).contents().find('#jform_associations_' + languageCode + '_id').val(targetLoadedId);
|
||||
$(reference).contents().find('#jform_associations_' + languageCode + '_name').val(title);
|
||||
|
||||
// - For chosen association selectors (menus).
|
||||
$(reference).contents().find('#jform_associations_' + languageCode).append('<option value=\"'+ targetLoadedId + '\">' + title + '</option>');
|
||||
$(reference).contents().find('#jform_associations_' + languageCode).val(targetLoadedId);
|
||||
}
|
||||
|
||||
// Update the target item associations tab.
|
||||
var reference = document.getElementById('reference-association');
|
||||
var referenceId = reference.getAttribute('data-id');
|
||||
var languageCode = reference.getAttribute('data-language').replace(/-/, '_');
|
||||
var target = document.getElementById('target-association');
|
||||
var targetTitle = target.getAttribute('data-title');
|
||||
var title = reference.getAttribute('data-title-value');
|
||||
var target = $(this).contents();
|
||||
|
||||
// - For modal association selectors.
|
||||
target.find('#jform_associations_' + languageCode + '_id').val(referenceId);
|
||||
target.find('#jform_associations_' + languageCode + '_name').val(title);
|
||||
|
||||
// - For chosen association selectors (menus).
|
||||
var chosenField = target.find('#jform_associations_' + languageCode);
|
||||
chosenField.append('<option value=\"'+ referenceId + '\">' + title + '</option>');
|
||||
chosenField.val(referenceId);
|
||||
|
||||
var parse, langAssociation;
|
||||
|
||||
$('#jform_itemlanguage option').each(function() {
|
||||
parse = $(this).val().split(':');
|
||||
|
||||
if (typeof parse[1] !== 'undefined' && parse[1] !== '0') {
|
||||
// - For modal association selectors.
|
||||
langAssociation = parse[0].replace(/-/,'_');
|
||||
target.find('#jform_associations_' + langAssociation + '_id').val(parse[1]);
|
||||
|
||||
// - For chosen association selectors (menus).
|
||||
chosenField = target.find('#jform_associations_' + langAssociation);
|
||||
chosenField.append('<option value=\"'+ parse[1] + '\"></option>');
|
||||
chosenField.val(parse[1]);
|
||||
}
|
||||
});
|
||||
|
||||
// Iframe load finished, hide Joomla loading layer.
|
||||
var spinner = document.querySelector('joomla-core-loader');
|
||||
if (spinner) {
|
||||
spinner.parentNode.removeChild(spinner);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
1
media/com_associations/js/sidebyside.min.js
vendored
Normal file
1
media/com_associations/js/sidebyside.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
media/com_associations/js/sidebyside.min.js.gz
Normal file
BIN
media/com_associations/js/sidebyside.min.js.gz
Normal file
Binary file not shown.
Reference in New Issue
Block a user