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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-24 / +21 lines)
Lines 145-180 Link Here
145
        return 0;
145
        return 0;
146
    }
146
    }
147
147
148
    function CalculateAge(dateofbirth) {
148
    function CalculateAge() {
149
        var today = new Date();
149
        if (!$("#dateofbirth").datepicker( 'getDate' )) {
150
        var dob = new Date($("#dateofbirth").datepicker( 'getDate' ));
150
            var elem = $("#dateofbirth").siblings(".hint").first().html('');
151
151
            return 1;
152
        var nowyear = today.getFullYear();
152
        }
153
        var nowmonth = today.getMonth();
154
        var nowday = today.getDate();
155
153
156
        var birthyear = dob.getFullYear();
154
        var dob = new Date($("#dateofbirth").datepicker( 'getDate' ));
157
        var birthmonth = dob.getMonth();
158
        var birthday = dob.getDate();
159
155
160
        var year = nowyear - birthyear;
156
        var year = dob.getFullYear();
161
        var month = nowmonth - birthmonth;
157
        var month = dob.getMonth();
162
        var day = nowday - birthday;
158
        var day = dob.getDate();
163
159
164
        if(day < 0) {
160
        $.ajax({
165
            month = parseInt(month) -1;
161
            url : '/cgi-bin/koha/svc/members/age',
166
        }
162
            type : 'GET',
163
            data: 'dateofbirth=' + year + '-' + month + '-' + day,
164
            dataType: 'json',
165
            success : function(json, statut){
166
                var age_string = "Age: ";
167
                if (json.years) { age_string += json.years + " year(s) "; }
168
                if (json.months) { age_string += json.months + " month(s) "; }
169
                var elem = $("#dateofbirth").siblings(".hint").first().html(age_string);
170
            },
171
        });
167
172
168
        if(month < 0) {
169
            year = parseInt(year) -1;
170
            month = 12 + month;
171
        }
172
173
173
        var age_string = "Age: ";
174
        var age_string = "Age: ";
174
        if (year) { age_string += year + " year(s) "; }
175
        if (month) { age_string += month + " month(s) "; }
176
175
177
        var elem = $("#dateofbirth").siblings(".hint").first().html(age_string);
178
    }
176
    }
179
177
180
178
181
- 

Return to bug 15206