Parcourir la source

Add tab layout

Thomas Rabaix il y a 12 ans
Parent
commit
325508ca99
4 fichiers modifiés avec 41 ajouts et 47 suppressions
  1. 0 19
      Resources/public/base.js
  2. 31 26
      Resources/views/CRUD/base_edit_form.html.twig
  3. 0 2
      UPGRADE-2.1.md
  4. 10 0
      UPGRADE-2.2.md

+ 0 - 19
Resources/public/base.js

@@ -1,7 +1,6 @@
 jQuery(document).ready(function() {
     jQuery('html').removeClass('no-js');
     Admin.add_pretty_errors(document);
-    Admin.add_collapsed_toggle(document);
     Admin.add_filters(document);
     Admin.set_object_field_value(document);
     Admin.setup_collection_buttons(document);
@@ -75,24 +74,6 @@ var Admin = {
         });
     },
 
-    /**
-     * Add the collapsed toggle option to the admin
-     *
-     * @param subject
-     */
-    add_collapsed_toggle: function(subject) {
-        jQuery('fieldset.sonata-ba-fieldset-collapsed').has('.error').addClass('sonata-ba-collapsed-fields-close');
-        jQuery('fieldset.sonata-ba-fieldset-collapsed div.sonata-ba-collapsed-fields').not(':has(.error)').hide();
-        jQuery(subject).on('click', 'fieldset legend a.sonata-ba-collapsed', function(event) {
-            event.preventDefault();
-
-            var fieldset = jQuery(this).closest('fieldset');
-
-            jQuery('div.sonata-ba-collapsed-fields', fieldset).slideToggle();
-            fieldset.toggleClass('sonata-ba-collapsed-fields-close');
-        });
-    },
-
     stopEvent: function(event) {
         // https://github.com/sonata-project/SonataAdminBundle/issues/151
         //if it is a standard browser use preventDefault otherwise it is IE then return false

+ 31 - 26
Resources/views/CRUD/base_edit_form.html.twig

@@ -13,33 +13,38 @@
                 </div>
             {% endif %}
 
-            {% block sonata_pre_fieldsets %}{% endblock %}
-
-            {% for name, form_group in admin.formgroups %}
-                <fieldset {% if form_group.collapsed %}class="sonata-ba-fieldset-collapsed"{% endif %}>
-                    <legend{% if form_group.description != false %} class="sonata-ba-fieldset-collapsed-description"{% endif %}>
-                        {% if form_group.collapsed %}
-                            <a href="" class="sonata-ba-collapsed" title="{{ 'link_expand'|trans({}, 'SonataAdminBundle') }}">{{ name|trans({}, admin.translationdomain) }}</a>
-                        {% else %}
-                            {{ name|trans({}, admin.translationdomain) }}
-                        {% endif %}
-                    </legend>
+            {% block sonata_pre_fieldsets %}
+                <div class="tabbable">
+                    <ul class="nav nav-tabs">
+                        {% for name, form_group in admin.formgroups %}
+                            <li class="{% if loop.first %}active{% endif %}"><a href="#{{ name }}" data-toggle="tab">{{ name }}</a></li>
+                        {% endfor %}
+                    </ul>
+            {% endblock %}
 
-                    <div class="sonata-ba-collapsed-fields">
-                        {% if form_group.description != false %}
-                            <p>{{ form_group.description|raw }}</p>
-                        {% endif %}
+                <div class="tab-content">
+                    {% for name, form_group in admin.formgroups %}
+                        <div class="tab-pane {% if loop.first %} active{% endif %}" id="{{ name }}">
+                            <fieldset>
+                                <div class="sonata-ba-collapsed-fields">
+                                    {% if form_group.description != false %}
+                                        <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])}}
-                            {% endif %}
-                        {% endfor %}
-                    </div>
-                </fieldset>
-            {% endfor %}
+                                    {% for field_name in form_group.fields %}
+                                        {% if admin.formfielddescriptions[field_name] is defined %}
+                                            {{ form_row(form[field_name])}}
+                                        {% endif %}
+                                    {% endfor %}
+                                </div>
+                            </fieldset>
+                        </div>
+                    {% endfor %}
+                </div>
 
-            {% block sonata_post_fieldsets %}{% endblock %}
+            {% block sonata_post_fieldsets %}
+                </div>
+            {% endblock %}
 
             {{ form_rest(form) }}
 
@@ -57,10 +62,10 @@
                         {% endif %}
                         {% if admin.id(object) %}
                             <input type="submit" class="btn btn-primary" name="btn_update_and_edit" value="{{ 'btn_update_and_edit_again'|trans({}, 'SonataAdminBundle') }}"/>
-                            
+
                             {% if admin.hasroute('list') %}
                                 <input type="submit" class="btn" name="btn_update_and_list" value="{{ 'btn_update_and_return_to_list'|trans({}, 'SonataAdminBundle') }}"/>
-                            {% endif %}                            
+                            {% endif %}
 
                             {% if admin.hasroute('delete') and admin.isGranted('DELETE', object) %}
                                 {{ 'delete_or'|trans({}, 'SonataAdminBundle') }}

+ 0 - 2
UPGRADE-2.1.md

@@ -1,8 +1,6 @@
 UPGRADE FROM 2.0 to 2.1
 =======================
 
-** Work In Progress - Please do not use this code in production **
-
 ### Form
 
   * Due to some refactoring in the Form Component, some types definition have been changed

+ 10 - 0
UPGRADE-2.2.md

@@ -0,0 +1,10 @@
+UPGRADE FROM 2.1 to 2.2
+=======================
+
+** Work In Progress - Please do not use this code in production **
+
+### Form
+
+  * Refactoring the general layout to be more compact
+  * Remove the collapsing option to migrate to tabbed form layout
+