Fixs managing sub options and sub categories in admin

parent 5bc63fc3
......@@ -343,18 +343,6 @@ services:
tags:
- { name: sonata.admin, manager_type: doctrine_mongodb, group: "Hide" }
admin.option.lite_hidden:
class: App\Admin\OptionLiteAdmin
arguments: [~, App\Document\Option, '']
tags:
- { name: sonata.admin, manager_type: doctrine_mongodb, group: "Hide" }
admin.categories.lite_hidden:
class: App\Admin\CategoryLiteAdmin
arguments: [~, App\Document\Category, '']
tags:
- { name: sonata.admin, manager_type: doctrine_mongodb, group: "Hide" }
# ------- SAAS ---------
admin.project:
......
......@@ -14,6 +14,9 @@ use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\CollectionType;
use Sonata\AdminBundle\Form\Type\ModelType;
use Sonata\AdminBundle\Route\RouteCollection;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use App\Form\OptionLiteType;
class CategoryAdmin extends AbstractAdmin
{
......@@ -52,7 +55,7 @@ class CategoryAdmin extends AbstractAdmin
->add('parent', ModelType::class, [
'class' => 'App\Document\Option',
'required' => false,
'query' => $parentQuery,
'query' => $parentQuery,
'label' => 'Catégorie parente', ], ['admin_code' => 'admin.option_hidden'])
->add('isMandatory', null, ['required' => false, 'label' => 'Choix obligatoire', 'label_attr' => ['title' => 'Une catégorie de ce groupe doit être obligatoirement selectionnée']])
->add('singleOption', null, ['required' => false, 'label' => 'Choix unique', 'label_attr' => ['title' => 'Une seule catégorie est selectionnable à la fois']])
......@@ -70,16 +73,14 @@ class CategoryAdmin extends AbstractAdmin
->add('displayInInfoBar', null, ['required' => false, 'label' => 'Dans la fiche détail', 'label_attr' => ['title' => 'Le nom du groupe ne sera pas affiché, mais les catégories le seront']])
->add('displayInForm', null, ['required' => false, 'label' => 'Dans le formulaire', 'label_attr' => ['title' => 'Ni le groupe ni les catégories ne seront affichés dans le formulaire']])
->end()
// ->with('Catégories contenues dans ce groupe', array('class' => 'col-xs-12 sub-options-container'))
// ->add('isFixture', 'text', ['attr' => ['class' => 'gogo-sort-options'], 'label_attr' => ['style' => 'display:none']])
// ->add('options', CollectionType::class, array('by_reference' => false, 'allow_add' => true, 'label_attr'=> ['style'=> 'display:none']), array(
// 'edit' => 'inline',
// 'inline' => 'table',
// 'label' => '',
// 'admin_code' => 'admin.option.lite_hidden',
// //'sortable' => 'index',
// ))
// ->end()
->with('Catégories contenues dans ce groupe', array('class' => 'col-xs-12 sub-options-container'))
->add('isFixture', HiddenType::class, ['attr' => ['class' => 'gogo-sort-options'], 'label_attr' => ['style' => 'display:none']])
->add('options', CollectionType::class, array(
'by_reference' => false,
'entry_type' => OptionLiteType::class,
'allow_add' => true,
'label_attr'=> ['style'=> 'display:none']))
->end()
;
}
......
<?php
/**
* @Author: Sebastian Castro
* @Date: 2017-03-28 15:29:03
* @Last Modified by: Sebastian Castro
* @Last Modified time: 2018-07-08 17:27:53
*/
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
class CategoryLiteAdmin extends AbstractAdmin
{
protected $baseRouteName = 'admin_app_category_lite';
protected $baseRoutePattern = 'admin_app_category_lite';
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', null, ['required' => true, 'label' => 'Nom du groupe'])
->add('pickingOptionText', null, ['required' => true, 'label' => 'Text à afficher dans le formulaire : Choisissez ....'])
->add('index', null, ['required' => false, 'label' => 'Position'])
->add('isMandatory', null, ['required' => false, 'label' => 'Obligatoire'])
->add('singleOption', null, ['required' => false, 'label' => 'Choix unique'])
->add('displayInMenu', null, ['required' => false, 'label' => 'Menu'])
->add('displayInInfoBar', null, ['required' => false, 'label' => 'Fiche'])
->add('displayInForm', null, ['required' => false, 'label' => 'Formulaire'])
->add('_link', 'text', ['required' => false, 'mapped' => false, 'label' => 'admin_app_category_edit']);
}
}
......@@ -13,6 +13,8 @@ use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelType;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Form\Type\CollectionType;
use App\Form\CategoryLiteType;
class OptionAdmin extends AbstractAdmin
{
......@@ -55,7 +57,7 @@ class OptionAdmin extends AbstractAdmin
'required' => true,
'query' => $parentQuery,
'label' => 'Groupe de Catégorie parent',
'mapped' => true, ], ['admin_code' => 'admin.categories.lite_hidden'])
'mapped' => true, ], [])
->end()
->with('Paramètres secondaires', ['class' => 'col-xs-12 col-md-6', 'box_class' => 'box'])
->add('useIconForMarker', null, ['required' => false, 'label' => "Utiliser l'icone de cette catégorie pour le marqueur", 'label_attr' => ['title' => 'Le marqueur affichera toutes icones de chaque catégorie ayant cette option activée. Les icones seront classées par ordre de selection des catégories dans le formulaire']])
......@@ -66,14 +68,13 @@ class OptionAdmin extends AbstractAdmin
->add('displayInInfoBar', null, ['required' => false, 'label' => 'Dans la fiche détail'])
->add('displayInForm', null, ['required' => false, 'label' => 'Dans le formulaire'])
->end()
// ->with('Sous groupes', array('class' => 'col-xs-12 sub-categories-container'))
// ->add('subcategories', 'sonata_type_collection', array('by_reference' => false, 'label_attr'=> ['style'=> 'display:none']),
// array(
// 'edit' => 'inline',
// 'inline' => 'table',
// 'admin_code' => 'admin.categories.lite_hidden'
// ))
// ->end()
->with('Sous groupes', array('class' => 'col-xs-12 sub-categories-container'))
->add('subcategories', CollectionType::class, array(
'by_reference' => false,
'entry_type' => CategoryLiteType::class,
'allow_add' => true,
'label_attr'=> ['style'=> 'display:none']))
->end()
->end()
->tab('Configuration avancée')
->with('Paramètres secondaires', ['class' => 'col-xs-12 col-md-6', 'box_class' => 'box'])
......
<?php
/**
* @Author: Sebastian Castro
* @Date: 2017-03-28 15:29:03
* @Last Modified by: Sebastian Castro
* @Last Modified time: 2018-07-08 17:28:56
*/
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Form\FormMapper;
class OptionLiteAdmin extends AbstractAdmin
{
protected $baseRouteName = 'admin_app_option_lite';
protected $baseRoutePattern = 'admin_app_option_lite';
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('name', null, ['required' => true, 'label' => 'Nom'])
->add('index', null, ['required' => false, 'label' => 'Position'])
->add('color', 'text', ['required' => false, 'label' => 'Couleur', 'attr' => ['class' => 'gogo-color-picker']])
->add('icon', null, ['required' => false, 'label' => 'Icone', 'attr' => ['class' => 'gogo-icon-picker']])
->add('useIconForMarker', null, ['required' => false, 'label' => 'Icone pour le marqueur', 'label_attr' => ['title' => 'Le marqueur affichera toutes icones de chaque catégorie ayant cette option activée. Les icones seront classées par ordre de selection des catégories dans le formulaire']])
->add('useColorForMarker', null, ['required' => false, 'label' => 'Couleur pour le marqueur', 'label_attr' => ['title' => 'Si un élément a plusieurs catégories qui donnent la couleur, on utilise la catégorie de plus bas niveau']])
->add('_link', 'text', ['required' => false, 'mapped' => false, 'label' => 'admin_app_option_edit']);
}
}
......@@ -217,6 +217,11 @@ class Category
return $this->id;
}
public function setId($value = null)
{
return $this;
}
/**
* Set name.
*
......
......@@ -314,7 +314,7 @@ class Option
return $this->customId ?: strval($this->id);
}
public function setId()
public function setId($param = null)
{
return $this;
}
......
<?php
/**
* This file is part of the GoGoCarto project.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) 2016 Sebastian Castro - 90scastro@gmail.com
* @license MIT License
* @Last Modified time: 2018-01-19 13:04:59
*/
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class CategoryLiteType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', null, ['required' => true, 'label' => 'Nom du groupe'])
->add('index', null, ['required' => false, 'label' => 'Position'])
->add('pickingOptionText', null, ['required' => true, 'label' => 'Text à afficher dans le formulaire : Choisissez ....'])
// ->add('isMandatory', null, ['required' => false, 'label' => 'Obligatoire'])
// ->add('singleOption', null, ['required' => false, 'label' => 'Choix unique'])
// ->add('displayInMenu', null, ['required' => false, 'label' => 'Menu'])
// ->add('displayInInfoBar', null, ['required' => false, 'label' => 'Fiche'])
// ->add('displayInForm', null, ['required' => false, 'label' => 'Formulaire'])
->add('id', null, ['required' => false, 'label' => 'Plus de paramètres', 'attr' => ['class' => 'gogo-route-id', 'data-route-id' => 'admin_app_category_edit']])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => 'App\Document\Category',
]);
}
/**
* @return string
*/
public function getName()
{
return 'gogo_form_category_lite';
}
}
<?php
/**
* This file is part of the GoGoCarto project.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) 2016 Sebastian Castro - 90scastro@gmail.com
* @license MIT License
* @Last Modified time: 2018-01-19 13:04:59
*/
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class OptionLiteType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', null, ['required' => true, 'label' => 'Nom'])
->add('index', null, ['required' => false, 'label' => 'Position'])
->add('color', null, ['required' => false, 'label' => 'Couleur', 'attr' => ['class' => 'gogo-color-picker']])
->add('icon', null, ['required' => false, 'label' => 'Icone', 'attr' => ['class' => 'gogo-icon-picker']])
->add('id', null, ['required' => false, 'label' => 'Plus de paramètres', 'attr' => ['class' => 'gogo-route-id', 'data-route-id' => 'admin_app_option_edit']])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => 'App\Document\Option',
]);
}
/**
* @return string
*/
public function getName()
{
return 'gogo_form_option_lite';
}
}
<div class="input-container">
{% set object = form.vars.sonata_admin.admin.subject %}
{% if object.getDefaultColor is defined %}
{% set defaultColor = object.getDefaultColor(form.vars.name) %}
{% if defaultColor and not form.vars.value %}
<div class="default-color" style="background-color: {{ defaultColor }}"></div>
{% if form.vars.sonata_admin.admin.subject is defined %}
{% set object = form.vars.sonata_admin.admin.subject %}
{% if object.getDefaultColor is defined %}
{% set defaultColor = object.getDefaultColor(form.vars.name) %}
{% if defaultColor and not form.vars.value %}
<div class="default-color" style="background-color: {{ defaultColor }}"></div>
{% endif %}
{% endif %}
{% endif %}
<input type='text' id="{{ form.vars.id }}" name="{{ form.vars.full_name }}" placeholder="Cliquez pour choisir une couleur" value="{{ form.vars.value }}" class="form-control gogo-color-picker" />
......
<a href="{{ url(form.vars.attr['data-route-id'], { 'id': form.vars.value|number_format }) }}" class="btn btn-default"><span class="fa fa-pencil-alt"></span></a>
\ No newline at end of file
<script>
function sortOptions() {
var inputs = $('#sort-options-btn').closest('.sonata-ba-collapsed-fields').find('.form-group:last-child').find('tr td:first-child input');
var inputs = $('#sort-options-btn').closest('.sonata-ba-collapsed-fields')
.find('.sonata-collection-row .sonata-ba-field .form-group:first-child input');
var values = [];
inputs.each(function() {
values.push({id: this.id, name: $(this).val()});
......@@ -8,7 +9,7 @@
values.sort(dynamicSort("name"));
for (var i = 0; i < values.length; i++) {
value = values[i];
$('#' + value.id).closest('tr').find('td:nth-child(2) input').val(i);
$('#' + value.id).closest('.sonata-collection-row-without-label').find('.form-group:nth-child(2) input').val(i);
}
console.log(values);
}
......@@ -26,7 +27,7 @@
return b[property].localeCompare(a[property]);
}else{
return a[property].localeCompare(b[property]);
}
}
}
}
</script>
......
{% extends '@SonataDoctrineMongoDBAdmin/Form/form_admin_fields.html.twig' %}
{% block sonata_admin_mongo_collection %}
{{ dump('coucou')}}
{% include 'admin/core_custom/custom-fields/edit_mongo_collection.html.twig' %}
{% endblock %}
......@@ -41,6 +42,8 @@
{% include 'admin/core_custom/custom-fields/mapping-taxonomy.html.twig' %}
{% elseif attr_class == "gogo-mapping-ontology" %}
{% include 'admin/core_custom/custom-fields/mapping-ontology.html.twig' %}
{% elseif attr_class == "gogo-route-id" %}
{% include 'admin/core_custom/custom-fields/route-id.html.twig' %}
{% else %}
{% set attr = attr|merge({'class': attr_class ~ ' form-control'}) %}
{{ parent() }}
......
......@@ -45,6 +45,23 @@
.sub-categories-container, .sub-options-container { display: none; }
</style>
{% endif %}
<style>
.sonata-collection-row:not(:first-child) .form-group label { display: none; }
.sonata-collection-row .sonata-ba-field > div:first-child { display: flex; }
.sonata-collection-row .sonata-ba-field .form-group { margin-right: 10px; }
.sonata-collection-row .sp-replacer { order: -1; }
.sonata-collection-row .input-group .input-group-addon {
width: 40px;
font-size: 2rem;
display: flex;
align-items: center;
justify-content: center;
}
.sonata-collection-row .sonata-ba-field .form-group:nth-child(2) { width: 60px; }
.sonata-collection-row .sonata-ba-field .form-group:nth-child(3) .input-container { margin-left: 8px; }
.sonata-collection-row .sonata-ba-field .form-group:nth-child(3) .gogo-color-picker { margin-left: -15px; width: 120%; }
.sonata-collection-row .sonata-ba-field .form-group:last-child { width: 120px; }
</style>
{{ parent() }}
{% endblock %}
......
......@@ -16,7 +16,6 @@
{% if form_group.description %}
<p>{{ form_group.description|raw }}</p>
{% endif %}
{% for field_name in form_group.fields if admin.formfielddescriptions[field_name] is defined %}
{{ form_row(form[field_name])}}
{% endfor %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment