Przeglądaj źródła

Evolution #145: Tags d'élément

bastien 13 lat temu
rodzic
commit
af14cbff2f

+ 8 - 1
app/Resources/translations/elements.fr.yml Wyświetl plik

@@ -30,6 +30,13 @@ element:
30 30
       sentence:         Vraiment supprimer ?
31 31
       yes:              Oui
32 32
       no:               Non
33
+  tag:
34
+    addtofav:
35
+      title:            Ajouter a vos tags favoris
36
+      confirm:
37
+        sentence:       Ajouter aux favoris ?
38
+        yes:            Oui
39
+        no:             Non
33 40
   comments: 
34 41
     add:                Ajouter un commentaire
35 42
     thereis:            Afficher le commentaire
@@ -68,4 +75,4 @@ show:
68 75
       x_count:          %count% personnes suivent %name%
69 76
     elements:
70 77
       no_count:         Aucun partage
71
-      count:            %count_owned% partages (dont %count_favorited% mis en favoris par %count_favorited_users% utilisateurs)
78
+      count:            %count_owned% partages (dont %count_favorited% mis en favoris par %count_favorited_users% utilisateurs)

+ 36 - 0
src/Muzich/CoreBundle/Controller/CoreController.php Wyświetl plik

@@ -15,6 +15,7 @@ use Muzich\CoreBundle\Form\Search\ElementSearchForm;
15 15
 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
16 16
 use Muzich\CoreBundle\Entity\Tag;
17 17
 use Muzich\CoreBundle\Managers\TagManager;
18
+use Muzich\CoreBundle\Entity\UsersTagsFavorites;
18 19
 
19 20
 class CoreController extends Controller
20 21
 {
@@ -382,4 +383,39 @@ class CoreController extends Controller
382 383
     ));
383 384
   }
384 385
   
386
+  public function addTagToFavoritesAction($tag_id, $token)
387
+  {
388
+    if (($response = $this->mustBeConnected(true)))
389
+    {
390
+      return $response;
391
+    }
392
+    
393
+    if (!($tag = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')
394
+      ->findOneById($tag_id)) || $this->getUser()->getPersonalHash() != $token)
395
+    {
396
+      return $this->jsonResponse(array(
397
+        'status' => 'error',
398
+        'errors' => array('NotFound')
399
+      ));
400
+    }
401
+    
402
+    if (!$this->getDoctrine()->getRepository('MuzichCoreBundle:UsersTagsFavorites')
403
+      ->findOneBy(array(
404
+        'user' => $this->getUserId(),
405
+        'tag'  => $tag->getId()
406
+      )))
407
+    {
408
+      $fav = new UsersTagsFavorites();
409
+      $fav->setTag($tag);
410
+      $fav->setUser($this->getUser());
411
+      $fav->setPosition(0);
412
+      $this->getDoctrine()->getEntityManager()->persist($fav);
413
+      $this->getDoctrine()->getEntityManager()->flush();
414
+    }
415
+    
416
+    return $this->jsonResponse(array(
417
+      'status' => 'success'
418
+    ));
419
+  }
420
+  
385 421
 }

+ 6 - 1
src/Muzich/CoreBundle/Resources/config/routing.yml Wyświetl plik

@@ -88,4 +88,9 @@ element_new_count:
88 88
 element_new_get:
89 89
   pattern: /ajax/element/new/get/{refid}
90 90
   defaults: { _controller: MuzichCoreBundle:Element:getNews, refid: null }
91
-  
91
+  
92
+##
93
+
94
+ajax_tag_add_to_favorites:
95
+  pattern: /ajax/tag/add-to-favorites/{tag_id}/{token}
96
+  defaults: { _controller: MuzichCoreBundle:Core:addTagToFavorites }

+ 11 - 0
src/Muzich/CoreBundle/Resources/views/SearchElement/element.html.twig Wyświetl plik

@@ -102,6 +102,17 @@
102 102
         {% for tag in element.tags %} 
103 103
           <li class="element_tag">
104 104
             <a href="#{{ tag.id }}" class="element_tag button">{{ tag.name }}</a>
105
+            <a 
106
+              href="{{ path('ajax_tag_add_to_favorites', {
107
+                'tag_id' : tag.id,
108
+                'token'  : app.user.getPersonalHash
109
+              }) }}" 
110
+              class="tag_to_favorites" 
111
+              style="display: none;"
112
+              title="{{ 'element.tag.addtofav.title'|trans({}, 'elements') }}"   
113
+            >
114
+              <img src="{{ asset('/bundles/muzichcore/img/1331734087_emblem-favorite.png') }}" alt="add-to-favorites"/>
115
+            </a>
105 116
           </li>
