Browse Source

Evolution #115: Ajax sur tag et filtre

bastien 13 years ago
parent
commit
87f7569c77

+ 25 - 0
src/Muzich/CoreBundle/Controller/CoreController.php View File

324
     return $this->redirect($this->container->get('request')->headers->get('referer'));
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 View File

40
   pattern: /filter/my-tags
40
   pattern: /filter/my-tags
41
   defaults: { _controller: MuzichCoreBundle:Core:filterMytags }
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
 info_about:
49
 info_about:
67
 element_remove:
71
 element_remove:
68
   pattern: /element/{element_id}/remove
72
   pattern: /element/{element_id}/remove
69
   defaults: { _controller: MuzichCoreBundle:Element:remove }
73
   defaults: { _controller: MuzichCoreBundle:Element:remove }
74
+  
70
   
75
   

+ 1 - 0
src/Muzich/CoreBundle/Resources/config/security.yml View File

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

+ 1 - 0
src/Muzich/CoreBundle/Resources/views/layout.html.twig View File

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

+ 39 - 8
web/bundles/muzichcore/js/muzich.js View File

185
     // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
185
     // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
186
     // *     example 2: explode('=', 'a=bc=d', 2);
186
     // *     example 2: explode('=', 'a=bc=d', 2);
187
     // *     returns 2: ['a', 'bc=d']
187
     // *     returns 2: ['a', 'bc=d']
188
-    var emptyArray = {        0: ''
188
+    var emptyArray = {0: ''
189
     };
189
     };
190
  
190
  
191
     // third argument is not required
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
     if (delimiter === '' || delimiter === false || delimiter === null) {
195
     if (delimiter === '' || delimiter === false || delimiter === null) {
196
-        return false;    }
196
+        return false;}
197
  
197
  
198
     if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
198
     if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
199
         return emptyArray;
199
         return emptyArray;
205
         return string.toString().split(delimiter.toString());
205
         return string.toString().split(delimiter.toString());
206
     }
206
     }
207
     // support for limit argument
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
     var partB = splitted.join(delimiter.toString());
209
     var partB = splitted.join(delimiter.toString());
210
     partA.push(partB);
210
     partA.push(partB);
211
     return partA;
211
     return partA;
242
   }
242
   }
243
   
243
   
244
   // Bouton de personalisation du filtre
244
   // Bouton de personalisation du filtre
245
-  // pour le moment ce ne sotn que des redirection vers des actions
246
   $('.tags_prompt input.clear, a.filter_clear_url').live("click", function(){
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
   $('.tags_prompt input.mytags').live("click", function(){
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
   // Affichage un/des embed
284
   // Affichage un/des embed
659
                       id = $(this).attr('href').substr(1,$(this).attr('href').length);
690
                       id = $(this).attr('href').substr(1,$(this).attr('href').length);
660
                       id = str_replace(name, '', id);
691
                       id = str_replace(name, '', id);
661
                       id = str_replace('#', '', id);
692
                       id = str_replace('#', '', id);
662
-                                            
693
+                                     
663
                       $('input#tags_selected_tag_'+form_name).val(id);
694
                       $('input#tags_selected_tag_'+form_name).val(id);
664
                       inputTag.val(name);
695
                       inputTag.val(name);
665
                       // Et on execute l'évènement selectTag de l'input
696
                       // Et on execute l'évènement selectTag de l'input

+ 1 - 1
web/js/tags/jquery.tagBox.js View File

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