瀏覽代碼

modification et suppression compatible sans ajax

bastien 13 年之前
父節點
當前提交
11d3375dc4

+ 5 - 1
app/Resources/translations/flash.fr.yml 查看文件

@@ -20,10 +20,14 @@ group:
20 20
 element:
21 21
   add:
22 22
     error:        Une erreur est survenus lors de l'ajout.
23
+  remove:
24
+    success:      Element supprimé avec succés.
25
+    error:        Une errur est survenue durant la suppression de l'élément.
23 26
     
24 27
 user:
25 28
   changeemail:
26 29
     mail_send:     Un email a été envoyé a l'adresse communiqué pour confirmation.
27 30
     token_invalid: Le lien pour mettre a jour votre email est périmé, veuillez relancer la procédure.
28 31
     success:       Votre email a correctement été mis a jour.
29
-    wait:          Vous devez attendre avant de pouvoir faire une nouvelle demande de changement d'email.
32
+    wait:          Vous devez attendre avant de pouvoir faire une nouvelle demande de changement d'email.
33
+    

+ 2 - 0
app/Resources/translations/navigationui.fr.yml 查看文件

@@ -35,6 +35,8 @@ my_groups:
35 35
   
36 36
 title:
37 37
   hello:                Découvrez et partagez la musique !
38
+  element:
39
+    edit:               Modification d'un élément
38 40
   
39 41
   
40 42
 bottom_menu:

+ 8 - 1
app/Resources/translations/userui.fr.yml 查看文件

@@ -60,4 +60,11 @@ tags_filter:
60 60
   
61 61
 index:
62 62
   beta:
63
-    warning:  L'accès au service est privé pendant le développement de l'application
63
+    warning:  L'accès au service est privé pendant le développement de l'application
64
+    
65
+system:
66
+  infos:
67
+    normally_js:   |
68
+                    Vous avez ouvert cette page dans un nouvel onglet/nouvelle page
69
+                    Sachez qu'avez le clic gauche de votre souris la modification
70
+                    de l'élément est intégré dans la page.

+ 58 - 21
src/Muzich/CoreBundle/Controller/ElementController.php 查看文件

@@ -14,12 +14,7 @@ class ElementController extends Controller
14 14
    * @return Muzich\CoreBundle\Entity\Element 
15 15
    */
16 16
   protected function checkExistingAndOwned($element_id)
17
-  {
18
-    if (!$this->getRequest()->isXmlHttpRequest())
19
-    {
20
-      throw $this->createNotFoundException('Not allowed');
21
-    }
22
-    
17
+  {    
23 18
     if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
24 19
       ->findOneById($element_id)))
