2015-02-10 15:35:40 +08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
|
|
|
export default Ember.Mixin.create({
|
|
|
|
showComposer: function(buildComposerContent) {
|
|
|
|
var composer = this.get('composer');
|
|
|
|
if (this.get('composerContent') !== composer.get('content')) {
|
|
|
|
this.set('composerContent', buildComposerContent());
|
|
|
|
composer.switchContent(this.get('composerContent'));
|
|
|
|
}
|
|
|
|
composer.send('show');
|
|
|
|
},
|
|
|
|
|
|
|
|
saveAndDismissComposer: function(model) {
|
|
|
|
var composer = this.get('composer');
|
2015-02-26 10:14:39 +08:00
|
|
|
var controller = this;
|
2015-02-10 15:35:40 +08:00
|
|
|
composer.set('content.loading', true);
|
|
|
|
this.get('alerts').send('clearAlerts');
|
|
|
|
|
|
|
|
return model.save().then(function(model) {
|
|
|
|
composer.send('hide');
|
|
|
|
return model;
|
|
|
|
}, function(reason) {
|
|
|
|
controller.showErrorsAsAlertMessages(reason.errors);
|
|
|
|
}).finally(function() {
|
|
|
|
composer.set('content.loading', false);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
showErrorsAsAlertMessages: function(errors) {
|
|
|
|
for (var i in errors) {
|
2015-02-26 07:13:53 +08:00
|
|
|
var message = AlertMessage.extend({
|
2015-02-10 15:35:40 +08:00
|
|
|
type: 'warning',
|
|
|
|
message: errors[i]
|
|
|
|
});
|
|
|
|
this.get('alerts').send('alert', message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|