Projet

Général

Profil

0001-templates-add-template-for-FC-information-retrieval-.patch

Serghei Mihai, 04 juin 2021 11:40

Télécharger (12,3 ko)

Voir les différences:

Subject: [PATCH] templates: add template for FC information retrieval (#54003)

 static/img/fc-avatar.png                      | Bin 0 -> 5304 bytes
 static/includes/_fc.scss                      |  48 +++++++++
 static/includes/_publik.scss                  |   1 +
 .../widgets/select_jsonp--franceconnect.html  |  98 ++++++++++++++++++
 4 files changed, 147 insertions(+)
 create mode 100644 static/img/fc-avatar.png
 create mode 100644 static/includes/_fc.scss
 create mode 100644 templates/qommon/forms/widgets/select_jsonp--franceconnect.html
static/includes/_fc.scss
1
div.template-franceconnect {
2
	.franceconnect--button {
3
		display: block;
4
		width: 160px;
5
		background-image: url('../img/fc-avatar.png');
6
		background-repeat: no-repeat;
7
		background-size: auto 85%;
8
		padding: 5px 2px 5px 40px;;
9
		background-position: 5px center;
10
		color: white;
11
		font-size: 85%;
12
		cursor: pointer;
13
		&:hover {
14
			background-image: url('../img/fc-avatar.png');
15
			background-repeat: no-repeat;
16
			background-size: auto 85%;
17
			padding: 5px 2px 5px 40px;;
18
			background-position: 5px center;
19
		}
20
	}
21

  
22
	.franceconnect--data {
23
		position: relative;
24
	}
25

  
26
	.franceconnect--text {
27
		width: calc(100% - 1em);
28
		display: none;
29
	}
30

  
31
	.franceconnect--clear {
32
		position: absolute;
33
		right: 0;
34
		bottom: 0.5em;
35
		display: none;
36
	}
37

  
38
	.franceconnect--clear::before {
39
		font-family: FontAwesome;
40
		content: "\f057";
41
		color: $link-color;
42
	}
43

  
44
	.franceconnect--error {
45
		color: $error-color;
46
		font-size: 90%;
47
	}
48
}
static/includes/_publik.scss
14 14
@import 'carrousel';
15 15
@import 'back-top';
16 16
@import 'library';
17
@import 'fc';
templates/qommon/forms/widgets/select_jsonp--franceconnect.html
1
{% extends "qommon/forms/widgets/select_jsonp.html" %}
2

  
3
{% block widget-control %}
4

  
5
<style>
6
  .select2-container {
7
      display: none;
8
  }
9
</style>
10

  
11
{{ block.super }}
12

  
13
<div class="franceconnect--data">
14
  <input class="franceconnect--text" readonly />
15
  <a class="franceconnect--clear" title="Supprimer"></a>
16
  <button class="franceconnect--button">Obtenir avec FranceConnect</button>
17
  <span class="franceconnect--error" style="display: none">Une erreur s'est produite lors de la récupération des données.</span>
18
</div>
19

  
20
<script>
21
$(function () {
22
    const fc_popup = function(url) {
23
        const popup = window.open(url, 'FranceConnect',
24
          scrollbars=true,
25
          width=1000,
26
          height=670,
27
          top=0,
28
          left=0
29
        );
30
        if (window.focus) popup.focus();
31
        return popup;
32
    };
33

  
34
   const $input = $('div.template-franceconnect #form_{{widget.name}}');
35
   const $input_display_value = $("<input name=['{{widget.name}}_display]'>");
36

  
37
   const $container = $input.parents('.wcs-widget-select2-container').siblings('.franceconnect--data');
38

  
39
   const $fc_button = $container.find('.franceconnect--button');
40
   const $fc_clear = $container.find('a.franceconnect--clear');
41
   const $fc_text = $container.find('.franceconnect--text');
42
   const $fc_error = $container.find('.franceconnect--error');
43

  
44
   $fc_clear.on('click', function () {
45
       $fc_button.show();
46
       $input.val('');
47
       $input_display_value.val('');
48
       $(this).hide();
49
       $fc_text.hide();
50
   });
51

  
52
   if ($input.val()) {
53
       $fc_text.val($input.data('initial-display-value'));
54
       $fc_text.show();
55
       $fc_clear.show();
56
       $fc_button.hide();
57
   }
58

  
59
   var popup_window = null;
60

  
61
  $(window).on('message', function (event) {
62
      if (!event.originalEvent.data.error) {
63
          $fc_text.val(event.originalEvent.data.text);
64
          $input.val(event.originalEvent.data.id);
65
          $input_display_value.val(event.originalEvent.data.text);
66
          $fc_text.show();
67
          $fc_error.hide();
68
          $fc_button.hide();
69
          $fc_clear.show();
70
      } else {
71
          $fc_error.show();
72
          console.log(event.originalEvent.data.error);
73
          console.log(event.originalEvent.data.data);
74
      }
75
      if (popup_window) {
76
          popup_window.close();
77
      }
78
      popup_window = null;
79
   });
80

  
81
   $.getJSON($input.data('select2-url') + '?q=', function (response) {
82
       const init_request_url = response.data[0].init_request_url;
83
       console.log(init_request_url);
84
       $fc_button.on('click', function (event) {
85
           event.preventDefault();
86
           if (popup_window) {
87
               popup_window.close();
88
           }
89
           if (init_request_url.indexOf('?') != -1) {
90
               popup_window = fc_popup(init_request_url + '&origin=' + window.location.origin);
91
           } else {
92
               popup_window = fc_popup(init_request_url + '?origin=' + window.location.origin);
93
           }
94
       });
95
   });
96
});
97
</script>
98
{% endblock %}
0
-