2020-05-29 13:41:58 +02:00
< ? php
2022-01-27 10:21:55 +01:00
$seed = 'f_' . mt_rand ();
2020-05-29 13:41:58 +02:00
if ( ! isset ( $data [ 'requirement' ]) || $data [ 'requirement' ]) {
2020-06-04 10:05:45 +02:00
if ( ! empty ( $data [ 'popover_url' ])) {
$onClick = sprintf (
2022-01-27 10:21:55 +01:00
'onClick="openModalForButton%s(this, \'%s\', \'%s\')"' ,
$seed ,
2021-01-18 17:25:18 +01:00
h ( $data [ 'popover_url' ]),
h ( ! empty ( $data [ 'reload_url' ]) ? $data [ 'reload_url' ] : '' )
2020-06-04 10:05:45 +02:00
);
}
2020-12-07 16:06:01 +01:00
if ( empty ( $onClick )) {
if ( ! empty ( $data [ 'onClick' ]) || empty ( $data [ 'url' ])) {
$onClickParams = array ();
if ( ! empty ( $data [ 'onClickParams' ])) {
foreach ( $data [ 'onClickParams' ] as $param ) {
if ( $param === 'this' ) {
$onClickParams [] = h ( $param );
} else {
$onClickParams [] = '\'' . h ( $param ) . '\'' ;
}
2020-05-29 13:41:58 +02:00
}
}
2020-12-07 16:06:01 +01:00
$onClickParams = implode ( ',' , $onClickParams );
$onClick = sprintf (
'onClick = "%s%s"' ,
( empty ( $data [ 'url' ])) ? 'event.preventDefault();' : '' ,
( ! empty ( $data [ 'onClick' ]) ? sprintf (
'%s(%s)' ,
h ( $data [ 'onClick' ]),
$onClickParams
) : '' )
);
} else if ( ! empty ( $data [ 'url' ])) {
$onClick = sprintf (
'onClick = "%s"' ,
sprintf ( 'window.location=\'%s\'' , $data [ 'url' ])
);
2020-05-29 13:41:58 +02:00
}
}
$dataFields = array ();
if ( ! empty ( $data [ 'data' ])) {
foreach ( $data [ 'data' ] as $dataKey => $dataValue ) {
$dataFields [] = sprintf (
'data-%s="%s"' ,
h ( $dataKey ),
h ( $dataValue )
);
}
}
$dataFields = implode ( ' ' , $dataFields );
echo sprintf (
2021-01-12 10:56:47 +01:00
'<button class="btn %s %s" %s href="%s" %s %s %s %s %s>%s%s%s</button>' ,
2020-05-29 13:41:58 +02:00
empty ( $data [ 'class' ]) ? '' : h ( $data [ 'class' ]),
2020-12-10 17:46:16 +01:00
empty ( $data [ 'isFilter' ]) ? 'btn-primary' : ( empty ( $data [ 'active' ]) ? 'btn-light' : 'btn-secondary' ), // Change the default class for highlighted/active toggles here
2020-05-29 13:41:58 +02:00
empty ( $data [ 'id' ]) ? '' : 'id="' . h ( $data [ 'id' ]) . '"' ,
2021-02-09 22:10:26 +01:00
empty ( $data [ 'url' ]) ? '#' : $baseurl . h ( $data [ 'url' ]), // prevent default is passed if the url is not set
2020-05-29 13:41:58 +02:00
empty ( $onClick ) ? '' : $onClick , // pass $data['onClick'] for the function name to call and $data['onClickParams'] for the parameter list
empty ( $dataFields ) ? '' : $dataFields ,
empty ( $data [ 'title' ]) ? '' : sprintf ( 'title="%s"' , h ( $data [ 'title' ])),
empty ( $data [ 'style' ]) ? '' : sprintf ( 'style="%s"' , h ( $data [ 'style' ])),
! empty ( $data [ 'text' ]) ? '' : ( ! empty ( $data [ 'title' ]) ? sprintf ( 'aria-label="%s"' , h ( $data [ 'title' ])) : '' ),
empty ( $data [ 'fa-icon' ]) ? '' : sprintf (
'<i class="%s fa-%s"></i> ' ,
empty ( $data [ 'fa-source' ]) ? 'fas' : h ( $data [ 'fa-source' ]),
2021-01-11 16:28:07 +01:00
h ( $data [ 'fa-icon' ])
),
2020-05-29 13:41:58 +02:00
empty ( $data [ 'html' ]) ? '' : $data [ 'html' ], // this has to be sanitised beforehand!
empty ( $data [ 'text' ]) ? '' : h ( $data [ 'text' ])
);
}
?>
2020-12-15 10:40:49 +01:00
< script >
2022-01-27 10:21:55 +01:00
function openModalForButton < ? = $seed ?> (clicked, url, reloadUrl='') {
2021-01-18 17:25:18 +01:00
const fallbackReloadUrl = '<?= $this->Url->build([' action ' => ' index ']); ?>'
reloadUrl = reloadUrl != '' ? reloadUrl : fallbackReloadUrl
2021-03-10 14:54:52 +01:00
UI . overlayUntilResolve ( clicked , UI . submissionModalForIndex ( url , reloadUrl , '<?= $tableRandomValue ?>' ))
2020-12-15 10:40:49 +01:00
}
</ script >