Projet

Général

Profil

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

Serghei Mihai, 07 juin 2021 18:05

Télécharger (12,7 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  |  92 ++++++++++++++++++
 4 files changed, 141 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/widget.html" %}
2

  
3
{% block widget-control %}
4
<input id="form_{{widget.name}}" type="hidden" name="{{widget.name}}" data-initial-display-value="{{widget.get_display_value|default_if_none:''}}" data-url="{{widget.get_select2_url}}"{% if widget.value %} value="{{ widget.value }}"{% endif %} />
5
<input id="form_{{widget.name}}_display" type="text" name="{{widget.name}}_display" style="display: none" readonly />
6

  
7
<div class="franceconnect--data">
8
  <a class="franceconnect--clear" title="Supprimer"></a>
9
  <button class="franceconnect--button">Obtenir avec FranceConnect</button>
10
  <span class="franceconnect--error" style="display: none">Une erreur s'est produite lors de la récupération des données.</span>
11
</div>
12

  
13
<script>
14
$(function () {
15
  const fc_popup = function(url) {
16
        const height = 670;
17
        const width = 1000;
18
        const left = (screen.width/2)-(width/2);
19
        const top = (screen.height/2)-(height/2);
20
        const popup = window.open(url, 'FranceConnect',
21
          'scrollbars=true, width='+width+', height='+height+',top='+top+', left='+left+', resizable=no,copyhistory=no'
22
        );
23
        if (window.focus) popup.focus();
24
        return popup;
25
    };
26

  
27
   const $input = $('div.template-franceconnect #form_{{widget.name}}');
28
   const $input_display_value = $('div.template-franceconnect #form_{{widget.name}}_display');
29

  
30
   const $container = $input.siblings('.franceconnect--data');
31

  
32
   const $fc_button = $container.find('.franceconnect--button');
33
   const $fc_clear = $container.find('a.franceconnect--clear');
34
   const $fc_error = $container.find('.franceconnect--error');
35

  
36
   $fc_clear.on('click', function () {
37
       $fc_button.show();
38
       $input.val('');
39
       $(this).hide();
40
       $input_display_value.hide();
41
       $input_display_value.val('');
42
   });
43

  
44
   if ($input.val()) {
45
       $input_display_value.val($input.data('initial-display-value'));
46
       $input_display_value.show();
47
       $fc_clear.show();
48
       $fc_button.hide();
49
   }
50

  
51
   var popup_window = null;
52
   var init_request_url = null;
53

  
54
  $.getJSON($input.data('url') + '?q=', function (response) {
55
       init_request_url = response.data[0].init_request_url;
56
       $fc_button.on('click', function (event) {
57
           event.preventDefault();
58
           if (popup_window) {
59
               popup_window.close();
60
           }
61
           if (init_request_url.indexOf('?') != -1) {
62
               popup_window = fc_popup(init_request_url + '&origin=' + window.location.href);
63
           } else {
64
               popup_window = fc_popup(init_request_url + '?origin=' + window.location.href);
65
           }
66
       });
67
   });
68

  
69
  $(window).on('message', function (event) {
70
      if(init_request_url.indexOf(event.originalEvent.origin) == -1) {
71
        return
72
      }
73
      if (!event.originalEvent.data.error) {
74
          $input.val(event.originalEvent.data.id);
75
          $input_display_value.val(event.originalEvent.data.text);
76
          $input_display_value.show();
77
          $fc_error.hide();
78
          $fc_button.hide();
79
          $fc_clear.show();
80
      } else {
81
          $fc_error.show();
82
          console.log(event.originalEvent.data.error);
83
          console.log(event.originalEvent.data.data);
84
      }
85
      if (popup_window) {
86
          popup_window.close();
87
      }
88
      popup_window = null;
89
   });
90
});
91
</script>
92
{% endblock %}
0
-