mirror of
https://github.com/flarum/framework.git
synced 2025-05-09 04:52:27 +08:00
Refresh avatar display after uploading
This commit is contained in:
parent
38bbfc78d0
commit
257a3fde1a
@ -9,12 +9,15 @@ export default Ember.Component.extend({
|
|||||||
classNames: ['avatar-editor', 'dropdown'],
|
classNames: ['avatar-editor', 'dropdown'],
|
||||||
classNameBindings: ['loading'],
|
classNameBindings: ['loading'],
|
||||||
|
|
||||||
click: function(e) {
|
didInsertElement: function() {
|
||||||
if (! this.get('user.avatarUrl')) {
|
var component = this;
|
||||||
|
this.$('.dropdown-toggle').click(function(e) {
|
||||||
|
if (! component.get('user.avatarUrl')) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.send('upload');
|
component.send('upload');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
@ -37,9 +40,18 @@ export default Ember.Component.extend({
|
|||||||
processData: false,
|
processData: false,
|
||||||
complete: function() {
|
complete: function() {
|
||||||
component.set('loading', false);
|
component.set('loading', false);
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
Ember.run.next(function() {
|
||||||
|
component.get('store').pushPayload(data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
remove: function() {
|
||||||
|
this.get('store').push('user', {id: this.get('user.id'), avatarUrl: null});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -18,5 +18,5 @@ export default Ember.Handlebars.makeBoundHelper(function(user, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new Ember.Handlebars.SafeString('<span '+attributes+'>'+content+'</span>');
|
return new Ember.Handlebars.SafeString('<span '+attributes+'>'+content+'</span>');
|
||||||
});
|
}, 'avatarUrl', 'username', 'color');
|
||||||
|
|
||||||
|
@ -6,5 +6,6 @@ export default {
|
|||||||
application.inject('component', 'composer', 'controller:composer')
|
application.inject('component', 'composer', 'controller:composer')
|
||||||
application.inject('model', 'session', 'simple-auth-session:main')
|
application.inject('model', 'session', 'simple-auth-session:main')
|
||||||
application.inject('component', 'session', 'simple-auth-session:main')
|
application.inject('component', 'session', 'simple-auth-session:main')
|
||||||
|
application.inject('component', 'store', 'store:main')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use Flarum\Api\Actions\BaseAction;
|
use Flarum\Api\Actions\BaseAction;
|
||||||
use Flarum\Core\Commands\UploadAvatarCommand;
|
use Flarum\Core\Commands\UploadAvatarCommand;
|
||||||
|
use Flarum\Api\Serializers\UserSerializer;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class UploadAvatarAction extends BaseAction
|
class UploadAvatarAction extends BaseAction
|
||||||
@ -11,11 +12,14 @@ class UploadAvatarAction extends BaseAction
|
|||||||
$userId = array_get($routeParams, 'id');
|
$userId = array_get($routeParams, 'id');
|
||||||
$file = $request->file('avatar');
|
$file = $request->file('avatar');
|
||||||
|
|
||||||
$this->dispatch(
|
$user = $this->dispatch(
|
||||||
new UploadAvatarCommand($userId, $file, $this->actor->getUser()),
|
new UploadAvatarCommand($userId, $file, $this->actor->getUser()),
|
||||||
$routeParams
|
$routeParams
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this->respondWithoutContent(201);
|
$serializer = new UserSerializer;
|
||||||
|
$document = $this->document()->setData($serializer->resource($user));
|
||||||
|
|
||||||
|
return $this->respondWithDocument($document);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,6 +226,16 @@ class User extends Model
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the URL of the user's avatar.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAvatarUrlAttribute()
|
||||||
|
{
|
||||||
|
return $this->avatar_path ? asset('avatars/'.$this->avatar_path) : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a given password matches the user's password.
|
* Check if a given password matches the user's password.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user