Browse Source

Création de playlists en live

Sevajol Bastien 12 years ago
parent
commit
41bdb580c6

+ 1 - 1
src/Muzich/CoreBundle/Entity/Playlist.php View File

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

+ 1 - 1
src/Muzich/CoreBundle/Form/Playlist/PlaylistForm.php View File

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

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

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
   $('ul.elements a.add_to_playlist').live('click', function(event){
3144
   $('ul.elements a.add_to_playlist').live('click', function(event){
3156
     
3145
     
3146
+    $('div.playlists_prompt').remove();
3157
     var prompt = $('<div class="playlists_prompt"><img class="loader" src="/bundles/muzichcore/img/ajax-loader.gif" alt="loading..." /></div>');
3147
     var prompt = $('<div class="playlists_prompt"><img class="loader" src="/bundles/muzichcore/img/ajax-loader.gif" alt="loading..." /></div>');
3158
     $('body').append(prompt);
3148
     $('body').append(prompt);
3159
     
3149
     
3174
       if (response.status == 'success')
3164
       if (response.status == 'success')
3175
       {
3165
       {
3176
         prompt.append(response.data);
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 View File

14
 use Muzich\CoreBundle\Entity\User;
14
 use Muzich\CoreBundle\Entity\User;
15
 use Muzich\CoreBundle\Security\Context as SecurityContext;
15
 use Muzich\CoreBundle\Security\Context as SecurityContext;
16
 use Muzich\CoreBundle\Managers\PlaylistManager;
16
 use Muzich\CoreBundle\Managers\PlaylistManager;
17
+use Muzich\CoreBundle\Form\Playlist\PlaylistForm;
17
 
18
 
18
 class Controller extends BaseController
19
 class Controller extends BaseController
19
 {
20
 {
679
       ->findOneById($element_id);
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 View File

44
     return $this->jsonSuccessResponse();
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 View File

5
 use Muzich\CoreBundle\lib\Controller;
5
 use Muzich\CoreBundle\lib\Controller;
6
 use Muzich\CoreBundle\Entity\Playlist;
6
 use Muzich\CoreBundle\Entity\Playlist;
7
 use Muzich\CoreBundle\lib\AutoplayManager;
7
 use Muzich\CoreBundle\lib\AutoplayManager;
8
-use Muzich\CoreBundle\Form\Playlist\PlaylistForm;
9
 
8
 
10
 class ShowController extends Controller
9
 class ShowController extends Controller
11
 {
10
 {
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 View File

28
 
28
 
29
 playlist_add_element_and_create:
29
 playlist_add_element_and_create:
30
   pattern: /ajax/playlist/element/add-and-create/{element_id}
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 View File

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

1
 
1
 
2
 <div class="create_playlist">
2
 <div class="create_playlist">
3
   <form action="{{ path('playlist_add_element_and_create', { 'element_id' : element_id }) }}" method="post">
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
   </form>
5
   </form>
14
 </div>
6
 </div>
15
 
7