Browse Source

Logiciel: Anomalie #824: Playlist: remove element

Bastien Sevajol 11 years ago
parent
commit
c8c5c31a7d

+ 11 - 1
src/Muzich/CoreBundle/Resources/public/js/muzich.js View File

@@ -3331,7 +3331,17 @@ $(document).ready(function(){
3331 3331
       $.getJSON(link.attr('href'), function(response) {
3332 3332
         window.ResponseController.execute(
3333 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 3345
           function(){}
3336 3346
         );
3337 3347
       });

+ 9 - 0
src/Muzich/CoreBundle/lib/Controller.php View File

@@ -447,6 +447,10 @@ class Controller extends BaseController
447 447
     return $response;
448 448
   }
449 449
   
450
+  /**
451
+   * @param array $data
452
+   * @return \Symfony\Component\HttpFoundation\Response
453
+   */
450 454
   protected function jsonSuccessResponse($data = array())
451 455
   {
452 456
     $response = new Response(json_encode(array(
@@ -709,6 +713,11 @@ class Controller extends BaseController
709 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 721
   protected function getUserManager()
713 722
   {
714 723
     return $this->container->get('muzich_user_manager');

+ 19 - 1
src/Muzich/PlaylistBundle/Controller/EditController.php View File

@@ -7,6 +7,7 @@ use Symfony\Component\HttpFoundation\Request;
7 7
 use Muzich\CoreBundle\Security\Context as SecurityContext;
8 8
 use Muzich\CoreBundle\Propagator\EventElement;
9 9
 use Muzich\CoreBundle\Form\Playlist\PrivateLinksForm;
10
+use Muzich\CoreBundle\Entity\Playlist;
10 11
 
11 12
 class EditController extends Controller
12 13
 {
@@ -45,7 +46,24 @@ class EditController extends Controller
45 46
     
46 47
     $this->persist($element);
47 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 69
   public function addElementAction($playlist_id, $element_id)