IT61/it61-rails

View on GitHub
app/assets/javascripts/image_loader.js

Summary

Maintainability
A
1 hr
Test Coverage
function deleteAvatar($imageForm) {
  $.ajax({
    url: $imageForm.data('avatar-path'),
    type: 'DELETE',
    success: function success() {
    },
    cache: false
  });
}

function uploadAvatar($imageForm) {
  var formData = new FormData($imageForm[0]);
  $.ajax({
    url: $imageForm.data('avatar-path'),
    type: 'POST',
    xhr: function () {  // Custom XMLHttpRequest
      var myXhr = $.ajaxSettings.xhr();
      if (myXhr.upload) { // Check if upload property exists
        myXhr.upload.addEventListener('progress', function progressHandlingFunction() {
        }, false); // For handling the progress of the upload
      }
      return myXhr;
    },
    //Ajax events
    beforeSend: function beforeSendHandler() {
    },
    success: function completeHandler() {
    },
    error: function errorHandler() {
    },
    // Form data
    data: formData,
    //Options to tell jQuery not to process data or worry about content-type.
    cache: false,
    contentType: false,
    processData: false
  });
}