avatar-gallery-form.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import Ember from 'ember';
  2. export default Ember.Component.extend({
  3. classNames: 'avatar-galleries',
  4. isBusy: false,
  5. activeItem: null,
  6. apiUrl: function() {
  7. return 'users/' + this.auth.get('user.id') + '/avatar';
  8. }.property(),
  9. actions: {
  10. setAvatar: function(image) {
  11. if (this.get('isBusy')) { return; }
  12. this.set('isBusy', true);
  13. this.set('activeItem', image);
  14. var self = this;
  15. this.ajax.post(this.get('apiUrl'), {
  16. avatar: 'galleries',
  17. image: image
  18. }).then(function(response) {
  19. if (self.isDestroyed) { return; }
  20. self.auth.set('user.avatar_hash', response.avatar_hash);
  21. self.toast.success(response.detail);
  22. self.get('options').setProperties(response.options);
  23. self.set('activeForm', 'select-avatar-type-form');
  24. }, function(jqXHR) {
  25. if (self.isDestroyed) { return; }
  26. self.toast.apiError(jqXHR);
  27. }).finally(function() {
  28. if (self.isDestroyed) { return; }
  29. self.setProperties({
  30. 'isBusy': false,
  31. 'activeItem': null
  32. });
  33. });
  34. },
  35. cancel: function() {
  36. this.set('activeForm', 'select-avatar-type-form');
  37. }
  38. }
  39. });