2015-03-12 09:40:58 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
|
|
|
layoutName: 'components/user/user-bio',
|
|
|
|
classNames: ['user-bio'],
|
|
|
|
classNameBindings: ['isEditable:editable', 'editing'],
|
|
|
|
|
|
|
|
isEditable: Ember.computed.and('user.canEdit', 'editable'),
|
|
|
|
editing: false,
|
|
|
|
|
|
|
|
didInsertElement: function() {
|
|
|
|
this.$().on('click', 'a', function(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
click: function() {
|
|
|
|
this.send('edit');
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
edit: function() {
|
|
|
|
if (!this.get('isEditable')) { return; }
|
|
|
|
|
|
|
|
this.set('editing', true);
|
|
|
|
var component = this;
|
2015-03-17 14:31:19 +08:00
|
|
|
var height = this.$().height();
|
2015-03-12 09:40:58 +08:00
|
|
|
Ember.run.scheduleOnce('afterRender', this, function() {
|
2015-03-17 14:31:19 +08:00
|
|
|
var save = function(e) {
|
|
|
|
if (e.shiftKey) { return; }
|
|
|
|
e.preventDefault();
|
2015-03-12 09:40:58 +08:00
|
|
|
component.send('save', $(this).val());
|
2015-03-17 14:31:19 +08:00
|
|
|
};
|
|
|
|
this.$('textarea').css('height', height).focus().bind('blur', save).bind('keydown', 'return', save);
|
2015-03-12 09:40:58 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
save: function(value) {
|
|
|
|
this.set('editing', false);
|
|
|
|
|
|
|
|
var user = this.get('user');
|
|
|
|
user.set('bio', value);
|
|
|
|
user.save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|