]> git.agnieray.net Git - galette.git/blob - galette/templates/default/pages/member_form.html.twig
Consistent display of groups accros members' pages
[galette.git] / galette / templates / default / pages / member_form.html.twig
1 {% extends parent_tpl %}
2
3 {% block content %}
4 <form action="{% if self_adh %}{{ path_for("storeselfmembers") }}{% elseif not member.id %}{{ path_for("doAddMember") }}{% else %}{{ path_for("doEditMember", {"id": member.id}) }}{% endif %}" method="post" enctype="multipart/form-data" id="form" class="ui form{% if member.id %} edit-member{% endif %}">
5 {% if member.id %}
6 <div class="ui stackable grid">
7 <div class="row">
8 <div class="sixteen wide tablet six wide computer five wide widescreen column order-2">
9 <div class="position-sticky">
10 <div class="ui basic clearing horizontally fitted segment">
11
12 <div class="ui left floated basic fitted segment">
13 {% include "elements/navigate.html.twig" with {"mpath": "editMember"} %}
14 </div>
15
16 <div class="ui right floated basic fitted segment">
17 <div class="ui small spaced buttons">
18 {% if member.id %}
19 <button type="submit" name="valid" class="action ui labeled icon primary button">
20 <i class="save icon"></i> {{ _T("Save") }}
21 </button>
22 {% endif %}
23 <a
24 href="{{ path_for("member", {"id": member.id}) }}"
25 class="ui basic labeled icon button"
26 >
27 <i class="eye outline icon"></i>
28 {{ _T("Display") }}
29 </a>
30 </div>
31 </div>
32 </div>
33 {% include "elements/member_card.html.twig" %}
34 {% endif %}
35
36 {% if not self_adh %}
37 <div class="ui{% if not member.id %} compact{% endif %} segment">
38 {% if member.hasParent() and not member.isDuplicate() %}
39 <div class="field">
40 <div class="ui label">
41 <i class="linkify icon"></i>
42 {{ _T("Attached to:") }}
43 </div>
44 <div class="ui celled list">
45 <a href="{{ path_for("member", {"id": member.parent.id}) }}" class="item">{{ member.parent.sfullname }}</a>
46 </div>
47 {% if not member.id %}
48 <input type="hidden" name="parent_id" value="{{ member.parent.id }}"/>
49 {% endif %}
50 </div>
51 {% if login.isAdmin() or login.isStaff() and (addchild is not defined or not addchild) %}
52 <div class="field">
53 <div class="ui toggle checkbox">
54 <input type="checkbox" name="detach_parent" id="detach_parent" value="1"/>
55 <label for="detach_parent">{{ _T("Detach?") }}</label>
56 </div>
57 </div>
58 {% endif %}
59 {% elseif (login.isAdmin() or login.isStaff()) and not member.hasChildren() and members.list is defined %}
60 <div id="attach-checkbox" class="ui{% if member.isDuplicate() %} checked{% endif %} toggle checkbox">
61 <input type="checkbox" name="attach" id="attach" value="1"{% if member.isDuplicate() %} checked="checked"{% endif %}/>
62 <label for="attach"><i class="linkify icon"></i> {{ _T("Attach member") }}</label>
63 </div>
64 <span id="parent_id_elt" class="">
65 <div id="parent_id" class="jsonly search-dropdown ui input nochosen">
66 <input id="parent_id_input" type="text" name="parent_id" value="{{ member.isDuplicate() and member.parent is defined and member.parent is not null ? member.parent.id }}" placeholder="{{ _T("Member ID") }}">
67 <i class="jsonly hidden dropdown icon"></i>
68 <div class="jsonly hidden default text">{{ _T("Search for name or ID and pick member") }}</div>
69 <div class="jsonly hidden menu">
70 {% for k, v in members.list %}
71 <div class="item" data-value="{{ k }}">{{ v }}</div>
72 {% endfor %}
73 </div>
74 </div>
75 <div class="jsonly hidden ui tiny icon button" id="reset-contributor"><i class="redo icon"></i><span class="hidden">{{ _T("Reset") }}</span></div>
76 </span>
77 {% if member.isDuplicate() %}
78 <input type="hidden" name="duplicate" value="1" />
79 {% endif %}
80 {% elseif member.hasChildren() %}
81 <div class="field">
82 <div class="ui label">
83 <i class="linkify icon"></i>
84 {{ _T("Parent of:") }}
85 </div>
86 <div class="ui celled list">
87 {% for child in member.children %}
88 <a href="{{ path_for("member", {"id": child.id}) }}" class="item">{{ child.sfullname }}</a>
89 {% endfor %}
90 </div>
91 </div>
92 {% endif %}
93 </div>
94 {% endif %}
95
96 {% if member.id %}
97 </div>
98 </div>
99 <div class="sixteen wide tablet ten wide computer eleven wide widescreen column">
100 {% endif %}
101 {# Main form entries #}
102 {% include "components/form.html.twig" %}
103
104 {% if not member.id and not self_adh %}
105 {% if login.isAdmin() or login.isStaff() %}
106 <div class="ui center aligned yellow segment">
107 <div class="inline field">
108 <label for="redirect_on_create">{{ _T("After member creation:") }}</label>
109 <select name="redirect_on_create" id="redirect_on_create"i class="ui search dropdown nochosen">
110 <option value="{{ constant('Galette\\Entity\\Adherent::AFTER_ADD_DEFAULT') }}"{% if preferences.pref_redirect_on_create == constant('Galette\\Entity\\Adherent::AFTER_ADD_DEFAULT') %} selected="selected"{% endif %}>{{ _T("create a new contribution (default action)") }}</option>
111 <option value="{{ constant('Galette\\Entity\\Adherent::AFTER_ADD_TRANS') }}"{% if preferences.pref_redirect_on_create == constant('Galette\\Entity\\Adherent::AFTER_ADD_TRANS') %} selected="selected"{% endif %}>{{ _T("create a new transaction") }}</option>
112 <option value="{{ constant('Galette\\Entity\\Adherent::AFTER_ADD_NEW') }}"{% if preferences.pref_redirect_on_create == constant('Galette\\Entity\\Adherent::AFTER_ADD_NEW') %} selected="selected"{% endif %}>{{ _T("create another new member") }}</option>
113 <option value="{{ constant('Galette\\Entity\\Adherent::AFTER_ADD_SHOW') }}"{% if preferences.pref_redirect_on_create == constant('Galette\\Entity\\Adherent::AFTER_ADD_SHOW') %} selected="selected"{% endif %}>{{ _T("show member") }}</option>
114 <option value="{{ constant('Galette\\Entity\\Adherent::AFTER_ADD_LIST') }}"{% if preferences.pref_redirect_on_create == constant('Galette\\Entity\\Adherent::AFTER_ADD_LIST') %} selected="selected"{% endif %}>{{ _T("go to members list") }}</option>
115 <option value="{{ constant('Galette\\Entity\\Adherent::AFTER_ADD_HOME') }}"{% if preferences.pref_redirect_on_create == constant('Galette\\Entity\\Adherent::AFTER_ADD_HOME') %} selected="selected"{% endif %}>{{ _T("go to main page") }}</option>
116 </select>
117 </div>
118 </div>
119 {% else %}
120 <input type="hidden" name="redirect_on_create" value="{{ constant('Galette\\Entity\\Adherent::AFTER_ADD_SHOW') }}"/>
121 {% endif %}
122 {% if addchild is defined and addchild %}
123 <input type="hidden" name="addchild" value="true"/>
124 {% endif %}
125 {% endif %}
126 {% if preferences.pref_mail_method != constant('Galette\\Core\\GaletteMail::METHOD_DISABLED') and (not self_adh and (login.isAdmin() or login.isStaff())) %}
127 <div class="ui center aligned yellow segment">
128 <div class="inline field">
129 <div class="ui toggle checkbox">
130 <input type="checkbox" name="mail_confirm" id="mail_confirm" value="1"{% if member.sendEMail() %} checked="checked"{% endif %}/>
131 <label for="mail_confirm">
132 {% if member.id %}
133 {{ _T("Notify member his account has been modified") }}
134 {% else %}
135 {{ _T("Notify member his account has been created") }}
136 {% endif %}
137 </label>
138 <br/>
139 <span class="exemple">
140 {% if member.id %}
141 {{ _T("Member will be notified by email his account has been modified.") }}
142 {% else %}
143 {{ _T("Member will receive his username and password by email, if he has an address.") }}
144 {% endif %}
145 </span>
146 </div>
147 </div>
148 </div>
149 {% endif %}
150 <div class="ui basic center aligned fitted segment">
151 <button type="submit" name="valid" class="action ui labeled icon primary button">
152 <i class="save icon"></i> {{ _T("Save") }}
153 </button>
154 {% for entry in hidden_elements %}
155 {% if entry.field_id != 'mdp_adh' %}
156 {% set title = null %}
157 {% set tip = null %}
158 {% set size = null %}
159 {% set propname = entry.propname %}
160 {% if entry.field_id == 'activite_adh' %}
161 {% set value = member.isActive() %}
162 {% else %}
163 {% set value = attribute(member, propname) %}
164 {% endif %}
165 {% set checked = null %}
166 {% set example = null %}
167
168 {% if value != '' and entry.field_id != 'parent_id' %}
169 {% include "components/forms/hidden.html.twig" with {
170 name: entry.field_id,
171 id: entry.field_id,
172 value: value
173 } %}
174 {% endif %}
175 {% endif %}
176 {% endfor %}
177 {% include "components/forms/csrf.html.twig" %}
178 </div>
179
180 {% if member.id %}
181 </div>
182 </div>
183 </div>
184 {% endif %}
185 </form>
186 {% endblock %}
187
188 {% block javascripts %}
189 <script type="text/javascript">
190 {% include "elements/js/choose_adh.js.twig" with {"js_chosen_id": "#parent_id"} %}
191 var _parent_id_input = document.getElementById('parent_id_input');
192 if ( typeof(_parent_id_input) != 'undefined' && _parent_id_input != null ) {
193 document.getElementById('parent_id_input').type = 'hidden';
194 }
195
196 $(function() {
197 $('#company_field.nocompany').addClass('hidden');
198 $('#is_company').change(function(){
199 $('#company_field').toggleClass('hidden');
200 $('#company_field').backgroundFade(
201 {
202 sColor:'#ffffff',
203 eColor:'#DDDDFF',
204 steps:10
205 },
206 function() {
207 $(this).backgroundFade(
208 {
209 sColor:'#DDDDFF',
210 eColor:'#ffffff'
211 }
212 );
213 });
214 });
215
216 {% if not self_adh %}
217 {# Groups popup #}
218 $('#btngroups, #btnmanagedgroups').click(function(){
219 var _managed = false;
220 if ( $(this).attr('id') == 'btnmanagedgroups' ) {
221 _managed = true;
222 }
223 var _groups = [];
224 var _form = (_managed) ? 'managed' : 'user';
225 $('#' + _form + 'groups_form input').each(function(){
226 _group = $(this).val().split('|');
227 _groups[_groups.length] = {
228 id: _group[0],
229 name: _group[1]
230 };
231 });
232 $.ajax({
233 url: '{{ path_for("ajax_groups") }}',
234 type: "POST",
235 data: {
236 ajax: true,
237 groups: _groups,
238 managed: _managed
239 },
240 {% include "elements/js/loader.js.twig" with {
241 selector: '#groups_field'
242 } %},
243 success: function(res){
244 _groups_dialog(res, _groups, _managed);
245 },
246 error: function() {
247 alert("{{ _T("An error occurred displaying groups interface :(")|e('js') }}");
248 }
249 });
250 return false;
251 });
252
253 var _groups_dialog = function(res, _groups, _managed){
254 var _title = '{{ _T("Groups selection")|e('js') }}';
255 if ( _managed ) {
256 _title = '{{ _T("Managed groups selection")|e('js') }}';
257 }
258 $('body').modal({
259 title: _title,
260 class: 'groups-selection fullscreen scrolling',
261 content: res,
262 actions: [{
263 text : '{{ _T("Close")|e('js') }}',
264 class : 'cancel'
265 }]
266 }).modal('show');
267 _groups_ajax_mapper(res, _groups, _managed);
268 }
269
270 var _groups_ajax_mapper = function(res, _groups, _managed){
271 $('#btnvalid').click(function(){
272 //remove actual groups
273 var _form = (_managed) ? 'managed' : 'user';
274 $('#' + _form + 'groups_form').empty();
275 var _groups = new Array();
276 var _groups_str = '<br/><strong>';
277 if ( _managed ) {
278 _groups_str += '{{ _T("Manager for:")|e('js') }}';
279 } else {
280 _groups_str += '{{ _T("Member of:")|e('js') }}';
281 }
282 _groups_str += '</strong> ';
283
284 $('li[id^="group_"]').each(function(){
285 //get group values
286 _gid = this.id.substring(6, this.id.length);
287 _gname = $(this).text();
288 _groups[_groups.length] = this.id.substring(6, this.id.length);
289 var _iname = (_managed) ? 'groups_managed_adh' : 'groups_adh';
290 $('#' + _form + 'groups_form').append(
291 '<input type="hidden" value="' +
292 _gid + '|' + _gname + '|' +
293 '" name="' + _iname + '[]">'
294 );
295 if ( _groups.length > 1 ) {
296 _groups_str += ', ';
297 }
298 _groups_str += _gname;
299 });
300 $('#' + _form + 'groups').html(_groups_str);
301 $('.groups-selection').modal('hide');
302 });
303 //Remap links
304 var _none = $('#none_selected').clone();
305 $('li input[type=checkbox]').click(function(e){
306 e.stopPropagation();
307 });
308 $('li[id^="group_"]').click(function(){
309 $(this).remove();
310 if ( $('#selected_groups ul li').length == 0 ) {
311 $('#selected_groups ul').append(_none);
312 }
313 });
314 $('#listing a').click(function(e){
315 e.preventDefault();
316 var _gid = this.href.match(/.*\/(\d+)$/)[1];
317 var _gname = $(this).text();
318 $('#none_selected').remove()
319 if ( $('#group_' + _gid).length == 0 ) {
320 var _li = '<li id="group_' + _gid + '" class="item">'
321 + '<i class="icons"><i class="users icon"><i class="top right corner minus icon"></i></i></i>'
322 + '<span class="ui content">' + _gname + '</span></li>';
323 $('#selected_groups ul').append(_li);
324 $('#group_' + _gid).click(function(){
325 $(this).remove();
326 if ( $('#selected_groups ul li').length == 0 ) {
327 $('#selected_groups ul').append(_none);
328 }
329 });
330 }
331 return false;
332 });
333
334 }
335
336 {% if not self_adh and not member.hasChildren() %}
337 {# Parent selection #}
338 {% if not member.isDuplicate() %}
339 $('#parent_id_elt').addClass('hidden');
340 {% endif %}
341 $('#attach-checkbox').checkbox({
342 onChecked: function() {
343 $('#parent_id_elt').removeClass('hidden');
344 },
345 onUnchecked: function() {
346 $('#parent_id_elt').addClass('hidden');
347 }
348 });
349 {% endif %}
350
351 {% if not self_adh %}
352 {% if parent_fields|length > 0 %}
353 $('#detach_parent').on('change', function(){
354 var _checked = $(this).is(':checked');
355 var _changes = '';
356 {% for req in parent_fields %}
357 _changes += '#{{ req }}';
358 {% if not loop.last %}
359 _changes += ',';
360 {% endif %}
361 {% endfor %}
362 if (_checked) {
363 $(_changes).attr('required', 'required');
364 } else {
365 $(_changes).removeAttr('required');
366 }
367 });
368
369 $('#parent_id').on('change', function(){
370 var _hasParent = $(this).attr('value') != '';
371 var _changes = '';
372 {% for req in parent_fields %}
373 _changes += '#{{ req }}';
374 {% if not loop.last %}
375 _changes += ',';
376 {% endif %}
377 {% endfor %}
378 if (_hasParent) {
379 $(_changes).removeAttr('required');
380 } else {
381 $(_changes).attr('required', 'required');
382 }
383 });
384 {% endif %}
385 {% endif %}
386 {% include "elements/js/photo_dnd.js.twig" %}
387
388 $('#ddn_adh').on('blur', function() {
389 var _bdate = $(this).val();
390 if ('{{ _T("Y-m-d") }}' === 'Y-m-d') {
391 _bdate = new Date(_bdate);
392 } else {
393 //try for dd/mm/yyyy
394 var _dparts = _bdate.split("/");
395 _bdate = new Date(_dparts[2], _dparts[1] - 1, _dparts[0]);
396 }
397
398 if (! isNaN(_bdate.getTime())) {
399 var _today = new Date();
400 var _age = Math.floor((_today-_bdate) / (365.25 * 24 * 60 * 60 * 1000));
401 $('#member_age').html('{{ _T(" (%age years old)") }}'.replace(/%age/, _age))
402 } else {
403 $('#member_age').html('');
404 }
405 });
406 {% endif %}
407 });
408 </script>
409 {% endblock %}