Bladeren bron

Evolution #777: Modification d'une playlist

Sevajol Bastien 11 jaren geleden
bovenliggende
commit
279565899c

+ 4 - 0
app/Resources/translations/elements.fr.yml Bestand weergeven

@@ -141,3 +141,7 @@ playlist:
141 141
                           Pour ajouter de la musique a vos listes de lectures vous devez utiliser
142 142
                           les boutons disponibles en haut à droite des partages. Vous pourrez ensuite
143 143
                           choisir a quelle liste ajouter la musique en question.
144
+  edit:                  Modifier
145
+  update_submit:         Mettre à jour
146
+  goback:                Retour
147
+  edit_title:            Modification de "%playlist_name%"

+ 3 - 1
app/Resources/translations/flash.fr.yml Bestand weergeven

@@ -51,4 +51,6 @@ presubscription:
51 51
 
52 52
 playlist:
53 53
   delete:
54
-    success:       Playlist supprimée
54
+    success:       Playlist supprimée
55
+  update:
56
+    success:       La liste de lecture a été mise à jour

Diff onderdrukt omdat het te groot bestand
+ 6612 - 0
q


+ 7 - 3
src/Muzich/CoreBundle/Form/Playlist/PlaylistForm.php Bestand weergeven

@@ -13,9 +13,13 @@ class PlaylistForm extends AbstractType
13 13
     $builder->add('name', 'text', array(
14 14
       'required' => true,
15 15
     ));
16
-    $builder->add('public', 'checkbox', array(
17
-      'required' => false,
18
-    ));
16
+    
17
+    if (!$options['data']->getId())
18
+    {
19
+      $builder->add('public', 'checkbox', array(
20
+        'required' => false,
21
+      ));
22
+    }
19 23
   }
20 24
 
21 25
   public function getName()

+ 12 - 0
src/Muzich/CoreBundle/Resources/public/css/main.css Bestand weergeven

@@ -2402,6 +2402,18 @@ ul.playlists_for_element li.in
2402 2402
   list-style-image: url(/img/in.png);
2403 2403
 }
2404 2404
 
2405
+form.playlist_edit input#playlist_name
2406
+{
2407
+  width: 600px;
2408
+}
2409
+
2410
+form.playlist_edit input[type="submit"]
2411
+{
2412
+  float: right;
2413
+  margin-right: 10px;
2414
+  margin-top: 5px;
2415
+}
2416
+
2405 2417
 /*
2406 2418
 *
2407 2419
 *

+ 35 - 0
src/Muzich/CoreBundle/Tests/Controller/PlaylistControllerTest.php Bestand weergeven

@@ -461,4 +461,39 @@ class PlaylistControllerTest extends FunctionalTest
461 461
     $this->isResponseSuccess();
462 462
   }
463 463
   
464
+  public function testUpdate()
465
+  {
466
+     $this->init();
467
+    $this->initReadContextData();
468
+    $this->connectUser('bux', 'toor');
469
+    $this->goToPage($this->generateUrl('playlist', array('user_slug' => $this->users['bux']->getSlug(), 'playlist_id' => $this->playlists['bux_1_pub']->getId())));
470
+    $this->checkReadPlaylist($this->playlists['bux_1_pub']);
471
+    $new_name = $this->playlists['bux_1_pub']->getName().' dans tes oreilles ?!';
472
+    $this->playlists['bux_1_pub']->setName($new_name);
473
+    $this->updatePlaylist($this->playlists['bux_1_pub']);
474
+    $this->checkPlaylistName($this->playlists['bux_1_pub'], $new_name);
475
+    $this->goToPage($this->generateUrl('playlist', array('user_slug' => $this->users['bux']->getSlug(), 'playlist_id' => $this->playlists['bux_1_pub']->getId())));
476
+    $this->checkReadPlaylist($this->playlists['bux_1_pub']);
477
+  }
478
+  
479
+  protected function updatePlaylist($playlist)
480
+  {
481
+    $this->goToPage($this->generateUrl('playlist_edit', array(
482
+      'user_slug' => $playlist->getOwner()->getSlug(),
483
+      'playlist_id' => $playlist->getId()
484
+    )));
485
+    $this->isResponseSuccess();
486
+    $this->exist('form.playlist_edit');
487
+    
488
+    $form = $this->selectForm('form.playlist_edit input[type="submit"]');
489
+    $form['playlist[name]'] = $playlist->getName();
490
+    $this->submit($form);
491
+  }
492
+  
493
+  protected function checkPlaylistName($playlist, $name)
494
+  {
495
+    $playlist_in_database = $this->findOneBy('Playlist', $name);
496
+    $this->assertTrue(!is_null($playlist_in_database));
497
+  }
498
+  
464 499
 }

+ 6 - 2
src/Muzich/CoreBundle/lib/Controller.php Bestand weergeven

@@ -12,6 +12,7 @@ use Muzich\CoreBundle\Searcher\GlobalSearcher;
12 12
 use Muzich\CoreBundle\Entity\Element;
13 13
 use Muzich\CoreBundle\Entity\Presubscription;
14 14
 use Muzich\CoreBundle\Entity\User;
15
+use Muzich\CoreBundle\Entity\Playlist;
15 16
 use Muzich\CoreBundle\Security\Context as SecurityContext;
16 17
 use Muzich\CoreBundle\Managers\PlaylistManager;
17 18
 use Muzich\CoreBundle\Form\Playlist\PlaylistForm;
@@ -680,9 +681,12 @@ class Controller extends BaseController
680 681
       ->findOneById($element_id);
681 682
   }
682 683
   
683
-  protected function getPlaylistForm()
684
+  protected function getPlaylistForm(Playlist $playlist = null)
684 685
   {
685
-    return $this->createForm(new PlaylistForm(), $this->getPlaylistManager()->getNewPlaylist($this->getUserOrNullIfVisitor()));
686
+    if (!$playlist)
687
+      $playlist = $this->getPlaylistManager()->getNewPlaylist($this->getUserOrNullIfVisitor());
688
+    
689
+    return $this->createForm(new PlaylistForm(), $playlist);
686 690
   }
687 691
   
688 692
   protected function tokenIsCorrect($intention = '')

+ 39 - 0
src/Muzich/PlaylistBundle/Controller/EditController.php Bestand weergeven

@@ -156,4 +156,43 @@ class EditController extends Controller
156 156
     return $this->redirect($this->generateUrl('playlists_user', array('user_slug' => $this->getUser()->getSlug())));
157 157
   }
158 158
   
159
+  public function editAction($playlist_id)
160
+  {
161
+    if (!($playlist = $this->getPlaylistManager()->findOwnedPlaylistWithId($playlist_id, $this->getUser())))
162
+      throw $this->createNotFoundException();
163
+    
164
+    return $this->render('MuzichPlaylistBundle:Edit:edit.html.twig', array(
165
+      'form'          => $this->getPlaylistForm($playlist)->createView(),
166
+      'playlist'      => $playlist,
167
+      'playlist_name' => $playlist->getName()
168
+    ));
169
+  }
170
+  
171
+  public function updateAction(Request $request, $playlist_id)
172
+  {
173
+    if (!($playlist = $this->getPlaylistManager()->findOwnedPlaylistWithId($playlist_id, $this->getUser())))
174
+      throw $this->createNotFoundException();
175
+    
176
+    $playlist_name = $playlist->getName();
177
+    $form = $this->getPlaylistForm($playlist);
178
+    $form->bind($request);
179
+    if ($form->isValid())
180
+    {
181
+      $this->persist($form->getData());
182
+      $this->flush();
183
+      
184
+      $this->setFlash('success', 'playlist.update.success');
185
+      return $this->redirect($this->generateUrl('playlist', array(
186
+        'user_slug'   => $playlist->getOwner()->getSlug(),
187
+        'playlist_id' => $playlist->getId()
188
+      )));
189
+    }
190
+    
191
+    return $this->render('MuzichPlaylistBundle:Edit:edit.html.twig', array(
192
+      'form'          => $form->createView(),
193
+      'playlist'      => $playlist,
194
+      'playlist_name' => $playlist_name
195
+    ));
196
+  }
197
+  
159 198
 }

+ 8 - 0
src/Muzich/PlaylistBundle/Resources/config/routing.yml Bestand weergeven

@@ -6,6 +6,14 @@ playlist:
6 6
   pattern: /user/{user_slug}/playlist/{playlist_id}
7 7
   defaults: { _controller: MuzichPlaylistBundle:Show:show }
8 8
 
9
+playlist_edit:
10
+  pattern: /user/{user_slug}/playlist/{playlist_id}/edit
11
+  defaults: { _controller: MuzichPlaylistBundle:Edit:edit }
12
+  
13
+playlist_update:
14
+  pattern: /user/{user_slug}/playlist/{playlist_id}/update
15
+  defaults: { _controller: MuzichPlaylistBundle:Edit:update }
16
+
9 17
 playlist_delete:
10 18
   pattern: /playlist/delete/{playlist_id}/{token}
11 19
   defaults: { _controller: MuzichPlaylistBundle:Edit:delete }

+ 36 - 0
src/Muzich/PlaylistBundle/Resources/views/Edit/edit.html.twig Bestand weergeven

@@ -0,0 +1,36 @@
1
+{% extends "MuzichFavoriteBundle::layout.html.twig" %}
2
+
3
+{% block title %}{{ 'playlist.edit_title'|trans({'%playlist_name%' : playlist_name}, 'elements') }}{% endblock %}
4
+{% block mainbox_classes %}{% endblock %}
5
+
6
+{% block content %}
7
+  
8
+  <div class="top_tools">
9
+    <div class="show_options">
10
+      
11
+      <a class="button darkbutton" href="{{ path('playlist', {
12
+        'user_slug' : playlist.owner.slug,
13
+        'playlist_id' : playlist.id}
14
+      ) }}" >
15
+        {{ 'playlist.goback'|trans({}, 'elements') }}
16
+      </a>
17
+      
18
+    </div>
19
+    
20
+    <h1>
21
+        {{ 'playlist.edit_title'|trans({'%playlist_name%' : playlist_name}, 'elements') }}
22
+    </h1>
23
+    
24
+    <form class="playlist_edit" action="{{ path('playlist_update', {
25
+      'user_slug' : playlist.owner.slug,
26
+      'playlist_id' : playlist.id
27
+    }) }}" method="post">
28
+      {% include 'MuzichPlaylistBundle:Show:form.html.twig' with {
29
+        'display_public_widget' : false,
30
+        'submit_value'          : 'playlist.update_submit'|trans({}, 'elements')
31
+      } %}
32
+    </form>
33
+  
34
+  </div>
35
+  
36
+{% endblock %}

+ 12 - 6
src/Muzich/PlaylistBundle/Resources/views/Show/form.html.twig Bestand weergeven

@@ -1,14 +1,20 @@
1
+{% if submit_value is not defined %}
2
+  {% set submit_value = 'playlist.create_submit'|trans({}, 'elements') %}
3
+{% endif %}
4
+
1 5
 {{ form_errors(form) }}
2 6
 {{ form_errors(form.name) }}
3
-{{ form_errors(form.public) }}
4 7
 
5
-{{ form_widget(form.public) }}
6
-<label for="playlist_public">{{ 'playlist.public_label'|trans({}, 'elements') }}</label>
7
-  
8
+{% if display_public_widget %}
9
+  {{ form_errors(form.public) }}
10
+  {{ form_widget(form.public) }}
11
+  <label for="playlist_public">{{ 'playlist.public_label'|trans({}, 'elements') }}</label>
12
+{% endif %}
13
+
8 14
 <div class="field">
9 15
   {{ form_widget(form.name, {'attr':{'class':'niceinput'}}) }}
10
-  <input class="niceinput" type="submit" value="{{ 'playlist.create_submit'|trans({}, 'elements') }}" />
16
+  <input class="niceinput" type="submit"
17
+    value="{{ submit_value }}" />
11 18
 </div>
12 19
 
13
-
14 20
 {{ form_rest(form) }}

+ 3 - 1
src/Muzich/PlaylistBundle/Resources/views/Show/prompt.html.twig Bestand weergeven

@@ -6,7 +6,9 @@
6 6
 <div class="create_playlist">
7 7
   <h2 class="nomargintop">{{ 'playlist.create_and_add'|trans({}, 'elements') }}</h2>
8 8
   <form action="{{ path('playlist_add_element_and_create', { 'element_id' : element_id }) }}" method="post">
9
-    {% include 'MuzichPlaylistBundle:Show:form.html.twig' %}
9
+    {% include 'MuzichPlaylistBundle:Show:form.html.twig' with {
10
+      'display_public_widget' : true
11
+    } %}
10 12
   </form>
11 13
 </div>
12 14
 

+ 16 - 2
src/Muzich/PlaylistBundle/Resources/views/Show/show.html.twig Bestand weergeven

@@ -33,16 +33,30 @@
33 33
     </div>
34 34
     
35 35
     <h1>
36
+      {% if app.user %}
37
+        {% if playlist.owned(app.user) %}
38
+          <a
39
+             href="{{ path('playlist_edit', { 'user_slug' : playlist.owner.slug, 'playlist_id' : playlist.id }) }}"
40
+             title="{{ 'playlist.edit'|trans({}, 'elements') }}"
41
+          >
42
+            <img src="{{ asset('/img/icon_pen_black.png') }}" alt="edit" />
43
+          </a>
44
+        {% endif %}
45
+      {% endif %}
46
+        
36 47
       {{ playlist.name }}
37 48
       {% if playlist.public %}
38 49
         {{ 'playlist.public_word'|trans({}, 'elements') }}
39 50
       {% endif %}
40 51
     </h1>
41 52
     
42
-    {% if playlist.owned(app.user) %}
43
-      <p>{{ 'playlist.how_add_element'|trans({}, 'elements') }}</p>
53
+    {% if app.user %}
54
+      {% if playlist.owned(app.user) %}
55
+        <p>{{ 'playlist.how_add_element'|trans({}, 'elements') }}</p>
56
+      {% endif %}
44 57
     {% endif %}
45 58
     
59
+    
46 60
     {% include "MuzichCoreBundle:Tag:tag_cloud.html.twig" with {
47 61
       'tags' : playlist.tags
48 62
     } %}