Browse Source

Flash messages: n'ont pas été embarqués depuis le layout old

Bastien Sevajol 11 years ago
parent
commit
f62c610d40

+ 19 - 1
src/Muzich/CoreBundle/Extension/MyTwigExtension.php View File

@@ -4,6 +4,7 @@ namespace Muzich\CoreBundle\Extension;
4 4
 
5 5
 use Symfony\Bundle\FrameworkBundle\Translation\Translator;
6 6
 use Muzich\CoreBundle\Entity\Event;
7
+use Symfony\Component\Form\FormView;
7 8
 
8 9
 class MyTwigExtension extends \Twig_Extension {
9 10
 
@@ -19,7 +20,8 @@ class MyTwigExtension extends \Twig_Extension {
19 20
     return array(
20 21
       'var_dump'               => new \Twig_Filter_Function('var_dump'),
21 22
       'date_or_relative_date'  => new \Twig_Filter_Method($this, 'date_or_relative_date'),
22
-      'date_epurate'            => new \Twig_Filter_Method($this, 'date_epurate')
23
+      'date_epurate'           => new \Twig_Filter_Method($this, 'date_epurate'),
24
+      'form_has_errors'        => new \Twig_Filter_Method($this, 'form_has_errors')
23 25
     );
24 26
   }
25 27
   
@@ -171,5 +173,21 @@ class MyTwigExtension extends \Twig_Extension {
171 173
       return 'list_length_default';
172 174
     }
173 175
   }
176
+  
177
+  public function form_has_errors(FormView $form)
178
+  {
179
+    $form_vars = $form->getVars();
180
+    $count_error = count($form_vars['errors']);
181
+    foreach ($form->getChildren() as $form_children)
182
+    {
183
+      $form_children_vars = $form_children->getVars();
184
+      $count_error += count($form_children_vars['errors']);
185
+    }
186
+    if ($count_error)
187
+    {
188
+      return true;
189
+    }
190
+    return false;
191
+  }
174 192
 
175 193
 }

+ 28 - 0
src/Muzich/CoreBundle/Resources/views/layout.html.twig View File

@@ -99,6 +99,17 @@
99 99
   </head>
100 100
   <body>
101 101
     
102
+    <noscript>
103
+    <div id="noscript_warning">
104
+      <p>
105
+        {{ 'noscript.message'|trans({}, 'messages') }}
106
+        <a href="{{ 'noscript.link_search'|trans({}, 'messages') }}" target="_blank">
107
+          {{ 'noscript.link_text'|trans({}, 'messages') }}
108
+        </a>
109
+      </p>
110
+    </div>
111
+  </noscript>
112
+    
102 113
     <div id="autoplay" class="popin_block" style="display: none;">
103 114
       
104 115
       <a href="javascript:void(0);" id="autoplay_previous">
@@ -259,6 +270,23 @@
259 270
         </hgroup>
260 271
       </header>
261 272
       
273
+      {% for key, flash in app.session.getFlashes() %}
274
+        <div class="{{ key }} message">
275
+          <a class="message-close" href="javascript:void(0);" title="fermer"><img alt="close" src="{{ asset('bundles/muzichcore/img/1317386146_cancel.png') }}" /></a>
276
+          <h3>{{ flash|trans({}, 'flash') }}</h3>
277
+        </div>
278
+
279
+        {% if key == 'success' %}
280
+        <script type="text/javascript" >
281
+          $(document).ready(function(){
282
+            window.setTimeout(function(){
283
+              $('div.success').slideUp();
284
+            }, 3000);
285
+          });
286
+        </script>
287
+        {% endif %}
288
+      {% endfor %}
289
+      
262 290
       <div id="content">
263 291
         
264 292
         <div id="main">

+ 16 - 4
src/Muzich/UserBundle/Resources/views/User/account.html.twig View File

@@ -34,8 +34,12 @@
34 34
     </p>
35 35
 
36 36
     <h2 data-open="myaccount_favorites_tags">{{ 'my_account.favorite_tags'|trans({}, 'userui') }}</h2>
37
-
38
-    <div id="myaccount_favorites_tags" class="myaccount_part" style="display: none;">
37
+    
38
+    <div id="myaccount_favorites_tags" class="myaccount_part"
39
+      {% if not form_tags_favorites|form_has_errors %}
40
+       style="display: none;"
41
+      {% endif %}
42
+    >
39 43
       {% include "MuzichCoreBundle:Tag:tagFavoritesForm.html.twig" with { 
40 44
         'form'             : form_tags_favorites,
41 45
         'redirect'         : 'account',
@@ -46,7 +50,11 @@
46 50
 
47 51
     <h2 data-open="myaccount_favorites_password">{{ 'my_account.change_password'|trans({}, 'userui') }}</h2>
48 52
 
49
-    <div id="myaccount_favorites_password" class="myaccount_part" style="display: none;">
53
+    <div id="myaccount_favorites_password" class="myaccount_part" 
54
+      {% if not form_password|form_has_errors %}
55
+       style="display: none;"
56
+      {% endif %}
57
+     >
50 58
       <form class="nicelabels changepassword" action="{{ path('change_password') }}" method="post" {{ form_enctype(form_password) }}>
51 59
 
52 60
         {% include "MuzichUserBundle:Security:change_password_form.html.twig" with { 
@@ -59,7 +67,11 @@
59 67
 
60 68
     <h2 data-open="myaccount_favorites_email">{{ 'my_account.change_email'|trans({}, 'userui') }}</h2>
61 69
 
62
-    <div id="myaccount_favorites_email" class="myaccount_part" style="display: none;">
70
+    <div id="myaccount_favorites_email" class="myaccount_part"
71
+      {% if not change_email_form|form_has_errors %}
72
+       style="display: none;"
73
+      {% endif %}
74
+    >
63 75
       <form class="nicelabels changeemail" action="{{ path('change_email_request') }}" method="post" {{ form_enctype(change_email_form) }}>
64 76
 
65 77
         {% include "MuzichUserBundle:User:change_email_form.html.twig" with {