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
|
|
|
|
*/
|
|
|
|
|
2018-03-27 09:57:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jQuery(document).ready(function()
|
|
|
|
{
|
|
|
|
// get the rule name
|
|
|
|
var ruleName = jQuery('#jform_name').val();
|
|
|
|
// check if this rule name is taken
|
|
|
|
checkRuleName(ruleName);
|
|
|
|
|
|
|
|
// get type value
|
|
|
|
var rulefilename = jQuery("#jform_inherit option:selected").val();
|
|
|
|
if(jQuery('#jform_php').length == 0) {
|
|
|
|
getExistingValidationRuleCode(rulefilename);
|
|
|
|
}
|
|
|
|
|
|
|
|
// load the used in div
|
|
|
|
// jQuery('#usedin').show();
|
2019-01-31 21:44:21 +00:00
|
|
|
|
|
|
|
// check and load all the customcode edit buttons
|
|
|
|
setTimeout(getEditCustomCodeButtons, 300);
|
2018-03-27 09:57:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function getExistingValidationRuleCode_server(rulefilename){
|
2019-07-15 20:00:46 +00:00
|
|
|
var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.getExistingValidationRuleCode&format=json&raw=true");
|
2018-03-27 09:57:16 +00:00
|
|
|
if(token.length > 0 && rulefilename.length > 0){
|
2019-07-08 16:05:54 +00:00
|
|
|
var request = token+'=1&name='+rulefilename;
|
2018-03-27 09:57:16 +00:00
|
|
|
}
|
|
|
|
return jQuery.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: getUrl,
|
2019-07-15 20:00:46 +00:00
|
|
|
dataType: 'json',
|
2018-03-27 09:57:16 +00:00
|
|
|
data: request,
|
2019-07-15 20:00:46 +00:00
|
|
|
jsonp: false
|
2018-03-27 09:57:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getExistingValidationRuleCode(rulefilename,setValue){
|
|
|
|
getExistingValidationRuleCode_server(rulefilename).done(function(result) {
|
|
|
|
if(result.values){
|
|
|
|
jQuery('textarea#jform_php').val(result.values);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkRuleName(ruleName) {
|
|
|
|
if (ruleName.length > 2) {
|
|
|
|
var ide = jQuery('#jform_id').val();
|
|
|
|
if (ide == 0) {
|
|
|
|
ide = -1;
|
|
|
|
}
|
|
|
|
checkRuleName_server(ruleName, ide).done(function(result) {
|
|
|
|
if(result.name && result.message){
|
|
|
|
// show notice that functioName is okay
|
|
|
|
jQuery.UIkit.notify({message: result.message, timeout: result.timeout, status: result.status, pos: 'top-right'});
|
|
|
|
jQuery('#jform_name').val(result.name);
|
|
|
|
// now start search for where the function is used
|
|
|
|
usedin(result.name, ide);
|
|
|
|
} else if(result.message){
|
|
|
|
// show notice that ruleName is not okay
|
|
|
|
jQuery.UIkit.notify({message: result.message, timeout: result.timeout, status: result.status, pos: 'top-right'});
|
|
|
|
jQuery('#jform_name').val('');
|
|
|
|
} else {
|
|
|
|
// set an error that message was not send
|
|
|
|
jQuery.UIkit.notify({message: Joomla.JText._('COM_COMPONENTBUILDER_VALIDATION_RULE_NAME_ALREADY_TAKEN_PLEASE_TRY_AGAIN'), timeout: 7000, status: 'danger', pos: 'top-right'});
|
|
|
|
jQuery('#jform_name').val('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// set an error that message was not send
|
|
|
|
jQuery.UIkit.notify({message: Joomla.JText._('COM_COMPONENTBUILDER_YOU_MUST_ADD_AN_UNIQUE_VALIDATION_RULE_NAME'), timeout: 5000, status: 'danger', pos: 'top-right'});
|
|
|
|
jQuery('#jform_name').val('');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check Function Name
|
|
|
|
function checkRuleName_server(ruleName, ide){
|
2019-07-15 20:00:46 +00:00
|
|
|
var getUrl = JRouter("index.php?option=com_componentbuilder&task=ajax.checkRuleName&format=json&raw=true");
|
2018-03-27 09:57:16 +00:00
|
|
|
if(token.length > 0){
|
2019-07-08 16:05:54 +00:00
|
|
|
var request = token+'=1&name='+ruleName+'&id='+ide;
|
2018-03-27 09:57:16 +00:00
|
|
|
}
|
|
|
|
return jQuery.ajax({
|
2019-07-15 20:00:46 +00:00
|
|
|
type: 'GET',
|
2018-03-27 09:57:16 +00:00
|
|
|
url: getUrl,
|
2019-07-15 20:00:46 +00:00
|
|
|
dataType: 'json',
|
2018-03-27 09:57:16 +00:00
|
|
|
data: request,
|
2019-07-15 20:00:46 +00:00
|
|
|
jsonp: false
|
2018-03-27 09:57:16 +00:00
|
|
|
});
|
2019-01-31 21:44:21 +00:00
|
|
|
}
|
|
|
|
|
2024-03-09 19:52:51 +00:00
|
|
|
function getEditCustomCodeButtons_server(id) {
|
2019-07-08 16:05:54 +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-01-31 21:44:21 +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-01-31 21:44:21 +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-01-31 21:44:21 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2024-03-09 19:52:51 +00:00
|
|
|
}).catch(error => {
|
|
|
|
console.error('Error:', error);
|
|
|
|
});
|
|
|
|
}
|