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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/curbside_pickups.tt (-1 / +1 lines)
Lines 477-483 Link Here
477
477
478
                                            <li>
478
                                            <li>
479
                                                <label for="pickup_date">Pickup date: </label>
479
                                                <label for="pickup_date">Pickup date: </label>
480
                                                <input id="pickup_date" name="pickup_date" required="required" class="flatpickr" />
480
                                                <input id="pickup_date" name="pickup_date" required="required" class="flatpickr" data-flatpickr-futuredate="true" />
481
                                            </li>
481
                                            </li>
482
482
483
                                            <li id="pickup-times" class="radio"></li>
483
                                            <li id="pickup-times" class="radio"></li>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/calendar.inc (-6 / +54 lines)
Lines 134-146 Link Here
134
    }
134
    }
135
135
136
        $(document).ready(function(){
136
        $(document).ready(function(){
137
            $(".flatpickr").flatpickr();
137
            $(".flatpickr").each(function(){
138
                let options = {};
139
                let refresh_max_date = 0;
140
                let disable_buttons = [];
138
141
139
            $(".clear-flatpickr").on("click", function(e){
142
                if( $(this).data("flatpickr-futuredate") === true ) {
140
                e.preventDefault();
143
                    let original_date = $(this).val();
141
                var element = $(this).data("fp");
144
                    if ( original_date ) {
142
                if( element ){
145
                        original_date = Date_from_syspref( original_date ).getTime();
143
                    document.querySelector("#" + element )._flatpickr.clear();
146
                        let tomorrow = new Date().fp_incr(1).getTime();
147
148
                        options['enable'] = [function(date){
149
                            date = date.getTime();
150
                            if ( date == original_date ) return true;
151
                            if ( date >= tomorrow)       return true;
152
                        }];
153
                    }
154
                    else {
155
                        options['minDate'] = new Date().fp_incr(1);
156
                    }
157
                    disable_buttons.push(0); /* Yesterday */
158
                    disable_buttons.push(1); /* Today */
159
                }
160
                if( $(this).data("flatpickr-pastinclusive") === true ) {
161
                    options['maxDate'] = new Date(); /* Not today or hh:mm will be 00:00 */
162
                    refresh_max_date = 1;
163
                    disable_buttons.push(2); /* Tomorrow */
164
                }
165
                if( $(this).data("flatpickr-pastdate") === true ) {
166
                    options['maxDate'] = new Date().fp_incr(-1).setHours(23, 59, 00, 00);
167
                    disable_buttons.push(1); /* Today */
168
                    disable_buttons.push(2); /* Tomorrow */
169
                }
170
                if ( $(this).data('flatpickr-enable-time') === true ) {
171
                    options['enableTime'] = true;
172
                    options['dateFormat'] = flatpickr_dateformat_string + " " + flatpickr_timeformat_string;
173
                }
174
175
                let fp = $(this).flatpickr(options);
176
177
                $(disable_buttons).each(function(index, value){
178
                    $(fp.calendarContainer).find(".shortcut-buttons-flatpickr-button[data-index='"+value+"']").prop("disabled", "disabled");
179
                });
180
181
                if ( refresh_max_date ) {
182
                    /* Refresh the maxDate every 30 secondes to make sure the user will not
183
                       be stuck with the minute passed.
184
                       Adding 1 minute to not introduce a gap.
185
                       Example: last update at 40s, a new minute passed at 00.
186
                       Between 00 and 10s the user won't be able click 'Today'.
187
                    */
188
                    setInterval(() => {
189
                        let now = new Date();
190
                        fp.set("maxDate", now.setMinutes(now.getMinutes() + 1));
191
                    }, 30000);
144
                }
192
                }
145
            });
193
            });
146
        });
194
        });
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-curbside-pickups.tt (-2 / +1 lines)
Lines 187-193 Link Here
187
                                                </li>
187
                                                </li>
188
                                                <li>
188
                                                <li>
189
                                                    <label for="pickup_date">Pickup date:</label>
189
                                                    <label for="pickup_date">Pickup date:</label>
190
                                                    <input name="pickup_date" type="text" class="flatpickr" id="pickup-date" disabled required="required"/>
190
                                                    <input name="pickup_date" type="text" class="flatpickr" id="pickup-date" disabled required="required" data-flatpickr-futuredate="true" />
191
                                                    <span class="required">Required</span>
191
                                                    <span class="required">Required</span>
192
                                                </li>
192
                                                </li>
193
193
194
- 

Return to bug 31261