Explorar el Código

Evolution #115: Ajax sur tag et filtre

bastien hace 12 años
padre
commit
87f7569c77

+ 25 - 0
src/Muzich/CoreBundle/Controller/CoreController.php Ver fichero

@@ -324,4 +324,29 @@ class CoreController extends Controller
324 324
     return $this->redirect($this->container->get('request')->headers->get('referer'));
325 325
   }
326 326
   
327
+  public function getFavoriteTagsAction()
328
+  {
329
+    if ($this->getUser() == 'anon.')
330
+    {
331
+      if ($this->getRequest()->isXmlHttpRequest())
332
+      {
333
+        return $this->jsonResponse(array(
334
+          'status' => 'mustbeconnected'
335
+        ));
336
+      }
337
+      else
338
+      {
339
+        return $this->redirect($this->generateUrl('index'));
340
+      }
341
+    }
342
+    
343
+    // On construit l'element searcher avec les tags favoris
344
+    $es = $this->getElementSearcher(null, true);
345
+    // Et on retourne les tags
346
+    return $this->jsonResponse(array(
347
+      'response' => 'success',
348
+      'tags'     => $es->getTags()
349
+    ));
350
+  }
351
+  
327 352
 }

+ 5 - 0
src/Muzich/CoreBundle/Resources/config/routing.yml Ver fichero

@@ -40,6 +40,10 @@ filter_mytags:
40 40
   pattern: /filter/my-tags
41 41
   defaults: { _controller: MuzichCoreBundle:Core:filterMytags }
42 42
 
43
+ajax_get_favorites_tags:
44
+  pattern: /ajax/my-favorites-tags
45
+  defaults: { _controller: MuzichCoreBundle:Core:getFavoriteTags }
46
+
43 47
 ####
44 48
 
45 49
 info_about:
@@ -67,4 +71,5 @@ element_update:
67 71
 element_remove:
68 72
   pattern: /element/{element_id}/remove
69 73
   defaults: { _controller: MuzichCoreBundle:Element:remove }
74
+  
70 75
   

+ 1 - 0
src/Muzich/CoreBundle/Resources/config/security.yml Ver fichero

@@ -75,6 +75,7 @@ security:
75 75
         - { path: ^/(?:fr|en)/show/user/, role: IS_AUTHENTICATED_ANONYMOUSLY }
76 76
         - { path: ^/(?:fr|en)/show/group/, role: IS_AUTHENTICATED_ANONYMOUSLY }
77 77
         - { path: ^/(?:fr|en)/favoritesajax, role: IS_AUTHENTICATED_ANONYMOUSLY }
78
+        - { path: ^/(?:fr|en)/ajax, role: IS_AUTHENTICATED_ANONYMOUSLY }
78 79
                                 
79 80
         - { path: ^/, roles: ROLE_USER }
80 81
         

+ 1 - 0
src/Muzich/CoreBundle/Resources/views/layout.html.twig Ver fichero

@@ -31,6 +31,7 @@
31 31
     
32 32
     url_index = "{{ path('index') }}";
33 33
     url_search_tag = "{{ path('search_tag') }}";
34
+    url_get_favorites_tags = "{{ path('ajax_get_favorites_tags') }}";
34 35
   </script>
35 36
   {% block js %}{% endblock %}
36 37
   

+ 39 - 8
web/bundles/muzichcore/js/muzich.js Ver fichero

@@ -185,15 +185,15 @@ function explode (delimiter, string, limit) {
185 185
     // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
186 186
     // *     example 2: explode('=', 'a=bc=d', 2);
187 187
     // *     returns 2: ['a', 'bc=d']
188
-    var emptyArray = {        0: ''
188
+    var emptyArray = {0: ''
189 189
     };
190 190
  
191 191
     // third argument is not required
192
-    if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined') {        return null;
192
+    if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined') {return null;
193 193
     }
194 194
  
195 195
     if (delimiter === '' || delimiter === false || delimiter === null) {
196
-        return false;    }
196
+        return false;}
197 197
  
198 198
     if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
199 199
         return emptyArray;
@@ -205,7 +205,7 @@ function explode (delimiter, string, limit) {
205 205
         return string.toString().split(delimiter.toString());
206 206
     }
207 207
     // support for limit argument
208
-    var splitted = string.toString().split(delimiter.toString());    var partA = splitted.splice(0, limit - 1);
208
+    var splitted = string.toString().split(delimiter.toString());var partA = splitted.splice(0, limit - 1);
209 209
     var partB = splitted.join(delimiter.toString());
210 210
     partA.push(partB);
211 211
     return partA;
@@ -242,12 +242,43 @@ $(document).ready(function(){
242 242
   }
243 243
   
244 244
   // Bouton de personalisation du filtre
245
-  // pour le moment ce ne sotn que des redirection vers des actions
246 245
   $('.tags_prompt input.clear, a.filter_clear_url').live("click", function(){
247
-    $(location).attr('href', $('input.filter_clear_url').val());
246
+    $('img.elements_more_loader').show();
247
+    $('ul.elements').html('');
248
+    form = $(this).parent('div').parent('form');
249
+    remove_tags(form.attr('name'));
250
+    form.submit();
248 251
   });
249 252
   $('.tags_prompt input.mytags').live("click", function(){
250
-    $(location).attr('href', $('input.filter_mytags_url').val());
253
+    
254
+    $('img.elements_more_loader').show();
255
+    $('ul.elements').html('');
256
+    
257
+    form = $(this).parent('div').parent('form');
258
+    
259
+    $.getJSON(url_get_favorites_tags, function(response) {
260
+      if (response.status == 'mustbeconnected')
261
+      {
262
+        $(location).attr('href', url_index);
263
+      }
264
+      
265
+      remove_tags(form.attr('name'));
266
+//      if (tags.length)
267
+//      {
268
+        inputTag = $("div#tags_prompt_"+form.attr('name')+" input.form-default-value-processed");
269
+        for (i in response.tags)
270
+        {
271
+          $('input#tags_selected_tag_'+form.attr('name')).val(i);
272
+          inputTag.val(response.tags[i]);
273
+                                        
274
+          // Et on execute l'évènement selectTag de l'input
275
+          inputTag.trigger("selectTag");
276
+        }
277
+        
278
+        form.submit();
279
+      //}
280
+      
281
+    });
251 282
   });
252 283
 
253 284
   // Affichage un/des embed
@@ -659,7 +690,7 @@ $(document).ready(function(){
659 690
                       id = $(this).attr('href').substr(1,$(this).attr('href').length);
660 691
                       id = str_replace(name, '', id);
661 692
                       id = str_replace('#', '', id);
662
-                                            
693
+                                     
663 694
                       $('input#tags_selected_tag_'+form_name).val(id);
664 695
                       inputTag.val(name);
665 696
                       // Et on execute l'évènement selectTag de l'input

+ 1 - 1
web/js/tags/jquery.tagBox.js Ver fichero

@@ -56,7 +56,7 @@
56 56
         });
57 57
         
58 58
         self.tagInput.bind("selectTag", function(event) {
59
-          
59
+                    
60 60
           if(!$(this).val()) {
61 61
               return;
62 62
           }