Просмотр исходного кода

Adminlte : status field

tags/0.1
Guillaume 3 лет назад
Родитель
Сommit
f13f308763
4 измененных файлов: 50 добавлений и 4 удалений
  1. +30
    -0
      Field/BooleanField.php
  2. +11
    -3
      Field/StatusField.php
  3. +0
    -1
      Resources/assets/tabler
  4. +9
    -0
      Resources/views/adminlte/crud/field/toggle.html.twig

+ 30
- 0
Field/BooleanField.php Просмотреть файл

@@ -0,0 +1,30 @@
<?php

namespace Lc\SovBundle\Field;

use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
use Lc\SovBundle\Form\Type\FileManagerType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;

/**
* @author La clic ! <contact@laclic.fr>
*/
final class BooleanField implements FieldInterface
{
use FieldTrait;

public static function new(string $propertyName, ?string $label = null): self
{
return (new self())
->setProperty($propertyName)
->setLabel($label)
->setTemplatePath('@LcSov/adminlte/crud/field/toggle.html.twig')
->setFormType(ChoiceType::class)
->setFormTypeOption('expanded', false)
->setFormTypeOption('multiple', false)
->setFormTypeOption('choices', ['En ligne' => 1, 'Hors ligne' => 0]);
}

}

+ 11
- 3
Field/StatusField.php Просмотреть файл

@@ -15,16 +15,24 @@ final class StatusField implements FieldInterface
{
use FieldTrait;

public static function new(string $propertyName, ?string $label = null): self
public static function new(string $propertyName, ?string $label = null, bool $templateToggle = true): self
{
return (new self())
$field = (new self())
->setProperty($propertyName)
->setLabel($label)
->setTemplatePath('@LcSov/adminlte/crud/field/status.html.twig')
->setFormType(ChoiceType::class)
->setFormTypeOption('expanded', false)
->setFormTypeOption('multiple', false)
->setFormTypeOption('choices', ['En ligne' => 1, 'Hors ligne' => 0]);

$template = 'toggle.html.twig' ;
if(!$templateToggle) {
$template = 'status.html.twig' ;
}

$field->setTemplatePath('@LcSov/adminlte/crud/field/'.$template) ;

return $field ;
}

}

+ 0
- 1
Resources/assets/tabler

@@ -1 +0,0 @@
Subproject commit 0046a14932327424d8cbba5fcea5b9c68db6a5b0

+ 9
- 0
Resources/views/adminlte/crud/field/toggle.html.twig Просмотреть файл

@@ -0,0 +1,9 @@

{% set item = entity.instance %}
{% set property_name = field.getProperty() %}
{% set id_toggle = 'toogle-'~item.id~'-'~property_name %}

<div class="custom-control custom-switch custom-switch-on-primary custom-switch-off-default" data-propertyname="{{ property_name }}" data-id={{ item.id }}>
<input type="checkbox" class="custom-control-input" id="{{ id_toggle }}" {{ field.value ? 'checked' }}>
<label class="custom-control-label" for="{{ id_toggle }}">{{ field.label }}</label>
</div>

Загрузка…
Отмена
Сохранить