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

(-)a/koha-tmpl/intranet-tmpl/prog/en/js/members.js (-42 / +11 lines)
Lines 147-202 function Dopopguarantor(link) { Link Here
147
    var newin=window.open(link,'popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=yes,top');
147
    var newin=window.open(link,'popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=yes,top');
148
}
148
}
149
149
150
function CalculateAge() {
150
function CalculateAge(dateofbirth) {
151
    var hint = $("#dateofbirth").siblings(".hint").first();
152
    hint.html(dateformat);
153
154
    if (dformat == 'metric' && false === CheckDate(document.form.dateofbirth)) {
155
        return;
156
    }
157
158
    if (!$("#dateofbirth").datepicker( 'getDate' )) {
159
        return;
160
    }
161
162
    var today = new Date();
151
    var today = new Date();
163
    var dob = new Date($("#dateofbirth").datepicker( 'getDate' ));
152
    var dob = Date_from_syspref(dateofbirth)
164
153
    var age = new Object();
165
    var nowyear = today.getFullYear();
166
    var nowmonth = today.getMonth();
167
    var nowday = today.getDate();
168
154
169
    var birthyear = dob.getFullYear();
155
    age.year = today.getFullYear() - dob.getFullYear();
170
    var birthmonth = dob.getMonth();
156
    age.month = today.getMonth() - dob.getMonth();
171
    var birthday = dob.getDate();
157
    var day = today.getDate() - dob.getDate();
172
173
    var year = nowyear - birthyear;
174
    var month = nowmonth - birthmonth;
175
    var day = nowday - birthday;
176
158
177
    if(day < 0) {
159
    if(day < 0) {
178
        month = parseInt(month) -1;
160
        age.month = parseInt(age.month) -1;
179
    }
180
181
    if(month < 0) {
182
        year = parseInt(year) -1;
183
        month = 12 + month;
184
    }
161
    }
185
162
186
    var age_string;
163
    if(age.month < 0) {
187
    if (year || month) {
164
        age.year = parseInt(age.year) -1;
188
        age_string = _('Age: ');
165
        age.month = 12 + age.month;
189
    }
190
    if (year) {
191
        age_string += _(year > 1 ? '%s years ' : '%s year ').format(year);
192
    }
166
    }
193
167
194
    if (month) {
168
    return age;
195
        age_string += _(month > 1 ? '%s months ' : '%s month ').format(month);
196
    }
197
198
    hint.html(age_string);
199
200
}
169
}
201
170
202
$(document).ready(function(){
171
$(document).ready(function(){
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-3 / +28 lines)
Lines 35-41 Link Here
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();
37
        dateformat = $("#dateofbirth").siblings(".hint").first().html();
38
        CalculateAge();
38
        write_age();
39
        $("#entryform").validate({
39
        $("#entryform").validate({
40
            rules: {
40
            rules: {
41
                email: {
41
                email: {
Lines 147-152 Link Here
147
        return 0;
147
        return 0;
148
    }
148
    }
149
149
150
    function write_age() {
151
        var hint = $("#dateofbirth").siblings(".hint").first();
152
        hint.html(dateformat);
153
154
        var age = CalculateAge(document.form.dateofbirth.value);
155
156
        if (!age.year && !age.month) {
157
            return;
158
        }
159
160
        var age_string;
161
        if (age.year || age.month) {
162
            age_string = _('Age: ');
163
        }
164
165
        if (age.year) {
166
            age_string += _(age.year > 1 ? '%s years ' : '%s year ').format(age.year);
167
        }
168
169
        if (age.month) {
170
            age_string += _(age.month > 1 ? '%s months ' : '%s month ').format(age.month);
171
        }
172
173
        hint.html(age_string);
174
    }
175
150
        var MSG_SEPARATOR = _("Separator must be / in field %s");
176
        var MSG_SEPARATOR = _("Separator must be / in field %s");
151
        var MSG_INCORRECT_DAY = _("Invalid day entered in field %s");
177
        var MSG_INCORRECT_DAY = _("Invalid day entered in field %s");
152
        var MSG_INCORRECT_MONTH = _("Invalid month entered in field %s");
178
        var MSG_INCORRECT_MONTH = _("Invalid month entered in field %s");
Lines 343-349 Link Here
343
                [% END %]
369
                [% END %]
344
                Date of birth: </label>
370
                Date of birth: </label>
345
371
346
                <input type="text" id="dateofbirth" name="dateofbirth" size="20" onchange="CalculateAge();" value="[% UNLESS opduplicate %][% dateofbirth %][% END %]" />
372
                <input type="text" id="dateofbirth" name="dateofbirth" size="20" onchange="write_age();" value="[% UNLESS opduplicate %][% dateofbirth %][% END %]" />
347
373
348
        [% IF ( mandatorydateofbirth ) %]<span class="required">Required</span>[% END %]
374
        [% IF ( mandatorydateofbirth ) %]<span class="required">Required</span>[% END %]
349
        [% IF ( ERROR_dateofbirth ) %]<span class="required">(Error)</span>[% END %]
375
        [% IF ( ERROR_dateofbirth ) %]<span class="required">(Error)</span>[% END %]
350
- 

Return to bug 15206