Browse Source

modification et suppression compatible sans ajax

bastien 13 years ago
parent
commit
11d3375dc4

+ 5 - 1
app/Resources/translations/flash.fr.yml View File

20
 element:
20
 element:
21
   add:
21
   add:
22
     error:        Une erreur est survenus lors de l'ajout.
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
 user:
27
 user:
25
   changeemail:
28
   changeemail:
26
     mail_send:     Un email a été envoyé a l'adresse communiqué pour confirmation.
29
     mail_send:     Un email a été envoyé a l'adresse communiqué pour confirmation.
27
     token_invalid: Le lien pour mettre a jour votre email est périmé, veuillez relancer la procédure.
30
     token_invalid: Le lien pour mettre a jour votre email est périmé, veuillez relancer la procédure.
28
     success:       Votre email a correctement été mis a jour.
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 View File

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

+ 8 - 1
app/Resources/translations/userui.fr.yml View File

60
   
60
   
61
 index:
61
 index:
62
   beta:
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 View File

14
    * @return Muzich\CoreBundle\Entity\Element 
14
    * @return Muzich\CoreBundle\Entity\Element 
15
    */
15
    */
16
   protected function checkExistingAndOwned($element_id)
16
   protected function checkExistingAndOwned($element_id)
17
-  {
18
-    if (!$this->getRequest()->isXmlHttpRequest())
19
-    {
20
-      throw $this->createNotFoundException('Not allowed');
21
-    }
22
-    
17
+  {    
23
     if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
18
     if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
24
       ->findOneById($element_id)))
19
       ->findOneById($element_id)))
25
     {
20
     {
38
    * 
33
    * 
39
    */
34
    */
40
   public function editAction($element_id)
35
   public function editAction($element_id)
41
-  {
36
+  {    
42
     $element = $this->checkExistingAndOwned($element_id);
37
     $element = $this->checkExistingAndOwned($element_id);
43
     
38
     
44
     $element_tags = $element->getTags();
39
     $element_tags = $element->getTags();
51
       $search_tags[$tag->getId()] = $tag->getName();
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
       'form'        => $form->createView(),
56
       'form'        => $form->createView(),
56
       'form_name'   => 'element_'.$element->getId(),
57
       'form_name'   => 'element_'.$element->getId(),
57
       'element_id'  => $element->getId(),
58
       'element_id'  => $element->getId(),
58
       'search_tags' => $search_tags
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
       }
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
       $em->remove($element);
151
       $em->remove($element);
125
       $em->flush();
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
     catch(Exception $e)
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 View File

224
   public function getTagsIdsJson()
224
   public function getTagsIdsJson()
225
   {
225
   {
226
     $ids = array();
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
     return json_encode($ids);
234
     return json_encode($ids);
232
   }
235
   }

+ 10 - 0
src/Muzich/CoreBundle/Resources/views/Element/ajax.element.edit.html.twig View File

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 View File

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 %}