-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
68 lines (58 loc) · 3.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
window.onload = function(e){
};
/* your script should have RangeCalendar class at this point, as well as moment.js for it */
/* example of UI functions for use with forms */
var RangeCalendarUI = {
addDateRangeNode: function(col_name){
var node = $('<div class="query-param range-'+ col_name +'">'
+ '<span class="column">' + col_name + '</span> '
+ '<input form="query-form" class="query-date-start" type="hidden" name="query[range][' + col_name + '][start]" value=""/>'
+ '<input form="query-form" class="query-date-end" type="hidden" name="query[range][' + col_name + '][end]" value=""/>'
+ '<span class="range-calendar-holder"></span>'
+ '<a class="close">×</a>'
+ '</div>').appendTo($(".table-queries-list"));
var pa = node.find(".range-calendar-holder");
new RangeCalendar({'pa': pa, 'callback': SearchQuery.setDateRangeInput });
SearchQuery.bind_inputs();
$(".table-query").show();
},
setDateRangeInput: function(range){
var inp_start = range.pa.siblings(".query-date-start");
var inp_end = range.pa.siblings(".query-date-end");
inp_start.val( range.from.format('Y-MM-DD HH:mm:ss'));
inp_end.val( range.to.format('Y-MM-DD HH:mm:ss'));
console.log(range.from.format('Y-MM-DD HH:mm:ss'), range.to.format('Y-MM-DD HH:mm:ss') );
}
};
var RangeCalendarUI2 = {
initSearchDatetimeInput: function(point, callback){
var node = $('<div class="btn-group search-date-range-ddn">'
+ '<input class="search-date-from" value="" type="hidden">'
+ '<input class="search-date-to" value="" type="hidden">'
+ '<span class="range-calendar-holder"></span>'
+ '<a href="#" class="btn suffix search-date-range-btn"><i class="icon-magnifier"></i></a>'
+ '</div>').appendTo(point);
var pa = node.find(".range-calendar-holder");
new RangeCalendar({'pa': pa, 'callback': callback });
$('.search-date-range-btn').off('click').on('click', RangeCalendarUI2.dateSearch);
},
setDateRangeInput: function(range){
var inp_start = range.pa.siblings(".search-date-from");
var inp_end = range.pa.siblings(".search-date-to");
inp_start.val( range.from.clone().utc().format('Y-MM-DD HH:mm:ss'));
inp_end.val( range.to.clone().utc().format('Y-MM-DD HH:mm:ss'));
},
dateSearch: function(e){
e.preventDefault();
var timeFrom = $('.search-date-from').val();
var timeTo = $('.search-date-to').val();
if( 'Invalid date' == timeFrom || 'Invalid date' == timeTo ){
console.log('danger', 'Enter valid dates');
return;
}
window.location = '?searchDateFrom=' + timeFrom + '&searchDateTo=' + timeTo;
},
init: function(){
RangeCalendarUI2.initSearchDatetimeInput( $('.wall-view-subpanel'), Wall.setDateRangeInput );
}
};