Upload improvements

This commit is contained in:
Chris Smith
2025-02-23 14:45:33 +01:00
parent 5065174a07
commit f9d1ff6e84

View File

@@ -37,34 +37,11 @@ $randEmojiIndex = array_rand($emoji, 1);
$this->registerJS( $this->registerJS(
" "
let foodEmojis = " . json_encode($emoji) . "; let foodEmojis = " . json_encode($emoji) . ";
let spinning = false; let emojiIndex = " . $randEmojiIndex . ";
setInterval(() => {
function startSlotMachine() { $('#upload-title').text('Upload Your ' + foodEmojis[emojiIndex]);
if (spinning) return; emojiIndex = (emojiIndex + 1) % foodEmojis.length; // Cycle through emojis
spinning = true; }, 1100); // Adjust the interval (in milliseconds) for the desired speed
let slotSpeed = 50;
let slowdownFactor = 1.1;
let spinCount = 0;
let maxSpins = Math.random();
let interval = setInterval(() => {
let randomIndex = Math.floor(Math.random() * foodEmojis.length);
$('#upload-title').text('Upload Your ' + foodEmojis[randomIndex]);
spinCount++;
slotSpeed *= slowdownFactor;
if (spinCount >= maxSpins) {
clearInterval(interval);
let finalIndex = Math.floor(Math.random() * foodEmojis.length);
$('#upload-title').text('Upload Your ' + foodEmojis[finalIndex]);
spinning = false;
}
}, slotSpeed);
}
$('#upload-title').click(startSlotMachine);
$('#mealform-picture').on('change', function(ev) { $('#mealform-picture').on('change', function(ev) {
if (localStorage.getItem('autoUpload') === 'true') { // Check localStorage if (localStorage.getItem('autoUpload') === 'true') { // Check localStorage
@@ -74,6 +51,14 @@ $this->registerJS(
ev.preventDefault(); ev.preventDefault();
} }
}); });
$('#submitButton').on('click', function(ev) {
$('#submitButton').text('Processing...');
$('#submitButton').attr('disabled', true);
$(this).parents('form').submit();
ev.preventDefault();
}
);
" "
); );
@@ -87,6 +72,7 @@ $this->registerCssFile('@web/css/upload.css');
<?php <?php
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
<?= $form->errorSummary($model); ?>
<?=$form->field($model, 'context')->textInput([ <?=$form->field($model, 'context')->textInput([
'class' => 'form-control mb-3', 'class' => 'form-control mb-3',
'placeholder' => 'Add context (optional)', 'placeholder' => 'Add context (optional)',
@@ -99,9 +85,8 @@ $this->registerCssFile('@web/css/upload.css');
</div> </div>
<?= Html::activeFileInput($model, 'picture', ['style' => 'display: none;', 'id' => 'file-input']) ?> <?= Html::activeFileInput($model, 'picture', ['style' => 'display: none;', 'id' => 'file-input']) ?>
<?= $form->field($model, 'day')->textInput()->label(false); ?> <?= $form->field($model, 'day')->hiddenInput()->label(false); ?>
<input type="file" id="camera-input" accept="image/*" capture="environment" style="display: none;">
<div id="metadata-fields"> <div id="metadata-fields">
<div class="mb-3"> <div class="mb-3">
<div class="btn-group d-flex justify-content-center" role="group"> <div class="btn-group d-flex justify-content-center" role="group">
@@ -121,8 +106,7 @@ $this->registerCssFile('@web/css/upload.css');
return $return; return $return;
}, },
]) ])
->label(false) ->label(false); ?>
; ?>
</div> </div>
<div class="mb-3 form-check mt-3"> <div class="mb-3 form-check mt-3">
@@ -170,14 +154,14 @@ $this->registerCssFile('@web/css/upload.css');
localStorage.setItem('autoUpload', autoUploadCheckbox.checked); localStorage.setItem('autoUpload', autoUploadCheckbox.checked);
}); });
let currentDate = new Date();
let today = new Date(); // Store today's date
const prevDayBtn = document.getElementById('prev-day-btn'); const prevDayBtn = document.getElementById('prev-day-btn');
const nextDayBtn = document.getElementById('next-day-btn'); const nextDayBtn = document.getElementById('next-day-btn');
const currentDayBtn = document.getElementById('current-day-btn'); // Changed to button const currentDayBtn = document.getElementById('current-day-btn'); // Changed to button
const day = document.getElementById('mealform-day'); // Changed to button const day = document.getElementById('mealform-day'); // Changed to button
let currentDate = new Date();
let today = new Date(); // Store today's date
currentDate.setDate(currentDate.getDate() - Math.abs(day.value));
function updateDayDisplay() { function updateDayDisplay() {
const diff = Math.floor((today - currentDate) / (1000 * 60 * 60 * 24)); // Difference in days const diff = Math.floor((today - currentDate) / (1000 * 60 * 60 * 24)); // Difference in days
const options = {weekday: 'long'}; const options = {weekday: 'long'};
@@ -230,6 +214,7 @@ $this->registerCssFile('@web/css/upload.css');
longPressTimer = setTimeout(() => { longPressTimer = setTimeout(() => {
isLongPress = true; isLongPress = true;
body.style.backgroundColor = ''; body.style.backgroundColor = '';
fileInput.removeAttribute('capture'); // Remove capture for long press
fileInput.click(); fileInput.click();
}, 1000); // Adjust duration as needed }, 1000); // Adjust duration as needed
@@ -246,7 +231,8 @@ $this->registerCssFile('@web/css/upload.css');
clearTimeout(longPressTimer); clearTimeout(longPressTimer);
body.style.backgroundColor = ''; body.style.backgroundColor = '';
if (!isLongPress) { if (!isLongPress) {
cameraInput.click(); fileInput.setAttribute('capture', 'environment'); // Set capture for tap
fileInput.click();
} }
isLongPress = false; isLongPress = false;
}); });