]> git.agnieray.net Git - galette.git/blob - galette/templates/default/elements/scripts.html.twig
544a39ece2411e76b9d36e5f1caf993cab8f4b9b
[galette.git] / galette / templates / default / elements / scripts.html.twig
1 <script type="text/javascript" src="{{ base_path() }}/{{ constant('GALETTE_THEME') }}ui/semantic.min.js"></script>
2 <script type="text/javascript" src="{{ base_path() }}/assets/js/galette-main.bundle.min.js"></script>
3 {% if login.isDarkModeEnabled() %}
4 <script type="text/javascript" src="{{ base_path() }}/assets/js/darkreader.min.js"></script>
5 {% endif %}
6
7 <script type="text/javascript">
8 function csrfSafeMethod(method) {
9 // these HTTP methods do not require CSRF protection
10 return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
11 }
12
13 $(function(){
14 function _darkMode() {
15 var _dark_enabled = Cookies.get('galette_dark_mode');
16 var _cookie_value = 1;
17 if (_dark_enabled && _dark_enabled == 1) {
18 var _cookie_value = 0;
19 {% set darkcssfile = constant('GALETTE_CACHE_DIR') ~ "dark.css" %}
20 {% if not file_exists(darkcssfile) %}
21 function writeDarkTheme() {
22 DarkReader.enable({
23 brightness: 100,
24 contrast: 90,
25 sepia: 10
26 });
27 return DarkReader.exportGeneratedCSS();
28 }
29 writeDarkTheme().then(function(cssdata) {
30 $.ajax({
31 url: '{{ url_for("writeDarkCSS") }}',
32 method: 'post',
33 data: cssdata.replaceAll('themes/galette/assets', 'themes/default/ui/themes/galette/assets'),
34 success: function(res) {
35 console.log('Dark theme CSS stored');
36 },
37 error: function() {
38 console.log('Error storing dark theme CSS');
39 }
40 });
41 });
42 {% endif %}
43 }
44 $('.darkmode').on('click', function(e) {
45 e.preventDefault();
46 Cookies.set(
47 'galette_dark_mode',
48 _cookie_value,
49 {
50 expires: 365,
51 path: '/'
52 }
53 );
54 window.location.reload();
55 });
56 if (window.matchMedia) {
57 window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
58 if (event.matches) {
59 _cookie_value = 1;
60 }
61 Cookies.set(
62 'galette_dark_mode',
63 _cookie_value,
64 {
65 expires: 365,
66 path: '/'
67 }
68 );
69 window.location.reload();
70 });
71 }
72 }
73 _darkMode();
74
75 $.ajaxPrefilter(function(options, originalOptions, jqXHR){
76 if (options.type.toLowerCase() === "post") {
77 // initialize `data` to empty string if it does not exist
78 options.data = options.data || "";
79
80 // add leading ampersand if `data` is non-empty
81 options.data += options.data?"&":"";
82
83 // add csrf
84 options.data += encodeURIComponent("{{ csrf_name_key }}") + "=" + encodeURIComponent("{{ csrf_name }}") + "&" + encodeURIComponent("{{ csrf_value_key }}") + "=" + encodeURIComponent("{{ csrf_value }}")
85 }
86 });
87
88 {% if login.isLogged() %}
89 // Display user menu in compact mode
90 var _compactMenu = function() {
91 var _hidden = Cookies.get('galette_compact_menu');
92 var _menu = document.getElementById('sidemenu');
93 var _content = _menu.nextElementSibling;
94 var _trigger = document.getElementById('compactmenu');
95 if (_hidden & _hidden == 1) {
96 _trigger.checked = true;
97 _menu.classList.add('compact_menu');
98 _content.classList.add('extended');
99 }
100 _trigger.addEventListener('change', function() {
101 var _checked = $(this).is(':checked');
102 Cookies.set(
103 'galette_compact_menu',
104 (_checked ? 1 : 0),
105 {
106 expires: 365,
107 path: '/'
108 }
109 );
110 window.location.reload();
111 });
112 }
113
114 _compactMenu();
115 {% endif %}
116
117 {% if autocomplete %}
118 $('#ville_adh_field, #lieu_naissance_field').search({
119 apiSettings: {
120 url: '{{ url_for('suggestTown', {'term': '{query}'}) }}',
121 method: 'post',
122 onFailure: function(response, element, xhr) {
123 console.log(response);
124 },
125 onError: function(errorMessage, element, xhr) {
126 {% include "elements/js/modal.js.twig" with {
127 modal_title_twig: _T("An error occurred :(")|e("js"),
128 modal_content: "errorMessage",
129 modal_class: "tiny",
130 modal_content_class: "scrolling",
131 modal_deny_only: true,
132 modal_cancel_text: _T("Close")|e("js"),
133 modal_classname: "redalert",
134 } %}
135 console.log(xhr);
136 }
137 },
138 minCharacters : 2
139 });
140 $('#pays_adh_field').search({
141 apiSettings: {
142 url: '{{ url_for('suggestCountry', {'term': '{query}'}) }}',
143 method: 'post',
144 onFailure: function(response, element, xhr) {
145 console.log(response);
146 },
147 onError: function(errorMessage, element, xhr) {
148 {% include "elements/js/modal.js.twig" with {
149 modal_title_twig: _T("An error occurred :(")|e("js"),
150 modal_content: "errorMessage",
151 modal_class: "tiny",
152 modal_content_class: "scrolling",
153 modal_deny_only: true,
154 modal_cancel_text: _T("Close")|e("js"),
155 modal_classname: "redalert",
156 } %}
157 console.log(xhr);
158 }
159 },
160 minCharacters : 2
161 });
162 {% endif %}
163
164 {% include "elements/js/calendar.js.twig" %}
165
166 {% if renew_telemetry is defined %}
167 {% include "modals/telemetry.html.twig" with {part: "jsdialog"} %}
168 {% endif %}
169
170 {% include "elements/js/messages.js.twig" %}
171
172 });
173 </script>
174 {% if login.isLogged() %}
175 <script type="module" src="{{ base_path() }}/assets/js/sortable.min.js"></script>
176 {% endif %}
177 {% if require_charts %}
178 <script type="module" src="{{ base_path() }}/assets/js/chartjs.min.js"></script>
179 {% endif %}
180 {% if require_mass %}
181 <script type="text/javascript" src="{{ base_path() }}/assets/js/masschanges.min.js"></script>
182 {% endif %}
183 {% if html_editor %}
184 <script type="text/javascript" src="{{ base_path() }}/assets/js/codemirror.js"></script>
185 <script type="text/javascript" src="{{ base_path() }}/assets/js/xml.js"></script>
186 <script type="text/javascript" src="{{ base_path() }}/assets/js/formatting.js"></script>
187 <script type="text/javascript" src="{{ base_path() }}/assets/js/summernote.min.js"></script>
188 <script type="text/javascript" src="{{ base_path() }}/assets/js/lang/summernote-{{ i18n.getID()|replace({'_': '-'}) }}.min.js"></script>
189 <script type="text/javascript">
190 function activateHtmlEditor(elt, basic) {
191 if (basic === true) {
192 var _toolbar = [
193 ['font', ['bold', 'italic', 'strikethrough', 'clear']],
194 ['para', ['ul', 'ol']],
195 ['insert', ['link']],
196 ['view', ['codeview']]
197 ];
198 } else {
199 var _toolbar = [
200 ['style', ['style']],
201 ['font', ['bold', 'italic', 'strikethrough', 'clear']],
202 ['para', ['ul', 'ol', 'paragraph']],
203 ['insert', ['link', 'picture']],
204 ['view', ['codeview']]
205 ];
206 }
207 elt.summernote({
208 lang: '{{ i18n.getID()|replace({'_': '-'}) }}',
209 disableDragAndDrop: true,
210 height: 240,
211 toolbar: _toolbar,
212 styleTags: [
213 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
214 ],
215 callbacks: {
216 onImageUpload: function (data) {
217 //prevent image copypaste
218 data.pop();
219 }
220 }
221 });
222 elt.summernote('focus');
223 }
224
225 function deactivateHtmlEditor(elt) {
226 elt.summernote('destroy');
227 }
228
229 function activateMailingEditor() {
230 if(!$('#mailing_html').attr('checked')){
231 $('#mailing_html').attr('checked', true);
232 }
233
234 $('input#html_editor_active').attr('value', '1');
235 $('#activate_editor').remove();
236 $('#summernote_toggler').html('<a class="ui blue tertiary button" href="javascript:deactivateMailingEditor();" id="deactivate_editor">{{ _T("Deactivate HTML editor") }}</a>');
237
238 activateHtmlEditor($('#mailing_corps'));
239 }
240 function deactivateMailingEditor() {
241 deactivateHtmlEditor($('#mailing_corps'));
242 $('#deactivate_editor').remove();
243 $('#summernote_toggler').html('<a class="ui blue tertiary button" href="javascript:activateMailingEditor();" id="activate_editor">{{ _T("Activate HTML editor") }}</a>');
244 }
245 {% if html_editor_active is defined and html_editor_active == 1 %}
246 $(function(){
247 activateMailingEditor();
248 });
249 {% endif %}
250 </script>
251 {% endif %}
252 {% set localjstracking = constant('_CURRENT_THEME_PATH') ~ "tracking.js" %}
253 {% if file_exists(localjstracking) %}
254 <script type="text/javascript" src="{{ base_path() }}/{{ constant('GALETTE_THEME') }}tracking.js"></script>
255 {% endif %}