Component-Builder/media/js/class_method.js
Robot 2a9a66b8a7
Release of v5.0.0-rc1
Improved the Schema Table update engine (more). Fix autoloader timing, and loading. Implement the Joomla Powers in JCB code, to move away from JClasses.
2024-04-27 16:00:36 +02:00

186 lines
5.4 KiB
JavaScript

/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Some Global Values
jform_vvvvwamvxa_required = false;
// Initial Script
document.addEventListener('DOMContentLoaded', function()
{
var extension_type_vvvvwam = jQuery("#jform_extension_type").val();
vvvvwam(extension_type_vvvvwam);
});
// the vvvvwam function
function vvvvwam(extension_type_vvvvwam)
{
if (isSet(extension_type_vvvvwam) && extension_type_vvvvwam.constructor !== Array)
{
var temp_vvvvwam = extension_type_vvvvwam;
var extension_type_vvvvwam = [];
extension_type_vvvvwam.push(temp_vvvvwam);
}
else if (!isSet(extension_type_vvvvwam))
{
var extension_type_vvvvwam = [];
}
var extension_type = extension_type_vvvvwam.some(extension_type_vvvvwam_SomeFunc);
// set this function logic
if (extension_type)
{
jQuery('#jform_joomla_plugin_group').closest('.control-group').show();
// add required attribute to joomla_plugin_group field
if (jform_vvvvwamvxa_required)
{
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');
jform_vvvvwamvxa_required = false;
}
}
else
{
jQuery('#jform_joomla_plugin_group').closest('.control-group').hide();
// remove required attribute from joomla_plugin_group field
if (!jform_vvvvwamvxa_required)
{
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');
jform_vvvvwamvxa_required = true;
}
}
}
// the vvvvwam Some function
function extension_type_vvvvwam_SomeFunc(extension_type_vvvvwam)
{
// set the function logic
if (extension_type_vvvvwam == 'plugins' || extension_type_vvvvwam == 'plugin')
{
return true;
}
return false;
}
// update fields required
function updateFieldRequired(name, status) {
// check if not_required exist
if (document.getElementById('jform_not_required')) {
var not_required = jQuery('#jform_not_required').val().split(",");
if(status == 1)
{
not_required.push(name);
}
else
{
not_required = removeFieldFromNotRequired(not_required, name);
}
jQuery('#jform_not_required').val(fixNotRequiredArray(not_required).toString());
}
}
// 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);
});
}
// remove empty from not_required array
function removeEmptyFromNotRequiredArray(array) {
return array.filter(function (el) {
// remove ( 一_一) as well - lol
return (el.length > 0 && '一_一' !== el);
});
}
// the isSet function
function isSet(val)
{
if ((val != undefined) && (val != null) && 0 !== val.length){
return true;
}
return false;
}
jQuery(document).ready(function()
{
// load the used in div
// jQuery('#usedin').show();
// check and load all the customcode edit buttons
setTimeout(getEditCustomCodeButtons, 300);
});
function getEditCustomCodeButtons_server(id) {
var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getEditCustomCodeButtons&format=json&raw=true&vdm="+vastDevMod);
let requestParams = '';
if (token.length > 0 && id > 0) {
requestParams = token+'=1&id='+id+'&return_here='+return_here;
}
// 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();
});
}
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;
});
});
}
}).catch(error => {
console.error('Error:', error);
});
}