Browse Source

Evolution #107: Evolution ergonomiques

bastien 12 years ago
parent
commit
81cd73b37c

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

@@ -64,6 +64,14 @@ element_add:
64 64
               que vous souhaitez partager.
65 65
   name:
66 66
     name:     Nom
67
+    
68
+  added_to_group:
69
+    sentence:       |
70
+                     L'élément que vous venez d'ajouter semble correspondre
71
+                     a un des groupes que vous gérez. Cliquez sur le nom d'un groupe
72
+                     pour diffuser cet élément dans le groupe.
73
+                     
74
+    nothanks:       Non, ne pas diffuser cet élément dans un de mes groupes
67 75
   
68 76
 element_edit:
69 77
   url:

+ 83 - 6
src/Muzich/CoreBundle/Controller/CoreController.php View File

@@ -161,7 +161,7 @@ class CoreController extends Controller
161 161
       throw $this->createNotFoundException('Cette ressource n\'est pas accessible');
162 162
     }
163 163
     
164
-    $user = $this->getUser();
164
+    $user = $this->getUser(true, array('join' => array('groups_owned_groups_tags')));
165 165
     $em = $this->getDoctrine()->getEntityManager();
166 166
     
167 167
     /*
@@ -235,14 +235,11 @@ class CoreController extends Controller
235 235
             'no_group_name' => true
236 236
           ))->getContent();
237 237
         }
238
-
239
-        
240
-        
241
-        
242 238
         
243 239
         return $this->jsonResponse(array(
244 240
           'status' => 'success',
245
-          'html'   => $html
241
+          'html'   => $html,
242
+          'groups' => (!$group)?$this->isAddedElementCanBeInGroup($element):array()
246 243
         ));
247 244
       }
248 245
       else
@@ -333,6 +330,40 @@ class CoreController extends Controller
333 330
     
334 331
   }
335 332
   
333
+  /**
334
+   * Cette méthode vérifie si l'élément qui vient d'être envoyé pourrais être
335
+   * associé a un groupe de l'utilisateur.
336
+   * 
337
+   * @param Element $element
338
+   * @return array
339
+   */
340
+  protected function isAddedElementCanBeInGroup(Element $element)
341
+  {
342
+    $element_tags = $element->getTags();
343
+    $groups = array();
344
+    foreach ($this->getUser()->getGroupsOwned() as $group)
345
+    {
346
+      foreach ($element_tags as $element_tag)
347
+      {
348
+        if ($group->hasThisTag($element_tag->getId()))
349
+        {
350
+          $groups[] = array(
351
+            'name' => $group->getName(),
352
+            'id'   => $group->getId(),
353
+            'url'  => $this->generateUrl('ajax_set_element_group', array(
354
+              'token'      => $this->getUser()->getPersonalHash(),
355
+              'element_id' => $element->getId(),
356
+              'group_id'   => $group->getId()
357
+            ))
358
+          );
359
+        }
360
+    
361
+      }
362
+    }
363
+    
364
+    return $groups;
365
+  }
366
+  
336 367
   public function filterClearAction()
337 368
   {
338 369
     $es = $this->getElementSearcher();
@@ -431,4 +462,50 @@ class CoreController extends Controller
431 462
     ));
432 463
   }
433 464
   
