Browse Source

Evolution #89: Modifier / Supprimer ses éléments

bastien 12 years ago
parent
commit
ad99da4d5a

+ 2 - 0
app/Resources/translations/elements.fr.yml View File

@@ -22,6 +22,8 @@ element:
22 22
     who:                (envoyé par <a href="%owner_url%">%owner_name%</a>)
23 23
     whoandgroup:        (envoyé par <a href="%owner_url%">%owner_name%</a> dans le groupe <a href="%group_url%">%group_name%</a>)
24 24
   link:                 Ouvrir la page d'origine
25
+  edit:
26
+    link:               Modifier
25 27
   
26 28
 elements:
27 29
   ajax:

+ 6 - 0
app/Resources/translations/userui.fr.yml View File

@@ -46,6 +46,12 @@ element_add:
46 46
               que vous souhaitez partager.
47 47
   name:
48 48
     name:     Nom
49
+  
50
+element_edit:
51
+  url:
52
+    name:     Lien
53
+  name:
54
+    name:     Nom
49 55
     
50 56
 tags_filter:
51 57
   help:       Pour ne pas filtrer avec des tags, supprimez les tous de la liste.

+ 57 - 0
src/Muzich/CoreBundle/Controller/ElementController.php View File

@@ -0,0 +1,57 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Controller;
4
+
5
+use Muzich\CoreBundle\lib\Controller;
6
+
7
+class ElementController extends Controller
8
+{
9
+  
10
+  /**
11
+   * 
12
+   */
13
+  public function editAction($element_id)
14
+  {
15
+    if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
16
+      ->findOneById($element_id)))
17
+    {
18
+      $this->createNotFoundException();
19
+    }
20
+    
21
+    if ($element->getOwner()->getId() != $this->getUserId())
22
+    {
23
+      $this->createNotFoundException();
24
+    }
25
+    
26
+    $element_tags = $element->getTags();
27
+    $element->setTags(array());
28
+    $form = $this->getAddForm($element);
29
+    
30
+    $search_tags = array();
31
+    foreach ($element_tags as $tag)
32
+    {
33
+      $search_tags[$tag->getId()] = $tag->getName();
34
+    }
35
+    
36
+    $html = $this->render('MuzichCoreBundle:Element:element.edit.html.twig', array(
37
+      'form'        => $form->createView(),
38
+      'form_name'   => $form->getName(),
39
+      'element_id'  => $element->getId(),
40
+      'search_tags' => $search_tags
41
+    ))->getContent();
42
+    
43
+    return $this->jsonResponse(array(
44
+      'status' => 'success',
45
+      'html'   => $html
46
+    ));
47
+  }
48
+  
49
+  /**
50
+   *
51
+   */
52
+  public function updateAction()
53
+  {
54
+    return array();
55
+  }
56
+  
57
+}

+ 11 - 15
src/Muzich/CoreBundle/Resources/config/routing.yml View File

@@ -8,20 +8,6 @@ search_elements_more:
8 8
   pattern:  /search-elements/{id_limit}/{invertcolors}
9 9
   defaults: { _controller: MuzichCoreBundle:Search:searchElements }
10 10
    
11
-#search_elements_show_more_empty:
12
-#  pattern:  /search-elements/show/{type}/{object_id}
13
-#  defaults: 
14
-#    - _controller: MuzichCoreBundle:Search:searchElementsShow
15
-#    - type:        group|user
16
-#    - object_id:   int+
17
-#    
18
-#search_elements_show_more:
19
-#  pattern:  /search-elements/show/{type}/{object_id}/{id_limit}/{invertcolors}
20
-#  defaults: 
21
-#    - _controller: MuzichCoreBundle:Search:searchElementsShow
22
-#    - type:        group|user
23
-#    - object_id:   int+
24
-   
25 11
 search_elements_show_more_empty:
26 12
   pattern:  /search-elements/show/{type}/{object_id}
27 13
   defaults: { _controller: MuzichCoreBundle:Search:searchElementsShow }
@@ -62,4 +48,14 @@ info_about:
62 48
   
63 49
 info_development:
64 50
   pattern: /info/development
