]> git.agnieray.net Git - galette.git/blob - galette/templates/default/elements/js/modal.js.twig
e3703020516259df3e4015d9bbc9d5e955a71892
[galette.git] / galette / templates / default / elements / js / modal.js.twig
1 {#
2 /**
3 * @file
4 * Fomantic UI Modal.
5 *
6 * Copyright © 2009-2023 The Galette Team
7 *
8 * This file is part of Galette (https://galette.eu).
9 *
10 * Galette is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Galette is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Galette. If not, see <https://www.gnu.org/licenses/>.
22 *
23 * @category Authentication
24 * @package Galette
25 *
26 * @author Guillaume Agniéray <dev@agnieray.net>
27 * @author Johan Cwiklinski <johan@x-tnd.be>
28 * @copyright 2009-2023 The Galette Team
29 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or later
30 * @link https://galette.eu
31 * @since Available since 1.0dev - 2023-02-23
32 *
33 * Available variables:
34 *
35 * - modal_selector: existing inline HTML modal.
36 * - modal_without_title: true to hide modal's header.
37 * - modal_title: value coming from js code.
38 * - modal_title_twig: value coming from twig.
39 * - modal_without_content: true to hide modal's content.
40 * - modal_content: value coming from js code.
41 * - modal_content_twig: value coming from twig.
42 * - modal_class: class(es) applied on modal.
43 * - modal_content_class: class(es) applied on modal's content.
44 * - modal_other_options: hash to add other options { option: value }.
45 * - modal_onshow: modal's onShow callback.
46 * - modal_onhidden: modal's onHidden callback.
47 * - modal_onapprove: modal's onApprove callback.
48 * - modal_ondeny: modal's onDeny callback.
49 * - modal_additional_button: hash to add a third button { text, icon, color, click }.
50 * - modal_deny_only: true hides the approve button.
51 * - modal_approve_text: modal's approve button's text.
52 * - modal_approve_icon: modal's approve button's icon.
53 * - modal_approve_color: modal's approve button's color.
54 * - modal_approve_click: modal's approve button's onclick event.
55 * - modal_cancel_text: modal's cancel button's icon.
56 * - modal_cancel_icon: modal's cancel button's icon.
57 * - modal_cancel_color: modal's cancel button's icon.
58 * - modal_cancel_click: modal's cancel button's onclick event.
59 * - modal_classname: string to override default Fomantic UI classes.
60 *
61 */
62 #}
63
64 {% if modal_selector is not defined %}
65 $.modal({
66 {% if modal_without_title is not defined %}
67 title: {% if modal_title_twig is defined %}'{{ modal_title_twig }}'{% elseif modal_title is defined %}{{ modal_title|raw }}{% endif %},
68 {% endif %}
69 {% if modal_without_content is not defined %}
70 content: {% if modal_content_twig is defined %}'{{ modal_content_twig }}'{% elseif modal_content is defined %}{{ modal_content|raw }}{% endif %},
71 {% endif %}
72 {% else %}
73 $('{{ modal_selector }}').modal({
74 {% endif %}
75 class: 'modal-form{% if modal_class is defined %} {{ modal_class }}{% endif %}',
76 classContent: '{% if modal_content_class is defined %}{{ modal_content_class }}{% endif %}',
77 {% if modal_other_options is defined and modal_other_options is iterable %}
78 {% for key, value in modal_other_options %}
79 {% if key == "observeChanges" and value == "1" %}
80 {{ key }}: true,
81 {% else %}
82 {{ key }}: "{{ value }}",
83 {% endif %}
84 {% endfor %}
85 {% endif %}
86 onShow: function() {
87 {% if modal_onshow is defined %}
88 {{ modal_onshow|raw }}
89 {% else %}
90 return true;
91 {% endif %}
92 },
93 onHidden: function() {
94 {% if modal_onhidden is defined %}
95 {{ modal_onhidden|raw }}
96 {% else %}
97 return true;
98 {% endif %}
99 },
100 onApprove: function() {
101 {% if modal_onapprove is defined %}
102 {{ modal_onapprove|raw }}
103 {% elseif modal_deny_only is not defined %}
104 $('.modal-form form').submit();
105 {% endif %}
106 },
107 onDeny: function() {
108 {% if modal_ondeny is defined %}
109 {{ modal_ondeny|raw }}
110 {% endif %}
111 },
112 actions: [
113 {% if modal_additional_button is defined and modal_additional_button is iterable %}
114 {
115 {% for key, value in modal_additional_button %}
116 {% if key == "click" %}
117 {{ key }}: {{ value|raw }},
118 {% else %}
119 {{ key }}: "{{ value }}",
120 {% endif %}
121 {% endfor %}
122 },
123 {% endif %}
124 {% if modal_deny_only is not defined %}
125 {
126 text: '{% if modal_approve_text is not defined %}{{ _T("Continue")|e("js") }}{% else %}{{ modal_approve_text }}{% endif %}',
127 icon: '{% if modal_approve_icon is not defined %}arrow right{% else %}{{ modal_approve_icon }}{% endif %}',
128 class: '{% if modal_approve_color is not defined %}primary{% else %}{{ modal_approve_color }}{% endif %} icon labeled approve',
129 click: {
130 {% if modal_approve_click is defined %}
131 {{ modal_approve_click|raw }}
132 {% endif %}
133 }
134 },
135 {% endif %}
136 {
137 text: '{% if modal_cancel_text is not defined %}{{ _T("Cancel")|e("js") }}{% else %}{{ modal_cancel_text }}{% endif %}',
138 icon: '{% if modal_cancel_icon is not defined %}times{% else %}{{ modal_cancel_icon }}{% endif %}',
139 class: '{% if modal_cancel_color is defined %}{{ modal_cancel_color }} {% endif %}icon labeled cancel',
140 click: {
141 {% if modal_cancel_click is defined %}
142 {{ modal_cancel_click|raw }}
143 {% endif %}
144 }
145 }
146 ],
147 {% if modal_classname is defined %}
148 {% if modal_classname == "redalert" %}
149 className: {
150 modal: 'ui redalert modal',
151 title: 'center aligned header',
152 content: 'center aligned content',
153 actions: 'center aligned actions'
154 }
155 {% else %}
156 className: {
157 {{ modal_classname|raw }}
158 }
159 {% endif %}
160 {% endif %}
161 }).modal('show');