From 3c1103092931f6d83858c698bdc7f50c4cef1443 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 21 Apr 2014 13:29:40 -0400 Subject: [PATCH] closes #1398 --- public/language/en_GB/topic.json | 1 + public/src/forum/categoryTools.js | 10 +++++++-- public/src/forum/topic/move.js | 11 +++++----- src/socket.io/topics.js | 34 +++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/public/language/en_GB/topic.json b/public/language/en_GB/topic.json index 2c0deace75..4b12428c86 100644 --- a/public/language/en_GB/topic.json +++ b/public/language/en_GB/topic.json @@ -48,6 +48,7 @@ "thread_tools.lock": "Lock Topic", "thread_tools.unlock": "Unlock Topic", "thread_tools.move": "Move Topic", + "thread_tools.move_all": "Move All", "thread_tools.fork": "Fork Topic", "thread_tools.delete": "Delete Topic", "thread_tools.delete_confirm": "Are you sure you want to delete this thread?", diff --git a/public/src/forum/categoryTools.js b/public/src/forum/categoryTools.js index 34608f6d63..b1fd02388f 100644 --- a/public/src/forum/categoryTools.js +++ b/public/src/forum/categoryTools.js @@ -68,13 +68,19 @@ define(['forum/topic/move', 'topicSelect'], function(move, topicSelect) { $('.move_thread').on('click', function() { var tids = topicSelect.getSelectedTids(); - console.log(tids); + if (tids.length) { move.init(tids, cid, onCommandComplete); } return false; }); + $('.move_all_threads').on('click', function() { + move.init(null, cid, function(err) { + ajaxify.refresh(); + }); + }); + socket.on('event:topic_deleted', setDeleteState); socket.on('event:topic_restored', setDeleteState); @@ -151,7 +157,7 @@ define(['forum/topic/move', 'topicSelect'], function(move, topicSelect) { var topic = getTopicEl(data.tid); topic.toggleClass('pinned', data.isPinned); topic.find('.fa-thumb-tack').toggleClass('hide', !data.isPinned); - ajaxify.go('category/' + CategoryTools.cid); + ajaxify.refresh(); } function setLockedState(data) { diff --git a/public/src/forum/topic/move.js b/public/src/forum/topic/move.js index 8c5efd6fe1..937b072124 100644 --- a/public/src/forum/topic/move.js +++ b/public/src/forum/topic/move.js @@ -15,11 +15,11 @@ define(function() { Move.tids = tids; Move.currentCid = currentCid; Move.onComplete = onComplete; + Move.moveAll = tids ? false : true; modal.on('shown.bs.modal', onMoveModalShown); $('#move-confirm').hide(); modal.modal('show'); - }; function onMoveModalShown() { @@ -60,14 +60,15 @@ define(function() { if (!commitEl.prop('disabled') && targetCid) { commitEl.prop('disabled', true); - moveTopic(); + moveTopics(); } } - function moveTopic() { - socket.emit('topics.move', { + function moveTopics() { + socket.emit(Move.moveAll ? 'topics.moveAll' : 'topics.move', { tids: Move.tids, - cid: targetCid + cid: targetCid, + currentCid: Move.currentCid }, function(err) { modal.modal('hide'); $('#move_thread_commit').prop('disabled', false); diff --git a/src/socket.io/topics.js b/src/socket.io/topics.js index 3185bb37f7..5b8da28dcf 100644 --- a/src/socket.io/topics.js +++ b/src/socket.io/topics.js @@ -4,6 +4,7 @@ var topics = require('../topics'), categories = require('../categories'), threadTools = require('../threadTools'), + categoryTools = require('../categoryTools'), index = require('./index'), user = require('../user'), db = require('./../database'), @@ -265,6 +266,39 @@ SocketTopics.move = function(socket, data, callback) { }, callback); }; +SocketTopics.moveAll = function(socket, data, callback) { + if(!data || !data.cid || !data.currentCid) { + return callback(new Error('[[error:invalid-data]]')); + } + + async.parallel({ + from: function(next) { + categoryTools.privileges(data.currentCid, socket.uid, next); + }, + to: function(next) { + categoryTools.privileges(data.cid, socket.uid, next); + } + }, function(err, results) { + if (err) { + return callback(err); + } + + if (!results.from.admin && (!results.from.moderator || !results.to.moderator)) { + return callback(new Error('[[error:no-privileges]]')); + } + + categories.getTopicIds(data.currentCid, 0, -1, function(err, tids) { + if (err) { + return callback(err); + } + + async.each(tids, function(tid, next) { + threadTools.move(tid, data.cid, next); + }, callback); + }); + }); +}; + SocketTopics.followCheck = function(socket, tid, callback) { threadTools.isFollowing(tid, socket.uid, callback); };