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