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