Assorted Ember 1.11 fixes
This commit is contained in:
parent
585583d38c
commit
098556c78d
|
@ -4,7 +4,7 @@ export default Ember.Component.extend({
|
||||||
}.observes("visible"),
|
}.observes("visible"),
|
||||||
|
|
||||||
render: function(buffer){
|
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; }
|
if (!this.get("visible")) { return; }
|
||||||
|
|
||||||
return this._super(buffer);
|
return this._super(buffer);
|
||||||
|
|
|
@ -7,22 +7,22 @@ export default ObjectController.extend({
|
||||||
message: Em.computed.alias('controllers.flag.message'),
|
message: Em.computed.alias('controllers.flag.message'),
|
||||||
|
|
||||||
customPlaceholder: function(){
|
customPlaceholder: function(){
|
||||||
return I18n.t("flagging.custom_placeholder_" + this.get('name_key'));
|
return I18n.t("flagging.custom_placeholder_" + this.get('model.name_key'));
|
||||||
}.property('name_key'),
|
}.property('model.name_key'),
|
||||||
|
|
||||||
formattedName: function(){
|
formattedName: function(){
|
||||||
if (this.get("is_custom_flag")) {
|
if (this.get("model.is_custom_flag")) {
|
||||||
return this.get('name').replace("{{username}}", this.get('controllers.flag.username'));
|
return this.get('model.name').replace("{{username}}", this.get('controllers.flag.model.username'));
|
||||||
} else {
|
} 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() {
|
selected: function() {
|
||||||
return this.get('model') === this.get('controllers.flag.selected');
|
return this.get('model') === this.get('controllers.flag.selected');
|
||||||
}.property('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'),
|
showDescription: Em.computed.not('showMessageInput'),
|
||||||
|
|
||||||
customMessageLengthClasses: function() {
|
customMessageLengthClasses: function() {
|
||||||
|
|
|
@ -2,8 +2,13 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
||||||
import ObjectController from 'discourse/controllers/object';
|
import ObjectController from 'discourse/controllers/object';
|
||||||
|
|
||||||
export default ObjectController.extend(ModalFunctionality, {
|
export default ObjectController.extend(ModalFunctionality, {
|
||||||
|
userDetails: null,
|
||||||
|
selected: null,
|
||||||
|
flagTopic: null,
|
||||||
|
message: null,
|
||||||
|
topicActionByName: null,
|
||||||
|
|
||||||
onShow: function() {
|
onShow() {
|
||||||
this.set('selected', null);
|
this.set('selected', null);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -11,32 +16,31 @@ export default ObjectController.extend(ModalFunctionality, {
|
||||||
if (!this.get('flagTopic')) {
|
if (!this.get('flagTopic')) {
|
||||||
return this.get('model.flagsAvailable');
|
return this.get('model.flagsAvailable');
|
||||||
} else {
|
} else {
|
||||||
var self = this,
|
const self = this,
|
||||||
lookup = Em.Object.create();
|
lookup = Em.Object.create();
|
||||||
|
|
||||||
_.each(this.get("actions_summary"),function(a) {
|
_.each(this.get("model.actions_summary"),function(a) {
|
||||||
var actionSummary;
|
|
||||||
a.flagTopic = self.get('model');
|
a.flagTopic = self.get('model');
|
||||||
a.actionType = self.site.topicFlagTypeById(a.id);
|
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);
|
lookup.set(a.actionType.get('name_key'), actionSummary);
|
||||||
});
|
});
|
||||||
this.set('topicActionByName', lookup);
|
this.set('topicActionByName', lookup);
|
||||||
|
|
||||||
return this.site.get('topic_flag_types').filter(function(item) {
|
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);
|
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() {
|
submitEnabled: function() {
|
||||||
var selected = this.get('selected');
|
const selected = this.get('selected');
|
||||||
if (!selected) return false;
|
if (!selected) return false;
|
||||||
|
|
||||||
if (selected.get('is_custom_flag')) {
|
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 &&
|
return len >= Discourse.SiteSettings.min_private_message_post_length &&
|
||||||
len <= Discourse.PostActionType.MAX_MESSAGE_LENGTH;
|
len <= Discourse.PostActionType.MAX_MESSAGE_LENGTH;
|
||||||
}
|
}
|
||||||
|
@ -63,22 +67,21 @@ export default ObjectController.extend(ModalFunctionality, {
|
||||||
}.property('selected.is_custom_flag'),
|
}.property('selected.is_custom_flag'),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
takeAction: function() {
|
takeAction() {
|
||||||
this.send('createFlag', {takeAction: true});
|
this.send('createFlag', {takeAction: true});
|
||||||
this.set('hidden', true);
|
this.set('model.hidden', true);
|
||||||
},
|
},
|
||||||
|
|
||||||
createFlag: function(opts) {
|
createFlag(opts) {
|
||||||
var self = this;
|
const self = this;
|
||||||
var postAction; // an instance of ActionSummary
|
let postAction; // an instance of ActionSummary
|
||||||
if (!this.get('flagTopic')) {
|
if (!this.get('flagTopic')) {
|
||||||
postAction = this.get('actionByName.' + this.get('selected.name_key'));
|
postAction = this.get('model.actionByName.' + this.get('selected.name_key'));
|
||||||
} else {
|
} else {
|
||||||
postAction = this.get('topicActionByName.' + this.get('selected.name_key'));
|
postAction = this.get('topicActionByName.' + this.get('selected.name_key'));
|
||||||
}
|
}
|
||||||
var params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {};
|
let params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {};
|
||||||
|
if (opts) { params = $.extend(params, opts); }
|
||||||
if (opts) params = $.extend(params, opts);
|
|
||||||
|
|
||||||
this.send('hideModal');
|
this.send('hideModal');
|
||||||
|
|
||||||
|
@ -97,7 +100,7 @@ export default ObjectController.extend(ModalFunctionality, {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
changePostActionType: function(action) {
|
changePostActionType(action) {
|
||||||
this.set('selected', action);
|
this.set('selected', action);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -115,12 +118,12 @@ export default ObjectController.extend(ModalFunctionality, {
|
||||||
usernameChanged: function() {
|
usernameChanged: function() {
|
||||||
this.set('userDetails', null);
|
this.set('userDetails', null);
|
||||||
this.fetchUserDetails();
|
this.fetchUserDetails();
|
||||||
}.observes('username'),
|
}.observes('model.username'),
|
||||||
|
|
||||||
fetchUserDetails: function() {
|
fetchUserDetails: function() {
|
||||||
if( Discourse.User.currentProp('staff') && this.get('username') ) {
|
if( Discourse.User.currentProp('staff') && this.get('model.username') ) {
|
||||||
var flagController = this;
|
const flagController = this;
|
||||||
Discourse.AdminUser.find(this.get('username').toLowerCase()).then(function(user){
|
Discourse.AdminUser.find(this.get('model.username').toLowerCase()).then(function(user){
|
||||||
flagController.set('userDetails', user);
|
flagController.set('userDetails', user);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ export default DiscourseController.extend({
|
||||||
if (this.get('buffer') === selectedText) return;
|
if (this.get('buffer') === selectedText) return;
|
||||||
|
|
||||||
// we need to retrieve the post data from the posts collection in the topic controller
|
// 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('post', postStream.findLoadedPost(postId));
|
||||||
this.set('buffer', selectedText);
|
this.set('buffer', selectedText);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Sharing from 'discourse/lib/sharing';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
needs: ['topic'],
|
needs: ['topic'],
|
||||||
title: Ember.computed.alias('controllers.topic.title'),
|
title: Ember.computed.alias('controllers.topic.model.title'),
|
||||||
|
|
||||||
displayDate: function() {
|
displayDate: function() {
|
||||||
return Discourse.Formatter.longDateNoYear(new Date(this.get('date')));
|
return Discourse.Formatter.longDateNoYear(new Date(this.get('date')));
|
||||||
|
|
|
@ -536,7 +536,7 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
|
||||||
return canDelete;
|
return canDelete;
|
||||||
}.property('selectedPostsCount'),
|
}.property('selectedPostsCount'),
|
||||||
|
|
||||||
hasError: Ember.computed.or('notFoundHtml', 'message'),
|
hasError: Ember.computed.or('model.notFoundHtml', 'model.message'),
|
||||||
noErrorYet: Ember.computed.not('hasError'),
|
noErrorYet: Ember.computed.not('hasError'),
|
||||||
|
|
||||||
multiSelectChanged: function() {
|
multiSelectChanged: function() {
|
||||||
|
@ -567,8 +567,8 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
|
||||||
},
|
},
|
||||||
|
|
||||||
showStarButton: function() {
|
showStarButton: function() {
|
||||||
return Discourse.User.current() && !this.get('isPrivateMessage');
|
return Discourse.User.current() && !this.get('model.isPrivateMessage');
|
||||||
}.property('isPrivateMessage'),
|
}.property('model.isPrivateMessage'),
|
||||||
|
|
||||||
loadingHTML: function() {
|
loadingHTML: function() {
|
||||||
return spinnerHTML;
|
return spinnerHTML;
|
||||||
|
@ -666,7 +666,7 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
|
||||||
readPosts(topicId, postNumbers) {
|
readPosts(topicId, postNumbers) {
|
||||||
const postStream = this.get('model.postStream');
|
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){
|
_.each(postStream.get('posts'), function(post){
|
||||||
// optimise heavy loop
|
// optimise heavy loop
|
||||||
// TODO identity map for postNumber
|
// TODO identity map for postNumber
|
||||||
|
@ -687,7 +687,7 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
|
||||||
if (!post) { return; }
|
if (!post) { return; }
|
||||||
|
|
||||||
const postStream = this.get('model.postStream'),
|
const postStream = this.get('model.postStream'),
|
||||||
firstLoadedPost = postStream.get('firstLoadedPost');
|
firstLoadedPost = postStream.get('firstLoadedPost');
|
||||||
|
|
||||||
this.set('model.currentPost', post.get('post_number'));
|
this.set('model.currentPost', post.get('post_number'));
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ export default Ember.Controller.extend({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
togglePosts(user) {
|
togglePosts(user) {
|
||||||
const postStream = this.get('controllers.topic.postStream');
|
const postStream = this.get('postStream');
|
||||||
postStream.toggleParticipant(user.get('username'));
|
postStream.toggleParticipant(user.get('username'));
|
||||||
this.close();
|
this.close();
|
||||||
},
|
},
|
||||||
|
|
|
@ -707,7 +707,7 @@ const PostStream = RestModel.extend({
|
||||||
const status = result.status;
|
const status = result.status;
|
||||||
|
|
||||||
const topic = this.get('topic');
|
const topic = this.get('topic');
|
||||||
topic.set('loadingFilter', false);
|
this.set('loadingFilter', false);
|
||||||
topic.set('errorLoading', true);
|
topic.set('errorLoading', true);
|
||||||
|
|
||||||
// If the result was 404 the post is not found
|
// If the result was 404 the post is not found
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import RestModel from 'discourse/models/rest';
|
import RestModel from 'discourse/models/rest';
|
||||||
|
|
||||||
const Topic = RestModel.extend({
|
const Topic = RestModel.extend({
|
||||||
|
message: null,
|
||||||
|
errorTitle: null,
|
||||||
|
errorLoading: false,
|
||||||
|
|
||||||
// returns createdAt if there's no bumped date
|
// returns createdAt if there's no bumped date
|
||||||
bumpedAt: function() {
|
bumpedAt: function() {
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
{{#each f in flagsAvailable itemController="flag-action-type"}}
|
{{#each f in flagsAvailable itemController="flag-action-type"}}
|
||||||
<div class='controls'>
|
<div class='controls'>
|
||||||
<label class='radio'>
|
<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}}
|
{{#if f.showDescription}}
|
||||||
<div class='description'>{{{f.description}}}</div>
|
<div class='description'>{{{f.model.description}}}</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</label>
|
</label>
|
||||||
{{#if f.showMessageInput}}
|
{{#if f.showMessageInput}}
|
||||||
|
|
|
@ -124,8 +124,8 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class='container'>
|
<div class='container'>
|
||||||
{{#conditional-loading-spinner condition=noErrorYet}}
|
{{#conditional-loading-spinner condition=noErrorYet}}
|
||||||
{{#if notFoundHtml}}
|
{{#if model.notFoundHtml}}
|
||||||
{{{notFoundHtml}}}
|
{{{model.notFoundHtml}}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="topic-error">
|
<div class="topic-error">
|
||||||
<div>{{message}}</div>
|
<div>{{message}}</div>
|
||||||
|
|
|
@ -240,7 +240,7 @@ const ComposerView = Discourse.View.extend(Ember.Evented, {
|
||||||
|
|
||||||
this.editor = editor = Discourse.Markdown.createEditor({
|
this.editor = editor = Discourse.Markdown.createEditor({
|
||||||
lookupAvatarByPostNumber(postNumber) {
|
lookupAvatarByPostNumber(postNumber) {
|
||||||
const posts = self.get('controller.controllers.topic.postStream.posts');
|
const posts = self.get('controller.controllers.topic.model.postStream.posts');
|
||||||
if (posts) {
|
if (posts) {
|
||||||
const quotedPost = posts.findProperty("post_number", postNumber);
|
const quotedPost = posts.findProperty("post_number", postNumber);
|
||||||
if (quotedPost) {
|
if (quotedPost) {
|
||||||
|
|
|
@ -7,14 +7,21 @@ export default ModalBodyView.extend({
|
||||||
return this.get('controller.flagTopic') ? I18n.t('flagging_topic.title') : I18n.t('flagging.title');
|
return this.get('controller.flagTopic') ? I18n.t('flagging_topic.title') : I18n.t('flagging.title');
|
||||||
}.property('controller.flagTopic'),
|
}.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() {
|
selectedChanged: function() {
|
||||||
Em.run.next(() => {
|
Ember.run.next(this, this._selectRadio);
|
||||||
this.$("input[type='radio']").prop('checked', false);
|
}.observes('controller.selected.name_key'),
|
||||||
|
|
||||||
const nameKey = this.get('controller.selected.name_key');
|
// See: https://github.com/emberjs/ember.js/issues/10869
|
||||||
if (!nameKey) { return; }
|
_selectedHack: function() {
|
||||||
|
this.removeObserver('controller.selected.name_key');
|
||||||
this.$('#radio_' + nameKey).prop('checked', 'true');
|
}.on('willDestroyElement')
|
||||||
});
|
|
||||||
}.observes('controller.selected.name_key')
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue