|
34 | 34 | } |
35 | 35 | break; |
36 | 36 | case 'date': |
37 | | - additional_control = |
38 | | - $('<input size="20" class="date additional-fieldset default input-sm form-control" type="text" />') |
39 | | - .css('display', (!field_operator || field_operator == "default") ? 'inline-block' : 'none') |
40 | | - .prop('name', value_name + '[]') |
41 | | - .prop('value', field_value[0] || '') |
42 | | - .add( |
43 | | - $('<input size="20" placeholder="-∞" class="date additional-fieldset between input-sm form-control" type="text" />') |
44 | | - .css('display', (field_operator == "between") ? 'inline-block' : 'none') |
45 | | - .prop('name', value_name + '[]') |
46 | | - .prop('value', field_value[1] || '') |
47 | | - ) |
48 | | - .add( |
49 | | - $('<input size="20" placeholder="∞" class="date additional-fieldset between input-sm form-control" type="text" />') |
50 | | - .css('display', (field_operator == "between") ? 'inline-block' : 'none') |
51 | | - .prop('name', value_name + '[]') |
52 | | - .prop('value', field_value[2] || '') |
53 | | - ); |
54 | 37 | case 'datetime': |
55 | 38 | case 'timestamp': |
| 39 | + case 'time': |
56 | 40 | control = control || $('<select class="switch-additional-fieldsets input-sm form-control"></select>') |
57 | 41 | .prop('name', operator_name) |
58 | | - .append($('<option data-additional-fieldset="default" value="default"></option>').prop('selected', field_operator == "default").text(RailsAdmin.I18n.t("date"))) |
| 42 | + .append($('<option data-additional-fieldset="default" value="default"></option>').prop('selected', field_operator == "default").text(RailsAdmin.I18n.t(field_type == "time" ? "time" : "date"))) |
59 | 43 | .append($('<option data-additional-fieldset="between" value="between"></option>').prop('selected', field_operator == "between").text(RailsAdmin.I18n.t("between_and_"))) |
60 | | - .append($('<option value="today"></option>').prop('selected', field_operator == "today").text(RailsAdmin.I18n.t("today"))) |
61 | | - .append($('<option value="yesterday"></option>').prop('selected', field_operator == "yesterday").text(RailsAdmin.I18n.t("yesterday"))) |
62 | | - .append($('<option value="this_week"></option>').prop('selected', field_operator == "this_week").text(RailsAdmin.I18n.t("this_week"))) |
63 | | - .append($('<option value="last_week"></option>').prop('selected', field_operator == "last_week").text(RailsAdmin.I18n.t("last_week"))) |
| 44 | + if (field_type != 'time') { |
| 45 | + control.append([ |
| 46 | + $('<option value="today"></option>').prop('selected', field_operator == "today").text(RailsAdmin.I18n.t("today")), |
| 47 | + $('<option value="yesterday"></option>').prop('selected', field_operator == "yesterday").text(RailsAdmin.I18n.t("yesterday")), |
| 48 | + $('<option value="this_week"></option>').prop('selected', field_operator == "this_week").text(RailsAdmin.I18n.t("this_week")), |
| 49 | + $('<option value="last_week"></option>').prop('selected', field_operator == "last_week").text(RailsAdmin.I18n.t("last_week")), |
| 50 | + ]) |
| 51 | + } |
64 | 52 | if (!required) { |
65 | 53 | control.append([ |
66 | 54 | '<option disabled="disabled">---------</option>', |
67 | 55 | $('<option value="_not_null"></option>').prop('selected', field_operator == "_not_null").text(RailsAdmin.I18n.t("is_present")), |
68 | 56 | $('<option value="_null"></option>').prop('selected', field_operator == "_null").text(RailsAdmin.I18n.t("is_blank")) |
69 | 57 | ]) |
70 | 58 | } |
71 | | - additional_control = additional_control || |
72 | | - $('<input size="25" class="datetime additional-fieldset default input-sm form-control" type="text" />') |
73 | | - .css('display', (!field_operator || field_operator == "default") ? 'inline-block' : 'none') |
74 | | - .prop('name', value_name + '[]') |
75 | | - .prop('value', field_value[0] || '') |
76 | | - .add( |
77 | | - $('<input size="25" placeholder="-∞" class="datetime additional-fieldset between input-sm form-control" type="text" />') |
78 | | - .css('display', (field_operator == "between") ? 'inline-block' : 'none') |
79 | | - .prop('name', value_name + '[]') |
80 | | - .prop('value', field_value[1] || '') |
81 | | - ) |
82 | | - .add( |
83 | | - $('<input size="25" placeholder="∞" class="datetime additional-fieldset between input-sm form-control" type="text" />') |
84 | | - .css('display', (field_operator == "between") ? 'inline-block' : 'none') |
85 | | - .prop('name', value_name + '[]') |
86 | | - .prop('value', field_value[2] || '') |
87 | | - ); |
| 59 | + additional_control = |
| 60 | + $.map([undefined, '-∞', '∞'], function(placeholder, index){ |
| 61 | + var visible = index == 0 ? (!field_operator || field_operator == "default") : (field_operator == "between"); |
| 62 | + return $('<span class="additional-fieldset"></span>') |
| 63 | + .addClass(index == 0 ? 'default' : 'between') |
| 64 | + .css('display', visible ? 'inline-block' : 'none') |
| 65 | + .html( |
| 66 | + $('<input type="hidden" />') |
| 67 | + .prop('name', value_name + '[]') |
| 68 | + .prop('value', field_value[index] || '') |
| 69 | + .add( |
| 70 | + $('<input class="input-sm form-control" type="text" />') |
| 71 | + .addClass(field_type == 'date' ? 'date' : 'datetime') |
| 72 | + .prop('size', field_type == 'date' || field_type == 'time' ? 20 : 25) |
| 73 | + .prop('placeholder', placeholder) |
| 74 | + ) |
| 75 | + ); |
| 76 | + }); |
88 | 77 | break; |
89 | 78 | case 'enum': |
90 | 79 | var multiple_values = ((field_value instanceof Array) ? true : false) |
|
193 | 182 |
|
194 | 183 | $('#filters_box').append($content); |
195 | 184 |
|
196 | | - $content.find('.date, .datetime').datetimepicker({ |
197 | | - locale: RailsAdmin.I18n.locale, |
198 | | - showTodayButton: true, |
199 | | - format: options['datetimepicker_format'] |
| 185 | + $content.find('.date, .datetime').each(function() { |
| 186 | + $(this).datetimepicker({ |
| 187 | + date: moment($(this).siblings('[type=hidden]').val()), |
| 188 | + locale: RailsAdmin.I18n.locale, |
| 189 | + showTodayButton: true, |
| 190 | + format: options['datetimepicker_format'] |
| 191 | + }); |
| 192 | + $(this).on('dp.change', function(e) { |
| 193 | + if (e.date) { |
| 194 | + $(this).siblings('[type=hidden]').val(e.date.format('YYYY-MM-DD[T]HH:mm:ss')); |
| 195 | + } |
| 196 | + }); |
200 | 197 | }); |
201 | 198 |
|
202 | 199 | $("hr.filters_box:hidden").show('slow'); |
|
0 commit comments