127 lines
3.6 KiB
JavaScript
127 lines
3.6 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
|
|
*/
|
|
|
|
// Initial Script
|
|
document.addEventListener('DOMContentLoaded', function()
|
|
{
|
|
var extension_type_vvvvwag = jQuery("#jform_extension_type").val();
|
|
vvvvwag(extension_type_vvvvwag);
|
|
});
|
|
|
|
// the vvvvwag function
|
|
function vvvvwag(extension_type_vvvvwag)
|
|
{
|
|
if (isSet(extension_type_vvvvwag) && extension_type_vvvvwag.constructor !== Array)
|
|
{
|
|
var temp_vvvvwag = extension_type_vvvvwag;
|
|
var extension_type_vvvvwag = [];
|
|
extension_type_vvvvwag.push(temp_vvvvwag);
|
|
}
|
|
else if (!isSet(extension_type_vvvvwag))
|
|
{
|
|
var extension_type_vvvvwag = [];
|
|
}
|
|
var extension_type = extension_type_vvvvwag.some(extension_type_vvvvwag_SomeFunc);
|
|
|
|
|
|
// set this function logic
|
|
if (extension_type)
|
|
{
|
|
jQuery('#jform_joomla_plugin_group').closest('.control-group').show();
|
|
}
|
|
else
|
|
{
|
|
jQuery('#jform_joomla_plugin_group').closest('.control-group').hide();
|
|
}
|
|
}
|
|
|
|
// the vvvvwag Some function
|
|
function extension_type_vvvvwag_SomeFunc(extension_type_vvvvwag)
|
|
{
|
|
// set the function logic
|
|
if (extension_type_vvvvwag == 'plugins' || extension_type_vvvvwag == 'plugin')
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// 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);
|
|
if (insertBeforeElement) {
|
|
insertBeforeElement.parentNode.insertBefore(div, insertBeforeElement);
|
|
}
|
|
|
|
// Adding buttons to the div
|
|
Object.entries(buttons).forEach(([name, button]) => {
|
|
const controlsDiv = document.querySelector(".control-customcode-buttons-"+field);
|
|
if (controlsDiv) {
|
|
controlsDiv.innerHTML += button;
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}).catch(error => {
|
|
console.error('Error:', error);
|
|
});
|
|
}
|