-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathform-post.js
42 lines (37 loc) · 989 Bytes
/
form-post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Ember from 'ember';
import BufferedProxy from 'ember-buffered-proxy/proxy';
export default Ember.Component.extend({
tagName: 'form',
resource: Ember.computed('post', function() {
return BufferedProxy.create({ content: this.get('post') });
}).readOnly(),
isNew: null,
isEditing: true,
focusOut() {
if (!this.get('isNew')) {
this.get('resource').applyChanges();
this.set('isEditing', false);
this.get('on-edit')(this.get('post')).finally(function() {
this.set('isEditing', true);
}.bind(this));
}
},
actions: {
edit() {
this.set('isEditing', true);
},
done() {
this.set('isEditing', false);
},
save() {
this.set('isEditing', false);
this.get('resource').applyChanges();
this.sendAction('on-save', this.get('post'));
},
cancel() {
this.set('isEditing', false);
this.get('resource').discardChanges();
this.sendAction('on-cancel');
}
}
});