106 117
         {% endfor %} 
107 118
       </ul>

+ 3 - 0
src/Muzich/CoreBundle/Resources/views/layout.html.twig Wyświetl plik

@@ -40,6 +40,9 @@
40 40
     string_comment_delete_confirm_sentence = "{{ 'comment.remove.confirm.sentence'|trans({}, 'elements') }}";
41 41
     string_comment_delete_confirm_yes = "{{ 'comment.remove.confirm.yes'|trans({}, 'elements') }}";
42 42
     string_comment_delete_confirm_no = "{{ 'comment.remove.confirm.no'|trans({}, 'elements') }}";
43
+    string_tag_addtofav_confirm_sentence = "{{ 'element.tag.addtofav.confirm.sentence'|trans({}, 'elements') }}";
44
+    string_tag_addtofav_confirm_yes = "{{ 'element.tag.addtofav.confirm.yes'|trans({}, 'elements') }}";
45
+    string_tag_addtofav_confirm_no = "{{ 'element.tag.addtofav.confirm.no'|trans({}, 'elements') }}";
43 46
     
44 47
     url_index = "{{ path('index') }}";
45 48
     url_search_tag = "{{ path('search_tag') }}";

+ 16 - 1
web/bundles/muzichcore/css/main.css Wyświetl plik

@@ -1005,4 +1005,19 @@ div.comments_loader
1005 1005
   text-align: center;
1006 1006
 }
1007 1007
 
1008
-/* END commentaires */
1008
+/* END commentaires */
1009
+
1010
+/* Ajouter tag d'élément a ses tags favoris */
1011
+
1012
+li.element a.tag_to_favorites
1013
+{
1014
+  margin-left: -15px;
1015
+  margin-right: 4px;
1016
+}
1017
+
1018
+li.element a.element_tag_large_for_fav
1019
+{
1020
+  padding-right: 15px;
1021
+}
1022
+
1023
+/* END Ajouter tag d'élément a ses tags favoris */

BIN
web/bundles/muzichcore/img/1331734087_emblem-favorite.png Wyświetl plik


+ 52 - 0
web/bundles/muzichcore/js/muzich.js Wyświetl plik

@@ -1510,5 +1510,57 @@ $(document).ready(function(){
1510 1510
     li.html(comments_edited[li.attr('id')]);
1511 1511
     delete(comments_edited[li.attr('id')]);
1512 1512
   });
1513
+  
1514
+  /*
1515
+   * Ajout d'un tag en favoris a partir d'un élément
1516
+   */
1517
+  
1518
+  $('li.element_tag').live({
1519
+      mouseenter:
1520
+        function()
1521
+        {
1522
+          $(this).find('a.tag_to_favorites').show();
1523
+          $(this).find('a.element_tag').addClass('element_tag_large_for_fav');
1524
+        },
1525
+      mouseleave:
1526
+        function()
1527
+        {
1528
+          if (!$(this).find('a.tag_to_favorites').hasClass('mustBeDisplayed'))
1529
+          {
1530
+            $(this).find('a.tag_to_favorites').hide();
1531
+            $(this).find('a.element_tag').removeClass('element_tag_large_for_fav');
1532
+          }
1533
+        }
1534
+      }
1535
+    );
1536
+      
1537
+  $('a.tag_to_favorites').jConfirmAction({
1538
+    question : string_tag_addtofav_confirm_sentence, 
1539
+    yesAnswer : string_tag_addtofav_confirm_yes, 
1540
+    cancelAnswer : string_tag_addtofav_confirm_no,
1541
+    onYes: function(link){
1542
+      
1543
+      $.getJSON(link.attr('href'), function(response){
1544
+        
1545
+        if (response.status == 'mustbeconnected')
1546
+        {
1547
+          $(location).attr('href', url_index);
1548
+        }
1549
+      });
1550
+      
1551
+      $('div.question').fadeOut();
1552
+      return false;
1553
+    },
1554
+    onOpen: function(link){
1555
+      li = link.parent('li.element_tag');
1556
+      li.find('a.tag_to_favorites').addClass('mustBeDisplayed');
1557
+    },
1558
+    onClose: function(link){
1559
+      li = link.parent('li.element_tag');
1560
+      li.find('a.tag_to_favorites').removeClass('mustBeDisplayed');
1561
+      li.find('a.element_tag').removeClass('element_tag_large_for_fav');
1562
+      li.find('a.tag_to_favorites').hide();
1563
+    }
1564
+  });
1513 1565
    
1514 1566
  });