Browse Source

Adaptation au plugin

Bastien Sevajol 11 years ago
parent
commit
af41460b68

+ 1 - 0
app/Resources/translations/elements.en.yml View File

19
     group:
19
     group:
20
       will_be_in:       This element will be add to the group.
20
       will_be_in:       This element will be add to the group.
21
     url_title_step2:    Ressource
21
     url_title_step2:    Ressource
22
+    shared_from_finish: Music shared, you can close the box (top-left cross)
22
   show:
23
   show:
23
     close_embed:        Close the player
24
     close_embed:        Close the player
24
     open_embed:         Display the player
25
     open_embed:         Display the player

+ 1 - 0
app/Resources/translations/elements.fr.yml View File

18
     group:
18
     group:
19
       will_be_in:       L'élément sera ajouté dans le groupe
19
       will_be_in:       L'élément sera ajouté dans le groupe
20
     url_title_step2:    Ressource
20
     url_title_step2:    Ressource
21
+    shared_from_finish: Le partage a été effectué, vous pouvez fermer la boite (croix en haut à gauche)
21
   show:
22
   show:
22
     close_embed:        Fermer le lecteur
23
     close_embed:        Fermer le lecteur
23
     open_embed:         Afficher le lecteur
24
     open_embed:         Afficher le lecteur

+ 11 - 1
src/Muzich/CoreBundle/Controller/CoreController.php View File

284
         return $this->jsonResponse(array(
284
         return $this->jsonResponse(array(
285
           'status' => 'success',
285
           'status' => 'success',
286
           'html'   => $html,
286
           'html'   => $html,
287
-          'groups' => (!$group)?$this->isAddedElementCanBeInGroup($element):array()
287
+          'groups' => (!$group)?$this->isAddedElementCanBeInGroup($element):array(),
288
+          'message' => ($this->getRequest()->get('shared_from'))?$this->trans('element.add.shared_from_finish', array(), 'elements'):''
288
         ));
289
         ));
289
       }
290
       }
290
       else
291
       else
691
     throw new \Exception('test error');
692
     throw new \Exception('test error');
692
   }
693
   }
693
   
694
   
695
+  public function getCsrfTokenAction()
696
+  {
697
+    if (($response = $this->mustBeConnected(true)))
698
+      return $response;
699
+    
700
+    $csrfToken = $this->container->get('form.csrf_provider')->generateCsrfToken('unknown');
701
+    return $this->jsonSuccessResponse($csrfToken);
702
+  }
703
+  
694
 }
704
 }

+ 6 - 1
src/Muzich/CoreBundle/Resources/config/routing.yml View File

212
 
212
 
213
 share_from:
213
 share_from:
214
   pattern: /element/share/from
214
   pattern: /element/share/from
215
-  defaults: { _controller: MuzichCoreBundle:Element:shareFrom }
215
+  defaults: { _controller: MuzichCoreBundle:Element:shareFrom }
216
+  
217
+get_csrf_token:
218
+  pattern: /ajax/getcsrf
219
+  defaults: { _controller: MuzichCoreBundle:Core:getCsrfToken }
220
+  

+ 7 - 0
src/Muzich/CoreBundle/Resources/public/css/main.css View File

2509
   width: 100%;
2509
   width: 100%;
2510
 }
2510
 }
2511
 
2511
 
