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

(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc (-2 / +74 lines)
Lines 5-10 Link Here
5
        var dformat  = "[% dateformat | html %]";
5
        var dformat  = "[% dateformat | html %]";
6
        var sentmsg = 0;
6
        var sentmsg = 0;
7
        if (debug > 1) {alert("dateformat: " + dformat + "\ndebug is on (level " + debug + ")");}
7
        if (debug > 1) {alert("dateformat: " + dformat + "\ndebug is on (level " + debug + ")");}
8
        var MSG_PLEASE_ENTER_A_VALID_DATE = (_("Please enter a valid date (should match %s)."));
9
10
        function is_valid_date(date) {
11
            // An empty string is considered as a valid date for convenient reasons.
12
            if ( date === '' ) return 1;
13
            var dateformat = dateformat_str = '[% Koha.Preference('dateformat') | html %]';
14
            if ( dateformat == 'us' ) {
15
                if ( date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1 ) return 0;
16
                dateformat = 'mm/dd/yy';
17
            } else if ( dateformat == 'metric' ) {
18
                if ( date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1 ) return 0;
19
                dateformat = 'dd/mm/yy';
20
            } else if (dateformat == 'iso' ) {
21
                if ( date.search(/^\d{4}-\d{2}-\d{2}($|\s)/) == -1 ) return 0;
22
                dateformat = 'yy-mm-dd';
23
            } else if ( dateformat == 'dmydot' ) {
24
                if ( date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1 ) return 0;
25
            }
26
            try {
27
                $.datepicker.parseDate(dateformat, date);
28
            } catch (e) {
29
                return 0;
30
            };
31
            return 1;
32
        }
33
34
        function get_dateformat_str(dateformat) {
35
            var dateformat_str;
36
            if ( dateformat == 'us' ) {
37
                dateformat_str = 'mm/dd/yyyy';
38
            } else if ( dateformat == 'metric' ) {
39
                dateformat_str = 'dd/mm/yyyy';
40
            } else if (dateformat == 'iso' ) {
41
                dateformat_str = 'yyyy-mm-dd';
42
            } else if ( dateformat == 'dmydot' ) {
43
                dateformat_str = 'dd.mm.yyyy';
44
            }
45
                return dateformat_str;
46
        }
47
48
        function validate_date (dateText, inst) {
49
            if ( !is_valid_date(dateText) ) {
50
                var dateformat_str = get_dateformat_str( '[% Koha.Preference('dateformat') | html %]' );
51
                alert(MSG_PLEASE_ENTER_A_VALID_DATE.format(dateformat_str));
52
                $('#'+inst.id).val('');
53
            }
54
        }        
8
55
9
        function Date_from_syspref(dstring) {
56
        function Date_from_syspref(dstring) {
10
                var dateX = dstring.split(/[-/.]/);
57
                var dateX = dstring.split(/[-/.]/);
Lines 23-28 Link Here
23
                }
70
                }
24
        }
71
        }
25
72
73
        jQuery.validator.addMethod("is_date_after",
74
        function(value, element, params) {
75
            var from = Date_from_syspref( $(params).val() );
76
            var to = Date_from_syspref(value);
77
            return to > from;
78
        });
79
80
        jQuery.validator.addMethod("date_on_or_after",
81
        function(value, element, params) {
82
            var from = Date_from_syspref( $(params).val() );
83
            var to = Date_from_syspref(value);
84
            return to >= from;
85
        });
86
26
        /* Instead of including multiple localization files as you would normally see with
87
        /* Instead of including multiple localization files as you would normally see with
27
           jQueryUI we expose the localization strings in the default configuration */
88
           jQueryUI we expose the localization strings in the default configuration */
28
        jQuery(function($){
89
        jQuery(function($){
Lines 64-70 Link Here
64
                yearRange: "c-100:c"
125
                yearRange: "c-100:c"
65
            });
126
            });
66
127
67
            $( ".datepicker" ).datepicker();
128
            $( ".datepicker" ).datepicker({
129
                onClose: function(dateText, inst) {
130
                    validate_date(dateText, inst);
131
                },
132
            }).on("change", function(e, value) {
133
                if ( ! is_valid_date( $(this).val() ) ) {$(this).val("");}
134
            });
68
            // http://jqueryui.com/demos/datepicker/#date-range
135
            // http://jqueryui.com/demos/datepicker/#date-range
69
            var dates = $( ".datepickerfrom, .datepickerto" ).datepicker({
136
            var dates = $( ".datepickerfrom, .datepickerto" ).datepicker({
70
                changeMonth: true,
137
                changeMonth: true,
Lines 77-83 Link Here
77
                            $.datepicker._defaults.dateFormat,
144
                            $.datepicker._defaults.dateFormat,
78
                            selectedDate, instance.settings );
145
                            selectedDate, instance.settings );
79
                    dates.not( this ).datepicker( "option", option, date );
146
                    dates.not( this ).datepicker( "option", option, date );
80
                }
147
                },
148
                onClose: function(dateText, inst) {
149
                    validate_date(dateText, inst);
150
                },
151
            }).on("change", function(e, value) {
152
                if ( ! is_valid_date( $(this).val() ) ) {$(this).val("");}
81
            });
153
            });
82
        });
154
        });
83
    //]]>
155
    //]]>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt (-2 / +1 lines)
Lines 332-338 Link Here
332
                                                <label for="borrower_dateofbirth">Date of birth:</label>
332
                                                <label for="borrower_dateofbirth">Date of birth:</label>
333
                                            [% END %]
333
                                            [% END %]
334
334
335
                                            <input type="text" id="borrower_dateofbirth" name="borrower_dateofbirth" value="[% borrower.dateofbirth | $KohaDates %]" size="10" />
335
                                            <input type="text" id="borrower_dateofbirth" name="borrower_dateofbirth" value="[% borrower.dateofbirth | $KohaDates %]" size="10" class="datepicker" />
336
336
337
                                            [% UNLESS action == 'edit' && !OPACPatronDetails %]
337
                                            [% UNLESS action == 'edit' && !OPACPatronDetails %]
338
                                                [% UNLESS ( mandatory.defined('dateofbirth') ) %]
338
                                                [% UNLESS ( mandatory.defined('dateofbirth') ) %]
339
- 

Return to bug 26218