2017-02-01 13:17:04 +00:00
/*--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
\ \ / / | | | _ _ \ | | | | | \ / | | | | | | |
\ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | _ _ _ | | _ | | _ _ _ _ _ _ _ | |
\ \ / / _` / _ _ | _ _ | | | | | / _ \ \ / / _ \ | / _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| ' _ \ / _ \ / _ ` |
\ / ( _ | \ _ _ \ | _ | | _ _ | | _ _ / \ V / _ _ / | ( _ ) | | _ ) | | | | | | _ _ / | | | | _ | | | | _ _ / | _ | | | | ( _ ) | ( _ | |
\ / \ _ _ , _ | _ _ _ / \ _ _ | | _ _ _ _ _ / \ _ _ _ | \ _ / \ _ _ _ | _ | \ _ _ _ / | . _ _ / | _ | | _ | | _ | \ _ _ _ | _ | | _ | \ _ _ | | _ | | _ | \ _ _ _ | \ _ _ | _ | | _ | \ _ _ _ / \ _ _ , _ |
| |
| _ |
/-------------------------------------------------------------------------------------------------------------------------------/
2017-02-13 23:24:38 +00:00
@ version @ update number 55 of this MVC
2017-02-16 14:02:23 +00:00
@ build 16 th February , 2017
2017-02-01 13:17:04 +00:00
@ created 11 th October , 2016
@ package Component Builder
@ subpackage custom _code . js
@ author Llewellyn van der Merwe < http : //vdm.bz/component-builder>
@ 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
2017-02-13 23:24:38 +00:00
jform _vvvvvzovzk _required = false ;
2017-02-09 16:11:10 +00:00
jform _vvvvvzpvzl _required = false ;
jform _vvvvvzpvzm _required = false ;
2017-02-13 23:24:38 +00:00
jform _vvvvvzpvzn _required = false ;
2017-02-09 16:11:10 +00:00
2017-02-01 13:17:04 +00:00
// Initial Script
jQuery ( document ) . ready ( function ( )
{
2017-02-09 16:11:10 +00:00
var target _vvvvvzo = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
vvvvvzo ( target _vvvvvzo ) ;
var target _vvvvvzp = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
vvvvvzp ( target _vvvvvzp ) ;
var target _vvvvvzq = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
var type _vvvvvzq = jQuery ( "#jform_type input[type='radio']:checked" ) . val ( ) ;
vvvvvzq ( target _vvvvvzq , type _vvvvvzq ) ;
var type _vvvvvzr = jQuery ( "#jform_type input[type='radio']:checked" ) . val ( ) ;
var target _vvvvvzr = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
vvvvvzr ( type _vvvvvzr , target _vvvvvzr ) ;
2017-02-01 13:17:04 +00:00
} ) ;
// the vvvvvzo function
2017-02-09 16:11:10 +00:00
function vvvvvzo ( target _vvvvvzo )
{
// set the function logic
if ( target _vvvvvzo == 2 )
{
2017-02-13 23:24:38 +00:00
jQuery ( '#jform_function_name' ) . closest ( '.control-group' ) . show ( ) ;
if ( jform _vvvvvzovzk _required )
{
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' ) ;
jform _vvvvvzovzk _required = false ;
}
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 ( ) ;
if ( ! jform _vvvvvzovzk _required )
{
updateFieldRequired ( 'function_name' , 1 ) ;
jQuery ( '#jform_function_name' ) . removeAttr ( 'required' ) ;
jQuery ( '#jform_function_name' ) . removeAttr ( 'aria-required' ) ;
jQuery ( '#jform_function_name' ) . removeClass ( 'required' ) ;
jform _vvvvvzovzk _required = true ;
}
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
}
}
// the vvvvvzp function
function vvvvvzp ( target _vvvvvzp )
{
// set the function logic
if ( target _vvvvvzp == 1 )
{
jQuery ( '#jform_component' ) . closest ( '.control-group' ) . show ( ) ;
2017-02-13 23:24:38 +00:00
if ( jform _vvvvvzpvzl _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' ) ;
2017-02-13 23:24:38 +00:00
jform _vvvvvzpvzl _required = false ;
2017-02-09 16:11:10 +00:00
}
jQuery ( '#jform_path' ) . closest ( '.control-group' ) . show ( ) ;
2017-02-13 23:24:38 +00:00
if ( jform _vvvvvzpvzm _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' ) ;
2017-02-13 23:24:38 +00:00
jform _vvvvvzpvzm _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 ( ) ;
2017-02-13 23:24:38 +00:00
if ( jform _vvvvvzpvzn _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' ) ;
2017-02-13 23:24:38 +00:00
jform _vvvvvzpvzn _required = false ;
2017-02-09 16:11:10 +00:00
}
}
else
{
jQuery ( '#jform_component' ) . closest ( '.control-group' ) . hide ( ) ;
2017-02-13 23:24:38 +00:00
if ( ! jform _vvvvvzpvzl _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' ) ;
2017-02-13 23:24:38 +00:00
jform _vvvvvzpvzl _required = true ;
2017-02-09 16:11:10 +00:00
}
jQuery ( '#jform_path' ) . closest ( '.control-group' ) . hide ( ) ;
2017-02-13 23:24:38 +00:00
if ( ! jform _vvvvvzpvzm _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' ) ;
2017-02-13 23:24:38 +00:00
jform _vvvvvzpvzm _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 ( ) ;
2017-02-13 23:24:38 +00:00
if ( ! jform _vvvvvzpvzn _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' ) ;
2017-02-13 23:24:38 +00:00
jform _vvvvvzpvzn _required = true ;
2017-02-09 16:11:10 +00:00
}
}
}
// the vvvvvzq function
function vvvvvzq ( target _vvvvvzq , type _vvvvvzq )
2017-02-01 13:17:04 +00:00
{
// set the function logic
2017-02-09 16:11:10 +00:00
if ( target _vvvvvzq == 1 && type _vvvvvzq == 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 ( ) ;
}
}
// the vvvvvzr function
function vvvvvzr ( type _vvvvvzr , target _vvvvvzr )
{
// set the function logic
if ( type _vvvvvzr == 1 && target _vvvvvzr == 1 )
{
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
}
jQuery ( document ) . ready ( function ( )
{
var target = jQuery ( "#jform_target input[type='radio']:checked" ) . val ( ) ;
if ( target == 2 ) {
var functioName = jQuery ( '#jform_function_name' ) . val ( ) ;
// check if this function name is taken
checkFunctionName ( functioName ) ;
}
} ) ;
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 ) {
// show notice that functioName is not okay
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
jQuery . UIkit . notify ( { message : 'Function name already taken, please try again.' , timeout : 5000 , status : 'danger' , pos : 'top-right' } ) ;
jQuery ( '#jform_function_name' ) . val ( '' ) ;
}
// set custom code placeholder
setCustomCodePlaceholder ( ) ;
} ) ;
} else {
// set an error that message was not send
jQuery . UIkit . notify ( { message : 'You must add an unique function name.' , timeout : 5000 , status : 'danger' , pos : 'top-right' } ) ;
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 ) {
usedin _server ( functioName , ide ) . done ( function ( used ) {
if ( used . in ) {
jQuery ( '#usedin' ) . html ( used . in ) ;
}
} ) ;
}
function usedin _server ( functioName , ide ) {
var getUrl = "index.php?option=com_componentbuilder&task=ajax.usedin&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'
} ) ;
2017-02-01 13:17:04 +00:00
}