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

Return to bug 31261