Quellcode durchsuchen

Création de playlists en live

Sevajol Bastien vor 11 Jahren
Ursprung
Commit
41bdb580c6

+ 1 - 1
src/Muzich/CoreBundle/Entity/Playlist.php Datei anzeigen

@@ -54,7 +54,7 @@ class Playlist
54 54
   /**
55 55
    * @ORM\Column(type="boolean")
56 56
    */
57
-  protected $public = true;
57
+  protected $public = false;
58 58
   
59 59
   /**
60 60
    * @ORM\OneToMany(targetEntity="UserPlaylistPicked", mappedBy="user")

+ 1 - 1
src/Muzich/CoreBundle/Form/Playlist/PlaylistForm.php Datei anzeigen

@@ -27,7 +27,7 @@ class PlaylistForm extends AbstractType
27 27
   {
28 28
     $resolver->setDefaults(array(
29 29
       'name'   => '',
30
-      'public' => true,
30
+      'public' => false,
31 31
     ));
32 32
   
33 33
     $resolver->setAllowedValues(array(

+ 19 - 11
src/Muzich/CoreBundle/Resources/public/js/muzich.js Datei anzeigen

@@ -3141,19 +3141,9 @@ $(document).ready(function(){
3141 3141
     }
3142 3142
   });
3143 3143
   
3144
-  $('html').click(function() {
3145
-    if ($("div.playlists_prompt").is(':visible'))
3146
-    {
3147
-      $("div.playlists_prompt").hide();
3148
-    }
3149
-  });
3150
-  $("div.playlists_prompt, div.playlists_prompt div, div.playlists_prompt a, div.playlists_prompt input").live('click', function(event){
3151
-    event.stopPropagation();
3152
-    $("div.playlists_prompt").show();
3153
-  });
3154
-  
3155 3144
   $('ul.elements a.add_to_playlist').live('click', function(event){
3156 3145
     
3146
+    $('div.playlists_prompt').remove();
3157 3147
     var prompt = $('<div class="playlists_prompt"><img class="loader" src="/bundles/muzichcore/img/ajax-loader.gif" alt="loading..." /></div>');
3158 3148
     $('body').append(prompt);
3159 3149
     
@@ -3174,6 +3164,24 @@ $(document).ready(function(){
3174 3164
       if (response.status == 'success')
3175 3165
       {
3176 3166
         prompt.append(response.data);
3167
+        prompt.find('div.create_playlist form').ajaxForm(function(response){
3168
+          window.ResponseController.execute(
3169
+            response,
3170
+            function(){},
3171
+            function(){}
3172
+          );
3173
+          
3174
+          if (response.status == 'success')
3175
+          {
3176
+            $('div.playlists_prompt').remove();
3177
+          }
3178
+          
3179
+          if (response.status == 'error')
3180
+          {
3181
+            prompt.find('div.create_playlist form').html(response.data);
3182
+          }
3183
+          
3184
+        });
3177 3185
       }
3178 3186
       
3179 3187
     });

+ 6 - 0
src/Muzich/CoreBundle/lib/Controller.php Datei anzeigen

@@ -14,6 +14,7 @@ use Muzich\CoreBundle\Entity\Presubscription;
14 14
 use Muzich\CoreBundle\Entity\User;
15 15
 use Muzich\CoreBundle\Security\Context as SecurityContext;
16 16
 use Muzich\CoreBundle\Managers\PlaylistManager;
17
+use Muzich\CoreBundle\Form\Playlist\PlaylistForm;
17 18
 
18 19
 class Controller extends BaseController
19 20
 {
@@ -679,4 +680,9 @@ class Controller extends BaseController
679 680
       ->findOneById($element_id);
680 681
   }
681 682
   
683
+  protected function getPlaylistForm()
684
+  {
685
+    return $this->createForm(new PlaylistForm(), $this->getPlaylistManager()->getNewPlaylist($this->getUserOrNullIfVisitor()));
686
+  }
687
+  
682 688
 }

+ 22 - 0
src/Muzich/PlaylistBundle/Controller/EditController.php Datei anzeigen

@@ -44,4 +44,26 @@ class EditController extends Controller
44 44
     return $this->jsonSuccessResponse();
45 45
   }
46 46
   
47
+  public function addElementAndCreateAction(Request $request, $element_id)
48
+  {
49
+    if (!($element = $this->getElementWithId($element_id)))
50
+      return $this->jsonNotFoundResponse();
51
+    
52
+    $form = $this->getPlaylistForm();
53
+    $form->bind($request);
54
+    if ($form->isValid())
55
+    {
56
+      $this->getPlaylistManager()->addElementToPlaylist($element, $form->getData());
57
+      $this->flush();
58
+      return $this->jsonSuccessResponse();
59
+    }
60
+    
61
+    return $this->jsonResponseError('form_error',
62
+      $this->render('MuzichPlaylistBundle:Show:form.html.twig', array(
63
+        'form'       => $form->createView(),
64
+        'element_id' => $element_id
65
+      ))->getContent()
66
+    );
67
+  }
68
+  
47 69
 }

+ 0 - 6
src/Muzich/PlaylistBundle/Controller/ShowController.php Datei anzeigen

@@ -5,7 +5,6 @@ namespace Muzich\PlaylistBundle\Controller;
5 5
 use Muzich\CoreBundle\lib\Controller;
6 6
 use Muzich\CoreBundle\Entity\Playlist;
7 7
 use Muzich\CoreBundle\lib\AutoplayManager;
8
-use Muzich\CoreBundle\Form\Playlist\PlaylistForm;
9 8
 
10 9
 class ShowController extends Controller
11 10
 {
@@ -59,9 +58,4 @@ class ShowController extends Controller
59 58
     );
60 59
   }
61 60
   
62
-  protected function getPlaylistForm()
63
-  {
64
-    return $this->createForm(new PlaylistForm(), $this->getPlaylistManager()->getNewPlaylist($this->getUserOrNullIfVisitor()));
65
-  }
66
-  
67 61
 }

+ 1 - 1
src/Muzich/PlaylistBundle/Resources/config/routing.yml Datei anzeigen

@@ -28,5 +28,5 @@ playlists_add_element:
28 28
 
29 29
 playlist_add_element_and_create:
30 30
   pattern: /ajax/playlist/element/add-and-create/{element_id}
31
-  defaults: { _controller: MuzichPlaylistBundle:Edit:addElementAndcreate }
31
+  defaults: { _controller: MuzichPlaylistBundle:Edit:addElementAndCreate }
32 32
   

+ 12 - 0
src/Muzich/PlaylistBundle/Resources/views/Show/form.html.twig Datei anzeigen

@@ -0,0 +1,12 @@
1
+{{ form_errors(form) }}
2
+{{ form_errors(form.name) }}
3
+{{ form_errors(form.public) }}
4
+
5
+<div class="field">
6
+  {{ form_widget(form.name, {'attr':{'class':'niceinput'}}) }}
7
+  {{ form_widget(form.public) }}
8
+</div>
9
+
10
+{{ form_rest(form) }}
11
+
12
+<input type="submit" value="CREATE" />

+ 1 - 9
src/Muzich/PlaylistBundle/Resources/views/Show/prompt.html.twig Datei anzeigen

@@ -1,15 +1,7 @@
1 1
 
2 2
 <div class="create_playlist">
3 3
   <form action="{{ path('playlist_add_element_and_create', { 'element_id' : element_id }) }}" method="post">
4
-    
5
-    <div class="field">
6
-      {{ form_widget(form.name, {'attr':{'class':'niceinput'}}) }}
7
-      {{ form_widget(form.public) }}
8
-    </div>
9
-    
10
-    {{ form_rest(form) }}
11
-    
12
-    <input type="submit" value="CREATE" />
4
+    {% include 'MuzichPlaylistBundle:Show:form.html.twig' %}
13 5
   </form>
14 6
 </div>
15 7