Explorar el Código

Logiciel: Anomalie #824: Playlist: remove element

Bastien Sevajol hace 10 años
padre
commit
c8c5c31a7d

+ 11 - 1
src/Muzich/CoreBundle/Resources/public/js/muzich.js Ver fichero

3331
       $.getJSON(link.attr('href'), function(response) {
3331
       $.getJSON(link.attr('href'), function(response) {
3332
         window.ResponseController.execute(
3332
         window.ResponseController.execute(
3333
           response,
3333
           response,
3334
-          function(){},
3334
+          function(response){
3335
+            
3336
+            if (response.data.element_remove_links.length)
3337
+            {
3338
+              for (index in response.data.element_remove_links)
3339
+              {
3340
+                $($('ul.playlist_elements li.playlist_element').get(index)).find('a.remove_element').attr('href', response.data.element_remove_links[index]);
3341
+              }
3342
+            }
3343
+            
3344
+          },
3335
           function(){}
3345
           function(){}
3336
         );
3346
         );
3337
       });
3347
       });

+ 9 - 0
src/Muzich/CoreBundle/lib/Controller.php Ver fichero

447
     return $response;
447
     return $response;
448
   }
448
   }
449
   
449
   
450
+  /**
451
+   * @param array $data
452
+   * @return \Symfony\Component\HttpFoundation\Response
453
+   */
450
   protected function jsonSuccessResponse($data = array())
454
   protected function jsonSuccessResponse($data = array())
451
   {
455
   {
452
     $response = new Response(json_encode(array(
456
     $response = new Response(json_encode(array(
709
     return true;
713
     return true;
710
   }
714
   }
711
   
715
   
716
+  protected function getToken($intention = 'unknown')
717
+  {
718
+    return $this->container->get('form.csrf_provider')->generateCsrfToken($intention);
719
+  }
720
+  
712
   protected function getUserManager()
721
   protected function getUserManager()
713
   {
722
   {
714
     return $this->container->get('muzich_user_manager');
723
     return $this->container->get('muzich_user_manager');

+ 19 - 1
src/Muzich/PlaylistBundle/Controller/EditController.php Ver fichero

7
 use Muzich\CoreBundle\Security\Context as SecurityContext;
7
 use Muzich\CoreBundle\Security\Context as SecurityContext;
8
 use Muzich\CoreBundle\Propagator\EventElement;
8
 use Muzich\CoreBundle\Propagator\EventElement;
9
 use Muzich\CoreBundle\Form\Playlist\PrivateLinksForm;
9
 use Muzich\CoreBundle\Form\Playlist\PrivateLinksForm;
10
+use Muzich\CoreBundle\Entity\Playlist;
10
 
11
 
11
 class EditController extends Controller
12
 class EditController extends Controller
12
 {
13
 {
45
     
46
     
46
     $this->persist($element);
47
     $this->persist($element);
47
     $this->flush();
48
     $this->flush();
48
-    return $this->jsonSuccessResponse();
49
+    return $this->jsonSuccessResponse(array(
50
+      'element_remove_links' => $this->getRemoveLinksForPlaylist($playlist)
51
+    ));
52
+  }
53
+  
54
+  protected function getRemoveLinksForPlaylist(Playlist $playlist)
55
+  {
56
+    $element_remove_urls = array();
57
+    foreach ($playlist->getElements() as $index => $element_data)
58
+    {
59
+      $element_remove_urls[] = $this->generateUrl('playlist_remove_element', array(
60
+        'playlist_id' => $playlist->getId(),
61
+        'index'       => $index,
62
+        'token'       => $this->getToken()
63
+      ));
64
+    }
65
+    
66
+    return $element_remove_urls;
49
   }
67
   }
50
   
68
   
51
   public function addElementAction($playlist_id, $element_id)
69
   public function addElementAction($playlist_id, $element_id)