2021-03-05 03:08:47 +00:00
/ * *
* @ package Joomla . Component . Builder
*
* @ created 30 th 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
* /
2017-02-09 16:11:10 +00:00
// Some Global Values
2022-07-09 15:16:21 +00:00
jform _vvvvwccvxf _required = false ;
jform _vvvvwcdvxg _required = false ;
jform _vvvvwcdvxh _required = false ;
jform _vvvvwcdvxi _required = false ;
2017-02-09 16:11:10 +00:00
2017-02-01 13:17:04 +00:00
// Initial Script
2024-03-02 20:10:30 +00:00
document . addEventListener ( 'DOMContentLoaded' , function ( )
2017-02-01 13:17:04 +00:00
{
2019-12-03 02:17:35 +00:00
var target _vvvvwcc = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
vvvvwcc ( target _vvvvwcc ) ;
2019-07-15 20:00:46 +00:00
2019-12-03 02:17:35 +00:00
var target _vvvvwcd = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
2022-07-09 15:16:21 +00:00
vvvvwcd ( target _vvvvwcd ) ;
2019-08-08 15:35:58 +00:00
2019-12-03 02:17:35 +00:00
var target _vvvvwce = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
2022-07-09 15:16:21 +00:00
var type _vvvvwce = jQuery ( "#jform_type input[type='radio']:checked" ) . val ( ) ;
vvvvwce ( target _vvvvwce , type _vvvvwce ) ;
var type _vvvvwcf = jQuery ( "#jform_type input[type='radio']:checked" ) . val ( ) ;
var target _vvvvwcf = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
vvvvwcf ( type _vvvvwcf , target _vvvvwcf ) ;
2017-02-01 13:17:04 +00:00
} ) ;
2022-07-09 15:16:21 +00:00
// the vvvvwcc function
function vvvvwcc ( target _vvvvwcc )
2017-02-09 16:11:10 +00:00
{
// set the function logic
2022-07-09 15:16:21 +00:00
if ( target _vvvvwcc == 2 )
2017-02-09 16:11:10 +00:00
{
2017-02-13 23:24:38 +00:00
jQuery ( '#jform_function_name' ) . closest ( '.control-group' ) . show ( ) ;
2018-09-10 11:04:52 +00:00
// add required attribute to function_name field
2022-07-09 15:16:21 +00:00
if ( jform _vvvvwccvxf _required )
2017-02-13 23:24:38 +00:00
{
updateFieldRequired ( 'function_name' , 0 ) ;
jQuery ( '#jform_function_name' ) . prop ( 'required' , 'required' ) ;
jQuery ( '#jform_function_name' ) . attr ( 'aria-required' , true ) ;
jQuery ( '#jform_function_name' ) . addClass ( 'required' ) ;
2022-07-09 15:16:21 +00:00
jform _vvvvwccvxf _required = false ;
2017-02-13 23:24:38 +00:00
}
2017-02-09 16:11:10 +00:00
jQuery ( '.note_jcb_placeholder' ) . closest ( '.control-group' ) . show ( ) ;
2017-02-11 02:24:26 +00:00
jQuery ( '#jform_system_name' ) . closest ( '.control-group' ) . show ( ) ;
2017-02-09 16:11:10 +00:00
}
else
{
2017-02-13 23:24:38 +00:00
jQuery ( '#jform_function_name' ) . closest ( '.control-group' ) . hide ( ) ;
2018-09-10 11:04:52 +00:00
// remove required attribute from function_name field
2022-07-09 15:16:21 +00:00
if ( ! jform _vvvvwccvxf _required )
2017-02-13 23:24:38 +00:00
{
updateFieldRequired ( 'function_name' , 1 ) ;
jQuery ( '#jform_function_name' ) . removeAttr ( 'required' ) ;
jQuery ( '#jform_function_name' ) . removeAttr ( 'aria-required' ) ;
jQuery ( '#jform_function_name' ) . removeClass ( 'required' ) ;
2022-07-09 15:16:21 +00:00
jform _vvvvwccvxf _required = true ;
2017-02-13 23:24:38 +00:00
}
2017-02-09 16:11:10 +00:00
jQuery ( '.note_jcb_placeholder' ) . closest ( '.control-group' ) . hide ( ) ;
2017-02-11 02:24:26 +00:00
jQuery ( '#jform_system_name' ) . closest ( '.control-group' ) . hide ( ) ;
2017-02-09 16:11:10 +00:00
}
}
2022-07-09 15:16:21 +00:00
// the vvvvwcd function
function vvvvwcd ( target _vvvvwcd )
2017-02-09 16:11:10 +00:00
{
// set the function logic
2022-07-09 15:16:21 +00:00
if ( target _vvvvwcd == 1 )
2017-02-09 16:11:10 +00:00
{
jQuery ( '#jform_component' ) . closest ( '.control-group' ) . show ( ) ;
2018-09-10 11:04:52 +00:00
// add required attribute to component field
2022-07-09 15:16:21 +00:00
if ( jform _vvvvwcdvxg _required )
2017-02-09 16:11:10 +00:00
{
updateFieldRequired ( 'component' , 0 ) ;
jQuery ( '#jform_component' ) . prop ( 'required' , 'required' ) ;
jQuery ( '#jform_component' ) . attr ( 'aria-required' , true ) ;
jQuery ( '#jform_component' ) . addClass ( 'required' ) ;
2022-07-09 15:16:21 +00:00
jform _vvvvwcdvxg _required = false ;
2017-02-09 16:11:10 +00:00
}
jQuery ( '#jform_path' ) . closest ( '.control-group' ) . show ( ) ;
2018-09-10 11:04:52 +00:00
// add required attribute to path field
2022-07-09 15:16:21 +00:00
if ( jform _vvvvwcdvxh _required )
2017-02-09 16:11:10 +00:00
{
updateFieldRequired ( 'path' , 0 ) ;
jQuery ( '#jform_path' ) . prop ( 'required' , 'required' ) ;
jQuery ( '#jform_path' ) . attr ( 'aria-required' , true ) ;
jQuery ( '#jform_path' ) . addClass ( 'required' ) ;
2022-07-09 15:16:21 +00:00
jform _vvvvwcdvxh _required = false ;
2017-02-09 16:11:10 +00:00
}
jQuery ( '#jform_from_line' ) . closest ( '.control-group' ) . show ( ) ;
jQuery ( '#jform_hashtarget' ) . closest ( '.control-group' ) . show ( ) ;
jQuery ( '#jform_to_line' ) . closest ( '.control-group' ) . show ( ) ;
jQuery ( '#jform_type' ) . closest ( '.control-group' ) . show ( ) ;
2018-09-10 11:04:52 +00:00
// add required attribute to type field
2022-07-09 15:16:21 +00:00
if ( jform _vvvvwcdvxi _required )
2017-02-09 16:11:10 +00:00
{
updateFieldRequired ( 'type' , 0 ) ;
jQuery ( '#jform_type' ) . prop ( 'required' , 'required' ) ;
jQuery ( '#jform_type' ) . attr ( 'aria-required' , true ) ;
jQuery ( '#jform_type' ) . addClass ( 'required' ) ;
2022-07-09 15:16:21 +00:00
jform _vvvvwcdvxi _required = false ;
2017-02-09 16:11:10 +00:00
}
}
else
{
jQuery ( '#jform_component' ) . closest ( '.control-group' ) . hide ( ) ;
2018-09-10 11:04:52 +00:00
// remove required attribute from component field
2022-07-09 15:16:21 +00:00
if ( ! jform _vvvvwcdvxg _required )
2017-02-09 16:11:10 +00:00
{
updateFieldRequired ( 'component' , 1 ) ;
jQuery ( '#jform_component' ) . removeAttr ( 'required' ) ;
jQuery ( '#jform_component' ) . removeAttr ( 'aria-required' ) ;
jQuery ( '#jform_component' ) . removeClass ( 'required' ) ;
2022-07-09 15:16:21 +00:00
jform _vvvvwcdvxg _required = true ;
2017-02-09 16:11:10 +00:00
}
jQuery ( '#jform_path' ) . closest ( '.control-group' ) . hide ( ) ;
2018-09-10 11:04:52 +00:00
// remove required attribute from path field
2022-07-09 15:16:21 +00:00
if ( ! jform _vvvvwcdvxh _required )
2017-02-09 16:11:10 +00:00
{
updateFieldRequired ( 'path' , 1 ) ;
jQuery ( '#jform_path' ) . removeAttr ( 'required' ) ;
jQuery ( '#jform_path' ) . removeAttr ( 'aria-required' ) ;
jQuery ( '#jform_path' ) . removeClass ( 'required' ) ;
2022-07-09 15:16:21 +00:00
jform _vvvvwcdvxh _required = true ;
2017-02-09 16:11:10 +00:00
}
jQuery ( '#jform_from_line' ) . closest ( '.control-group' ) . hide ( ) ;
jQuery ( '#jform_hashtarget' ) . closest ( '.control-group' ) . hide ( ) ;
jQuery ( '#jform_to_line' ) . closest ( '.control-group' ) . hide ( ) ;
jQuery ( '#jform_type' ) . closest ( '.control-group' ) . hide ( ) ;
2018-09-10 11:04:52 +00:00
// remove required attribute from type field
2022-07-09 15:16:21 +00:00
if ( ! jform _vvvvwcdvxi _required )
2017-02-09 16:11:10 +00:00
{
updateFieldRequired ( 'type' , 1 ) ;
jQuery ( '#jform_type' ) . removeAttr ( 'required' ) ;
jQuery ( '#jform_type' ) . removeAttr ( 'aria-required' ) ;
jQuery ( '#jform_type' ) . removeClass ( 'required' ) ;
2022-07-09 15:16:21 +00:00
jform _vvvvwcdvxi _required = true ;
2017-02-09 16:11:10 +00:00
}
}
}
2022-07-09 15:16:21 +00:00
// the vvvvwce function
function vvvvwce ( target _vvvvwce , type _vvvvwce )
2017-02-01 13:17:04 +00:00
{
// set the function logic
2022-07-09 15:16:21 +00:00
if ( target _vvvvwce == 1 && type _vvvvwce == 1 )
2017-02-01 13:17:04 +00:00
{
jQuery ( '#jform_hashendtarget' ) . closest ( '.control-group' ) . show ( ) ;
2017-02-09 16:11:10 +00:00
jQuery ( '#jform_to_line' ) . closest ( '.control-group' ) . show ( ) ;
2017-02-01 13:17:04 +00:00
}
else
{
jQuery ( '#jform_hashendtarget' ) . closest ( '.control-group' ) . hide ( ) ;
2017-02-09 16:11:10 +00:00
jQuery ( '#jform_to_line' ) . closest ( '.control-group' ) . hide ( ) ;
}
}
2022-07-09 15:16:21 +00:00
// the vvvvwcf function
function vvvvwcf ( type _vvvvwcf , target _vvvvwcf )
2017-02-09 16:11:10 +00:00
{
// set the function logic
2022-07-09 15:16:21 +00:00
if ( type _vvvvwcf == 1 && target _vvvvwcf == 1 )
2017-02-09 16:11:10 +00:00
{
jQuery ( '#jform_hashendtarget' ) . closest ( '.control-group' ) . show ( ) ;
jQuery ( '#jform_to_line' ) . closest ( '.control-group' ) . show ( ) ;
2017-02-01 13:17:04 +00:00
}
2017-02-09 16:11:10 +00:00
else
{
jQuery ( '#jform_hashendtarget' ) . closest ( '.control-group' ) . hide ( ) ;
jQuery ( '#jform_to_line' ) . closest ( '.control-group' ) . hide ( ) ;
}
}
2020-02-27 21:05:28 +00:00
// update fields required
function updateFieldRequired ( name , status ) {
// check if not_required exist
2024-03-02 20:10:30 +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 ( "," ) ;
2017-02-09 16:11:10 +00:00
2020-02-27 21:05:28 +00:00
if ( status == 1 )
2017-02-09 16:11:10 +00:00
{
2020-02-27 21:05:28 +00:00
not _required . push ( name ) ;
2017-02-09 16:11:10 +00:00
}
else
{
2020-02-27 21:05:28 +00:00
not _required = removeFieldFromNotRequired ( not _required , name ) ;
2017-02-09 16:11:10 +00:00
}
2020-02-27 21:05:28 +00:00
jQuery ( '#jform_not_required' ) . val ( fixNotRequiredArray ( not _required ) . toString ( ) ) ;
2017-02-09 16:11:10 +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 ) ;
} ) ;
}
2017-02-09 16:11:10 +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 ) ;
} ) ;
2017-02-01 13:17:04 +00:00
}
// the isSet function
function isSet ( val )
{
if ( ( val != undefined ) && ( val != null ) && 0 !== val . length ) {
return true ;
}
return false ;
2017-02-13 23:24:38 +00:00
}
2018-03-11 02:44:43 +00:00
2017-02-13 23:24:38 +00:00
jQuery ( document ) . ready ( function ( )
{
var target = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
if ( target == 2 ) {
2017-02-17 18:35:18 +00:00
jQuery ( '#usedin' ) . show ( ) ;
2017-02-13 23:24:38 +00:00
var functioName = jQuery ( '#jform_function_name' ) . val ( ) ;
// check if this function name is taken
checkFunctionName ( functioName ) ;
}
2017-02-17 18:35:18 +00:00
var type = jQuery ( "#jform_comment_type input[type='radio']:checked" ) . val ( ) ;
if ( type == 2 ) {
jQuery ( '#html-comment-info' ) . show ( ) ;
jQuery ( '#phpjs-comment-info' ) . hide ( ) ;
} else {
jQuery ( '#html-comment-info' ) . hide ( ) ;
jQuery ( '#phpjs-comment-info' ) . show ( ) ;
}
2019-01-31 21:44:21 +00:00
// check and load all the custom code edit buttons
getEditCustomCodeButtons ( ) ;
2017-02-13 23:24:38 +00:00
} ) ;
function setCustomCodePlaceholder ( ) {
var ide = jQuery ( '#jform_id' ) . val ( ) ;
var functioName = jQuery ( '#jform_function_name' ) . val ( ) ;
if ( ide > 0 && functioName . length > 2 ) {
2018-09-28 15:46:21 +00:00
jQuery ( '#jcb-placeholder' ) . html ( '<code>[CUSTO' + 'MCODE=' + functioName + ']</code>' ) ;
jQuery ( '#jcb-placeholder-arg' ) . html ( '<code>[CUSTO' + 'MCODE=' + functioName + '+value1,value2]</code>' ) ;
2017-02-13 23:24:38 +00:00
} else if ( ide > 0 ) {
2018-09-28 15:46:21 +00:00
jQuery ( '#jcb-placeholder' ) . html ( '<code>[not ready]</code>' ) ;
jQuery ( '#jcb-placeholder-arg' ) . html ( '<code>[not ready]</code>' ) ;
2017-02-13 23:24:38 +00:00
} else if ( functioName . length > 2 ) {
2018-09-29 00:57:11 +00:00
jQuery ( '#jcb-placeholder' ) . html ( '<code>[CUSTO' + 'MCODE=' + functioName + ']</code>' ) ;
2018-09-28 15:46:21 +00:00
jQuery ( '#jcb-placeholder-arg' ) . html ( '<code>[CUSTO' + 'MCODE=' + functioName + '+value1,value2]</code>' ) ;
2017-02-13 23:24:38 +00:00
} else {
jQuery ( '#jcb-placeholder' ) . html ( '<code>[save to see]</code>' ) ;
jQuery ( '#jcb-placeholder-arg' ) . html ( '<code>[save to see]</code>' ) ;
}
// update the notes
if ( ide > 0 ) {
jQuery ( '.placeholder-key-id' ) . text ( ide ) ;
}
}
2019-02-23 13:28:54 +00:00
2017-02-13 23:24:38 +00:00
function checkFunctionName ( functioName ) {
if ( functioName . length > 2 ) {
var ide = jQuery ( '#jform_id' ) . val ( ) ;
if ( ide == 0 ) {
ide = - 1 ;
}
checkFunctionName _server ( functioName , ide ) . done ( function ( result ) {
if ( result . name && result . message ) {
// show notice that functioName is okay
jQuery . UIkit . notify ( { message : result . message , timeout : 5000 , status : result . status , pos : 'top-right' } ) ;
jQuery ( '#jform_function_name' ) . val ( result . name ) ;
// now start search for where the function is used
usedin ( result . name , ide ) ;
} else if ( result . message ) {
2019-02-23 13:28:54 +00:00
// show notice that functioName is not okay
2017-02-13 23:24:38 +00:00
jQuery . UIkit . notify ( { message : result . message , timeout : 5000 , status : result . status , pos : 'top-right' } ) ;
jQuery ( '#jform_function_name' ) . val ( '' ) ;
} else {
// set an error that message was not send
2018-03-27 09:57:16 +00:00
jQuery . UIkit . notify ( { message : Joomla . JText . _ ( 'COM_COMPONENTBUILDER_FUNCTION_NAME_ALREADY_TAKEN_PLEASE_TRY_AGAIN' ) , timeout : 5000 , status : 'danger' , pos : 'top-right' } ) ;
2017-02-13 23:24:38 +00:00
jQuery ( '#jform_function_name' ) . val ( '' ) ;
}
// set custom code placeholder
setCustomCodePlaceholder ( ) ;
} ) ;
} else {
// set an error that message was not send
2018-03-27 09:57:16 +00:00
jQuery . UIkit . notify ( { message : Joomla . JText . _ ( 'COM_COMPONENTBUILDER_YOU_MUST_ADD_AN_UNIQUE_FUNCTION_NAME' ) , timeout : 5000 , status : 'danger' , pos : 'top-right' } ) ;
2017-02-13 23:24:38 +00:00
jQuery ( '#jform_function_name' ) . val ( '' ) ;
// set custom code placeholder
setCustomCodePlaceholder ( ) ;
}
}
2019-02-23 13:28:54 +00:00
// check Function name
2017-02-13 23:24:38 +00:00
function checkFunctionName _server ( functioName , ide ) {
2019-02-23 13:28:54 +00:00
var getUrl = "index.php?option=com_componentbuilder&task=ajax.checkFunctionName&raw=true&format=json" ;
2017-02-13 23:24:38 +00:00
if ( token . length > 0 ) {
var request = 'token=' + token + '&functioName=' + functioName + '&id=' + ide ;
}
return jQuery . ajax ( {
type : 'POST' ,
url : getUrl ,
2019-02-23 13:28:54 +00:00
dataType : 'json' ,
2017-02-13 23:24:38 +00:00
data : request ,
2019-02-23 13:28:54 +00:00
jsonp : false
2017-02-13 23:24:38 +00:00
} ) ;
}
2019-02-23 13:28:54 +00:00
2017-02-13 23:24:38 +00:00
// check where this Function is used
function usedin ( functioName , ide ) {
2017-02-17 18:35:18 +00:00
var found = false ;
jQuery ( '#before-usedin' ) . hide ( ) ;
jQuery ( '#note-usedin-not' ) . hide ( ) ;
jQuery ( '#note-usedin-found' ) . hide ( ) ;
jQuery ( '#loading-usedin' ) . show ( ) ;
2021-10-18 20:12:19 +00:00
var targets = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' ] ; // if you update this, also update (below 21) & [customcode-codeUsedInHtmlNote]!
var targetNumber = 21 ;
2017-02-17 18:35:18 +00:00
var run = 0 ;
var usedinChecker = setInterval ( function ( ) {
var target = targets [ run ] ;
usedin _server ( functioName , ide , target ) . done ( function ( used ) {
if ( used . in ) {
jQuery ( '#usedin-' + used . id ) . show ( ) ;
jQuery ( '#area-' + used . id ) . html ( used . in ) ;
2017-10-14 03:37:18 +00:00
jQuery . UIkit . notify ( { message : used . in , timeout : 5000 , status : 'success' , pos : 'top-right' } ) ;
2017-02-17 18:35:18 +00:00
found = true ;
} else {
jQuery ( '#usedin-' + target ) . hide ( ) ;
}
2018-10-29 16:38:00 +00:00
if ( run == targetNumber ) {
2017-02-17 18:35:18 +00:00
jQuery ( '#loading-usedin' ) . hide ( ) ;
if ( found ) {
jQuery ( '#note-usedin-found' ) . show ( ) ;
} else {
jQuery ( '#note-usedin-not' ) . show ( ) ;
}
}
} ) ;
2018-10-29 16:38:00 +00:00
if ( run == targetNumber ) {
2017-02-17 18:35:18 +00:00
clearInterval ( usedinChecker ) ;
2017-02-13 23:24:38 +00:00
}
2017-02-17 18:35:18 +00:00
run ++ ;
} , 800 ) ;
2017-02-13 23:24:38 +00:00
}
2017-02-17 18:35:18 +00:00
function usedin _server ( functioName , ide , target ) {
2017-02-13 23:24:38 +00:00
var getUrl = "index.php?option=com_componentbuilder&task=ajax.usedin&format=json" ;
if ( token . length > 0 ) {
2019-11-08 16:07:08 +00:00
var request = token + '=1&functioName=' + functioName + '&id=' + ide + '&target=' + target + '&raw=true&return_here=' + return _here ;
2017-02-13 23:24:38 +00:00
}
return jQuery . ajax ( {
2017-02-17 18:35:18 +00:00
type : 'GET' ,
2017-02-13 23:24:38 +00:00
url : getUrl ,
2019-02-23 13:28:54 +00:00
dataType : 'json' ,
2017-02-13 23:24:38 +00:00
data : request ,
2019-02-23 13:28:54 +00:00
jsonp : false
2017-02-13 23:24:38 +00:00
} ) ;
2019-01-31 21:44:21 +00:00
}
2019-02-23 13:28:54 +00:00
2019-01-31 21:44:21 +00:00
2024-03-02 20:10:30 +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-02 20:10:30 +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-02 20:10:30 +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-02 20:10:30 +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-02 20:10:30 +00:00
} ) . catch ( error => {
console . error ( 'Error:' , error ) ;
} ) ;
}