Files
NodeBB/public/src/forum/accountedit.js

223 lines
4.8 KiB
JavaScript
Raw Normal View History

var gravatarPicture = templates.get('gravatarpicture');
var uploadedPicture = templates.get('uploadedpicture');
$(document).ready(function() {
2013-06-20 16:48:17 -04:00
$('#uploadForm').submit(function() {
status('uploading the file ...');
$('#upload-progress-bar').css('width', '0%');
$('#upload-progress-box').show();
if(!$('#userPhotoInput').val()) {
error('select an image to upload!');
return false;
}
2013-06-21 15:51:03 -04:00
$(this).find('#imageUploadCsrf').val($('#csrf_token').val());
2013-06-20 16:48:17 -04:00
$(this).ajaxSubmit({
error: function(xhr) {
error('Error: ' + xhr.status);
},
2013-06-20 16:48:17 -04:00
uploadProgress : function(event, position, total, percent) {
$('#upload-progress-bar').css('width', percent+'%');
},
success: function(response) {
if(response.error) {
error(response.error);
return;
}
var imageUrlOnServer = response.path;
2013-06-20 16:48:17 -04:00
$('#user-current-picture').attr('src', imageUrlOnServer);
$('#user-uploaded-picture').attr('src', imageUrlOnServer);
uploadedPicture = imageUrlOnServer;
2013-06-20 16:48:17 -04:00
setTimeout(function() {
hideAlerts();
2013-06-20 16:48:17 -04:00
$('#upload-picture-modal').modal('hide');
}, 750);
2013-06-20 16:48:17 -04:00
2013-06-24 14:33:53 -04:00
socket.emit('api:updateHeader', { fields: ['username', 'picture', 'userslug'] });
success('File uploaded successfully!');
2013-06-20 16:48:17 -04:00
}
});
return false;
2013-06-20 16:48:17 -04:00
});
2013-06-20 16:48:17 -04:00
function hideAlerts() {
$('#alert-status').hide();
$('#alert-success').hide();
$('#alert-error').hide();
$('#upload-progress-box').hide();
2013-06-20 16:48:17 -04:00
}
2013-06-20 16:48:17 -04:00
function status(message) {
hideAlerts();
$('#alert-status').text(message).show();
2013-06-20 16:48:17 -04:00
}
function success(message) {
hideAlerts();
$('#alert-success').text(message).show();
2013-06-20 16:48:17 -04:00
}
function error(message) {
hideAlerts();
$('#alert-error').text(message).show();
2013-06-20 16:48:17 -04:00
}
function changeUserPicture(type) {
var userData = {
2013-06-20 16:48:17 -04:00
uid: $('#inputUID').val(),
2013-06-20 16:29:44 -04:00
type: type,
_csrf:$('#csrf_token').val()
2013-06-20 16:48:17 -04:00
};
$.post('/users/changepicture',
2013-06-20 16:48:17 -04:00
userData,
function(data) {
2013-06-24 14:33:53 -04:00
socket.emit('api:updateHeader', { fields: ['username', 'picture', 'userslug'] });
2013-06-20 16:48:17 -04:00
}
);
}
2013-06-20 16:48:17 -04:00
var selectedImageType = '';
2013-06-20 16:48:17 -04:00
$('#submitBtn').on('click',function(){
var userData = {
uid:$('#inputUID').val(),
email:$('#inputEmail').val(),
fullname:$('#inputFullname').val(),
website:$('#inputWebsite').val(),
birthday:$('#inputBirthday').val(),
location:$('#inputLocation').val(),
signature:$('#inputSignature').val(),
_csrf:$('#csrf_token').val()
};
$.post('/users/doedit',
2013-06-20 16:48:17 -04:00
userData,
function(data) {
if(data.error) {
app.alert({
'alert_id': 'user_profile_updated',
type: 'error',
title: 'Profile Update Error',
message: data.error,
timeout: 2000
});
return;
}
app.alert({
2013-06-20 16:48:17 -04:00
'alert_id': 'user_profile_updated',
type: 'success',
title: 'Profile Updated',
message: 'Your profile has been updated successfully',
2013-06-21 17:48:53 -04:00
timeout: 2000
2013-06-20 16:48:17 -04:00
});
}
);
return false;
2013-06-20 16:48:17 -04:00
});
function updateImages() {
var currentPicture = $('#user-current-picture').attr('src');
if(gravatarPicture) {
2013-06-20 16:48:17 -04:00
$('#user-gravatar-picture').attr('src', gravatarPicture);
$('#gravatar-box').show();
}
else
$('#gravatar-box').hide();
2013-06-20 16:48:17 -04:00
if(uploadedPicture) {
$('#user-uploaded-picture').attr('src', uploadedPicture);
$('#uploaded-box').show();
}
else
$('#uploaded-box').hide();
if(currentPicture == gravatarPicture)
$('#gravatar-box .icon-ok').show();
else
2013-06-20 16:48:17 -04:00
$('#gravatar-box .icon-ok').hide();
if(currentPicture == uploadedPicture)
$('#uploaded-box .icon-ok').show();
else
2013-06-20 16:48:17 -04:00
$('#uploaded-box .icon-ok').hide();
}
$('#changePictureBtn').on('click', function() {
selectedImageType = '';
updateImages();
2013-06-20 16:48:17 -04:00
$('#change-picture-modal').modal('show');
return false;
});
$('#gravatar-box').on('click', function(){
$('#gravatar-box .icon-ok').show();
2013-06-20 16:48:17 -04:00
$('#uploaded-box .icon-ok').hide();
selectedImageType = 'gravatar';
});
$('#uploaded-box').on('click', function(){
$('#gravatar-box .icon-ok').hide();
2013-06-20 16:48:17 -04:00
$('#uploaded-box .icon-ok').show();
selectedImageType = 'uploaded';
});
$('#savePictureChangesBtn').on('click', function() {
2013-06-20 16:48:17 -04:00
$('#change-picture-modal').modal('hide');
2013-06-20 16:48:17 -04:00
if(selectedImageType) {
changeUserPicture(selectedImageType);
if(selectedImageType == 'gravatar')
$('#user-current-picture').attr('src', gravatarPicture);
else if(selectedImageType == 'uploaded')
2013-06-20 16:48:17 -04:00
$('#user-current-picture').attr('src', uploadedPicture);
}
});
$('#upload-picture-modal').on('hide', function() {
$('#userPhotoInput').val('');
});
$('#uploadPictureBtn').on('click', function(){
2013-06-20 16:48:17 -04:00
$('#change-picture-modal').modal('hide');
$('#upload-picture-modal').modal('show');
2013-06-20 16:48:17 -04:00
hideAlerts();
return false;
});
$('#pictureUploadSubmitBtn').on('click', function() {
$('#uploadForm').submit();
});
2013-06-20 16:48:17 -04:00
});