Assorted Ember 1.11 fixes

This commit is contained in:
Robin Ward 2015-05-06 11:57:27 -04:00
parent 585583d38c
commit 098556c78d
13 changed files with 66 additions and 53 deletions

View File

@ -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);

View File

@ -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() {

View File

@ -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);
});
}

View File

@ -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);

View File

@ -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')));

View File

@ -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'));

View File

@ -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();
},

View File

@ -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

View File

@ -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() {

View File

@ -4,9 +4,9 @@
{{#each f in flagsAvailable itemController="flag-action-type"}}
<div class='controls'>
<label class='radio'>
<input type='radio' id="radio_{{unbound f.name_key}}" {{action "changePostActionType" f}} name='post_action_type_index'> <strong>{{f.formattedName}}</strong>
<input type='radio' id="radio_{{unbound f.model.name_key}}" {{action "changePostActionType" f}} name='post_action_type_index'> <strong>{{f.formattedName}}</strong>
{{#if f.showDescription}}
<div class='description'>{{{f.description}}}</div>
<div class='description'>{{{f.model.description}}}</div>
{{/if}}
</label>
{{#if f.showMessageInput}}

View File

@ -124,8 +124,8 @@
{{else}}
<div class='container'>
{{#conditional-loading-spinner condition=noErrorYet}}
{{#if notFoundHtml}}
{{{notFoundHtml}}}
{{#if model.notFoundHtml}}
{{{model.notFoundHtml}}}
{{else}}
<div class="topic-error">
<div>{{message}}</div>

View File

@ -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) {

View File

@ -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')
});