|
2 | 2 | document.addEventListener('DOMContentLoaded', function() { |
3 | 3 | const checkbox = document.getElementById('use_manual_input'); |
4 | 4 | const hiddenInput = document.getElementById('file_size_manual'); |
| 5 | + const sizeUnitInput = document.getElementById('size_unit_input'); |
| 6 | +
|
| 7 | + if (sizeUnitInput.value === 'mb') { |
| 8 | + document.getElementById('size-mb').checked = true; |
| 9 | + } else { |
| 10 | + document.getElementById('size-kb').checked = true; |
| 11 | + } |
5 | 12 |
|
6 | 13 | if (hiddenInput.value === "true") { |
7 | 14 | checkbox.checked = true; |
8 | | - toggleSizeInputType(checkbox); |
| 15 | + } |
| 16 | +
|
| 17 | + changeFilesizeInputType(checkbox); |
| 18 | +
|
| 19 | + const slider = document.getElementById('file_size'); |
| 20 | + const sizeValueDisplay = document.getElementById('size_value'); |
| 21 | + if (slider && sizeValueDisplay) { |
| 22 | + updateSliderDisplay(slider.value); |
9 | 23 | } |
10 | 24 | }); |
11 | 25 |
|
|
27 | 41 | }); |
28 | 42 | } |
29 | 43 |
|
30 | | - function toggleSizeInputType(element) { |
| 44 | + function changeFilesizeInputType(element) { |
31 | 45 | const hiddenInput = document.getElementById('file_size_manual'); |
32 | 46 | const sliderContainer = document.getElementById('slider_container'); |
33 | 47 | const manualSizeInput = document.getElementById('manual_size_input_container'); |
34 | 48 | const manualSizeValueInput = document.getElementById('max_file_size_manual_input'); |
35 | 49 | const hiddenSizeInput = document.getElementById('max_file_size_manual'); |
36 | | - hiddenSizeInput.value = manualSizeValueInput.value; |
| 50 | + const sizeUnitInput = document.getElementById('size_unit_input'); |
| 51 | +
|
| 52 | + if (sizeUnitInput.value === 'mb') { |
| 53 | + document.getElementById('size-mb').checked = true; |
| 54 | + } else { |
| 55 | + document.getElementById('size-kb').checked = true; |
| 56 | + } |
| 57 | +
|
37 | 58 | hiddenInput.value = element.checked ? "true" : "false"; |
38 | 59 |
|
39 | 60 | if (element.checked) { |
|
61 | 82 | hiddenSizeInput.value = element.value || "1024"; |
62 | 83 | console.log("Manual size updated to: " + hiddenSizeInput.value + "KB"); |
63 | 84 | } |
| 85 | +
|
| 86 | + function updateSizeUnit(element) { |
| 87 | + const hiddenSizeUnitInput = document.getElementById('size_unit_input'); |
| 88 | + const hiddenSizeInput = document.getElementById('max_file_size_manual'); |
| 89 | + const manualSizeValueInput = document.getElementById('max_file_size_manual_input'); |
| 90 | + const sizeUnit = element.value; |
| 91 | + const currentValue = parseInt(manualSizeValueInput.value); |
| 92 | +
|
| 93 | + // Update the hidden size unit input |
| 94 | + hiddenSizeUnitInput.value = sizeUnit; |
| 95 | +
|
| 96 | + // Update the max attribute of the manual size input |
| 97 | + const maxValue = sizeUnit === 'kb' ? 100 * 1024 : 100; |
| 98 | + manualSizeValueInput.max = maxValue; |
| 99 | +
|
| 100 | + // If switching to MB and current value is over 100, set it to 100 |
| 101 | + if (sizeUnit === 'mb' && currentValue > 100) { |
| 102 | + manualSizeValueInput.value = 100; |
| 103 | + // Also update the hidden input |
| 104 | + hiddenSizeInput.value = 100; |
| 105 | + } |
| 106 | +
|
| 107 | + console.log("Size unit changed to: " + sizeUnit.toUpperCase()); |
| 108 | + } |
| 109 | +
|
| 110 | + // Add input validation to prevent values over max |
| 111 | + document.getElementById('max_file_size_manual_input').addEventListener('input', function() { |
| 112 | + const maxValue = parseInt(this.max); |
| 113 | + const currentValue = parseInt(this.value); |
| 114 | +
|
| 115 | + if (currentValue > maxValue) { |
| 116 | + this.value = maxValue; |
| 117 | + } |
| 118 | + }); |
64 | 119 | </script> |
65 | 120 | <div class="relative"> |
66 | 121 | <div class="w-full h-full absolute inset-0 bg-gray-900 rounded-xl translate-y-2 translate-x-2"></div> |
|
90 | 145 | <input type="hidden" |
91 | 146 | id="file_size_manual" |
92 | 147 | name="use_manual_input" |
93 | | - value="{{ use_manual_input }}"> |
| 148 | + value="{{ use_manual_input|default('false') }}"> |
94 | 149 | <input type="hidden" |
95 | 150 | id="max_file_size_manual" |
96 | 151 | name="max_file_size_manual" |
97 | 152 | value="{{ max_file_size_manual }}"> |
| 153 | + <input type="hidden" |
| 154 | + id="size_unit_input" |
| 155 | + name="size_unit" |
| 156 | + value="{{ size_unit|default('kb') }}"> |
98 | 157 | <input type="hidden" name="pattern_type" value="exclude"> |
99 | 158 | <input type="hidden" name="pattern" value=""> |
100 | 159 | </form> |
|
138 | 197 | <div class="flex items-center gap-4 h-[50px]"> |
139 | 198 | <div class="mt-4"> |
140 | 199 | <label class="flex flex-col items-center cursor-pointer"> |
141 | | - <input type="checkbox" id="use_manual_input" name="use_manual_input" value="false" checked={false} class="sr-only peer w-12" onchange="toggleSizeInputType(this)"> |
| 200 | + <input type="checkbox" |
| 201 | + id="use_manual_input" |
| 202 | + name="use_manual_input" |
| 203 | + value="false" |
| 204 | + class="sr-only peer w-12" |
| 205 | + onchange="changeFilesizeInputType(this)"> |
142 | 206 | <div class="relative w-12 h-6 bg-[#ebdbb7] peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-[#FE4A60]/30 rounded-full peer border-[2px] border-gray-900 peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-5 after:transition-all peer-checked:bg-[#FE4A60]"> |
143 | 207 | </div> |
144 | 208 | <p class="ms-1 text-sm font-medium text-gray-900">Manual</p> |
|
157 | 221 | value="{{ default_file_size }}" |
158 | 222 | class="w-full h-3 bg-[#FAFAFA] bg-no-repeat bg-[length:50%_100%] bg-[#ebdbb7] appearance-none border-[3px] border-gray-900 rounded-sm focus:outline-none bg-gradient-to-r from-[#FE4A60] to-[#FE4A60] [&::-webkit-slider-thumb]:w-5 [&::-webkit-slider-thumb]:h-7 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:bg-white [&::-webkit-slider-thumb]:rounded-sm [&::-webkit-slider-thumb]:cursor-pointer [&::-webkit-slider-thumb]:border-solid [&::-webkit-slider-thumb]:border-[3px] [&::-webkit-slider-thumb]:border-gray-900 [&::-webkit-slider-thumb]:shadow-[3px_3px_0_#000]"> |
159 | 223 | </div> |
160 | | - <div id="manual_size_input_container" class="hidden mt-3"> |
161 | | - <label for="max_file_size_manual_input" class="block text-gray-700 mb-1">Manual size (kb):</label> |
162 | | - <input type="number" |
163 | | - id="max_file_size_manual_input" |
164 | | - name="max_file_size_manual" |
165 | | - min="1" |
166 | | - max="102400" |
167 | | - value="1024" |
168 | | - class="lg:w-[150px] sm:w-[100px] border-[3px] border-gray-900 rounded-sm focus:outline-none bg-[#ebdbb7] appearance-none indent-2" |
169 | | - style="-webkit-appearance: none; |
170 | | - color: #333" |
171 | | - onchange="updateManualSizeValue(this)"> |
| 224 | + <div id="manual_size_input_container" class="hidden mt-3 flex gap-2"> |
| 225 | + <div> |
| 226 | + <label for="max_file_size_manual_input" class="block text-gray-700 mb-1">Include files under:</label> |
| 227 | + <input type="number" |
| 228 | + id="max_file_size_manual_input" |
| 229 | + name="max_file_size_manual" |
| 230 | + min="1" |
| 231 | + max="{{ '102400' if size_unit == 'kb' else '100' }}" |
| 232 | + value="{{ max_file_size_manual }}" |
| 233 | + class="lg:w-[150px] sm:w-[100px] border-[3px] border-gray-900 rounded-sm focus:outline-none bg-[#ebdbb7] appearance-none indent-2" |
| 234 | + style="-webkit-appearance: none; |
| 235 | + color: #333" |
| 236 | + onchange="updateManualSizeValue(this)"> |
| 237 | + </div> |
| 238 | + <div class="flex flex-col justify-end mb-1"> |
| 239 | + <div class="flex items-center"> |
| 240 | + <input id="size-kb" |
| 241 | + type="radio" |
| 242 | + value="kb" |
| 243 | + name="size_unit" |
| 244 | + class="w-4 h-4" |
| 245 | + {% if size_unit == 'kb' %}checked{% endif %} |
| 246 | + onchange="updateSizeUnit(this)" |
| 247 | + style="background-color:red"> |
| 248 | + <label for="size-kb" class="ms-2 text-sm font-medium text-gray-900">KB</label> |
| 249 | + </div> |
| 250 | + <div class="flex items-center mt-1"> |
| 251 | + <input id="size-mb" |
| 252 | + type="radio" |
| 253 | + value="mb" |
| 254 | + name="size_unit" |
| 255 | + class="w-4 h-4 text-[#FE4A60] bg-[#FE4A60] border-[#FE4A60] focus:ring-[#FE4A60]" |
| 256 | + {% if size_unit == 'mb' %}checked{% endif %} |
| 257 | + onchange="updateSizeUnit(this)"> |
| 258 | + <label for="size-mb" class="ms-2 text-sm font-medium text-gray-900">MB</label> |
| 259 | + </div> |
| 260 | + </div> |
172 | 261 | </div> |
173 | 262 | </div> |
174 | 263 | </div> |
|
187 | 276 | </div> |
188 | 277 | {% endif %} |
189 | 278 | </div> |
190 | | -</div> |
|
0 commit comments