FIX: select posts

This commit is contained in:
Régis Hanol 2015-05-12 12:54:28 +02:00
parent ab80240900
commit ff227eabe6
9 changed files with 31 additions and 39 deletions

View File

@ -1,9 +1,10 @@
import Presence from 'discourse/mixins/presence';
import SelectedPostsCount from 'discourse/mixins/selected-posts-count';
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import ObjectController from 'discourse/controllers/object';
// Modal related to changing the ownership of posts
export default ObjectController.extend(Presence, Discourse.SelectedPostsCount, ModalFunctionality, {
export default ObjectController.extend(Presence, SelectedPostsCount, ModalFunctionality, {
needs: ['topic'],
topicController: Em.computed.alias('controllers.topic'),

View File

@ -1,9 +1,10 @@
import Presence from 'discourse/mixins/presence';
import SelectedPostsCount from 'discourse/mixins/selected-posts-count';
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import ObjectController from 'discourse/controllers/object';
// Modal related to merging of topics
export default ObjectController.extend(Discourse.SelectedPostsCount, ModalFunctionality, Presence, {
export default ObjectController.extend(SelectedPostsCount, ModalFunctionality, Presence, {
needs: ['topic'],
topicController: Em.computed.alias('controllers.topic'),

View File

@ -1,9 +1,10 @@
import Presence from 'discourse/mixins/presence';
import SelectedPostsCount from 'discourse/mixins/selected-posts-count';
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import ObjectController from 'discourse/controllers/object';
// Modal related to auto closing of topics
export default ObjectController.extend(Discourse.SelectedPostsCount, ModalFunctionality, Presence, {
export default ObjectController.extend(SelectedPostsCount, ModalFunctionality, Presence, {
needs: ['topic'],
topicController: Em.computed.alias('controllers.topic'),

View File

@ -1,9 +1,10 @@
import ObjectController from 'discourse/controllers/object';
import BufferedContent from 'discourse/mixins/buffered-content';
import SelectedPostsCount from 'discourse/mixins/selected-posts-count';
import { spinnerHTML } from 'discourse/helpers/loading-spinner';
import Topic from 'discourse/models/topic';
export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedContent, {
export default ObjectController.extend(SelectedPostsCount, BufferedContent, {
multiSelect: false,
needs: ['header', 'modal', 'composer', 'quote-button', 'search', 'topic-progress', 'application'],
allPostsSelected: false,
@ -646,11 +647,8 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
return false;
} else {
selectedPosts.addObject(post);
// If the user manually selects all posts, all posts are selected
if (selectedPosts.length === this.get('posts_count')) {
this.set('allPostsSelected', true);
}
this.set('allPostsSelected', selectedPosts.length === this.get('model.posts_count'));
return true;
}
},

View File

@ -1,15 +1,9 @@
/**
This mixin allows a modal to list a selected posts count nicely.
@class Discourse.SelectedPostsCount
@extends Ember.Mixin
@namespace Discourse
@module Discourse
**/
Discourse.SelectedPostsCount = Em.Mixin.create({
export default Em.Mixin.create({
selectedPostsCount: function() {
if (this.get('allPostsSelected')) return this.get('posts_count') || this.get('topic.posts_count');
if (this.get('allPostsSelected')) {
return this.get('model.posts_count') || this.get('topic.posts_count') || this.get('posts_count');
}
var sum = this.get('selectedPosts.length') || 0;
if (this.get('selectedReplies')) {
@ -21,19 +15,14 @@ Discourse.SelectedPostsCount = Em.Mixin.create({
return sum;
}.property('selectedPosts.length', 'allPostsSelected', 'selectedReplies.length'),
/**
The username that owns every selected post, or undefined if no selection or if
ownership is mixed.
@returns {String|undefined} username that owns all selected posts
**/
// The username that owns every selected post, or undefined if no selection or if ownership is mixed.
selectedPostsUsername: function() {
// Don't proceed if replies are selected or usernames are mixed
// Changing ownership in those cases normally doesn't make sense
if (this.get('selectedReplies') && this.get('selectedReplies').length > 0) return;
if (this.get('selectedPosts').length <= 0) return;
if (this.get('selectedReplies') && this.get('selectedReplies').length > 0) { return; }
if (this.get('selectedPosts').length <= 0) { return; }
var selectedPosts = this.get('selectedPosts'),
const selectedPosts = this.get('selectedPosts'),
username = selectedPosts[0].username;
if (selectedPosts.every(function(post) { return post.username === username; })) {
@ -41,5 +30,3 @@ Discourse.SelectedPostsCount = Em.Mixin.create({
}
}.property('selectedPosts.length', 'selectedReplies.length')
});

View File

@ -1,4 +1,4 @@
<p>{{count-i18n key=topic.multi_select.description count=selectedPostsCount}}</p>
<p>{{count-i18n key="topic.multi_select.description" count=selectedPostsCount}}</p>
{{#if canSelectAll}}
<p><a href {{action "selectAll"}}>{{i18n 'topic.multi_select.select_all'}}</a></p>
@ -9,17 +9,19 @@
{{/if}}
{{#if canDeleteSelected}}
<button class='btn' {{action "deleteSelected"}}><i class='fa fa-trash-o'></i> {{i18n 'topic.multi_select.delete'}}</button>
{{d-button action="deleteSelected" icon="trash-o" label="topic.multi_select.delete"}}
{{/if}}
{{#if canSplitTopic}}
<button class='btn' {{action "splitTopic"}}><i class='fa fa-sign-out'></i> {{i18n 'topic.split_topic.action'}}</button>
{{d-button action="splitTopic" icon="sign-out" label="topic.split_topic.action"}}
{{/if}}
{{#if canMergeTopic}}
<button class='btn' {{action "mergeTopic"}}><i class='fa fa-sign-out'></i> {{i18n 'topic.merge_topic.action'}}</button>
{{d-button action="mergeTopic" icon="sign-out" label="topic.merge_topic.action"}}
{{/if}}
{{#if canChangeOwner}}
<button class='btn' {{action "changeOwner"}}><i class='fa fa-user'></i> {{i18n 'topic.change_owner.action'}}</button>
{{d-button action="changeOwner" icon="user" label="topic.change_owner.action"}}
{{/if}}
<p class='cancel'><a href {{action "toggleMultiSelect"}}>{{i18n 'topic.multi_select.cancel'}}</a></p>

View File

@ -1,7 +1,7 @@
export default Discourse.View.extend({
elementId: 'selected-posts',
topic: Ember.computed.alias('controller.model'),
classNameBindings: ['customVisibility'],
templateName: "selected-posts",
customVisibility: function() {
if (!this.get('controller.multiSelect')) return 'hidden';

View File

@ -1,6 +1,7 @@
import SelectedPostsCount from 'discourse/mixins/selected-posts-count';
import ModalBodyView from "discourse/views/modal-body";
export default ModalBodyView.extend(Discourse.SelectedPostsCount, {
export default ModalBodyView.extend(SelectedPostsCount, {
templateName: 'modal/split_topic',
title: I18n.t('topic.split_topic.title')
});

View File

@ -1,9 +1,10 @@
module("Discourse.SelectedPostsCount");
module("SelectedPostsCount");
import SelectedPostsCount from 'discourse/mixins/selected-posts-count';
import Topic from 'discourse/models/topic';
var buildTestObj = function(params) {
return Ember.Object.createWithMixins(Discourse.SelectedPostsCount, params || {});
return Ember.Object.createWithMixins(SelectedPostsCount, params || {});
};
test("without selectedPosts", function () {