2020-05-29 13:41:58 +02:00
< ? php
if ( ! isset ( $data [ 'requirement' ]) || $data [ 'requirement' ]) {
2020-06-04 10:05:45 +02:00
if ( ! empty ( $data [ 'popover_url' ])) {
$onClick = sprintf (
2021-01-12 11:36:33 +01:00
'onClick="openModalForButton(this, %s)"' ,
2020-06-04 10:05:45 +02:00
sprintf ( " '%s' " , h ( $data [ 'popover_url' ]))
);
}
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' ]) . '"' ,
empty ( $data [ 'url' ]) ? '#' : h ( $data [ 'url' ]), // prevent default is passed if the url is not set
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 >
2021-01-12 11:36:33 +01:00
function openModalForButton ( clicked , url ) {
const loadingOverlay = new OverlayFactory ( clicked );
loadingOverlay . show ()
UI . openModalFromURL ( url , '<?= $this->Url->build([' action ' => ' index ']); ?>' , '<?= $tableRandomValue ?>' ) . finally (() => {
loadingOverlay . hide ()
})
2020-12-15 10:40:49 +01:00
}
</ script >