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