mirror of
https://github.com/flarum/core.git
synced 2025-07-31 13:40:20 +02:00
Have a go at some error handling
Still not happy with how this is all fitting together. But good enough for now
This commit is contained in:
@@ -25,12 +25,17 @@ export default JsonApiAdapter.extend({
|
||||
// If it's a server error, show an alert message. The alerts controller
|
||||
// has been injected into this adapter.
|
||||
if (errors instanceof JsonApiAdapter.ServerError) {
|
||||
var message = AlertMessage.create({
|
||||
var message;
|
||||
if (errors.status === 401) {
|
||||
message = 'You don\'t have permission to do this.';
|
||||
} else {
|
||||
message = errors.message;
|
||||
}
|
||||
var alert = AlertMessage.create({
|
||||
type: 'warning',
|
||||
message: 'Something went wrong: '+errors.message.errors[0].code
|
||||
message: message
|
||||
});
|
||||
this.get('alerts').send('alert', message);
|
||||
return;
|
||||
this.get('alerts').send('alert', alert);
|
||||
}
|
||||
|
||||
return errors;
|
||||
|
@@ -76,15 +76,19 @@ export default Ember.Controller.extend(Ember.Evented, UseComposerMixin, {
|
||||
reply: function() {
|
||||
var discussion = this.get('model');
|
||||
var controller = this;
|
||||
this.showComposer(function() {
|
||||
return ComposerReply.create({
|
||||
user: controller.get('session.user'),
|
||||
discussion: discussion,
|
||||
submit: function(data) {
|
||||
controller.saveReply(discussion, data);
|
||||
}
|
||||
if (this.get('session.isAuthenticated')) {
|
||||
this.showComposer(function() {
|
||||
return ComposerReply.create({
|
||||
user: controller.get('session.user'),
|
||||
discussion: discussion,
|
||||
submit: function(data) {
|
||||
controller.saveReply(discussion, data);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.send('signup');
|
||||
}
|
||||
},
|
||||
|
||||
// This action is called when the start position of the discussion
|
||||
|
@@ -24,8 +24,10 @@ export default Ember.Controller.extend(UseComposer, Paneable, {
|
||||
|
||||
var controller = this;
|
||||
return this.saveAndDismissComposer(discussion).then(function(discussion) {
|
||||
controller.get('index').send('loadResults');
|
||||
controller.transitionToRoute('discussion', discussion);
|
||||
if (discussion) {
|
||||
controller.get('index').send('loadResults');
|
||||
controller.transitionToRoute('discussion', discussion);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -46,14 +48,18 @@ export default Ember.Controller.extend(UseComposer, Paneable, {
|
||||
|
||||
newDiscussion: function() {
|
||||
var controller = this;
|
||||
this.showComposer(function() {
|
||||
return ComposerDiscussion.create({
|
||||
user: controller.get('session.user'),
|
||||
submit: function(data) {
|
||||
controller.saveDiscussion(data);
|
||||
}
|
||||
if (this.get('session.isAuthenticated')) {
|
||||
this.showComposer(function() {
|
||||
return ComposerDiscussion.create({
|
||||
user: controller.get('session.user'),
|
||||
submit: function(data) {
|
||||
controller.saveDiscussion(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
this.send('signup');
|
||||
}
|
||||
},
|
||||
|
||||
discussionRemoved: function(discussion) {
|
||||
|
@@ -62,7 +62,7 @@ export default Ember.View.extend(HasItemLists, {
|
||||
populateControls: function(items) {
|
||||
var view = this;
|
||||
|
||||
this.addActionItem(items, 'reply', 'Reply', 'reply', 'discussion.canReply', function() {
|
||||
this.addActionItem(items, 'reply', 'Reply', 'reply', null, function() {
|
||||
view.get('streamContent').send('goToLast');
|
||||
view.get('controller').send('reply');
|
||||
});
|
||||
|
Reference in New Issue
Block a user