|
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 |
|
-
|