Advertisement
marcelobarreto

Untitled

Apr 5th, 2017
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. handleUpload = () ->
  2.   $('#upload').on 'change', () ->
  3.     files = $(this)[0].files;
  4.     accepted_formats = [
  5.       'application/docx', 'application/doc', 'application/pdf', 'application/zip',
  6.       'application/rar', 'image/jpg', 'image/png', 'plain/text'
  7.     ];
  8.     max_size = 1e+7; # equivalent to 10mb
  9.  
  10.     _.each files, (file) ->
  11.       unless _.contains(accepted_formats, file.type)
  12.         resetUploadInput();
  13.         Noty.new('Arquivo inválido. Apenas arquivos com extensão .zip, .rar, .pdf, .png, . jpg, .doc, .docx e .txt são aceitos.', 'alert');
  14.       else if file.size > max_size
  15.         resetUploadInput();
  16.         Noty.new('O arquivo não pode ser maior que 10mb.', 'alert');
  17.  
  18. resetUploadInput = () ->
  19.   $("#upload").val('');
  20.   $("label[for='upload'] span")[0].innerText = 'Incluir novo Anexo'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement