2022-03-03 02:58:38 +00:00
/*----------------------------------------------------------------------------------| www.giz.de |----/
Deutsche Gesellschaft für International Zusammenarbeit ( GIZ ) Gmb
/-------------------------------------------------------------------------------------------------------/
@ version 3.4 . x
@ build 2 nd March , 2022
@ created 15 th June , 2012
@ package Cost Benefit Projection
@ subpackage intervention . js
@ author Llewellyn van der Merwe < http : //www.vdm.io>
@ owner Deutsche Gesellschaft für International Zusammenarbeit ( GIZ ) Gmb
@ copyright Copyright ( C ) 2015. All Rights Reserved
@ license GNU / GPL Version 2 or later - http : //www.gnu.org/licenses/gpl-2.0.html
/-------------------------------------------------------------------------------------------------------/
Cost Benefit Projection Tool .
/------------------------------------------------------------------------------------------------------*/
2015-12-01 05:06:34 +00:00
// Some Global Values
2016-02-26 13:57:23 +00:00
jform _vvvvvvyvwj _required = false ;
jform _vvvvvwavwk _required = false ;
2015-12-01 05:06:34 +00:00
// Initial Script
jQuery ( document ) . ready ( function ( )
{
2016-02-26 13:57:23 +00:00
var type _vvvvvvy = jQuery ( "#jform_type input[type='radio']:checked" ) . val ( ) ;
vvvvvvy ( type _vvvvvvy ) ;
2015-12-01 05:06:34 +00:00
2016-02-26 13:57:23 +00:00
var type _vvvvvvz = jQuery ( "#jform_type input[type='radio']:checked" ) . val ( ) ;
vvvvvvz ( type _vvvvvvz ) ;
2016-01-14 07:44:50 +00:00
2016-02-26 13:57:23 +00:00
var company _vvvvvwa = jQuery ( "#jform_company" ) . val ( ) ;
vvvvvwa ( company _vvvvvwa ) ;
2015-12-01 05:06:34 +00:00
} ) ;
2016-02-26 13:57:23 +00:00
// the vvvvvvy function
function vvvvvvy ( type _vvvvvvy )
2015-12-01 05:06:34 +00:00
{
2016-01-14 07:44:50 +00:00
// set the function logic
2016-02-26 13:57:23 +00:00
if ( type _vvvvvvy == 2 )
2015-12-01 05:06:34 +00:00
{
jQuery ( '#jform_interventions' ) . closest ( '.control-group' ) . show ( ) ;
2019-04-04 11:51:37 +00:00
// add required attribute to interventions field
2016-02-26 13:57:23 +00:00
if ( jform _vvvvvvyvwj _required )
2015-12-01 05:06:34 +00:00
{
updateFieldRequired ( 'interventions' , 0 ) ;
jQuery ( '#jform_interventions' ) . prop ( 'required' , 'required' ) ;
jQuery ( '#jform_interventions' ) . attr ( 'aria-required' , true ) ;
jQuery ( '#jform_interventions' ) . addClass ( 'required' ) ;
2016-02-26 13:57:23 +00:00
jform _vvvvvvyvwj _required = false ;
2015-12-01 05:06:34 +00:00
}
}
else
{
jQuery ( '#jform_interventions' ) . closest ( '.control-group' ) . hide ( ) ;
2019-04-04 11:51:37 +00:00
// remove required attribute from interventions field
2016-02-26 13:57:23 +00:00
if ( ! jform _vvvvvvyvwj _required )
2015-12-01 05:06:34 +00:00
{
updateFieldRequired ( 'interventions' , 1 ) ;
jQuery ( '#jform_interventions' ) . removeAttr ( 'required' ) ;
jQuery ( '#jform_interventions' ) . removeAttr ( 'aria-required' ) ;
jQuery ( '#jform_interventions' ) . removeClass ( 'required' ) ;
2016-02-26 13:57:23 +00:00
jform _vvvvvvyvwj _required = true ;
2015-12-01 05:06:34 +00:00
}
}
}
2016-02-26 13:57:23 +00:00
// the vvvvvvz function
function vvvvvvz ( type _vvvvvvz )
2015-12-01 05:06:34 +00:00
{
2016-01-14 07:44:50 +00:00
// set the function logic
2016-02-26 13:57:23 +00:00
if ( type _vvvvvvz == 1 )
2015-12-01 05:06:34 +00:00
{
jQuery ( '#jform_intervention' ) . closest ( '.control-group' ) . show ( ) ;
}
else
{
jQuery ( '#jform_intervention' ) . closest ( '.control-group' ) . hide ( ) ;
}
}
2016-02-26 13:57:23 +00:00
// the vvvvvwa function
function vvvvvwa ( company _vvvvvwa )
2016-01-14 07:44:50 +00:00
{
2016-02-26 13:57:23 +00:00
if ( isSet ( company _vvvvvwa ) && company _vvvvvwa . constructor !== Array )
2016-01-14 07:44:50 +00:00
{
2016-02-26 13:57:23 +00:00
var temp _vvvvvwa = company _vvvvvwa ;
var company _vvvvvwa = [ ] ;
company _vvvvvwa . push ( temp _vvvvvwa ) ;
2016-01-14 07:44:50 +00:00
}
2016-02-26 13:57:23 +00:00
else if ( ! isSet ( company _vvvvvwa ) )
2016-01-14 07:44:50 +00:00
{
2016-02-26 13:57:23 +00:00
var company _vvvvvwa = [ ] ;
2016-01-14 07:44:50 +00:00
}
2016-02-26 13:57:23 +00:00
var company = company _vvvvvwa . some ( company _vvvvvwa _SomeFunc ) ;
2016-01-14 07:44:50 +00:00
// set this function logic
if ( company )
{
jQuery ( '#jform_country' ) . closest ( '.control-group' ) . show ( ) ;
2019-04-04 11:51:37 +00:00
// add required attribute to country field
2016-02-26 13:57:23 +00:00
if ( jform _vvvvvwavwk _required )
2016-01-14 07:44:50 +00:00
{
updateFieldRequired ( 'country' , 0 ) ;
jQuery ( '#jform_country' ) . prop ( 'required' , 'required' ) ;
jQuery ( '#jform_country' ) . attr ( 'aria-required' , true ) ;
jQuery ( '#jform_country' ) . addClass ( 'required' ) ;
2016-02-26 13:57:23 +00:00
jform _vvvvvwavwk _required = false ;
2016-01-14 07:44:50 +00:00
}
}
else
{
jQuery ( '#jform_country' ) . closest ( '.control-group' ) . hide ( ) ;
2019-04-04 11:51:37 +00:00
// remove required attribute from country field
2016-02-26 13:57:23 +00:00
if ( ! jform _vvvvvwavwk _required )
2016-01-14 07:44:50 +00:00
{
updateFieldRequired ( 'country' , 1 ) ;
jQuery ( '#jform_country' ) . removeAttr ( 'required' ) ;
jQuery ( '#jform_country' ) . removeAttr ( 'aria-required' ) ;
jQuery ( '#jform_country' ) . removeClass ( 'required' ) ;
2016-02-26 13:57:23 +00:00
jform _vvvvvwavwk _required = true ;
2016-01-14 07:44:50 +00:00
}
}
}
2016-02-26 13:57:23 +00:00
// the vvvvvwa Some function
function company _vvvvvwa _SomeFunc ( company _vvvvvwa )
2016-01-14 07:44:50 +00:00
{
// set the function logic
2016-02-26 13:57:23 +00:00
if ( company _vvvvvwa == 0 )
2016-01-14 07:44:50 +00:00
{
return true ;
}
return false ;
}
2020-05-30 22:55:13 +00:00
// update fields required
function updateFieldRequired ( name , status ) {
// check if not_required exist
if ( jQuery ( '#jform_not_required' ) . length > 0 ) {
var not _required = jQuery ( '#jform_not_required' ) . val ( ) . split ( "," ) ;
2015-12-01 05:06:34 +00:00
2020-05-30 22:55:13 +00:00
if ( status == 1 )
2015-12-01 05:06:34 +00:00
{
2020-05-30 22:55:13 +00:00
not _required . push ( name ) ;
2015-12-01 05:06:34 +00:00
}
else
{
2020-05-30 22:55:13 +00:00
not _required = removeFieldFromNotRequired ( not _required , name ) ;
2015-12-01 05:06:34 +00:00
}
2020-05-30 22:55:13 +00:00
jQuery ( '#jform_not_required' ) . val ( fixNotRequiredArray ( not _required ) . toString ( ) ) ;
2015-12-01 05:06:34 +00:00
}
2020-05-30 22:55:13 +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 ) ;
} ) ;
}
2015-12-01 05:06:34 +00:00
2020-05-30 22:55:13 +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 ) ;
} ) ;
2015-12-01 05:06:34 +00:00
}
// the isSet function
function isSet ( val )
{
if ( ( val != undefined ) && ( val != null ) && 0 !== val . length ) {
return true ;
}
return false ;
}
2018-05-05 13:43:04 +00:00
2015-12-01 05:06:34 +00:00
jQuery ( document ) . ready ( function ( )
{
var inter _type = jQuery ( "#jform_type input[type='radio']:checked" ) . val ( ) ;
var interventions = jQuery ( '#jform_intervention' ) . val ( ) ;
if ( 1 == inter _type && interventions ) {
getBuildTable ( interventions , 'jform_intervention' , 'nee' ) ;
} else if ( 2 == inter _type && interventions ) {
getBuildTable ( interventions , 'jform_interventions' , 'ja' ) ;
}
jQuery ( '.save-modal-data' ) . text ( 'Done' ) ;
} ) ;
function getClusterData ( array , idName ) {
var cluster = JSON . stringify ( array ) ;
getClusterData _server ( cluster , idName ) . done ( function ( result ) {
if ( result . table ) {
buildTable ( result . table , idName ) ;
// ubdate the main set of values
jQuery ( '#jform_intervention' ) . val ( result . values ) ;
} else {
jQuery ( '#table_' + idName ) . remove ( ) ;
jQuery ( '#jform_intervention' ) . val ( '' ) ;
jQuery ( '.btn-wrapper' ) . show ( ) ;
jQuery ( '#inputYYYNote' ) . remove ( ) ;
}
} )
}
function getClusterData _server ( cluster , idName ) {
var getUrl = "index.php?option=com_costbenefitprojection&task=ajax.getClusterData&format=json" ;
if ( token . length > 0 && cluster . length > 0 && idName . length > 0 ) {
var request = 'token=' + token + '&idName=' + idName + '&cluster=' + cluster ;
}
return jQuery . ajax ( {
type : 'GET' ,
url : getUrl ,
dataType : 'jsonp' ,
data : request ,
jsonp : 'callback'
} ) ;
}
function getBuildTable _server ( string , idName , cluster ) {
var getUrl = "index.php?option=com_costbenefitprojection&task=ajax.interventionBuildTable&format=json" ;
if ( token . length > 0 && string . length > 0 && idName . length > 0 ) {
var request = 'token=' + token + '&idName=' + idName + '&oject=' + string + '&cluster=' + cluster ;
}
return jQuery . ajax ( {
type : 'GET' ,
url : getUrl ,
dataType : 'jsonp' ,
data : request ,
jsonp : 'callback'
} ) ;
}
function getBuildTable ( intervention , idName , cluster ) {
if ( 'ne' == cluster )
{
var intervention = JSON . stringify ( intervention ) ;
cluster = 'nee' ;
}
getBuildTable _server ( intervention , idName , cluster ) . done ( function ( result ) {
if ( result ) {
buildTable ( result , idName ) ;
} else {
jQuery ( '#table_' + idName ) . remove ( ) ;
}
} )
}
function buildTable ( result , idName ) {
jQuery ( '#table_' + idName ) . remove ( ) ;
jQuery ( '#' + idName ) . closest ( '.control-group' ) . append ( result ) ;
// check if we have cross match values
if ( jQuery ( ".eRrOr" ) . length > 0 ) {
jQuery ( '.btn-wrapper' ) . hide ( ) ;
if ( jQuery ( '#inputYYYNote' ) . length <= 0 ) {
jQuery ( '#system-message-container' ) . append ( '<div id="inputYYYNote" class="alert alert-error"><p>Values cross match between selected interventions please update all in red!</p></div>' ) ;
}
} else {
jQuery ( '.btn-wrapper' ) . show ( ) ;
jQuery ( '#inputYYYNote' ) . remove ( ) ;
}
}
function updateSelection ( row )
{
var groupId = jQuery ( row ) . find ( "select:first" ) . attr ( "id" ) ;
var percentValue = jQuery ( row ) . find ( ".text_area:first" ) . val ( ) ;
var arr = groupId . split ( '-' ) ;
if ( arr [ 1 ] != 1 )
{
var selection = { } ;
jQuery ( row ) . find ( "select:first option" ) . each ( function ( )
{
// first get the values and text
selection [ jQuery ( this ) . text ( ) ] = jQuery ( this ) . val ( ) ;
} ) ;
jQuery . each ( causerisk , function ( i , group ) {
jQuery ( row ) . find ( "select:first option[value='" + group + "']" ) . remove ( ) ;
} ) ;
if ( percentValue )
{
var text = jQuery ( row ) . find ( ".chzn-single:first span" ) . text ( ) ;
jQuery ( row ) . find ( "select:first" ) . append ( jQuery ( '<option>' , {
value : selection [ text ] ,
text : text
} ) ) ;
}
jQuery ( row ) . find ( "select:first" ) . trigger ( "liszt:updated" ) ;
if ( percentValue )
{
jQuery ( row ) . find ( "select:first option:selected" ) . val ( selection [ text ] ) ;
jQuery ( row ) . find ( ".chzn-single:first span" ) . text ( text ) ;
}
}
}
function changeFieldValue ( id , value ) {
if ( id . length > 0 ) {
value = jQuery . trim ( value ) ;
if ( value . match ( /[^0-9\.]/g ) || ! value ) {
jQuery ( '#' + id ) . css ( { 'color' : 'red' } ) ;
jQuery ( '#' + id ) . removeClass ( 'eRrOr' ) ;
jQuery ( '#' + id ) . addClass ( 'eRrOr' ) ;
alert ( 'Only numbers should be used, not (' + value + ')' ) ;
} else {
// update value
jQuery ( '#' + id ) . val ( value ) ;
// we must also update the main set of values
var mainset = jQuery ( '#jform_intervention' ) . val ( ) ;
mainset = jQuery . parseJSON ( mainset )
var key = id . split ( '_' ) ;
mainset [ key [ 0 ] ] [ key [ 1 ] ] = value ;
mainset = JSON . stringify ( mainset ) ;
jQuery ( '#jform_intervention' ) . val ( mainset ) ;
jQuery ( '#' + id ) . removeClass ( 'eRrOr' ) ;
jQuery ( '#' + id ) . css ( { 'color' : '' } ) ;
}
// okay update the value
if ( jQuery ( ".eRrOr" ) . length > 0 ) {
jQuery ( '.btn-wrapper' ) . hide ( ) ;
if ( jQuery ( '#inputYYYNote' ) . length <= 0 ) {
jQuery ( '#system-message-container' ) . append ( '<div id="inputYYYNote" class="alert alert-error"><p>Values cross match between selected interventions please update all in red!</p></div>' ) ;
}
} else {
jQuery ( '.btn-wrapper' ) . show ( ) ;
jQuery ( '#inputYYYNote' ) . remove ( ) ;
}
}
}
2022-03-03 02:58:38 +00:00