Commit 552b1bb0 authored by Sebastian Castro's avatar Sebastian Castro

Feature: sort sub options by alphabetical order

parent 3d4e5344
v2.3
====
* FEATURE: Sort sub options by alphabetical order
* FEATURE: In the map categories menu, display next to each categorie how many elements are available for this category
* FEATURE: Edit marker popup template
* FEATURE: Ability to destroy my project
......
......@@ -67,7 +67,8 @@ class CategoryAdmin extends AbstractAdmin
->add('displayInForm', null, array('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('options', 'sonata_type_collection', array('by_reference' => false, 'type_options' => array('delete' => false), 'label_attr'=> ['style'=> 'display:none']), array(
->add('isFixture', 'text', ['attr' => ['class' => 'gogo-sort-options'], 'label_attr' => ['style' => 'display:none']])
->add('options', 'sonata_type_collection', array('by_reference' => false, 'type_options' => array('delete' => false), 'label_attr'=> ['style'=> 'display:none']), array(
'edit' => 'inline',
'inline' => 'table',
'label' => '',
......
<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 values = [];
inputs.each(function() {
values.push({id: this.id, name: $(this).val()});
});
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);
}
console.log(values);
}
function dynamicSort(property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
if(sortOrder == -1){
return b[property].localeCompare(a[property]);
}else{
return a[property].localeCompare(b[property]);
}
}
}
</script>
<span class="btn btn-sm btn-default" id="sort-options-btn" onClick="sortOptions()">Ranger les catégories par ordre alphabétique</span>
\ No newline at end of file
......@@ -35,6 +35,8 @@
{% include '@BiopenAdmin/core_custom/custom-fields/display-array.html.twig' %}
{% elseif attr_class == "gogo-display-logs" %}
{% include '@BiopenAdmin/core_custom/custom-fields/display-logs.html.twig' %}
{% elseif attr_class == "gogo-sort-options" %}
{% include '@BiopenAdmin/core_custom/custom-fields/sort-options.html.twig' %}
{% else %}
{% set attr = attr|merge({'class': attr_class ~ ' form-control'}) %}
{{ parent() }}
......
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