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