2021-03-05 03:08:47 +00:00
|
|
|
/**
|
|
|
|
* @package Joomla.Component.Builder
|
|
|
|
*
|
|
|
|
* @created 30th April, 2015
|
2022-07-09 15:45:08 +00:00
|
|
|
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
|
|
|
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
2021-03-05 03:08:47 +00:00
|
|
|
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2019-07-15 20:00:46 +00:00
|
|
|
// Some Global Values
|
2024-04-21 23:15:03 +00:00
|
|
|
jform_vvvvwanvxa_required = false;
|
2019-07-15 20:00:46 +00:00
|
|
|
|
|
|
|
// Initial Script
|
2024-03-09 19:52:51 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', function()
|
2019-07-15 20:00:46 +00:00
|
|
|
{
|
2024-04-21 23:15:03 +00:00
|
|
|
var extension_type_vvvvwan = jQuery("#jform_extension_type").val();
|
|
|
|
vvvvwan(extension_type_vvvvwan);
|
2019-07-15 20:00:46 +00:00
|
|
|
});
|
|
|
|
|
2024-04-21 23:15:03 +00:00
|
|
|
// the vvvvwan function
|
|
|
|
function vvvvwan(extension_type_vvvvwan)
|
2019-07-15 20:00:46 +00:00
|
|
|
{
|
2024-04-21 23:15:03 +00:00
|
|
|
if (isSet(extension_type_vvvvwan) && extension_type_vvvvwan.constructor !== Array)
|
2019-07-15 20:00:46 +00:00
|
|
|
{
|
2024-04-21 23:15:03 +00:00
|
|
|
var temp_vvvvwan = extension_type_vvvvwan;
|
|
|
|
var extension_type_vvvvwan = [];
|
|
|
|
extension_type_vvvvwan.push(temp_vvvvwan);
|
2019-07-15 20:00:46 +00:00
|
|
|
}
|
2024-04-21 23:15:03 +00:00
|
|
|
else if (!isSet(extension_type_vvvvwan))
|
2019-07-15 20:00:46 +00:00
|
|
|
{
|
2024-04-21 23:15:03 +00:00
|
|
|
var extension_type_vvvvwan = [];
|
2019-07-15 20:00:46 +00:00
|
|
|
}
|
2024-04-21 23:15:03 +00:00
|
|
|
var extension_type = extension_type_vvvvwan.some(extension_type_vvvvwan_SomeFunc);
|
2019-07-15 20:00:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
// set this function logic
|
|
|
|
if (extension_type)
|
|
|
|
{
|
|
|
|
jQuery('#jform_joomla_plugin_group').closest('.control-group').show();
|
|
|
|
// add required attribute to joomla_plugin_group field
|
2024-04-21 23:15:03 +00:00
|
|
|
if (jform_vvvvwanvxa_required)
|
2019-07-15 20:00:46 +00:00
|
|
|
{
|
|
|
|
updateFieldRequired('joomla_plugin_group',0);
|
|
|
|
jQuery('#jform_joomla_plugin_group').prop('required','required');
|
|
|
|
jQuery('#jform_joomla_plugin_group').attr('aria-required',true);
|
|
|
|
jQuery('#jform_joomla_plugin_group').addClass('required');
|
2024-04-21 23:15:03 +00:00
|
|
|
jform_vvvvwanvxa_required = false;
|
2019-07-15 20:00:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
jQuery('#jform_joomla_plugin_group').closest('.control-group').hide();
|
|
|
|
// remove required attribute from joomla_plugin_group field
|
2024-04-21 23:15:03 +00:00
|
|
|
if (!jform_vvvvwanvxa_required)
|
2019-07-15 20:00:46 +00:00
|
|
|
{
|
|
|
|
updateFieldRequired('joomla_plugin_group',1);
|
|
|
|
jQuery('#jform_joomla_plugin_group').removeAttr('required');
|
|
|
|
jQuery('#jform_joomla_plugin_group').removeAttr('aria-required');
|
|
|
|
jQuery('#jform_joomla_plugin_group').removeClass('required');
|
2024-04-21 23:15:03 +00:00
|
|
|
jform_vvvvwanvxa_required = true;
|
2019-07-15 20:00:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-21 23:15:03 +00:00
|
|
|
// the vvvvwan Some function
|
|
|
|
function extension_type_vvvvwan_SomeFunc(extension_type_vvvvwan)
|
2019-07-15 20:00:46 +00:00
|
|
|
{
|
|
|
|
// set the function logic
|
2024-04-21 23:15:03 +00:00
|
|
|
if (extension_type_vvvvwan == 'plugins' || extension_type_vvvvwan == 'plugin')
|
2019-07-15 20:00:46 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-27 21:05:28 +00:00
|
|
|
// update fields required
|
|
|
|
function updateFieldRequired(name, status) {
|
|
|
|
// check if not_required exist
|
2024-03-09 19:52:51 +00:00
|
|
|
if (document.getElementById('jform_not_required')) {
|
2020-02-27 21:05:28 +00:00
|
|
|
var not_required = jQuery('#jform_not_required').val().split(",");
|
2019-07-15 20:00:46 +00:00
|
|
|
|
2020-02-27 21:05:28 +00:00
|
|
|
if(status == 1)
|
2019-07-15 20:00:46 +00:00
|
|
|
{
|
2020-02-27 21:05:28 +00:00
|
|
|
not_required.push(name);
|
2019-07-15 20:00:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-27 21:05:28 +00:00
|
|
|
not_required = removeFieldFromNotRequired(not_required, name);
|
2019-07-15 20:00:46 +00:00
|
|
|
}
|
2020-02-27 21:05:28 +00:00
|
|
|
|
|
|
|
jQuery('#jform_not_required').val(fixNotRequiredArray(not_required).toString());
|
2019-07-15 20:00:46 +00:00
|
|
|
}
|
2020-02-27 21:05:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove field from not_required
|
|
|
|
function removeFieldFromNotRequired(array, what) {
|
|
|
|
return array.filter(function(element){
|
|
|
|
return element !== what;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// fix not required array
|
|
|
|
function fixNotRequiredArray(array) {
|
|
|
|
var seen = {};
|
|
|
|
return removeEmptyFromNotRequiredArray(array).filter(function(item) {
|
|
|
|
return seen.hasOwnProperty(item) ? false : (seen[item] = true);
|
|
|
|
});
|
|
|
|
}
|
2019-07-15 20:00:46 +00:00
|
|
|
|
2020-02-27 21:05:28 +00:00
|
|
|
// remove empty from not_required array
|
|
|
|
function removeEmptyFromNotRequiredArray(array) {
|
|
|
|
return array.filter(function (el) {
|
|
|
|
// remove ( 一_一) as well - lol
|
|
|
|
return (el.length > 0 && '一_一' !== el);
|
|
|
|
});
|
2019-07-15 20:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// the isSet function
|
|
|
|
function isSet(val)
|
|
|
|
{
|
|
|
|
if ((val != undefined) && (val != null) && 0 !== val.length){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2019-07-16 23:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
jQuery(document).ready(function()
|
|
|
|
{
|
|
|
|
// load the used in div
|
|
|
|
// jQuery('#usedin').show();
|
|
|
|
// check and load all the customcode edit buttons
|
|
|
|
setTimeout(getEditCustomCodeButtons, 300);
|
|
|
|
});
|
|
|
|
|
2024-03-09 19:52:51 +00:00
|
|
|
function getEditCustomCodeButtons_server(id) {
|
2019-07-16 23:15:42 +00:00
|
|
|
var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod);
|
2024-03-09 19:52:51 +00:00
|
|
|
let requestParams = '';
|
|
|
|
if (token.length > 0 && id > 0) {
|
|
|
|
requestParams = token+'=1&id='+id+'&return_here='+return_here;
|
2019-07-16 23:15:42 +00:00
|
|
|
}
|
2024-03-09 19:52:51 +00:00
|
|
|
// Construct URL with parameters for GET request
|
|
|
|
const urlWithParams = getUrl + '&' + requestParams;
|
|
|
|
|
|
|
|
// Using the Fetch API for the GET request
|
|
|
|
return fetch(urlWithParams, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}).then(response => {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error('Network response was not ok');
|
|
|
|
}
|
|
|
|
return response.json();
|
2019-07-16 23:15:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-03-09 19:52:51 +00:00
|
|
|
function getEditCustomCodeButtons() {
|
|
|
|
// Get the id using pure JavaScript
|
|
|
|
const id = document.querySelector("#jform_id").value;
|
|
|
|
getEditCustomCodeButtons_server(id).then(function(result) {
|
|
|
|
if (typeof result === 'object') {
|
|
|
|
Object.entries(result).forEach(([field, buttons]) => {
|
|
|
|
// Creating the div element for buttons
|
|
|
|
const div = document.createElement('div');
|
|
|
|
div.className = 'control-group';
|
|
|
|
div.innerHTML = '<div class="control-label"><label>Add/Edit Customcode</label></div><div class="controls control-customcode-buttons-'+field+'"></div>';
|
|
|
|
|
|
|
|
// Insert the div before .control-wrapper-{field}
|
|
|
|
const insertBeforeElement = document.querySelector(".control-wrapper-"+field);
|
|
|
|
insertBeforeElement.parentNode.insertBefore(div, insertBeforeElement);
|
|
|
|
|
|
|
|
// Adding buttons to the div
|
|
|
|
Object.entries(buttons).forEach(([name, button]) => {
|
|
|
|
const controlsDiv = document.querySelector(".control-customcode-buttons-"+field);
|
|
|
|
controlsDiv.innerHTML += button;
|
2019-07-16 23:15:42 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2024-03-09 19:52:51 +00:00
|
|
|
}).catch(error => {
|
|
|
|
console.error('Error:', error);
|
|
|
|
});
|
|
|
|
}
|