mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	select the current category on open
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							d2066f59c0
						
					
				
				
					commit
					6b51dd5a2f
				
			| @@ -1,14 +1,18 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
|  |  | ||||||
|  |  | ||||||
| define('forum/topic/fork', ['components', 'postSelect', 'alerts'], function (components, postSelect, alerts) { | define('forum/topic/fork', [ | ||||||
|  | 	'components', 'postSelect', 'alerts', 'categorySelector', | ||||||
|  | ], function (components, postSelect, alerts, categorySelector) { | ||||||
| 	const Fork = {}; | 	const Fork = {}; | ||||||
| 	let forkModal; | 	let forkModal; | ||||||
| 	let forkCommit; | 	let forkCommit; | ||||||
| 	let fromTid; | 	let fromTid; | ||||||
|  | 	let selectedCategory; | ||||||
|  |  | ||||||
| 	Fork.init = function () { | 	Fork.init = function () { | ||||||
| 		fromTid = ajaxify.data.tid; | 		fromTid = ajaxify.data.tid; | ||||||
|  | 		selectedCategory = ajaxify.data.category; | ||||||
|  |  | ||||||
| 		$(window).off('action:ajaxify.end', onAjaxifyEnd).on('action:ajaxify.end', onAjaxifyEnd); | 		$(window).off('action:ajaxify.end', onAjaxifyEnd).on('action:ajaxify.end', onAjaxifyEnd); | ||||||
|  |  | ||||||
| @@ -16,13 +20,22 @@ define('forum/topic/fork', ['components', 'postSelect', 'alerts'], function (com | |||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		app.parseAndTranslate('modals/fork-topic', {}, function (html) { | 		app.parseAndTranslate('modals/fork-topic', { | ||||||
|  | 			selectedCategory: selectedCategory, | ||||||
|  | 		}, function (html) { | ||||||
| 			forkModal = html; | 			forkModal = html; | ||||||
|  |  | ||||||
| 			forkCommit = forkModal.find('#fork_thread_commit'); | 			forkCommit = forkModal.find('#fork_thread_commit'); | ||||||
|  |  | ||||||
| 			$('body').append(forkModal); | 			$('body').append(forkModal); | ||||||
|  |  | ||||||
|  | 			categorySelector.init(forkModal.find('[component="category-selector"]'), { | ||||||
|  | 				onSelect: function (category) { | ||||||
|  | 					selectedCategory = category; | ||||||
|  | 				}, | ||||||
|  | 				privilege: 'moderate', | ||||||
|  | 			}); | ||||||
|  |  | ||||||
| 			forkModal.find('#fork_thread_cancel').on('click', closeForkModal); | 			forkModal.find('#fork_thread_cancel').on('click', closeForkModal); | ||||||
| 			forkModal.find('#fork-title').on('keyup', checkForkButtonEnable); | 			forkModal.find('#fork-title').on('keyup', checkForkButtonEnable); | ||||||
|  |  | ||||||
| @@ -44,11 +57,15 @@ define('forum/topic/fork', ['components', 'postSelect', 'alerts'], function (com | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	function createTopicFromPosts() { | 	function createTopicFromPosts() { | ||||||
|  | 		if (!selectedCategory) { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
| 		forkCommit.attr('disabled', true); | 		forkCommit.attr('disabled', true); | ||||||
| 		socket.emit('topics.createTopicFromPosts', { | 		socket.emit('topics.createTopicFromPosts', { | ||||||
| 			title: forkModal.find('#fork-title').val(), | 			title: forkModal.find('#fork-title').val(), | ||||||
| 			pids: postSelect.pids, | 			pids: postSelect.pids, | ||||||
| 			fromTid: fromTid, | 			fromTid: fromTid, | ||||||
|  | 			cid: selectedCategory.cid, | ||||||
| 		}, function (err, newTopic) { | 		}, function (err, newTopic) { | ||||||
| 			function fadeOutAndRemove(pid) { | 			function fadeOutAndRemove(pid) { | ||||||
| 				components.get('post', 'pid', pid).fadeOut(500, function () { | 				components.get('post', 'pid', pid).fadeOut(500, function () { | ||||||
|   | |||||||
| @@ -50,7 +50,7 @@ SocketTopics.createTopicFromPosts = async function (socket, data) { | |||||||
| 		throw new Error('[[error:invalid-data]]'); | 		throw new Error('[[error:invalid-data]]'); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	const result = await topics.createTopicFromPosts(socket.uid, data.title, data.pids, data.fromTid); | 	const result = await topics.createTopicFromPosts(socket.uid, data.title, data.pids, data.fromTid, data.cid); | ||||||
| 	await events.log({ | 	await events.log({ | ||||||
| 		type: `topic-fork`, | 		type: `topic-fork`, | ||||||
| 		uid: socket.uid, | 		uid: socket.uid, | ||||||
|   | |||||||
| @@ -9,7 +9,7 @@ const plugins = require('../plugins'); | |||||||
| const meta = require('../meta'); | const meta = require('../meta'); | ||||||
|  |  | ||||||
| module.exports = function (Topics) { | module.exports = function (Topics) { | ||||||
| 	Topics.createTopicFromPosts = async function (uid, title, pids, fromTid) { | 	Topics.createTopicFromPosts = async function (uid, title, pids, fromTid, cid) { | ||||||
| 		if (title) { | 		if (title) { | ||||||
| 			title = title.trim(); | 			title = title.trim(); | ||||||
| 		} | 		} | ||||||
| @@ -27,7 +27,9 @@ module.exports = function (Topics) { | |||||||
| 		pids.sort((a, b) => a - b); | 		pids.sort((a, b) => a - b); | ||||||
|  |  | ||||||
| 		const mainPid = pids[0]; | 		const mainPid = pids[0]; | ||||||
| 		const cid = await posts.getCidByPid(mainPid); | 		if (!cid) { | ||||||
|  | 			cid = await posts.getCidByPid(mainPid); | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		const [postData, isAdminOrMod] = await Promise.all([ | 		const [postData, isAdminOrMod] = await Promise.all([ | ||||||
| 			posts.getPostData(mainPid), | 			posts.getPostData(mainPid), | ||||||
|   | |||||||
| @@ -10,7 +10,13 @@ | |||||||
| 			<label class="form-label" for="fork-title"><strong>[[topic:title]]</strong></label> | 			<label class="form-label" for="fork-title"><strong>[[topic:title]]</strong></label> | ||||||
| 			<input id="fork-title" type="text" class="form-control" placeholder="[[topic:enter-new-topic-title]]"> | 			<input id="fork-title" type="text" class="form-control" placeholder="[[topic:enter-new-topic-title]]"> | ||||||
| 		</div> | 		</div> | ||||||
| 		<strong><span id="fork-pids"></span></strong> | 		<div class="mb-3"> | ||||||
|  | 			<label class="form-label"><strong>[[category:category]]</strong></label> | ||||||
|  | 			<div> | ||||||
|  | 			<!-- IMPORT partials/category/selector-dropdown-right.tpl --> | ||||||
|  | 			</div> | ||||||
|  | 		</div> | ||||||
|  | 		<strong id="fork-pids"></strong> | ||||||
| 	</div> | 	</div> | ||||||
| 	<div class="card-footer text-end"> | 	<div class="card-footer text-end"> | ||||||
| 		<button class="btn btn-link btn-sm" id="fork_thread_cancel">[[global:buttons.close]]</button> | 		<button class="btn btn-link btn-sm" id="fork_thread_cancel">[[global:buttons.close]]</button> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user