@@ -218,5 +180,46 @@ if ($hasError) {
}
});
- // Validator handled by AlpineJS validateForm() method.
+ document.addEventListener('alpine:init', () => {
+ Alpine.data('orderForm', (initialShow, initialMsg) => ({
+ showModal: initialShow,
+ modalTitle: 'Aviso',
+ modalMessage: initialMsg || '',
+
+ validateForm(e) {
+ let totalSize = 0;
+ let maxSize = 20 * 1024 * 1024; // 20 MB
+
+ let attachments = document.querySelector('input[name=\'attachments[]\']').files;
+ for(let i = 0; i < attachments.length; i++) {
+ if (attachments[i].size > maxSize) {
+ this.showError('Arquivo Muito Grande', 'O anexo \'' + attachments[i].name + '\' excede o limite permitido de 20 MB.');
+ e.preventDefault();
+ return false;
+ }
+ totalSize += attachments[i].size;
+ }
+
+ let csvFile = document.querySelector('input[name=\'csv_file\']').files[0];
+ if (csvFile) {
+ totalSize += csvFile.size;
+ }
+
+ if (totalSize > 40 * 1024 * 1024) { // 40 MB limite de segurança frontend
+ this.showError('Tamanho Total Excedido', 'O tamanho total de todos os arquivos excede o limite de submissão do servidor.');
+ e.preventDefault();
+ return false;
+ }
+
+ // Popula o campo oculto do Quill
+ document.querySelector('input[name=content]').value = window.quill.root.innerHTML;
+ return true;
+ },
+ showError(title, message) {
+ this.modalTitle = title;
+ this.modalMessage = message;
+ this.showModal = true;
+ }
+ }));
+ });
\ No newline at end of file