PageSourceSearch

https://cross-club.info/nassets/d5b79c02/date.js?v=1790428180

js cross-club.info collected 2026-10-09 05:07:55 UTC 14,512 bytes, 410 lines download raw bytes

1function DateFieldWidget() {
2
3    this.dateFrom = null;
4    this.dateTo = null;
5    this.dateType = null;
6
7	this.toNDays = null;
8    this.fromNDays = null;
9
10	this.controlEl = null;
11    this.withTime = false;
12    this.datepickersInitialized = false;
13    // this.withTime =
14    var widget = this;
15
16    this.getDates = function(field) {
17        var params = {
18            dateFrom: this.dateFrom,
19            dateTo: this.dateTo,
20            dateType: this.dateType,
21            toNDays: this.toNDays,
22            fromNDays: this.fromNDays
23        };
24
25        var widget = this;
26
27        if (this.dateType) {
28            ajaxCall("/pl/system/get-date-by-params", {params: params}, {}, function (response) {
29                widget.controlEl.find('.date-helper').html(response.label).removeClass('hide');
30            });
31        } else {
32            widget.controlEl.find('.date-helper').addClass('hide');
33        }
34    };
35
36    this.initEl = function( $el, field, value ) {
37
38        $el.addClass("date-field-widget");
39        if ( field.one_line ) {
40            $el.addClass("one-line");
41        }
42
43        $controlEl = $( "<div style='white-space: nowrap'>" + "<div class='manual-selected-date'><span class='from'/><span class='to'  size=20 /></div>"
44            + "<div class='n-days-selected-wrap'><span class='from_n'/><span class='to_n'/></div>" + "<label class='date-helper'></label></div>"   );
45        this.controlEl = $controlEl;
46        var self = this;
47
48        this.fromElWrapper = $controlEl.find('.from');
49        this.toElWrapper = $controlEl.find('.to');
50
51        this.fromNDaysWrapper = $controlEl.find('.from_n');
52        this.toNDaysWrapper = $controlEl.find('.to_n');
53
54        var dateType = null;
55        if ( value ) {
56            if ( value.from ) this.dateFrom = value.from;
57            if ( value.to ) this.dateTo = value.to;
58            if ( value.toNDays ) this.toNDays = value.toNDays;
59			if ( value.fromNDays ) this.fromNDays = value.fromNDays;
60            if ( value.dateType ) dateType = value.dateType;
61			if ( value.withTime ) this.withTime = value.withTime;
62        }
63
64        this.initDatepickers( value, field );
65        widget.dateTypeChanged( dateType )
66
67        $selectDateTypeEl = $("<div class='date-type-selector'/>");
68        this.typeSelectWidget = new window.logicFieldWidgets["select"]();
69
70        var datetypesUrl = '/pl/logic/logic-ajax/date-types';
71
72        if (field.period_type) {
73            datetypesUrl += "?periodType=" + field.period_type;
74        }
75
76        var labelSelectDates = 'Выбрать даты';
77        if (typeof Yii != 'undefined') {
78            labelSelectDates = Yii.t( "common", "Select dates" );
79        }
80
81        this.typeSelectWidget.init( $selectDateTypeEl, { "name" : "status", not_multiple: true, values_url: datetypesUrl, emptyLabel: labelSelectDates  }, { selected_id: dateType } );
82        this.typeSelectWidget.changed = function() {
83            var value = this.getValue();
84            var selected = null;
85            if ( value ) {
86                selected = value.selected_id;
87            }
88            widget.dateTypeChanged( selected )
89            widget.changed();
90            widget.getDates();
91        };
92
93        $withTimeEl = $("<input style='display: none' type='checkbox' >");
94        if(window.isPageRedesigned) {
95            this.withTimeElWrapperEl = $withTimeElWrapperEl = $("<label class='with-time-checkbox manual-selected-date' title='Указать точное время'> <i class='gc-icons gc-time f-size-20'></i></label>");
96        } else {
97            this.withTimeElWrapperEl = $withTimeElWrapperEl = $("<label class='with-time-checkbox manual-selected-date' title='Указать точное время'> <span class='fa fa-clock-o'></span></label>");
98        }
99        $withTimeEl.prependTo( $withTimeElWrapperEl );
100
101        $withTimeEl.change( function() {
102            self.withTime = $(this).prop('checked');
103
104            if ( self.withTime ) {
105                $withTimeElWrapperEl.addClass('checked');
106            }
107            else {
108                $withTimeElWrapperEl.removeClass('checked');
109            }
110
111            self.initDatepickers( self.getValue(), field );
112            self.changed();
113        });
114
115
116		if (self.withTime) {
117			$withTimeElWrapperEl.addClass('checked');
118		}
119
120        this.withTimeChecker = $withTimeEl;
121
122        $addControlsEl = $("<div class='additional-controls'>");
123        $selectDateTypeEl.appendTo( $addControlsEl );
124        $withTimeElWrapperEl.appendTo( $addControlsEl );
125
126        //this.dateTypeChanged( dateType )
127
128        $addControlsEl.prependTo( $controlEl );
129
130        this.initFieldEl( $el, $controlEl, field )
131	    if (field.sub_label) {
132			setTimeout(function () {
133				$el.parent().find('label').first().after(
134					'<br><span class="text-muted">' + field.sub_label + '</span>'
135				);
136			}, 1000);
137	    }
138    };
139
140    this.initDatepickers = function( value, field ) {
141        this.fromElWrapper.empty();
142        this.toElWrapper.empty();
143        this.toNDaysWrapper.empty();
144        this.fromNDaysWrapper.empty();
145
146        var placeholderFrom = 'с';
147        var placeholderTo = 'по';
148        var placeholderFrom2 = 'от';
149        var placeholderTo2 = 'до';
150        if (typeof Yii != 'undefined') {
151            placeholderFrom = Yii.t("common", "from");
152            placeholderTo = Yii.t("common", "to");
153            placeholderFrom2 = Yii.t("common", placeholderFrom2);
154            placeholderTo2 = Yii.t("common", placeholderTo2);
155        }
156        if(window.isPageRedesigned) {
157            this.fromEl = $('<input class="form-control" type="text" autocomplete="off" size="14" placeholder="' + placeholderFrom + '"/><i class="gc-icons gc-calendar f-size-16"></i>');
158            this.toEl = $('<input class="form-control" type="text" autocomplete="off" size="14" placeholder="' + placeholderTo + '"/><i class="gc-icons gc-calendar f-size-16"></i>');
159        } else {
160            this.fromEl = $('<input class="form-control" type="text" autocomplete="off" size="14" placeholder="' + placeholderFrom + '" style="margin-right: 4px; display: inline; width: 130px;"/>');
161            this.toEl = $('<input class="form-control" type="text" autocomplete="off" size="14" placeholder="' + placeholderTo + '" style="display: inline; width: 130px"/>');
162        }
163
164        this.fromNDaysEl = $('<label>' + placeholderFrom2 + ' <input type="text" size=16/></label>');
165        this.fromNDaysEl.find('input:first').val(this.fromNDays);
166
167        this.toNDaysEl = $('<label>' + placeholderTo2 + ' <input type="text" size=16/></label>');
168        this.toNDaysEl.find('input:first').val(this.toNDays);
169
170        this.toEl.appendTo( this.toElWrapper );
171        this.fromEl.appendTo( this.fromElWrapper );
172
173        this.toNDaysEl.appendTo( this.toNDaysWrapper );
174        this.fromNDaysEl.appendTo( this.fromNDaysWrapper );
175
176        if ( value ) {
177            var setVal = null;
178
179            if ( value.from ) {
180                if ( this.withTime ) {
181                    setVal = value.from;
182                    if ( setVal.length == 10 ) {
183                        setVal += " 00:00";
184                    }
185                }
186                else {
187                    this.dateFrom = value.from.substring(0,10);
188                    setVal = this.dateFrom;
189                }
190
191                this.fromEl.val( setVal );
192            }
193            if ( value.to ) {
194                if ( this.withTime ) {
195                    setVal = value.to;
196                    if ( setVal.length == 10 ) {
197                        setVal += " 23:59";
198                    }
199                }
200                else {
201                    this.dateTo = value.to.substring(0,10);
202                    setVal = this.dateTo;
203                }
204
205                this.toEl.val( setVal );
206            }
207        }
208        var dateOptions = {
209            autoclose: true,
210            format: "dd.mm.yyyy",
211            language: "ru",
212            weekStart: 1
213        };
214        var dateTimeOptions = {
215            autoclose: true,
216            format: "dd.mm.yyyy hh:ii",
217            language: "ru",
218            weekStart: 1
219        };
220
221        if (field.without_year) {
222            //options.format = 'dd.mm';
223        }
224
225        if (window.isPageRedesigned) {
226            if (this.withTime) {
227                $(this.fromEl[0]).datetimepicker(dateTimeOptions);
228                $(this.toEl[0]).datetimepicker(dateTimeOptions);
229            } else {
230                $(this.fromEl[0]).datepicker(dateOptions);
231                $(this.toEl[0]).datepicker(dateOptions);
232            }
233
234            var bindCalendarIcon = function ($input) {
235                var $icon = $input.next('.gc-calendar');
236
237                function setOpenedState(isOpened) {
238                    $icon.toggleClass('gc-calendar', !isOpened);
239                    $icon.toggleClass('gc-close', isOpened);
240                    $icon.toggleClass('is-opened', isOpened);
241                }
242
243                $input
244                    .off('.dateFieldCalendarState')
245                    .on('show.dateFieldCalendarState', function () {
246                        setOpenedState(true);
247                    })
248                    .on('hide.dateFieldCalendarState', function () {
249                        setOpenedState(false);
250                    });
251
252                $icon
253                    .off('.dateFieldCalendar')
254                    .on('mousedown.dateFieldCalendar', function (e) {
255                        e.preventDefault();
256                        e.stopImmediatePropagation();
257                    })
258                    .on('click.dateFieldCalendar', function (e) {
259                        e.preventDefault();
260                        e.stopImmediatePropagation();
261
262                        var isOpened = $icon.hasClass('is-opened');
263
264                        if (self.withTime) {
265                            $input.datetimepicker(isOpened ? 'hide' : 'show');
266                        } else {
267                            $input.datepicker(isOpened ? 'hide' : 'show');
268                        }
269
270                        return false;
271                    });
272            };
273
274            bindCalendarIcon($(this.fromEl[0]));
275            bindCalendarIcon($(this.toEl[0]));
276        } else {
277            if ( this.withTime ) {
278                this.fromEl.datetimepicker(dateTimeOptions);
279                this.toEl.datetimepicker(dateTimeOptions);
280            }
281            else {
282                this.fromEl.datepicker(dateOptions);
283                this.toEl.datepicker(dateOptions);
284            }
285        }
286
287        var self = this;
288
289        var dateChanged = function( field, obj  ) {
290            if (field != 'toNDays' && field != 'fromNDays') {
291                if ( self.withTime ) {
292                    var date = $(obj).datetimepicker('getDate' );
293                }
294                else {
295                    var date = $(obj).datepicker('getDate' );
296                }
297                var value = null;
298                if( date ) {
299                    value = ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
300                }
301                if ( self.withTime ) {
302                    value += " ";
303                    value += date.getHours() >= 12 ? date.getHours() : ( '0' + date.getHours() ).slice(-2)
304                    value += ":";
305                    value += date.getMinutes() >= 10 ? date.getMinutes() : ( '0' + date.getMinutes() ).slice(-2)
306                }
307            } else {
308				value = $(obj).find('input:first').val();
309            }
310
311            widget[field] = value;
312            widget.changed();
313            widget.getDates();
314        };
315
316
317        this.toEl.on( 'keyUp', function() {
318            dateChanged( "dateTo", this )
319        } );
320
321        this.toEl.on( 'changeDate', function() {
322            dateChanged( "dateTo", this )
323        });
324
325        this.fromEl.on( 'keyUp', function() {
326            dateChanged( "dateFrom", this )
327        } );
328
329        this.fromEl.on( 'changeDate', function() {
330            dateChanged( "dateFrom", this )
331        });
332
333        this.toNDaysEl.on( 'change', function() {
334            dateChanged( "toNDays", this )
335        });
336
337        this.fromNDaysEl.on( 'change', function() {
338            dateChanged( "fromNDays", this )
339        });
340
341        this.datepickersInitialized = this.withTime ? "time" : "date";
342
343
344    };
345
346    this.dateTypeChanged = function( type ) {
347        if ( type ) {
348            this.controlEl.addClass('date-type-selected');
349            this.controlEl.removeClass("manual-type-selected")
350
351            if ( type  == 'next_n_days' || type  == 'next_n_days_from_now' || type == 'last_n_days' || type == 'last_n_hours') {
352                this.controlEl.addClass('n-days-selected');
353            } else {
354                this.controlEl.removeClass('n-days-selected');
355            }
356
357        } else {
358            this.controlEl.removeClass('date-type-selected');
359            this.controlEl.removeClass('n-days-selected');
360            this.controlEl.addClass("manual-type-selected")
361        }
362
363        this.dateType = type;
364    };
365
366    this.getValue = function() {
367        return { from: this.dateFrom, to: this.dateTo, toNDays: this.toNDays, fromNDays: this.fromNDays, dateType: this.dateType, withTime: this.withTime };
368    };
369
370    this.setValue = function( value ) {
371        if ( value ) {
372            var withTime = value.withTime;
373
374            var from = value.from && !withTime ? value.from.substring(0, 10) : value.from;
375            var to = value.to && !withTime ? value.to.substring(0, 10) : value.to;
376
377            //this.fromEl.val( from )
378            this.dateFrom = from;
379            this.dateTypeChanged(value.dateType)
380            this.typeSelectWidget.setValue({selected_id: value.dateType})
381
382            //this.toEl.val( value.to )
383            this.dateTo = value.to;
384            this.withTime = withTime;
385            this.withTimeChecker.prop('checked', withTime)
386
387            if ( this.withTime ) {
388                this.withTimeElWrapperEl.addClass('checked');
389            }
390            else {
391                this.withTimeElWrapperEl.removeClass('checked');
392            }
393
394
395
396            this.toNDays = value.toNDays;
397			this.fromNDays = value.fromNDays;
398
399            this.initDatepickers(value, this.field);
400            widget.getDates();
401        }
402    }
403
404}
405
406extend( DateFieldWidget, FieldWidget )
407DateFieldWidget.prototype = new FieldWidget()
408
409
410window.logicFieldWidgets["date"] = DateFieldWidget

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.