65
-  defaults: { _controller: MuzichCoreBundle:Info:development }
51
+  defaults: { _controller: MuzichCoreBundle:Info:development }
52
+  
53
+####
54
+
55
+element_edit:
56
+  pattern: /element/{element_id}/edit
57
+  defaults: { _controller: MuzichCoreBundle:Element:edit }
58
+
59
+element_update:
60
+  pattern: /element/{element_id}/update
61
+  defaults: { _controller: MuzichCoreBundle:Element:update }

+ 9 - 0
src/Muzich/CoreBundle/Resources/views/Element/element.edit.html.twig View File

@@ -0,0 +1,9 @@
1
+<form name="{{ form_name }}" action="{{ path('element_update', {'element_id': element_id}) }}" method="post" {{ form_enctype(form) }}>
2
+
3
+  {% include "MuzichCoreBundle:Element:form.edit.html.twig" with { 
4
+    'form'          : form, 
5
+    'form_name'     : form_name
6
+  } %}
7
+
8
+  <input type="submit" />
9
+</form>

+ 21 - 0
src/Muzich/CoreBundle/Resources/views/Element/form.edit.html.twig View File

@@ -0,0 +1,21 @@
1
+{% form_theme form 'MuzichCoreBundle:Form:errors.html.twig' %}
2
+
3
+{{ form_errors(form) }}
4
+
5
+<div class="field">
6
+  {{ form_errors(form.url) }}
7
+  {{ form_label(form.url, 'element_edit.url.name'|trans({}, 'userui')) }}
8
+  {{ form_widget(form.url) }}
9
+</div>
10
+
11
+<div class="field">
12
+  {{ form_errors(form.name) }}
13
+  {{ form_label(form.name, 'element_edit.name.name'|trans({}, 'userui')) }}
14
+  {{ form_widget(form.name) }}
15
+</div>
16
+
17
+  {% include "MuzichCoreBundle:Tag:tagsPrompt.html.twig" with { 'form_name': form_name } %}
18
+
19
+  {{ form_row(form.tags) }}
20
+
21
+{{ form_row(form._token) }}

+ 8 - 0
src/Muzich/CoreBundle/Resources/views/SearchElement/default.html.twig View File

@@ -57,6 +57,14 @@
57 57
           <img src="{{ asset('bundles/muzichcore/img/1324917097_link.png') }}" alt="link" />
58 58
         </a>
59 59
           
60
+        {% if app.user.id == element.owner.id %}
61
+          <a title="{{ 'element.edit.link'|trans({}, 'elements') }}" class="element_edit_link" 
62
+             href="{{ path('element_edit', {'element_id' : element.id})  }}" style="display: none;"
63
+          >
64
+            <img src="{{ asset('bundles/muzichcore/img/1327151338_desktop.png') }}" alt="edit" />
65
+          </a>
66
+        {% endif %}
67
+            
60 68
         {% if element.embed %}
61 69
           {% autoescape false %}
62 70
             <div id="embed_{{ element.id }}" class="element_embed" style="display: none;">

BIN
web/bundles/muzichcore/img/1327151338_desktop.png View File


+ 25 - 1
web/bundles/muzichcore/js/muzich.js View File

@@ -212,7 +212,31 @@ $(document).ready(function(){
212 212
      });
213 213
      return false;
214 214
   });
215
-   
215
+    
216
+  // Affichage du bouton Modifier
217
+  $('ul.elements li.element').live({
218
+    mouseenter:
219
+      function()
220
+      {
221
+        $(this).find('a.element_edit_link').show();
222
+      },
223
+    mouseleave:
224
+      function()
225
+      {
226
+        $(this).find('a.element_edit_link').hide();
227
+      }
228
+    }
229
+  );
230
+
231
+ // Ouverture du formulaire de modification
232
+ $('a.element_edit_link').live('click', function(){
233
+   link = $(this);
234
+   $.getJSON($(this).attr('href'), function(response) {
235
+     li = link.parent('li.element');
236
+     li.html(response.html);
237
+   });
238
+   return false;
239
+ });
216 240
    
217 241
    // Plus d'éléments
218 242
    last_id = null;