]> git.agnieray.net Git - galette.git/blob - galette/templates/default/elements/scripts.html.twig
89c0ef72c98a477cd9574db2d87f48363a7646b5
[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 language="javascript">
190 function activateMailingEditor() {
191 if(!$('#mailing_html').attr('checked')){
192 $('#mailing_html').attr('checked', true);
193 }
194
195 $('input#html_editor_active').attr('value', '1');
196 $('#activate_editor').remove();
197 $('#summernote_toggler').html('<a class="ui blue tertiary button" href="javascript:deactivateMailingEditor();" id="deactivate_editor">{{ _T("Deactivate HTML editor") }}</a>');
198
199 $('#mailing_corps').summernote({
200 lang: '{{ i18n.getID()|replace({'_': '-'}) }}',
201 disableDragAndDrop: true,
202 height: 240,
203 toolbar: [
204 ['style', ['style']],
205 ['font', ['bold', 'italic', 'strikethrough', 'clear']],
206 ['para', ['ul', 'ol', 'paragraph']],
207 ['insert', ['link', 'picture']],
208 ['view', ['codeview', 'help']]
209 ],
210 styleTags: [
211 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'
212 ],
213 callbacks: {
214 onImageUpload: function (data) {
215 //prevent image copypaste
216 data.pop();
217 }
218 }
219 });
220 $('#mailing_corps').summernote('focus');
221 }
222 function deactivateMailingEditor() {
223 $('#mailing_corps').summernote('destroy');
224 $('#deactivate_editor').remove();
225 $('#summernote_toggler').html('<a class="ui blue tertiary button" href="javascript:activateMailingEditor();" id="activate_editor">{{ _T("Activate HTML editor") }}</a>');
226 }
227 {% if html_editor_active is defined and html_editor_active == 1 %}
228 $(function(){
229 activateMailingEditor();
230 });
231 {% endif %}
232 </script>
233 {% endif %}
234 {% set localjstracking = constant('_CURRENT_THEME_PATH') ~ "tracking.js" %}
235 {% if file_exists(localjstracking) %}
236 <script type="text/javascript" src="{{ base_path() }}/{{ constant('GALETTE_THEME') }}tracking.js"></script>
237 {% endif %}