Files
Component-Builder/media/js/admin_fields_relations.js
Robot 442263e387 Release of v5.1.0
Add [AllowDynamicProperties] in the base view class for J5. Move the _prepareDocument  above the display call in the base view class. Remove all backward compatibility issues, so JCB will not need the [Backward Compatibility] plugin to run. Added new import powers for custom import of spreadsheets. Move the setDocument and _prepareDocument above the display in the site view and custom admin view. Update the trashhelper layout to work in Joomla 5. Add AllowDynamicProperties (Joomla 4+5) to view class to allow Custom Dynamic Get methods to work without issues. Fix Save failed issue in dynamicGet. #1148. Move all [TEXT, EDITOR, TEXTAREA] fields from [NOT NULL] to [NULL]. Add the DateHelper class and improve the date methods. Add simple SessionHelper class. Add first classes for the new import engine. Improve the [VDM Registry] to be Joomla Registry Compatible. Move all registries to the [VDM Registry] class. Fix Checked Out to be null and not 0. (#1194). Fix created_by, modified_by, checked_out fields in the compiler of the SQL. (#1194). Update all core date fields in table class. (#1188). Update created_by, modified_by, checked_out fields in table class. Implementation of the decentralized Super-Power CORE repository network. (#1190). Fix the noticeboard to display Llewellyn's Joomla Social feed. Started compiling JCB5 on Joomla 5 with PHP 8.2. Add init_defaults option for dynamic form selection setup (to int new items with default values dynamically). Update all JCB 5 tables to utf8mb4_unicode_ci collation if misaligned. Move all internal ID linking to GUID inside of JCB 5. Updated the admin-tab-fields in add-fields view. #1205. Remove Custom Import Tab from admin view. Improved the customcode and placeholder search features.
2025-02-14 22:55:55 +02:00

144 lines
4.3 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
*/
jQuery(document).ready(function()
{
// check and load all the customcode edit buttons
getEditCustomCodeButtons();
});
// the isSet function
function _isSet(value) {
return value !== undefined && value !== null && value !== '';
}
// Function to set the value
function getCodeGlueOptions(field) {
// Get the ID
var id = field.id;
var target = id.split('__');
// Set the subID
var subID = target[0] + '__' + target[1];
// Get listfield value
var listfield = document.getElementById(subID + '__listfield')?.value || '';
// Get type value
var type = document.getElementById(subID + '__join_type')?.value || '';
// Get area value
var area = document.getElementById(subID + '__area')?.value || '';
// Check that values are set
if (_isSet(listfield) && _isSet(type) && _isSet(area)) {
// Get joinfields values
var joinfields = document.getElementById(subID + '__joinfields')?.value || '';
// Fetch CodeGlueOptions
getCodeGlueOptions_server(listfield, joinfields, type, area)
.then(result => {
document.getElementById(subID + '__set').value = result || '';
})
.catch(() => {
document.getElementById(subID + '__set').value = '';
});
} else {
document.getElementById(subID + '__set').value = '';
}
}
// Function to fetch data from the server
function getCodeGlueOptions_server(listfield, joinfields, type, area) {
var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getCodeGlueOptions&format=json");
// Ensure joinfields is set
if (!_isSet(joinfields)) {
joinfields = 'none';
}
if (typeof token !== 'undefined' && token.length > 0 && listfield.length > 0 && type > 0 && area > 0) {
var params = new URLSearchParams({
[token]: '1',
listfield: listfield,
type: type,
area: area,
joinfields: joinfields
});
return fetch(getUrl + '&' + params.toString(), {
method: 'GET',
headers: {
'Accept': 'application/json'
}
})
.then(response => response.json())
.catch(() => null);
}
return Promise.resolve(null);
}
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);
});
}