2017-02-01 13:17:04 +00:00
/*--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
\ \ / / | | | _ _ \ | | | | | \ / | | | | | | |
\ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | _ _ _ | | _ | | _ _ _ _ _ _ _ | |
\ \ / / _` / _ _ | _ _ | | | | | / _ \ \ / / _ \ | / _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| ' _ \ / _ \ / _ ` |
\ / ( _ | \ _ _ \ | _ | | _ _ | | _ _ / \ V / _ _ / | ( _ ) | | _ ) | | | | | | _ _ / | | | | _ | | | | _ _ / | _ | | | | ( _ ) | ( _ | |
\ / \ _ _ , _ | _ _ _ / \ _ _ | | _ _ _ _ _ / \ _ _ _ | \ _ / \ _ _ _ | _ | \ _ _ _ / | . _ _ / | _ | | _ | | _ | \ _ _ _ | _ | | _ | \ _ _ | | _ | | _ | \ _ _ _ | \ _ _ | _ | | _ | \ _ _ _ / \ _ _ , _ |
| |
| _ |
2017-11-06 14:15:03 +00:00
/-------------------------------------------------------------------------------------------------------------------------------/
2017-02-01 13:17:04 +00:00
2018-03-21 03:10:34 +00:00
@ version 2.7 . x
2017-11-06 14:04:23 +00:00
@ created 30 th April , 2015
2017-02-01 13:17:04 +00:00
@ package Component Builder
@ subpackage custom _code . js
2017-12-27 03:45:35 +00:00
@ author Llewellyn van der Merwe < http : //joomlacomponentbuilder.com>
2017-11-06 14:04:23 +00:00
@ github Joomla Component Builder < https : //github.com/vdm-io/Joomla-Component-Builder>
2017-02-01 13:17:04 +00:00
@ copyright Copyright ( C ) 2015. All Rights Reserved
@ license GNU / GPL Version 2 or later - http : //www.gnu.org/licenses/gpl-2.0.html
Builds Complex Joomla Components
/-----------------------------------------------------------------------------------------------------------------------------*/
2017-02-09 16:11:10 +00:00
// Some Global Values
2018-03-11 22:36:14 +00:00
jform _vvvvvzzvzo _required = false ;
jform _vvvvwaavzp _required = false ;
2018-03-09 03:26:44 +00:00
jform _vvvvwaavzq _required = false ;
jform _vvvvwaavzr _required = false ;
2017-02-09 16:11:10 +00:00
2017-02-01 13:17:04 +00:00
// Initial Script
jQuery ( document ) . ready ( function ( )
{
2018-01-23 22:05:57 +00:00
var target _vvvvvzz = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
2018-03-09 03:26:44 +00:00
vvvvvzz ( target _vvvvvzz ) ;
2018-01-15 15:54:05 +00:00
2018-01-23 22:05:57 +00:00
var target _vvvvwaa = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
2018-03-09 03:26:44 +00:00
vvvvwaa ( target _vvvvwaa ) ;
var target _vvvvwab = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
var type _vvvvwab = jQuery ( "#jform_type input[type='radio']:checked" ) . val ( ) ;
vvvvwab ( target _vvvvwab , type _vvvvwab ) ;
var type _vvvvwac = jQuery ( "#jform_type input[type='radio']:checked" ) . val ( ) ;
var target _vvvvwac = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
vvvvwac ( type _vvvvwac , target _vvvvwac ) ;
2017-02-01 13:17:04 +00:00
} ) ;
2018-03-09 03:26:44 +00:00
// the vvvvvzz function
function vvvvvzz ( target _vvvvvzz )
2017-02-09 16:11:10 +00:00
{
// set the function logic
2018-03-09 03:26:44 +00:00
if ( target _vvvvvzz == 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-03-11 22:36:14 +00:00
if ( jform _vvvvvzzvzo _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' ) ;
2018-03-11 22:36:14 +00:00
jform _vvvvvzzvzo _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-03-11 22:36:14 +00:00
if ( ! jform _vvvvvzzvzo _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' ) ;
2018-03-11 22:36:14 +00:00
jform _vvvvvzzvzo _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
}
}
2018-03-09 03:26:44 +00:00
// the vvvvwaa function
function vvvvwaa ( target _vvvvwaa )
2017-02-09 16:11:10 +00:00
{
// set the function logic
2018-03-09 03:26:44 +00:00
if ( target _vvvvwaa == 1 )
2017-02-09 16:11:10 +00:00
{
jQuery ( '#jform_component' ) . closest ( '.control-group' ) . show ( ) ;
2018-03-11 22:36:14 +00:00
if ( jform _vvvvwaavzp _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' ) ;
2018-03-11 22:36:14 +00:00
jform _vvvvwaavzp _required = false ;
2017-02-09 16:11:10 +00:00
}
jQuery ( '#jform_path' ) . closest ( '.control-group' ) . show ( ) ;
2018-03-11 22:36:14 +00:00
if ( jform _vvvvwaavzq _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' ) ;
2018-03-11 22:36:14 +00:00
jform _vvvvwaavzq _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-03-11 22:36:14 +00:00
if ( jform _vvvvwaavzr _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' ) ;
2018-03-11 22:36:14 +00:00
jform _vvvvwaavzr _required = false ;
2017-02-09 16:11:10 +00:00
}
}
else
{
jQuery ( '#jform_component' ) . closest ( '.control-group' ) . hide ( ) ;
2018-03-11 22:36:14 +00:00
if ( ! jform _vvvvwaavzp _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' ) ;
2018-03-11 22:36:14 +00:00
jform _vvvvwaavzp _required = true ;
2017-02-09 16:11:10 +00:00
}
jQuery ( '#jform_path' ) . closest ( '.control-group' ) . hide ( ) ;
2018-03-11 22:36:14 +00:00
if ( ! jform _vvvvwaavzq _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' ) ;
2018-03-11 22:36:14 +00:00
jform _vvvvwaavzq _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-03-11 22:36:14 +00:00
if ( ! jform _vvvvwaavzr _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' ) ;
2018-03-11 22:36:14 +00:00
jform _vvvvwaavzr _required = true ;
2017-02-09 16:11:10 +00:00
}
}
}
2018-03-09 03:26:44 +00:00
// the vvvvwab function
function vvvvwab ( target _vvvvwab , type _vvvvwab )
2017-02-01 13:17:04 +00:00
{
// set the function logic
2018-03-09 03:26:44 +00:00
if ( target _vvvvwab == 1 && type _vvvvwab == 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 ( ) ;
}
}
2018-03-09 03:26:44 +00:00
// the vvvvwac function
function vvvvwac ( type _vvvvwac , target _vvvvwac )
2017-02-09 16:11:10 +00:00
{
// set the function logic
2018-03-09 03:26:44 +00:00
if ( type _vvvvwac == 1 && target _vvvvwac == 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 ( ) ;
}
}
// update required fields
function updateFieldRequired ( name , status )
{
var not _required = jQuery ( '#jform_not_required' ) . val ( ) ;
if ( status == 1 )
{
if ( isSet ( not _required ) && not _required != 0 )
{
not _required = not _required + ',' + name ;
}
else
{
not _required = ',' + name ;
}
}
else
{
if ( isSet ( not _required ) && not _required != 0 )
{
not _required = not _required . replace ( ',' + name , '' ) ;
}
}
jQuery ( '#jform_not_required' ) . val ( not _required ) ;
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 ( ) ;
}
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 ) {
jQuery ( '#jcb-placeholder' ) . html ( '<code>[CUSTO' + 'MCODE=' + ide + ']</code> or <code>[CUSTO' + 'MCODE=' + functioName + ']</code>' ) ;
jQuery ( '#jcb-placeholder-arg' ) . html ( '<code>[CUSTO' + 'MCODE=' + ide + '+value1,value2]</code> or <code>[CUSTO' + 'MCODE=' + functioName + '+value1,value2]</code>' ) ;
} else if ( ide > 0 ) {
jQuery ( '#jcb-placeholder' ) . html ( '<code>[CUSTO' + 'MCODE=' + ide + ']</code> or <code>[not ready]</code>' ) ;
jQuery ( '#jcb-placeholder-arg' ) . html ( '<code>[CUSTO' + 'MCODE=' + ide + '+value1,value2]</code> or <code>[not ready]</code>' ) ;
} else if ( functioName . length > 2 ) {
jQuery ( '#jcb-placeholder' ) . html ( '<code>[save to see]</code> or <code>[CUSTO' + 'MCODE=' + functioName + ']</code>' ) ;
jQuery ( '#jcb-placeholder-arg' ) . html ( '<code>[save to see]</code> or <code>[CUSTO' + 'MCODE=' + functioName + '+value1,value2]</code>' ) ;
} 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 ) ;
}
}
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 ) {
2018-03-27 09:57:16 +00:00
// show notice that functionName 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 ( ) ;
}
}
// check Function Name
function checkFunctionName _server ( functioName , ide ) {
var getUrl = "index.php?option=com_componentbuilder&task=ajax.checkFunctionName&format=json" ;
if ( token . length > 0 ) {
var request = 'token=' + token + '&functioName=' + functioName + '&id=' + ide ;
}
return jQuery . ajax ( {
type : 'POST' ,
url : getUrl ,
dataType : 'jsonp' ,
data : request ,
jsonp : 'callback'
} ) ;
}
// 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 ( ) ;
2017-12-10 19:17:26 +00:00
var targets = [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' ] ;
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 ( ) ;
}
2017-11-01 03:16:21 +00:00
if ( target === 'i' ) {
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 ( ) ;
}
}
} ) ;
2017-12-10 19:17:26 +00:00
if ( run == 9 ) {
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 ) {
2017-02-17 18:35:18 +00:00
var request = 'token=' + token + '&functioName=' + functioName + '&id=' + ide + '&target=' + target ;
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 ,
dataType : 'jsonp' ,
data : request ,
jsonp : 'callback'
} ) ;
2017-02-01 13:17:04 +00:00
}