1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 07:24:27 +02:00
Files
php-flarum/ember/forum/app/components/user/avatar-editor.js
Toby Zerner 40a6d77e74 Big front-end asset/filestructure refactor
- Extract shared Ember components into a “flarum-common” ember-cli
addon. This can be used by both the forum + admin Ember apps, keeping
things DRY
- Move LESS styles into their own top-level directory and do a similar
thing (extract common styles)
- Add LESS/JS compilation and versioning to PHP (AssetManager)
- Set up admin entry point

(Theoretical) upgrade instructions:
- Delete everything in [app_root]/public
- Set up tooling in forum/admin Ember apps (npm install/update, bower
install/update) and then build them (ember build)
- php artisan vendor:publish
- Upgrade flarum/flarum repo (slight change in a config file)
- If you need to trigger a LESS/JS recompile, delete the .css/.js files
in [app_root]/public/flarum. I set up LiveReload to do this for me when
I change files in less/ or ember/

Todo:
- Start writing admin app!
- Remove bootstrap/font-awesome from repo and instead depend on their
composer packages? Maybe? (Bower is not an option here)
2015-03-29 22:13:26 +10:30

58 lines
1.5 KiB
JavaScript

import Ember from 'ember';
import config from 'flarum-forum/config/environment';
var $ = Ember.$;
export default Ember.Component.extend({
layoutName: 'components/user/avatar-editor',
classNames: ['avatar-editor', 'dropdown'],
classNameBindings: ['loading'],
didInsertElement: function() {
var component = this;
this.$('.dropdown-toggle').click(function(e) {
if (! component.get('user.avatarUrl')) {
e.preventDefault();
e.stopPropagation();
component.send('upload');
}
});
},
actions: {
upload: function() {
if (this.get('loading')) { return; }
var $input = $('<input type="file">');
var userId = this.get('user.id');
var component = this;
$input.appendTo('body').hide().click().on('change', function() {
var formData = new FormData();
formData.append('avatar', $(this)[0].files[0]);
component.set('loading', true);
$.ajax({
type: 'POST',
url: config.apiURL+'/users/'+userId+'/avatar',
data: formData,
cache: false,
contentType: false,
processData: false,
complete: function() {
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});
}
}
});