mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	closes #1948
This commit is contained in:
		| @@ -9,11 +9,12 @@ var dependencies = [ | |||||||
| 	'composer/formatting', | 	'composer/formatting', | ||||||
| 	'composer/drafts', | 	'composer/drafts', | ||||||
| 	'composer/tags', | 	'composer/tags', | ||||||
|  | 	'composer/categoryList', | ||||||
| 	'composer/preview', | 	'composer/preview', | ||||||
| 	'composer/resize' | 	'composer/resize' | ||||||
| ]; | ]; | ||||||
|  |  | ||||||
| define('composer', dependencies, function(taskbar, controls, uploads, formatting, drafts, tags, preview, resize) { | define('composer', dependencies, function(taskbar, controls, uploads, formatting, drafts, tags, categoryList, preview, resize) { | ||||||
| 	var composer = { | 	var composer = { | ||||||
| 		active: undefined, | 		active: undefined, | ||||||
| 		posts: {}, | 		posts: {}, | ||||||
| @@ -200,84 +201,96 @@ define('composer', dependencies, function(taskbar, controls, uploads, formatting | |||||||
|  |  | ||||||
| 		var template = (composer.bsEnvironment === 'xs' || composer.bsEnvironment === 'sm') ? 'composer-mobile' : 'composer'; | 		var template = (composer.bsEnvironment === 'xs' || composer.bsEnvironment === 'sm') ? 'composer-mobile' : 'composer'; | ||||||
|  |  | ||||||
| 		templates.parse(template, {allowTopicsThumbnail: allowTopicsThumbnail, showTags: isTopic || isMain}, function(composerTemplate) { | 		var data = { | ||||||
| 			translator.translate(composerTemplate, function(composerTemplate) { | 			allowTopicsThumbnail: allowTopicsThumbnail, | ||||||
| 				composerTemplate = $(composerTemplate); | 			showTags: isTopic || isMain, | ||||||
|  | 			isTopic: isTopic | ||||||
|  | 		}; | ||||||
|  |  | ||||||
| 				composerTemplate.attr('id', 'cmp-uuid-' + post_uuid); | 		parseAndTranslate(template, data, function(composerTemplate) { | ||||||
|  |  | ||||||
| 				$(document.body).append(composerTemplate); | 			composerTemplate = $(composerTemplate); | ||||||
|  |  | ||||||
| 				var postContainer = $(composerTemplate[0]), | 			composerTemplate.attr('id', 'cmp-uuid-' + post_uuid); | ||||||
| 					postData = composer.posts[post_uuid], |  | ||||||
| 					bodyEl = postContainer.find('textarea'), |  | ||||||
| 					draft = drafts.getDraft(postData.save_id); |  | ||||||
|  |  | ||||||
| 				tags.init(postContainer, composer.posts[post_uuid]); | 			$(document.body).append(composerTemplate); | ||||||
| 				updateTitle(postData, postContainer); |  | ||||||
|  |  | ||||||
| 				activate(post_uuid); | 			var postContainer = $(composerTemplate[0]), | ||||||
| 				resize.reposition(postContainer); | 				postData = composer.posts[post_uuid], | ||||||
|  | 				bodyEl = postContainer.find('textarea'), | ||||||
|  | 				draft = drafts.getDraft(postData.save_id); | ||||||
|  |  | ||||||
| 				if (config.allowFileUploads || config.hasImageUploadPlugin) { | 			tags.init(postContainer, composer.posts[post_uuid]); | ||||||
| 					uploads.initialize(post_uuid); | 			categoryList.init(postContainer, composer.posts[post_uuid]); | ||||||
|  | 			updateTitle(postData, postContainer); | ||||||
|  |  | ||||||
|  | 			activate(post_uuid); | ||||||
|  | 			resize.reposition(postContainer); | ||||||
|  |  | ||||||
|  | 			if (config.allowFileUploads || config.hasImageUploadPlugin) { | ||||||
|  | 				uploads.initialize(post_uuid); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			formatting.addHandler(postContainer); | ||||||
|  |  | ||||||
|  | 			if (allowTopicsThumbnail) { | ||||||
|  | 				uploads.toggleThumbEls(postContainer, composer.posts[post_uuid].topic_thumb || ''); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			postContainer.on('change', 'input, textarea', function() { | ||||||
|  | 				composer.posts[post_uuid].modified = true; | ||||||
|  | 			}); | ||||||
|  |  | ||||||
|  | 			postContainer.on('click', '.action-bar button[data-action="post"]', function() { | ||||||
|  | 				$(this).attr('disabled', true); | ||||||
|  | 				post(post_uuid); | ||||||
|  | 			}); | ||||||
|  |  | ||||||
|  | 			postContainer.on('click', '.action-bar button[data-action="discard"]', function() { | ||||||
|  | 				if (!composer.posts[post_uuid].modified) { | ||||||
|  | 					discard(post_uuid); | ||||||
|  | 					return; | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
| 				formatting.addHandler(postContainer); | 				translator.translate('[[modules:composer.discard]]', function(translated) { | ||||||
|  | 					bootbox.confirm(translated, function(confirm) { | ||||||
| 				if (allowTopicsThumbnail) { | 						if (confirm) { | ||||||
| 					uploads.toggleThumbEls(postContainer, composer.posts[post_uuid].topic_thumb || ''); | 							discard(post_uuid); | ||||||
| 				} | 						} | ||||||
|  |  | ||||||
| 				postContainer.on('change', 'input, textarea', function() { |  | ||||||
| 					composer.posts[post_uuid].modified = true; |  | ||||||
| 				}); |  | ||||||
|  |  | ||||||
| 				postContainer.on('click', '.action-bar button[data-action="post"]', function() { |  | ||||||
| 					$(this).attr('disabled', true); |  | ||||||
| 					post(post_uuid); |  | ||||||
| 				}); |  | ||||||
|  |  | ||||||
| 				postContainer.on('click', '.action-bar button[data-action="discard"]', function() { |  | ||||||
| 					if (!composer.posts[post_uuid].modified) { |  | ||||||
| 						discard(post_uuid); |  | ||||||
| 						return; |  | ||||||
| 					} |  | ||||||
|  |  | ||||||
| 					translator.translate('[[modules:composer.discard]]', function(translated) { |  | ||||||
| 						bootbox.confirm(translated, function(confirm) { |  | ||||||
| 							if (confirm) { |  | ||||||
| 								discard(post_uuid); |  | ||||||
| 							} |  | ||||||
| 						}); |  | ||||||
| 					}); | 					}); | ||||||
| 				}); | 				}); | ||||||
|  |  | ||||||
| 				bodyEl.on('input propertychange', function() { |  | ||||||
| 					preview.render(postContainer); |  | ||||||
| 				}); |  | ||||||
|  |  | ||||||
| 				bodyEl.on('scroll', function() { |  | ||||||
| 					preview.matchScroll(postContainer); |  | ||||||
| 				}); |  | ||||||
|  |  | ||||||
| 				bodyEl.val(draft ? draft : postData.body); |  | ||||||
| 				preview.render(postContainer, function() { |  | ||||||
| 					preview.matchScroll(postContainer); |  | ||||||
| 				}); |  | ||||||
| 				drafts.init(postContainer, postData); |  | ||||||
|  |  | ||||||
| 				resize.handleResize(postContainer); |  | ||||||
|  |  | ||||||
| 				handleHelp(postContainer); |  | ||||||
|  |  | ||||||
| 				$(window).trigger('action:composer.loaded', { |  | ||||||
| 					post_uuid: post_uuid |  | ||||||
| 				}); |  | ||||||
|  |  | ||||||
| 				formatting.addComposerButtons(); |  | ||||||
| 				focusElements(postContainer); |  | ||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
|  | 			bodyEl.on('input propertychange', function() { | ||||||
|  | 				preview.render(postContainer); | ||||||
|  | 			}); | ||||||
|  |  | ||||||
|  | 			bodyEl.on('scroll', function() { | ||||||
|  | 				preview.matchScroll(postContainer); | ||||||
|  | 			}); | ||||||
|  |  | ||||||
|  | 			bodyEl.val(draft ? draft : postData.body); | ||||||
|  | 			preview.render(postContainer, function() { | ||||||
|  | 				preview.matchScroll(postContainer); | ||||||
|  | 			}); | ||||||
|  | 			drafts.init(postContainer, postData); | ||||||
|  |  | ||||||
|  | 			resize.handleResize(postContainer); | ||||||
|  |  | ||||||
|  | 			handleHelp(postContainer); | ||||||
|  |  | ||||||
|  | 			$(window).trigger('action:composer.loaded', { | ||||||
|  | 				post_uuid: post_uuid | ||||||
|  | 			}); | ||||||
|  |  | ||||||
|  | 			formatting.addComposerButtons(); | ||||||
|  | 			focusElements(postContainer); | ||||||
|  | 		}); | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	function parseAndTranslate(template, data, callback) { | ||||||
|  | 		templates.parse(template, data, function(composerTemplate) { | ||||||
|  | 			translator.translate(composerTemplate, callback); | ||||||
| 		}); | 		}); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										37
									
								
								public/src/modules/composer/categoryList.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								public/src/modules/composer/categoryList.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | |||||||
|  |  | ||||||
|  | 'use strict'; | ||||||
|  |  | ||||||
|  | /*globals define, config, socket, app*/ | ||||||
|  |  | ||||||
|  | define('composer/categoryList', function() { | ||||||
|  | 	var categoryList = {}; | ||||||
|  |  | ||||||
|  | 	categoryList.init = function(postContainer, postData) { | ||||||
|  | 		var listEl = postContainer.find('.category-list'); | ||||||
|  | 		if (!listEl.length) { | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		socket.emit('categories.getCategoriesByPrivilege', 'topics:create', function(err, categories) { | ||||||
|  | 			if (err) { | ||||||
|  | 				return app.alertError(err.message); | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			categories.forEach(function(category) { | ||||||
|  | 				$('<option value="' + category.cid + '">' + category.name + '</option>').appendTo(listEl); | ||||||
|  | 			}); | ||||||
|  |  | ||||||
|  | 			if (postData.cid) { | ||||||
|  | 				listEl.find('option[value="' + postData.cid + '"]').prop('selected', true); | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  |  | ||||||
|  | 		listEl.on('change', function() { | ||||||
|  | 			if (postData.cid) { | ||||||
|  | 				postData.cid = this.value; | ||||||
|  | 			} | ||||||
|  | 		}); | ||||||
|  | 	}; | ||||||
|  |  | ||||||
|  | 	return categoryList; | ||||||
|  | }); | ||||||
| @@ -137,8 +137,8 @@ define('composer/resize', function() { | |||||||
|  |  | ||||||
|  |  | ||||||
| 	function resizeWritePreview(postContainer) { | 	function resizeWritePreview(postContainer) { | ||||||
| 		var h1 = postContainer.find('.title').outerHeight(true); | 		var h1 = postContainer.find('.title-container').outerHeight(true); | ||||||
| 		var h2 = postContainer.find('.tags-container').outerHeight(true); | 		var h2 = postContainer.find('.category-tag-row').outerHeight(true); | ||||||
| 		var h3 = postContainer.find('.formatting-bar').outerHeight(true); | 		var h3 = postContainer.find('.formatting-bar').outerHeight(true); | ||||||
| 		var h4 = postContainer.find('.topic-thumb-container').outerHeight(true); | 		var h4 = postContainer.find('.topic-thumb-container').outerHeight(true); | ||||||
| 		var h5 = $('.taskbar').height(); | 		var h5 = $('.taskbar').height(); | ||||||
|   | |||||||
| @@ -188,7 +188,7 @@ var db = require('./database'), | |||||||
| 		}); | 		}); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	Categories.getVisibleCategories = function(uid, callback) { | 	Categories.getCategoriesByPrivilege = function(uid, privilege, callback) { | ||||||
| 		db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) { | 		db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) { | ||||||
| 			if (err) { | 			if (err) { | ||||||
| 				return callback(err); | 				return callback(err); | ||||||
| @@ -198,7 +198,7 @@ var db = require('./database'), | |||||||
| 				return callback(null, []); | 				return callback(null, []); | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			privileges.categories.filter('find', cids, uid, function(err, cids) { | 			privileges.categories.filter(privilege, cids, uid, function(err, cids) { | ||||||
| 				if (err) { | 				if (err) { | ||||||
| 					return callback(err); | 					return callback(err); | ||||||
| 				} | 				} | ||||||
|   | |||||||
| @@ -64,7 +64,7 @@ Controllers.home = function(req, res, next) { | |||||||
| 		}, | 		}, | ||||||
| 		categories: function (next) { | 		categories: function (next) { | ||||||
| 			var uid = req.user ? req.user.uid : 0; | 			var uid = req.user ? req.user.uid : 0; | ||||||
| 			categories.getVisibleCategories(uid, function (err, categoryData) { | 			categories.getCategoriesByPrivilege(uid, 'find', function (err, categoryData) { | ||||||
| 				if (err) { | 				if (err) { | ||||||
| 					return next(err); | 					return next(err); | ||||||
| 				} | 				} | ||||||
|   | |||||||
| @@ -31,7 +31,7 @@ var path = require('path'), | |||||||
| 			async.parallel([ | 			async.parallel([ | ||||||
| 				function(next) { | 				function(next) { | ||||||
| 					var categoryUrls = []; | 					var categoryUrls = []; | ||||||
| 					categories.getVisibleCategories(0, function(err, categoriesData) { | 					categories.getCategoriesByPrivilege(0, 'find', function(err, categoriesData) { | ||||||
| 						if (err) { | 						if (err) { | ||||||
| 							return next(err); | 							return next(err); | ||||||
| 						} | 						} | ||||||
|   | |||||||
| @@ -79,4 +79,8 @@ SocketCategories.getUsersInCategory = function(socket, cid, callback) { | |||||||
| 	user.getMultipleUserFields(uids, ['uid', 'userslug', 'username', 'picture'], callback); | 	user.getMultipleUserFields(uids, ['uid', 'userslug', 'username', 'picture'], callback); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | SocketCategories.getCategoriesByPrivilege = function(socket, privilege, callback) { | ||||||
|  | 	categories.getCategoriesByPrivilege(socket.uid, privilege, callback); | ||||||
|  | }; | ||||||
|  |  | ||||||
| module.exports = SocketCategories; | module.exports = SocketCategories; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user