Procházet zdrojové kódy

Evolution #204: token de filtre

Bastien Sevajol před 12 roky
rodič
revize
b5d417d804

+ 34 - 2
src/Muzich/CoreBundle/Controller/ElementController.php Zobrazit soubor

@@ -298,7 +298,23 @@ class ElementController extends Controller
298 298
       return $response;
299 299
     }
300 300
     
301
-    $es = $this->getElementSearcher();
301
+    if ($this->getRequest()->getMethod() != 'POST')
302
+    {
303
+      throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
304
+    }
305
+    
306
+    /*
307
+     * On met à jour l'ElementSearcher avec le form
308
+     */
309
+    $es = $this->getElementSearcher(null, true);
310
+    $search_form = $this->getSearchForm($es);
311
+    $search_form->bindRequest($this->getRequest());
312
+    
313
+    if ($search_form->isValid())
314
+    {
315
+      $es->update($search_form->getData());
316
+    }
317
+    
302 318
     $es->update(array(
303 319
       // On veux de nouveaux éléments
304 320
       'searchnew' => true,
@@ -335,7 +351,23 @@ class ElementController extends Controller
335 351
       return $response;
336 352
     }
337 353
     
338
-    $es = $this->getElementSearcher();
354
+    if ($this->getRequest()->getMethod() != 'POST')
355
+    {
356
+      throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
357
+    }
358
+    
359
+    /*
360
+     * On met à jour l'ElementSearcher avec le form
361
+     */
362
+    $es = $this->getElementSearcher(null, true);
363
+    $search_form = $this->getSearchForm($es);
364
+    $search_form->bindRequest($this->getRequest());
365
+    
366
+    if ($search_form->isValid())
367
+    {
368
+      $es->update($search_form->getData());
369
+    }
370
+    
339 371
     $es->update(array(
340 372
       // On veux de nouveaux éléments
341 373
       'searchnew' => true,

+ 18 - 3
src/Muzich/CoreBundle/Repository/ElementRepository.php Zobrazit soubor

@@ -113,14 +113,29 @@ class ElementRepository extends EntityRepository
113 113
     // Construction des conditions pour la selection d'ids
114 114
     $where_tags = '';
115 115
     $join_tags  = '';
116
-    if (count(($tags = $searcher->getTags())))
116
+    
117
+    /*
118
+     * des fois on se retrouve avec un string au lieu d'un tableau
119
+     */
120
+    $tags = $searcher->getTags();
121
+    
122
+    if (!is_array($tags))
123
+    {
124
+      $tags_decoded = json_decode($tags);
125
+      $tags = array();
126
+      foreach ($tags_decoded as $tag_id)
127
+      {
128
+        $tags[$tag_id] = $tag_id;
129
+      }
130
+    }
131
+    
132
+    if (count($tags))
117 133
     {
118
-      
119 134
       foreach ($tags as $tag_id => $tag_name)
120 135
       {
121 136
         // LEFT JOIN car un element n'est pas obligatoirement lié a un/des tags
122 137
         $join_tags = " LEFT JOIN e_.tags t_";
123
-        
138
+
124 139
         // Construction du chere pour les tags
125 140
         if ($where_tags == '')
126 141
         {

+ 89 - 30
web/bundles/muzichcore/js/muzich.js Zobrazit soubor

@@ -1289,21 +1289,46 @@ $(document).ready(function(){
1289 1289
           +'/'
1290 1290
           +str_replace('element_', '', $('ul.elements li:first').attr('id'))
1291 1291
         ;
1292
-        $.getJSON(url, function(response){
1292
+        
1293
+        $.ajax({
1294
+          type: 'POST',
1295
+          url: url,
1296
+          data: $('form[name="search"]').serialize(),
1297
+          success: function(response){
1293 1298
           
1294
-          if (response.status == 'mustbeconnected')
1295
-          {
1296
-            $(location).attr('href', url_index);
1297
-          }
1299
+            if (response.status == 'mustbeconnected')
1300
+            {
1301
+              $(location).attr('href', url_index);
1302
+            }
1298 1303
 
1299
-          if (response.status == 'success' && response.count)
1300
-          {
1301
-            $('div.display_more_elements').show();
1302
-            $('div.display_more_elements span').html(response.message);
1303
-          }
1304
+            if (response.status == 'success' && response.count)
1305
+            {
1306
+              $('div.display_more_elements').show();
1307
+              $('div.display_more_elements span').html(response.message);
1308
+            }
1304 1309
 
1305
-          setTimeout(check_new_elements, 150000);
1310
+            setTimeout(check_new_elements, 150000);
1311
+          },
1312
+          dataType: "json"
1306 1313
         });
1314
+        
1315
+        
1316
+//        $.getJSON(url, function(response){
1317
+//          
1318
+//          if (response.status == 'mustbeconnected')
1319
+//          {
1320
+//            $(location).attr('href', url_index);
1321
+//          }
1322
+//
1323
+//          if (response.status == 'success' && response.count)
1324
+//          {
1325
+//            $('div.display_more_elements').show();
1326
+//            $('div.display_more_elements span').html(response.message);
1327
+//          }
1328
+//
1329
+//          setTimeout(check_new_elements, 150000);
1330
+//        });
1331
+        
1307 1332
         do_check_new_elements = false;
1308 1333
       }
1309 1334
       
@@ -1321,31 +1346,65 @@ $(document).ready(function(){
1321 1346
       +str_replace('element_', '', $('ul.elements li:first').attr('id'))
1322 1347
     ;
1323 1348
     $('img.elements_new_loader').show();
1324
-    $.getJSON(url, function(response){
1325
-      
1326
-      if (response.status == 'mustbeconnected')
1327
-      {
1328
-        $(location).attr('href', url_index);
1329
-      }
1349
+    
1350
+    
1351
+    $.ajax({
1352
+      type: 'POST',
1353
+      url: url,
1354
+      data: $('form[name="search"]').serialize(),
1355
+      success: function(response){
1330 1356
       
1331
-      if (response.status == 'success')
1332
-      {
1333
-        if (response.count)
1357
+        if (response.status == 'mustbeconnected')
1334 1358
         {
1335
-          $('div.display_more_elements').show();
1336
-          $('div.display_more_elements span').html(response.message);
1359
+          $(location).attr('href', url_index);
1337 1360
         }
1338
-        else
1361
+
1362
+        if (response.status == 'success')
1339 1363
         {
1340
-          $('div.display_more_elements').hide();
1364
+          if (response.count)
1365
+          {
1366
+            $('div.display_more_elements').show();
1367
+            $('div.display_more_elements span').html(response.message);
1368
+          }
1369
+          else
1370
+          {
1371
+            $('div.display_more_elements').hide();
1372
+          }
1373
+
1374
+          $('ul.elements').prepend(response.html);
1375
+          recolorize_element_list();
1341 1376
         }
1342
-        
1343
-        $('ul.elements').prepend(response.html);
1344
-        recolorize_element_list();
1345
-      }
1346
-      
1347
-      $('img.elements_new_loader').hide();
1377
+
1378
+        $('img.elements_new_loader').hide();
1379
+      },
1380
+      dataType: "json"
1348 1381
     });
1382
+    
1383
+//    $.getJSON(url, function(response){
1384
+//      
1385
+//      if (response.status == 'mustbeconnected')
1386
+//      {
1387
+//        $(location).attr('href', url_index);
1388
+//      }
1389
+//      
1390
+//      if (response.status == 'success')
1391
+//      {
1392
+//        if (response.count)
1393
+//        {
1394
+//          $('div.display_more_elements').show();
1395
+//          $('div.display_more_elements span').html(response.message);
1396
+//        }
1397
+//        else
1398
+//        {
1399
+//          $('div.display_more_elements').hide();
1400
+//        }
1401
+//        
1402
+//        $('ul.elements').prepend(response.html);
1403
+//        recolorize_element_list();
1404
+//      }
1405
+//      
1406
+//      $('img.elements_new_loader').hide();
1407
+//    });
1349 1408
   });
1350 1409
 
1351 1410
   function recolorize_element_list()