diff --git a/app/assets/javascripts/discourse/components/visible.js.es6 b/app/assets/javascripts/discourse/components/visible.js.es6 index 1c3532c2081..f9570e412ea 100644 --- a/app/assets/javascripts/discourse/components/visible.js.es6 +++ b/app/assets/javascripts/discourse/components/visible.js.es6 @@ -4,7 +4,7 @@ export default Ember.Component.extend({ }.observes("visible"), render: function(buffer){ - if (this._state !== 'inDOM' && this._state !== 'preRender') { return; } + if (this._state !== 'inDOM' && this._state !== 'preRender' && this._state !== 'inBuffer') { return; } if (!this.get("visible")) { return; } return this._super(buffer); diff --git a/app/assets/javascripts/discourse/controllers/flag-action-type.js.es6 b/app/assets/javascripts/discourse/controllers/flag-action-type.js.es6 index 484fd12f66e..7ff592a4c19 100644 --- a/app/assets/javascripts/discourse/controllers/flag-action-type.js.es6 +++ b/app/assets/javascripts/discourse/controllers/flag-action-type.js.es6 @@ -7,22 +7,22 @@ export default ObjectController.extend({ message: Em.computed.alias('controllers.flag.message'), customPlaceholder: function(){ - return I18n.t("flagging.custom_placeholder_" + this.get('name_key')); - }.property('name_key'), + return I18n.t("flagging.custom_placeholder_" + this.get('model.name_key')); + }.property('model.name_key'), formattedName: function(){ - if (this.get("is_custom_flag")) { - return this.get('name').replace("{{username}}", this.get('controllers.flag.username')); + if (this.get("model.is_custom_flag")) { + return this.get('model.name').replace("{{username}}", this.get('controllers.flag.model.username')); } else { - return I18n.t("flagging.formatted_name." + this.get('name_key')); + return I18n.t("flagging.formatted_name." + this.get('model.name_key')); } - }.property('name', 'name_key', 'is_custom_flag'), + }.property('model.name', 'model.name_key', 'model.is_custom_flag'), selected: function() { return this.get('model') === this.get('controllers.flag.selected'); }.property('controllers.flag.selected'), - showMessageInput: Em.computed.and('is_custom_flag', 'selected'), + showMessageInput: Em.computed.and('model.is_custom_flag', 'selected'), showDescription: Em.computed.not('showMessageInput'), customMessageLengthClasses: function() { diff --git a/app/assets/javascripts/discourse/controllers/flag.js.es6 b/app/assets/javascripts/discourse/controllers/flag.js.es6 index 0a24d0d280a..4708d2e9505 100644 --- a/app/assets/javascripts/discourse/controllers/flag.js.es6 +++ b/app/assets/javascripts/discourse/controllers/flag.js.es6 @@ -2,8 +2,13 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality'; import ObjectController from 'discourse/controllers/object'; export default ObjectController.extend(ModalFunctionality, { + userDetails: null, + selected: null, + flagTopic: null, + message: null, + topicActionByName: null, - onShow: function() { + onShow() { this.set('selected', null); }, @@ -11,32 +16,31 @@ export default ObjectController.extend(ModalFunctionality, { if (!this.get('flagTopic')) { return this.get('model.flagsAvailable'); } else { - var self = this, + const self = this, lookup = Em.Object.create(); - _.each(this.get("actions_summary"),function(a) { - var actionSummary; + _.each(this.get("model.actions_summary"),function(a) { a.flagTopic = self.get('model'); a.actionType = self.site.topicFlagTypeById(a.id); - actionSummary = Discourse.ActionSummary.create(a); + const actionSummary = Discourse.ActionSummary.create(a); lookup.set(a.actionType.get('name_key'), actionSummary); }); this.set('topicActionByName', lookup); return this.site.get('topic_flag_types').filter(function(item) { - return _.any(self.get("actions_summary"), function(a) { + return _.any(self.get("model.actions_summary"), function(a) { return (a.id === item.get('id') && a.can_act); }); }); } - }.property('post', 'flagTopic', 'actions_summary.@each.can_act'), + }.property('post', 'flagTopic', 'model.actions_summary.@each.can_act'), submitEnabled: function() { - var selected = this.get('selected'); + const selected = this.get('selected'); if (!selected) return false; if (selected.get('is_custom_flag')) { - var len = this.get('message.length') || 0; + const len = this.get('message.length') || 0; return len >= Discourse.SiteSettings.min_private_message_post_length && len <= Discourse.PostActionType.MAX_MESSAGE_LENGTH; } @@ -63,22 +67,21 @@ export default ObjectController.extend(ModalFunctionality, { }.property('selected.is_custom_flag'), actions: { - takeAction: function() { + takeAction() { this.send('createFlag', {takeAction: true}); - this.set('hidden', true); + this.set('model.hidden', true); }, - createFlag: function(opts) { - var self = this; - var postAction; // an instance of ActionSummary + createFlag(opts) { + const self = this; + let postAction; // an instance of ActionSummary if (!this.get('flagTopic')) { - postAction = this.get('actionByName.' + this.get('selected.name_key')); + postAction = this.get('model.actionByName.' + this.get('selected.name_key')); } else { postAction = this.get('topicActionByName.' + this.get('selected.name_key')); } - var params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {}; - - if (opts) params = $.extend(params, opts); + let params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {}; + if (opts) { params = $.extend(params, opts); } this.send('hideModal'); @@ -97,7 +100,7 @@ export default ObjectController.extend(ModalFunctionality, { }); }, - changePostActionType: function(action) { + changePostActionType(action) { this.set('selected', action); }, }, @@ -115,12 +118,12 @@ export default ObjectController.extend(ModalFunctionality, { usernameChanged: function() { this.set('userDetails', null); this.fetchUserDetails(); - }.observes('username'), + }.observes('model.username'), fetchUserDetails: function() { - if( Discourse.User.currentProp('staff') && this.get('username') ) { - var flagController = this; - Discourse.AdminUser.find(this.get('username').toLowerCase()).then(function(user){ + if( Discourse.User.currentProp('staff') && this.get('model.username') ) { + const flagController = this; + Discourse.AdminUser.find(this.get('model.username').toLowerCase()).then(function(user){ flagController.set('userDetails', user); }); } diff --git a/app/assets/javascripts/discourse/controllers/quote-button.js.es6 b/app/assets/javascripts/discourse/controllers/quote-button.js.es6 index c73822188c0..0a4c0e3ada6 100644 --- a/app/assets/javascripts/discourse/controllers/quote-button.js.es6 +++ b/app/assets/javascripts/discourse/controllers/quote-button.js.es6 @@ -43,7 +43,7 @@ export default DiscourseController.extend({ if (this.get('buffer') === selectedText) return; // we need to retrieve the post data from the posts collection in the topic controller - const postStream = this.get('controllers.topic.postStream'); + const postStream = this.get('controllers.topic.model.postStream'); this.set('post', postStream.findLoadedPost(postId)); this.set('buffer', selectedText); diff --git a/app/assets/javascripts/discourse/controllers/share.js.es6 b/app/assets/javascripts/discourse/controllers/share.js.es6 index abf8cd081dd..2e662dc217a 100644 --- a/app/assets/javascripts/discourse/controllers/share.js.es6 +++ b/app/assets/javascripts/discourse/controllers/share.js.es6 @@ -2,7 +2,7 @@ import Sharing from 'discourse/lib/sharing'; export default Ember.Controller.extend({ needs: ['topic'], - title: Ember.computed.alias('controllers.topic.title'), + title: Ember.computed.alias('controllers.topic.model.title'), displayDate: function() { return Discourse.Formatter.longDateNoYear(new Date(this.get('date'))); diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index 245b5d99730..321d2740ad0 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -536,7 +536,7 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon return canDelete; }.property('selectedPostsCount'), - hasError: Ember.computed.or('notFoundHtml', 'message'), + hasError: Ember.computed.or('model.notFoundHtml', 'model.message'), noErrorYet: Ember.computed.not('hasError'), multiSelectChanged: function() { @@ -567,8 +567,8 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon }, showStarButton: function() { - return Discourse.User.current() && !this.get('isPrivateMessage'); - }.property('isPrivateMessage'), + return Discourse.User.current() && !this.get('model.isPrivateMessage'); + }.property('model.isPrivateMessage'), loadingHTML: function() { return spinnerHTML; @@ -666,7 +666,7 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon readPosts(topicId, postNumbers) { const postStream = this.get('model.postStream'); - if(this.get('model.postStream.topic.id') === topicId){ + if (postStream.get('topic.id') === topicId){ _.each(postStream.get('posts'), function(post){ // optimise heavy loop // TODO identity map for postNumber @@ -687,7 +687,7 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon if (!post) { return; } const postStream = this.get('model.postStream'), - firstLoadedPost = postStream.get('firstLoadedPost'); + firstLoadedPost = postStream.get('firstLoadedPost'); this.set('model.currentPost', post.get('post_number')); diff --git a/app/assets/javascripts/discourse/controllers/user-card.js.es6 b/app/assets/javascripts/discourse/controllers/user-card.js.es6 index 8534bfdd3b8..2786d25f779 100644 --- a/app/assets/javascripts/discourse/controllers/user-card.js.es6 +++ b/app/assets/javascripts/discourse/controllers/user-card.js.es6 @@ -90,7 +90,7 @@ export default Ember.Controller.extend({ actions: { togglePosts(user) { - const postStream = this.get('controllers.topic.postStream'); + const postStream = this.get('postStream'); postStream.toggleParticipant(user.get('username')); this.close(); }, diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6 index 532cc6a991b..c96a4f9e31e 100644 --- a/app/assets/javascripts/discourse/models/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/post-stream.js.es6 @@ -707,7 +707,7 @@ const PostStream = RestModel.extend({ const status = result.status; const topic = this.get('topic'); - topic.set('loadingFilter', false); + this.set('loadingFilter', false); topic.set('errorLoading', true); // If the result was 404 the post is not found diff --git a/app/assets/javascripts/discourse/models/topic.js.es6 b/app/assets/javascripts/discourse/models/topic.js.es6 index abd3ef443f2..9823080304b 100644 --- a/app/assets/javascripts/discourse/models/topic.js.es6 +++ b/app/assets/javascripts/discourse/models/topic.js.es6 @@ -1,6 +1,9 @@ import RestModel from 'discourse/models/rest'; const Topic = RestModel.extend({ + message: null, + errorTitle: null, + errorLoading: false, // returns createdAt if there's no bumped date bumpedAt: function() { diff --git a/app/assets/javascripts/discourse/templates/modal/flag.hbs b/app/assets/javascripts/discourse/templates/modal/flag.hbs index 154c1926692..d7a6cc872b7 100644 --- a/app/assets/javascripts/discourse/templates/modal/flag.hbs +++ b/app/assets/javascripts/discourse/templates/modal/flag.hbs @@ -4,9 +4,9 @@ {{#each f in flagsAvailable itemController="flag-action-type"}}
{{#if f.showMessageInput}} diff --git a/app/assets/javascripts/discourse/templates/topic.hbs b/app/assets/javascripts/discourse/templates/topic.hbs index 5bf5be51ae7..113ec187afa 100644 --- a/app/assets/javascripts/discourse/templates/topic.hbs +++ b/app/assets/javascripts/discourse/templates/topic.hbs @@ -124,8 +124,8 @@ {{else}}
{{#conditional-loading-spinner condition=noErrorYet}} - {{#if notFoundHtml}} - {{{notFoundHtml}}} + {{#if model.notFoundHtml}} + {{{model.notFoundHtml}}} {{else}}
{{message}}
diff --git a/app/assets/javascripts/discourse/views/composer.js.es6 b/app/assets/javascripts/discourse/views/composer.js.es6 index f985345da2c..e76962a56bc 100644 --- a/app/assets/javascripts/discourse/views/composer.js.es6 +++ b/app/assets/javascripts/discourse/views/composer.js.es6 @@ -240,7 +240,7 @@ const ComposerView = Discourse.View.extend(Ember.Evented, { this.editor = editor = Discourse.Markdown.createEditor({ lookupAvatarByPostNumber(postNumber) { - const posts = self.get('controller.controllers.topic.postStream.posts'); + const posts = self.get('controller.controllers.topic.model.postStream.posts'); if (posts) { const quotedPost = posts.findProperty("post_number", postNumber); if (quotedPost) { diff --git a/app/assets/javascripts/discourse/views/flag.js.es6 b/app/assets/javascripts/discourse/views/flag.js.es6 index 583452fca48..388735c7c5f 100644 --- a/app/assets/javascripts/discourse/views/flag.js.es6 +++ b/app/assets/javascripts/discourse/views/flag.js.es6 @@ -7,14 +7,21 @@ export default ModalBodyView.extend({ return this.get('controller.flagTopic') ? I18n.t('flagging_topic.title') : I18n.t('flagging.title'); }.property('controller.flagTopic'), + _selectRadio: function() { + this.$("input[type='radio']").prop('checked', false); + + const nameKey = this.get('controller.selected.name_key'); + if (!nameKey) { return; } + + this.$('#radio_' + nameKey).prop('checked', 'true'); + }, + selectedChanged: function() { - Em.run.next(() => { - this.$("input[type='radio']").prop('checked', false); + Ember.run.next(this, this._selectRadio); + }.observes('controller.selected.name_key'), - const nameKey = this.get('controller.selected.name_key'); - if (!nameKey) { return; } - - this.$('#radio_' + nameKey).prop('checked', 'true'); - }); - }.observes('controller.selected.name_key') + // See: https://github.com/emberjs/ember.js/issues/10869 + _selectedHack: function() { + this.removeObserver('controller.selected.name_key'); + }.on('willDestroyElement') });