25 20
     {
@@ -38,7 +33,7 @@ class ElementController extends Controller
38 33
    * 
39 34
    */
40 35
   public function editAction($element_id)
41
-  {
36
+  {    
42 37
     $element = $this->checkExistingAndOwned($element_id);
43 38
     
44 39
     $element_tags = $element->getTags();
@@ -51,19 +46,30 @@ class ElementController extends Controller
51 46
       $search_tags[$tag->getId()] = $tag->getName();
52 47
     }
53 48
     
54
-    $html = $this->render('MuzichCoreBundle:Element:element.edit.html.twig', array(
49
+    $template = 'MuzichCoreBundle:Element:ajax.element.edit.html.twig'; 
50
+    if (!$this->getRequest()->isXmlHttpRequest())
51
+    {
52
+      $template = 'MuzichCoreBundle:Element:element.edit.html.twig'; 
53
+    }
54
+    
55
+    $response = $this->render($template, array(
55 56
       'form'        => $form->createView(),
56 57
       'form_name'   => 'element_'.$element->getId(),
57 58
       'element_id'  => $element->getId(),
58 59
       'search_tags' => $search_tags
59
-    ))->getContent();
60
-    
61
-    return $this->jsonResponse(array(
62
-      'status'    => 'success',
63
-      'form_name' => 'element_'.$element->getId(),
64
-      'tags'      => $search_tags,
65
-      'html'      => $html
66 60
     ));
61
+    
62
+    if ($this->getRequest()->isXmlHttpRequest())
63
+    {
64
+      return $this->jsonResponse(array(
65
+        'status'    => 'success',
66
+        'form_name' => 'element_'.$element->getId(),
67
+        'tags'      => $search_tags,
68
+        'html'      => $response->getContent()
69
+      ));
70
+    }
71
+    
72
+    return $response;
67 73
   }
68 74
   
69 75
   /**
@@ -109,10 +115,31 @@ class ElementController extends Controller
109 115
       }
110 116
     }
111 117
     
112
-    return $this->jsonResponse(array(
113
-      'status'  => $status,
114
-      'html'    => $html,
115
-      'errors'  => $errors
118
+    if ($this->getRequest()->isXmlHttpRequest())
119
+    {
120
+      return $this->jsonResponse(array(
121
+        'status'  => $status,
122
+        'html'    => $html,
123
+        'errors'  => $errors
124
+      ));
125
+    }
126
+    
127
+    if ($status == 'success')
128
+    {
129
+      return $this->redirect($this->generateUrl('home'));
130
+    }
131
+    
132
+    
133
+    $element->setTagsWithIds(
134
+      $this->getDoctrine()->getEntityManager(), 
135
+      json_decode($element->getTags())
136
+    );
137
+    
138
+    return $this->render('MuzichCoreBundle:Element:element.edit.html.twig', array(
139
+      'form'        => $form->createView(),
140
+      'form_name'   => 'element_'.$element->getId(),
141
+      'element_id'  => $element->getId(),
142
+      'search_tags' => $element->getTagsIdsJson()
116 143
     ));
117 144
   }
118 145
   
@@ -124,11 +151,21 @@ class ElementController extends Controller
124 151
       $em->remove($element);
125 152
       $em->flush();
126 153
       
127
-      return $this->jsonResponse(array('status' => 'success'));
154
+      if ($this->getRequest()->isXmlHttpRequest())
155
+      {
156
+        return $this->jsonResponse(array('status' => 'success'));
157
+      }
158
+      $this->setFlash('success', 'element.remove.success');
159
+      return $this->redirect($this->container->get('request')->headers->get('referer'));
128 160
     } 
129 161
     catch(Exception $e)
130 162
     {
131
-      return $this->jsonResponse(array('status' => 'error'));
163
+      if ($this->getRequest()->isXmlHttpRequest())
164
+      {
165
+        return $this->jsonResponse(array('status' => 'error'));
166
+      }
167
+      $this->setFlash('error', 'element.remove.error');
168
+      return $this->redirect($this->container->get('request')->headers->get('referer'));
132 169
     }
133 170
   }
134 171
   

+ 5 - 2
src/Muzich/CoreBundle/Entity/Element.php 查看文件

@@ -224,9 +224,12 @@ class Element
224 224
   public function getTagsIdsJson()
225 225
   {
226 226
     $ids = array();
227
-    foreach ($this->getTags() as $tag)
227
+    if (count($this->getTags()))
228 228
     {
229
-      $ids[] = $tag->getId();
229
+      foreach ($this->getTags() as $tag)
230
+      {
231
+        $ids[] = $tag->getId();
232
+      }
230 233
     }
231 234
     return json_encode($ids);
232 235
   }

+ 10 - 0
src/Muzich/CoreBundle/Resources/views/Element/ajax.element.edit.html.twig 查看文件

@@ -0,0 +1,10 @@
1
+
2
+<form name="{{ form_name }}" action="{{ path('element_update', {'element_id': element_id}) }}" method="post" {{ form_enctype(form) }}>
3
+
4
+  {% include "MuzichCoreBundle:Element:form.edit.html.twig" with { 
5
+    'form'          : form, 
6
+    'form_name'     : form_name
7
+  } %}
8
+
9
+  <input type="submit" value="{{ 'element_edit.submit.value'|trans({}, 'userui') }}" />
10
+</form>

+ 17 - 7
src/Muzich/CoreBundle/Resources/views/Element/element.edit.html.twig 查看文件

@@ -1,9 +1,19 @@
1
-<form name="{{ form_name }}" action="{{ path('element_update', {'element_id': element_id}) }}" method="post" {{ form_enctype(form) }}>
1
+{% extends "MuzichHomeBundle::layout.html.twig" %}
2 2
 
3
-  {% include "MuzichCoreBundle:Element:form.edit.html.twig" with { 
4
-    'form'          : form, 
5
-    'form_name'     : form_name
6
-  } %}
3
+{% block title %}{{ 'title.element.edit'|trans({}, 'userui') }}{% endblock %}
7 4
 
8
-  <input type="submit" value="{{ 'element_edit.submit.value'|trans({}, 'userui') }}" />
9
-</form>
5
+{% block content %}
6
+
7
+  <span class="sinfo">{{ 'system.infos.normally_js'|trans({}, 'userui') }}</span>
8
+
9
+  <form name="{{ form_name }}" action="{{ path('element_update', {'element_id': element_id}) }}" method="post" {{ form_enctype(form) }}>
10
+
11
+    {% include "MuzichCoreBundle:Element:form.edit.html.twig" with { 
12
+      'form'          : form, 
13
+      'form_name'     : form_name
14
+    } %}
15
+
16
+    <input type="submit" value="{{ 'element_edit.submit.value'|trans({}, 'userui') }}" />
17
+  </form>
18
+  
19
+{% endblock %}