Skip to content

Instantly share code, notes, and snippets.

@ben-caplan
Last active August 29, 2015 14:22
Show Gist options
  • Save ben-caplan/c33f0279ce945dfdff82 to your computer and use it in GitHub Desktop.
Save ben-caplan/c33f0279ce945dfdff82 to your computer and use it in GitHub Desktop.
getTempImage : function(t, blob, cropData){
// get the CSRF token, or get out if we can't find it
var csrfToken = $("body").attr("data-csrf-token"),
ajaxArgs = {};
// show loading indicator - wait for response to continue
radius.loading.show();
//DO WE HAVE WHAT WE NEED? If we dont have a blob or csrf token get out
if (!csrfToken || typeof blob == 'undefined') return {};
//ADD CROP DATA TO AJAX ARGS
if( typeof cropData != 'undefined' ) ajaxArgs.crop = cropData;
//ADD BLOB DATA TO AJAX ARGUMENTS OBJECT
ajaxArgs.filedata = blob;
// send the request
$.ajax({
datatype: 'json',
data : JSON.stringify( ajaxArgs ),
method: 'POST',
url: '/api/v1/onboarding-user-picture/prepare',
headers: {
'X-CSRF-Token': csrfToken,
'Content-Type': 'application/json'
},
success: function(data, textStatus, jqXHR) {
//HAVE SERVICE CROP IMAGE
if( typeof cropData != 'undefined' ){
var $resetBtn = t.resetBtn,
$previewImg = t.previewImage,
$srcField = t.srcField;
//UPDATE UI
$srcField.val( data.url );
$previewImg.attr('src', data.url);
//re-enable buttons
//RE-ENABLE/UPDATE BUTTONS
$resetBtn.parent().addClass('has-image');
t.modalBtns.removeClass('loading');
//CLOSE MODAL
t.closeModal(t);
}
//LET JS CROP THE IMAGE
t.fidField.val( data.fid );
//deselect any radio options that might be checked
$('.avatar-option input').prop("checked", false);
// hide loading indicator
radius.loading.hide();
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("ajax error trying to get a temporary avatar image");
// hide loading indicator
radius.loading.hide();
}
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment