Skip to content

Commit

Permalink
Merge pull request #33 from pdir/fix-enabled-button
Browse files Browse the repository at this point in the history
Fix enabled button
  • Loading branch information
MDevster authored Aug 9, 2022
2 parents 754a708 + a505eb7 commit ae463de
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Types of changes
Security in case of vulnerabilities.
)

## [3.3.2](https://github.com/pdir/mobilede-bundle/tree/3.3.2) – 2022-08-09

- [Fixed] account creation
- [Fixed] fix enabled button

## [3.3.1](https://github.com/pdir/mobilede-bundle/tree/3.3.1) – 2022-08-02

- [Fixed] fix demo data for Contao 4.13
Expand Down
51 changes: 40 additions & 11 deletions src/EventListener/DataContainerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
use Contao\BackendTemplate;
use Contao\BackendUser;
use Contao\Controller;
use Contao\CoreBundle\Security\ContaoCorePermissions;
use Contao\CoreBundle\ServiceAnnotation\Callback;
use Contao\Database;
use Contao\DataContainer;
use Contao\Image;
use Contao\Input;
use Contao\StringUtil;
use Contao\System;
use Pdir\MobileDeBundle\Module\MobileDeSetup;
Expand Down Expand Up @@ -120,21 +123,47 @@ public function getVehicleVehicleAccountOptions(DataContainer $dc)
*/
public function visibleButtonCallback(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string
{
// disable the button if the user is not admin or apiType = man
if (!$this->user->isAdmin || 'man' === $row['apiType']) {
$title = !$this->user->isAdmin ? $GLOBALS['TL_LANG']['pdirMobileDe']['visibleButtonCallbackAdminOnly'] : $GLOBALS['TL_LANG']['pdirMobileDe']['visibleButtonCallbackUnused'];
$security = System::getContainer()->get('security.helper');

// disable the button if the user has no access or apiType = man
if (!$security->isGranted(ContaoCorePermissions::USER_CAN_EDIT_FIELD_OF_TABLE, 'tl_vehicle_account::enabled') ||
'man' === $row['apiType']
) {
$title = 'man' === $row['apiType'] ? $GLOBALS['TL_LANG']['pdirMobileDe']['visibleButtonCallbackUnused']: $GLOBALS['TL_LANG']['pdirMobileDe']['visibleButtonCallbackAdminOnly'];

return '<span title="'.$title.'">'.Image::getHtml(preg_replace('/\.svg$/i', '_.svg', $icon)).'</span>';
}

// build variables
$published = $row['enabled'] ? 1 : 0;
$unpublished = $row['enabled'] ? 0 : 1;
$url = Controller::addToUrl("&amp;tid={$row['id']}&amp;state=$published");
$icon = 0 === $row['enabled'] ? 'invisible.svg' : $icon;
$_title = StringUtil::specialchars($title);
$image = Image::getHtml($icon, $label, "data-state='$unpublished'");
// toggle visibility
if (strlen(Input::get('state'))) {
$this->toggleVisibility($row['id'], (Input::get('state')));
Controller::redirect(Controller::getReferer());
}

$href .= '&amp;state=' . ($row['enabled'] ? 1 : 0) . '&amp;id=' . $row['id'] . '&amp;rt=' . REQUEST_TOKEN;

if (!$row['enabled'])
{
$icon = 'invisible.svg';
}

return '<a href="' . Controller::addToUrl($href) . '" title="' . StringUtil::specialchars($title) . '" onclick="Backend.getScrollOffset();return AjaxRequest.toggleField(this,true)">' . Image::getHtml($icon, $label, 'data-icon="' . Image::getPath('visible.svg') . '" data-icon-disabled="' . Image::getPath('invisible.svg') . '" data-state="' . ($row['enabled'] ? 1 : 0) . '"') . '</a> ';
}

/**
* Disable/enable a vehicle account
*
* @param integer $intId
* @param boolean $blnVisible
* @param DataContainer $dc
*/
public function toggleVisibility(int $intId, bool $blnVisible)
{
Input::setGet('id', $intId);
Input::setGet('act', 'toggle');

return "<a href='$url' title='$_title' $attributes>$image</a>";
// Update the database
Database::getInstance()->prepare("UPDATE tl_vehicle_account SET tstamp=". time() .", enabled='" . ($blnVisible ? '' : 1) . "' WHERE id=?")
->execute($intId);
}
}
2 changes: 1 addition & 1 deletion src/Module/MobileDeSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MobileDeSetup extends \BackendModule
/**
* mobilede version.
*/
const VERSION = '3.3.0';
const VERSION = '3.3.2';

/**
* Extension mode.
Expand Down
11 changes: 6 additions & 5 deletions src/Resources/contao/dca/tl_vehicle_account.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'icon' => 'delete.svg',
],
'toggle' => [
'href' => 'act=toggle&amp;field=enabled',
'label' => &$GLOBALS['TL_LANG'][$strTable]['enable'],
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
'icon' => 'visible.svg',
Expand Down Expand Up @@ -108,7 +109,7 @@
'exclude' => true,
'inputType' => 'select',
'options' => &$GLOBALS['TL_LANG'][$strTable]['apiTypeOptions'],
'eval' => ['includeBlankOption' => true, 'tl_class' => 'w50'],
'eval' => ['includeBlankOption' => true, 'tl_class' => 'w50', 'submitOnChange' => true],
'sql' => "varchar(64) NOT NULL default ''",
],
'api_explanation' => [
Expand Down Expand Up @@ -148,11 +149,11 @@
'sql' => "varchar(64) NOT NULL default ''",
],
'enabled' => [
'exclude' => true,
'default' => false,
'toggle' => true,
'filter' => true,
'inputType' => 'checkbox',
'eval' => ['doNotCopy'=>true],
'sql' => ['type' => 'boolean', 'default' => false],
'eval' => ['doNotCopy' => true],
'sql' => ['type' => 'boolean', 'default' => false]
],
],
];

0 comments on commit ae463de

Please sign in to comment.