465
+  public function setElementGroupAction($element_id, $group_id, $token)
466
+  {
467
+    if (($response = $this->mustBeConnected(true)))
468
+    {
469
+      return $response;
470
+    }
471
+    
472
+    if (!($element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
473
+      ->findOneById($element_id)) 
474
+      || !($group = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
475
+      ->findOneById($group_id)) 
476
+      || $this->getUser()->getPersonalHash() != $token)
477
+    {
478
+      return $this->jsonResponse(array(
479
+        'status' => 'error',
480
+        'errors' => array('NotFound')
481
+      ));
482
+    }
483
+    
484
+    if ($element->getOwner()->getId() != $this->getUserId()
485
+      || $group->getOwner()->getId() != $this->getUserId()
486
+    )
487
+    {
488
+      return $this->jsonResponse(array(
489
+        'status' => 'error',
490
+        'errors' => array('NotAllowed')
491
+      ));
492
+    }
493
+    
494
+    // a partir d'ici on a tout ce qu'il faut
495
+    $element->setGroup($group);
496
+    $this->getDoctrine()->getEntityManager()->persist($element);
497
+    $this->getDoctrine()->getEntityManager()->flush();
498
+    
499
+    // On récupère le nouveau dom de l'élément
500
+    $html = $this->render('MuzichCoreBundle:SearchElement:element.html.twig', array(
501
+      'element'     => $element
502
+    ))->getContent();
503
+    
504
+    return $this->jsonResponse(array(
505
+      'status' => 'success',
506
+      'html'   => $html,
507
+      'dom_id' => 'element_'.$element->getId()
508
+    ));
509
+  }
510
+  
434 511
 }

+ 12 - 0
src/Muzich/CoreBundle/Entity/Group.php View File

@@ -375,4 +375,16 @@ class Group
375 375
     
376 376
     return false;
377 377
   }
378
+  
379
+  public function hasThisTag($tag_id)
380
+  {
381
+    foreach ($this->tags as $tag)
382
+    {
383
+      if ($tag_id == $tag->getTag()->getId())
384
+      {
385
+        return true;
386
+      }
387
+    }
388
+    return false;
389
+  }
378 390
 }

+ 6 - 0
src/Muzich/CoreBundle/Repository/UserRepository.php View File

@@ -52,6 +52,12 @@ class UserRepository extends EntityRepository
52 52
       $join   .= ' LEFT JOIN u.groups_owned og';
53 53
     }
54 54
     
55
+    if (in_array('groups_owned_groups_tags', $join_list))
56
+    {
57
+      $select .= ', og, ogt';
58
+      $join   .= ' LEFT JOIN u.groups_owned og LEFT JOIN og.tags ogt';
59
+    }
60
+    
55 61
     return $this->getEntityManager()
56 62
       ->createQuery("
57 63
         SELECT $select FROM MuzichCoreBundle:User u

+ 5 - 0
src/Muzich/CoreBundle/Resources/config/routing.yml View File

@@ -94,3 +94,8 @@ element_new_get:
94 94
 ajax_tag_add_to_favorites:
95 95
   pattern: /ajax/tag/add-to-favorites/{tag_id}/{token}
96 96
   defaults: { _controller: MuzichCoreBundle:Core:addTagToFavorites }
97
+
98
+ajax_set_element_group:
99
+  pattern: /ajax/element/set-group/{element_id}/{group_id}/{token}
100
+  defaults: { _controller: MuzichCoreBundle:Core:setElementGroup }
101
+  

+ 13 - 0
src/Muzich/HomeBundle/Resources/views/Home/index.html.twig View File

@@ -22,6 +22,19 @@
22 22
     </form>
23 23
   </div>
24 24
 
25
+  <div id="added_element_to_group" style="display: none;">
26
+    <img class="loader" style="display: none;" src="{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}" alt="loading" />
27
+    <p class="help">
28
+      {{ 'element_add.added_to_group.sentence'|trans({}, 'userui') }}
29
+    </p>
30
+    <ul id="groups_to_add_element"></ul>
31
+    <p class="cancel">
32
+      <a href="" class="cancel">
33
+        {{ 'element_add.added_to_group.nothanks'|trans({}, 'userui') }}
34
+      </a>
35
+    </p>
36
+  </div>
37
+
25 38
   <a href="#" id="element_add_link" class="button">
26 39
     {{ 'home.add_element'|trans({}, 'navigationui') }} &gt;&gt;
27 40
   </a>

+ 8 - 0
web/bundles/muzichcore/css/main.css View File

@@ -1021,3 +1021,11 @@ li.element a.element_tag_large_for_fav
1021 1021
 }
