spacedeck_avatars.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. var SpacedeckAvatars = {
  2. data: {
  3. uploading_avatar: false,
  4. uploading_folder_avatar: false,
  5. uploading_cover: false
  6. },
  7. methods: {
  8. save_avatar_image: function(input, object_type, object) {
  9. if (input.files.length > 0) {
  10. var f = input.files[0];
  11. var finished = function() {
  12. this.uploading_avatar = false;
  13. this.uploading_cover = false;
  14. this.uploading_folder_avatar = false;
  15. }.bind(this);
  16. if (!_.include(["image/jpeg","image/jpg","image/png","image/gif"], f.type)) {
  17. alert("Unsupported file type. Please upload JPEG, PNG or GIF.");
  18. finished();
  19. return;
  20. }
  21. if (f.size > 1024*1024*3) {
  22. alert("File must be smaller than 3 megabytes.");
  23. finished();
  24. return;
  25. }
  26. save_avatar_file(object_type, object, f, function(res) {
  27. finished();
  28. this.uploading_avatar = false;
  29. this.uploading_cover = false;
  30. var newUri = res.avatar_thumb_uri;
  31. object.avatar_thumb_uri = newUri + "?cachebuster=" + Math.random();
  32. }.bind(this), function(error) {
  33. alert("Upload failed: " + error);
  34. finished();
  35. });
  36. }
  37. },
  38. save_space_avatar_image: function(viewmodel) {
  39. this.uploading_avatar = true;
  40. var func = this.save_avatar_image.bind(this);
  41. func(viewmodel.$event.target, "space", this.active_space);
  42. },
  43. save_folder_avatar_image: function(viewmodel) {
  44. this.uploading_folder_avatar = true;
  45. var func = this.save_avatar_image.bind(this);
  46. func(viewmodel.$event.target, "space", this.active_folder);
  47. },
  48. save_user_avatar_image: function(viewmodel) {
  49. this.uploading_avatar = true;
  50. var func = this.save_avatar_image.bind(this);
  51. func(viewmodel.$event.target, "user", viewmodel.$root.user);
  52. },
  53. delete_user_avatar_image: function() {
  54. this.user.avatar_original_uri = "";
  55. this.user.avatar_thumb_uri = "";
  56. save_user(this.user,function(updated) {
  57. }.bind(this));
  58. },
  59. save_user_background_image: function(viewmodel) {
  60. var input = viewmodel.$event.target;
  61. this.uploading_cover = true;
  62. var f = input.files[0];
  63. save_user_background_file(this.user, f, function(res) {
  64. this.user.background_original_uri = res.background_original_uri;
  65. this.uploading_cover = false;
  66. }.bind(this));
  67. }
  68. }
  69. }