mirror of
https://github.com/discourse/discourse.git
synced 2025-02-11 14:23:17 +08:00
![Régis Hanol](/assets/img/avatar_default.png)
- new "show-footer" mixins - converted most of the routes to ES6 - FIX: handling of "indexStream" in user pages There will now be a footer on all the following pages - /exception - /about - /latest - /new - /unread - /starred - /top - /categories - /c/:category - /c/:category/l/latest - /c/:category/l/new - /c/:category/l/unread - /c/:category/l/top - /t/:topic/:id - /groups/:name/members - /user/activity - /user/activity/topics - /user/activity/posts - /user/activity/replies - /user/activity/likes-given - /user/activity/likes-received - /user/activity/bookmarks - /user/activity/starred - /user/badges - /user/notifications - /user/flagged-posts - /user/deleted-posts - /user/private-messages - /user/private-messages/mine - /user/private-messages/unread - /user/invited - /user/:username/preferences - /faq (static pages) - /badges - /badges/:id/:badge
104 lines
2.4 KiB
JavaScript
104 lines
2.4 KiB
JavaScript
// A controller for displaying messages as the user composes a message.
|
|
export default Ember.ArrayController.extend({
|
|
needs: ['composer'],
|
|
|
|
// Whether we've checked our messages
|
|
checkedMessages: false,
|
|
|
|
/**
|
|
Initialize the controller
|
|
**/
|
|
init: function() {
|
|
this._super();
|
|
this.reset();
|
|
},
|
|
|
|
actions: {
|
|
/**
|
|
Closes and hides a message.
|
|
|
|
@method closeMessage
|
|
@params {Object} message The message to dismiss
|
|
**/
|
|
closeMessage: function(message) {
|
|
this.removeObject(message);
|
|
},
|
|
|
|
hideMessage: function(message) {
|
|
var messagesByTemplate = this.get('messagesByTemplate'),
|
|
templateName = message.get('templateName');
|
|
|
|
// kind of hacky but the visibility depends on this
|
|
messagesByTemplate[templateName] = undefined;
|
|
this.removeObject(message);
|
|
}
|
|
},
|
|
|
|
/**
|
|
Displays a new message
|
|
|
|
@method popup
|
|
@params {Object} msg The message to display
|
|
**/
|
|
popup: function(msg) {
|
|
var messagesByTemplate = this.get('messagesByTemplate'),
|
|
templateName = msg.get('templateName'),
|
|
existing = messagesByTemplate[templateName];
|
|
|
|
if (!existing) {
|
|
this.pushObject(msg);
|
|
messagesByTemplate[templateName] = msg;
|
|
}
|
|
},
|
|
|
|
/**
|
|
Resets all active messages. For example if composing a new post.
|
|
|
|
@method reset
|
|
**/
|
|
reset: function() {
|
|
this.clear();
|
|
this.set('messagesByTemplate', {});
|
|
this.set('queuedForTyping', []);
|
|
this.set('checkedMessages', false);
|
|
},
|
|
|
|
/**
|
|
Called after the user has typed a reply. Some messages only get shown after being
|
|
typed.
|
|
|
|
@method typedReply
|
|
**/
|
|
typedReply: function() {
|
|
var self = this;
|
|
this.get('queuedForTyping').forEach(function (msg) {
|
|
self.popup(msg);
|
|
});
|
|
},
|
|
|
|
/**
|
|
Figure out if there are any messages that should be displayed above the composer.
|
|
|
|
@method queryFor
|
|
@params {Discourse.Composer} composer The composer model
|
|
**/
|
|
queryFor: function(composer) {
|
|
if (this.get('checkedMessages')) { return; }
|
|
|
|
var self = this,
|
|
queuedForTyping = self.get('queuedForTyping');
|
|
|
|
Discourse.ComposerMessage.find(composer).then(function (messages) {
|
|
self.set('checkedMessages', true);
|
|
messages.forEach(function (msg) {
|
|
if (msg.wait_for_typing) {
|
|
queuedForTyping.addObject(msg);
|
|
} else {
|
|
self.popup(msg);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
});
|