View | Details | Raw Unified | Return to bug 15206
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-3 / +53 lines)
Lines 34-39 Link Here
34
            }
34
            }
35
        [% END %]
35
        [% END %]
36
        $("#dateofbirth").datepicker({ maxDate: "-1D", yearRange: "c-120:" });
36
        $("#dateofbirth").datepicker({ maxDate: "-1D", yearRange: "c-120:" });
37
        dateformat = $("#dateofbirth").siblings(".hint").first().html();
38
        CalculateAge(dformat == 'metric' ? true : false);
37
        $("#entryform").validate({
39
        $("#entryform").validate({
38
            rules: {
40
            rules: {
39
                email: {
41
                email: {
Lines 145-150 Link Here
145
        return 0;
147
        return 0;
146
    }
148
    }
147
149
150
    function CalculateAge(checkdate) {
151
        var hint = $("#dateofbirth").siblings(".hint").first();
152
        hint.html(dateformat);
153
154
        if (checkdate && false === CheckDate(document.form.dateofbirth)) {
155
            return;
156
        }
157
158
        if (!$("#dateofbirth").datepicker( 'getDate' )) {
159
            return;
160
        }
161
162
        var today = new Date();
163
        var dob = new Date($("#dateofbirth").datepicker( 'getDate' ));
164
165
        var nowyear = today.getFullYear();
166
        var nowmonth = today.getMonth();
167
        var nowday = today.getDate();
168
169
        var birthyear = dob.getFullYear();
170
        var birthmonth = dob.getMonth();
171
        var birthday = dob.getDate();
172
173
        var year = nowyear - birthyear;
174
        var month = nowmonth - birthmonth;
175
        var day = nowday - birthday;
176
177
        if(day < 0) {
178
            month = parseInt(month) -1;
179
        }
180
181
        if(month < 0) {
182
            year = parseInt(year) -1;
183
            month = 12 + month;
184
        }
185
186
        var age_string = _('Age: ');
187
        if (year) {
188
            age_string += _(year > 1 ? '%s years ' : '%s year ').format(year);
189
        }
190
191
        if (month) {
192
            age_string += _(month > 1 ? '%s months ' : '%s month ').format(month);
193
        }
194
195
        hint.html(age_string);
196
197
    }
198
148
199
149
200
150
        var MSG_SEPARATOR = _("Separator must be / in field %s");
201
        var MSG_SEPARATOR = _("Separator must be / in field %s");
Lines 344-352 Link Here
344
                Date of birth: </label>
395
                Date of birth: </label>
345
396
346
        [% IF ( dateformat == "metric" ) %]
397
        [% IF ( dateformat == "metric" ) %]
347
                <input type="text" id="dateofbirth" name="dateofbirth" size="20" onchange="CheckDate(document.form.dateofbirth);" value="[% UNLESS opduplicate %][% dateofbirth %][% END %]" />
398
                <input type="text" id="dateofbirth" name="dateofbirth" size="20" onchange="CalculateAge(true);" value="[% UNLESS opduplicate %][% dateofbirth %][% END %]" />
348
        [% ELSE %]
399
        [% ELSE %]
349
                <input type="text" id="dateofbirth" name="dateofbirth" size="20" value="[% UNLESS opduplicate %][% dateofbirth %][% END %]" />
400
                <input type="text" id="dateofbirth" name="dateofbirth" size="20" onchange="CalculateAge(false);" value="[% UNLESS opduplicate %][% dateofbirth %][% END %]" />
350
        [% END %]
401
        [% END %]
351
402
352
        [% IF ( mandatorydateofbirth ) %]<span class="required">Required</span>[% END %]
403
        [% IF ( mandatorydateofbirth ) %]<span class="required">Required</span>[% END %]
353
- 

Return to bug 15206