2512
+div#share_from_message
2513
+{
2514
+  font-weight: bold;
2515
+  padding: 15px;
2516
+  font-size: 115%;
2517
+}
2518
+
2512
 /*
2519
 /*
2513
 *
2520
 *
2514
 *
2521
 *

+ 57 - 11
src/Muzich/CoreBundle/Resources/public/js/muzich.js View File

23
 
23
 
24
 function ResponseController()
24
 function ResponseController()
25
 {
25
 {
26
-  var propagate = function(response)
26
+  var propagate = function(response, after_login_success_callback)
27
   {
27
   {
28
     if (response.status === 'error')
28
     if (response.status === 'error')
29
     {
29
     {
35
       }
35
       }
36
       else if (response.error === 'UserNotConnected')
36
       else if (response.error === 'UserNotConnected')
37
       {
37
       {
38
-        open_connection_or_subscription_window();
38
+        open_connection_or_subscription_window(false, {}, after_login_success_callback);
39
       }
39
       }
40
     }
40
     }
41
     else if (response.status === 'mustbeconnected')
41
     else if (response.status === 'mustbeconnected')
42
     {
42
     {
43
-      open_connection_or_subscription_window(true);
43
+      open_connection_or_subscription_window(true, {}, after_login_success_callback);
44
     }
44
     }
45
-  }
45
+  };
46
   
46
   
47
-  this.execute = function(response, success_callback, failure_callback)
47
+  this.execute = function(response, success_callback, failure_callback, after_login_success_callback)
48
   {
48
   {
49
-    propagate(response);
49
+    propagate(response, after_login_success_callback);
50
+    
50
     if (response.status === 'success')
51
     if (response.status === 'success')
51
     {
52
     {
52
       success_callback(response);
53
       success_callback(response);
55
     {
56
     {
56
       failure_callback(response);
57
       failure_callback(response);
57
     }
58
     }
58
-  }
59
+  };
59
 }
60
 }
60
 
61
 
61
 window.ResponseController = new ResponseController();
62
 window.ResponseController = new ResponseController();
1320
       
1321
       
1321
       form_add_hide_errors();
1322
       form_add_hide_errors();
1322
       
1323
       
1324
+      // Dans le cas d'un ajout depuis l'extérieur (iframe)
1325
+      if ($('form[name="add"] input[name="shared_from"]').val() === "1")
1326
+      {
1327
+        var elements = $('<ul class="elements"></ul>')
1328
+        elements.prepend(response.html);
1329
+        $('div#share_from_content').append(elements);
1330
+        $('div#share_from_message').text(response.message);
1331
+        //$('form[name="add"]').append($('<input type="hidden" name="shared_from_finished" id="shared_from_finished" value="1" />'));
1332
+      }
1333
+      
1323
       return true;
1334
       return true;
1324
     }
1335
     }
1325
     else if (response.status == 'error')
1336
     else if (response.status == 'error')
1540
   });
1551
   });
1541
   $('form[name="add"]').ajaxForm(function(response) {
1552
   $('form[name="add"]').ajaxForm(function(response) {
1542
     
1553
     
1554
+    var callback_login = null;
1555
+    // Dans le cas d'un ajout depuis l'extérieur (iframe)
1556
+    if ($('form[name="add"] input[name="shared_from"]').val() === "1")
1557
+    {
1558
+      callback_login = function(){ 
1559
+        $('#form_add_loader').show();
1560
+        JQueryJson(url_csrf, {}, function(response){
1561
+          if (response.status == 'success')
1562
+          {
1563
+            $('form[name="add"] input[name="element_add[_token]"]').val(response.data);
1564
+            $('form[name="add"]').submit();
1565
+            $('#form_add_loader').hide();
1566
+          }
1567
+        });
1568
+         
1569
+      };
1570
+    }
1571
+    
1543
     $('form[name="add"] img.tag_loader').hide();
1572
     $('form[name="add"] img.tag_loader').hide();
1544
     window.ResponseController.execute(
1573
     window.ResponseController.execute(
1545
       response,
1574
       response,
1546
       function(){},
1575
       function(){},
1547
-      function(){}
1576
+      function(){},
1577
+      callback_login
1548
     );
1578
     );
1549
     
1579
     
1550
       // Si on en est a la première étape la réponse sera des données récupérés auprès
1580
       // Si on en est a la première étape la réponse sera des données récupérés auprès
3361
   }
3391
   }
3362
 }
3392
 }
3363
 
3393
 
3364
-function open_connection_or_subscription_window(open_login_part, data)
3394
+function open_connection_or_subscription_window(open_login_part, data, login_success_callback)
3365
 {
3395
 {
3366
   if (window_login_or_subscription_opened == false)
3396
   if (window_login_or_subscription_opened == false)
3367
   {
3397
   {
3390
         $('div.login form').find('img.loader').hide();
3420
         $('div.login form').find('img.loader').hide();
3391
         if (response.status == 'success')
3421
         if (response.status == 'success')
3392
         {
3422
         {
3393
-          $(location).attr('href', response.data.redirect_url);
3423
+          if (login_success_callback)
3424
+          {
3425
+            $('a#helpbox_close').click();
3426
+            login_success_callback();
3427
+          }
3428
+          else
3429
+          {
3430
+            $(location).attr('href', response.data.redirect_url);
3431
+          }
3394
         }
3432
         }
3395
         else if (response.status == 'error')
3433
         else if (response.status == 'error')
3396
         {
3434
         {
3407
         $('div.register form.fos_user_registration_register').find('img.loader').hide();
3445
         $('div.register form.fos_user_registration_register').find('img.loader').hide();
3408
         if (response.status == 'success')
3446
         if (response.status == 'success')
3409
         {
3447
         {
3410
-          $(location).attr('href', url_home);
3448
+          if (login_success_callback)
3449
+          {
3450
+            $('a#helpbox_close').click();
3451
+            login_success_callback();
3452
+          }
3453
+          else
3454
+          {
3455
+            $(location).attr('href', url_home);
3456
+          }
3411
         }
3457
         }
3412
         else if (response.status == 'error')
3458
         else if (response.status == 'error')
3413
         {
3459
         {

+ 5 - 0
src/Muzich/CoreBundle/Resources/views/Component/element_add_box.html.twig View File

7
 {% if show_add_to_group is not defined %}
7
 {% if show_add_to_group is not defined %}
8
   {% set show_add_to_group = true %}
8
   {% set show_add_to_group = true %}
9
 {% endif %}
9
 {% endif %}
10
+{% if shared_from is not defined %}
11
+  {% set shared_from = 0 %}
12
+{% endif %}
10
 
13
 
11
 {% if not group_slug %}
14
 {% if not group_slug %}
12
   {% set form_action = path('element_add') %}
15
   {% set form_action = path('element_add') %}
37
       'form_name'     : add_form_name
40
       'form_name'     : add_form_name
38
     } %}
41
     } %}
39
   
42
   
43
+     <input type="hidden" name="shared_from" value="{{ shared_from }}" />
44
+          
40
   </form>
45
   </form>
41
 </div>
46
 </div>
42
 
47
 

+ 4 - 0
src/Muzich/CoreBundle/Resources/views/Element/share_from.html.twig View File

7
   {% include 'MuzichCoreBundle:Component:element_add_box.html.twig' with {
7
   {% include 'MuzichCoreBundle:Component:element_add_box.html.twig' with {
8
     'box_title'     : 'home.add_element_box.title_external'|trans({}, 'navigationui'),
8
     'box_title'     : 'home.add_element_box.title_external'|trans({}, 'navigationui'),
9
     'add_form_name' : 'add',
9
     'add_form_name' : 'add',
10
+    'shared_from'   : 1
10
   } %}
11
   } %}
11
 
12
 
12
   <script type="text/javascript">
13
   <script type="text/javascript">
19
       $('form[name="add"]').submit();
20
       $('form[name="add"]').submit();
20
     });
21
     });
21
   </script>
22
   </script>
23
+  
24
+  <div id="share_from_content"></div>
25
+  <div id="share_from_message"></div>
22
 
26
 
23
 {% endblock %}
27
 {% endblock %}

+ 1 - 1
src/Muzich/CoreBundle/Resources/views/Layout/head_js.html.twig View File

129
   url_img_ajax_loader = "{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}";
129
   url_img_ajax_loader = "{{ asset('/bundles/muzichcore/img/ajax-loader.gif') }}";
130
   url_get_embed_for_element = "{{ path('url_get_embed_for_element') }}";
130
   url_get_embed_for_element = "{{ path('url_get_embed_for_element') }}";
131
   url_helpbox_tags_favorites = "{{ path('helpbox_tags_favorites') }}";
131
   url_helpbox_tags_favorites = "{{ path('helpbox_tags_favorites') }}";
132
-  
132
+  url_csrf = "{{ path('get_csrf_token') }}";
133
   url_subscription_or_login = "{{ path('subscribe_or_login') }}";
133
   url_subscription_or_login = "{{ path('subscribe_or_login') }}";
134
   url_email_not_confirmed = "{{ path('email_not_confirmed') }}";
134
   url_email_not_confirmed = "{{ path('email_not_confirmed') }}";
135
   url_send_email_confirmation = "{{ path('send_email_confirmation') }}";
135
   url_send_email_confirmation = "{{ path('send_email_confirmation') }}";

+ 1 - 2
src/Muzich/CoreBundle/lib/Controller.php View File

499
     
499
     
500
     if ($this->getUser() == 'anon.')
500
     if ($this->getUser() == 'anon.')
501
     {
501
     {
502
-      $this->setFlash('error', 'user.session_expired');
503
-      
504
       if ($this->getRequest()->isXmlHttpRequest())
502
       if ($this->getRequest()->isXmlHttpRequest())
505
       {
503
       {
506
         return $this->mustBeConnectedResponse();
504
         return $this->mustBeConnectedResponse();
507
       }
505
       }
508
       else
506
       else
509
       {
507
       {
508
+        $this->setFlash('error', 'user.session_expired');
510
         return $this->redirect($this->generateUrl('home'));
509
         return $this->redirect($this->generateUrl('home'));
511
       }
510
       }
512
     }
511
     }