1022 1022
 
1023 1023
 /* END Ajouter tag d'élément a ses tags favoris */
1024
+
1025
+div#added_element_to_group
1026
+{
1027
+  background-color: #E3F6FD;
1028
+  padding: 20px;
1029
+  font-size: 115%;
1030
+  font-weight: bold;
1031
+}

+ 65 - 3
web/bundles/muzichcore/js/muzich.js View File

@@ -1021,7 +1021,7 @@ $(document).ready(function(){
1021 1021
     }
1022 1022
   });
1023 1023
 
1024
-  // Ajout d'un element
1024
+  // Ajout d'un element #ajouter
1025 1025
   $('form[name="add"] input[type="submit"]').live('click', function(){
1026 1026
     $('form[name="add"]').find('img.tag_loader').show();
1027 1027
   });
@@ -1037,14 +1037,40 @@ $(document).ready(function(){
1037 1037
       $('form[name="add"]').find('ul.error_list').remove();
1038 1038
       $('ul.elements').prepend(response.html);
1039 1039
       $('form[name="add"] input[type="text"]').val('');
1040
-      $('div#element_add_box').slideUp();
1041
-      $('a#element_add_link').show();
1040
+      
1042 1041
       if ($('form[name="search"]').length)
1043 1042
       {
1044 1043
         $('form[name="search"]').slideDown();
1045 1044
       }
1046 1045
       remove_tags('add');
1047 1046
       recolorize_element_list();
1047
+      
1048
+      $('div#element_add_box').slideUp();
1049
+      
1050
+      if (response.groups.length)
1051
+      {
1052
+        // Des groupes sont proposés pour diffuser cet élément
1053
+        $('div#added_element_to_group').slideDown();
1054
+        for (i in response.groups)
1055
+        {
1056
+          var group = response.groups[i];
1057
+          $('ul#groups_to_add_element').html('');
1058
+          $('ul#groups_to_add_element')
1059
+            .append($('<li>')
1060
+              .append($('<a>')
1061
+                .addClass('added_element_add_to_group')
1062
+                .attr('href', group.url)
1063
+                .append(group.name)
1064
+              )
1065
+            )
1066
+          ;
1067
+        }
1068
+      }
1069
+      else
1070
+      {
1071
+        $('a#element_add_link').show();
1072
+      }
1073
+      
1048 1074
     }
1049 1075
     else if (response.status == 'error')
1050 1076
     {
@@ -1562,5 +1588,41 @@ $(document).ready(function(){
1562 1588
       li.find('a.tag_to_favorites').hide();
1563 1589
     }
1564 1590
   });
1591
+  
1592
+  /*
1593
+   * Ajout dans un groupe de l'élément envoyé 
1594
+   */
1595
+  
1596
+  $('a.added_element_add_to_group').live('click', function(){
1597
+    
1598
+    div = $(this).parent('li').parent('ul').parent('div');
1599
+    div.find('img.loader').show();
1600
+    
1601
+    $.getJSON($(this).attr('href'), function(response) {
1602
+      
1603
+      div.find('img.loader').hide();
1604
+    
1605
+      if (response.status == 'mustbeconnected')
1606
+      {
1607
+        $(location).attr('href', url_index);
1608
+      }
1609
+      
1610
+      if (response.status == 'success')
1611
+      {
1612
+        $('li#'+response.dom_id).html(response.html);
1613
+      }
1614
+      
1615
+      $('div#added_element_to_group').slideUp();
1616
+      $('a#element_add_link').show();
1617
+      
1618
+    });
1619
+    return false;
1620
+  });
1621
+  
1622
+  $('div#added_element_to_group a.cancel').live('click', function(){
1623
+    $('div#added_element_to_group').slideUp();
1624
+    $('a#element_add_link').show();
1625
+    return false;
1626
+  });
1565 1627
    
1566 1628
  });