| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-28 13:02:13 -04:00
										 |  |  | /* globals define, app, translator, ajaxify, socket, bootbox */ | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-29 17:24:38 -04:00
										 |  |  | define('forum/topic/postTools', ['composer', 'share', 'navigator'], function(composer, share, navigator) { | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:47:53 -04:00
										 |  |  | 	var PostTools = {}, | 
					
						
							|  |  |  | 		topicName; | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	PostTools.init = function(tid, threadState) { | 
					
						
							| 
									
										
										
										
											2014-03-28 13:02:13 -04:00
										 |  |  | 		topicName = ajaxify.variables.get('topic_name'); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:47:53 -04:00
										 |  |  | 		addPostHandlers(tid, threadState); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-31 15:22:35 -04:00
										 |  |  | 		share.addShareHandlers(topicName); | 
					
						
							| 
									
										
										
										
											2014-05-03 20:56:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		addFavouriteHandler(); | 
					
						
							| 
									
										
										
										
											2014-03-19 15:47:53 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-03 20:56:26 -04:00
										 |  |  | 	PostTools.toggle = function(pid, isDeleted) { | 
					
						
							|  |  |  | 		var postEl = $('#post-container li[data-pid="' + pid + '"]'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		postEl.find('.quote, .favourite, .post_reply, .chat').toggleClass('none', isDeleted); | 
					
						
							| 
									
										
										
										
											2014-06-10 14:24:50 -04:00
										 |  |  | 		postEl.find('.purge').toggleClass('none', !isDeleted); | 
					
						
							| 
									
										
										
										
											2014-07-05 16:58:57 -04:00
										 |  |  | 		postEl.find('.delete .i').toggleClass('fa-trash-o', !isDeleted).toggleClass('fa-history', isDeleted); | 
					
						
							|  |  |  | 		postEl.find('.delete span').translateHtml(isDeleted ? ' [[topic:restore]]' : ' [[topic:delete]]'); | 
					
						
							| 
									
										
										
										
											2014-05-03 20:56:26 -04:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	PostTools.updatePostCount = function() { | 
					
						
							|  |  |  | 		socket.emit('topics.postcount', ajaxify.variables.get('topic_id'), function(err, postCount) { | 
					
						
							|  |  |  | 			if (!err) { | 
					
						
							|  |  |  | 				$('.topic-post-count').html(postCount); | 
					
						
							|  |  |  | 				navigator.setCount(postCount); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function addFavouriteHandler() { | 
					
						
							|  |  |  | 		$('#post-container').on('mouseenter', '.favourite-tooltip', function(e) { | 
					
						
							|  |  |  | 			if (!$(this).data('users-loaded')) { | 
					
						
							|  |  |  | 				$(this).data('users-loaded', "true"); | 
					
						
							|  |  |  | 				var pid = $(this).parents('.post-row').attr('data-pid'); | 
					
						
							|  |  |  | 				var el = $(this).attr('title', "Loading..."); | 
					
						
							|  |  |  | 				socket.emit('posts.getFavouritedUsers', pid, function(err, usernames) { | 
					
						
							|  |  |  | 					el.attr('title', usernames).tooltip('show'); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:47:53 -04:00
										 |  |  | 	function addPostHandlers(tid, threadState) { | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 		$('.topic').on('click', '.post_reply', function() { | 
					
						
							| 
									
										
										
										
											2014-06-10 16:56:55 -04:00
										 |  |  | 			if (!threadState.locked) { | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 				onReplyClicked($(this), tid, topicName); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-03-31 15:22:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:56:22 -04:00
										 |  |  | 		var postContainer = $('#post-container'); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:56:22 -04:00
										 |  |  | 		postContainer.on('click', '.quote', function() { | 
					
						
							| 
									
										
										
										
											2014-06-10 16:56:55 -04:00
										 |  |  | 			if (!threadState.locked) { | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 				onQuoteClicked($(this), tid, topicName); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:56:22 -04:00
										 |  |  | 		postContainer.on('click', '.favourite', function() { | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 			favouritePost($(this), getPid($(this))); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:56:22 -04:00
										 |  |  | 		postContainer.on('click', '.upvote', function() { | 
					
						
							| 
									
										
										
										
											2014-03-21 14:00:13 -04:00
										 |  |  | 			return toggleVote($(this), '.upvoted', 'posts.upvote'); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:56:22 -04:00
										 |  |  | 		postContainer.on('click', '.downvote', function() { | 
					
						
							| 
									
										
										
										
											2014-03-21 14:00:13 -04:00
										 |  |  | 			return toggleVote($(this), '.downvoted', 'posts.downvote'); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:56:22 -04:00
										 |  |  | 		postContainer.on('click', '.flag', function() { | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 			flagPost(getPid($(this))); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:56:22 -04:00
										 |  |  | 		postContainer.on('click', '.edit', function(e) { | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 			composer.editPost(getPid($(this))); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:56:22 -04:00
										 |  |  | 		postContainer.on('click', '.delete', function(e) { | 
					
						
							| 
									
										
										
										
											2014-03-19 15:04:56 -04:00
										 |  |  | 			deletePost($(this), tid); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-10 14:24:50 -04:00
										 |  |  | 		postContainer.on('click', '.purge', function(e) { | 
					
						
							|  |  |  | 			purgePost($(this), tid); | 
					
						
							| 
									
										
										
										
											2014-07-07 12:57:31 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-06-10 14:24:50 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:56:22 -04:00
										 |  |  | 		postContainer.on('click', '.move', function(e) { | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 			openMovePostModal($(this)); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:56:22 -04:00
										 |  |  | 		postContainer.on('click', '.chat', function(e) { | 
					
						
							|  |  |  | 			openChat($(this)); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-03-19 15:47:53 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 	function onReplyClicked(button, tid, topicName) { | 
					
						
							|  |  |  | 		var selectionText = '', | 
					
						
							|  |  |  | 			selection = window.getSelection ? window.getSelection() : document.selection.createRange(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ($(selection.baseNode).parents('.post-content').length > 0) { | 
					
						
							|  |  |  | 			var snippet = selection.toString(); | 
					
						
							| 
									
										
										
										
											2014-04-03 18:07:31 -04:00
										 |  |  | 			if (snippet.length) { | 
					
						
							|  |  |  | 				selectionText = '> ' + snippet.replace(/\n/g, '\n> ') + '\n\n'; | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-04 15:56:17 -04:00
										 |  |  | 		var username = getUserName(selectionText ? $(selection.baseNode) : button); | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-03 18:07:31 -04:00
										 |  |  | 		if (selectionText.length) { | 
					
						
							|  |  |  | 			composer.addQuote(tid, getPid(button), topicName, username, selectionText); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-04-04 15:56:17 -04:00
										 |  |  | 			composer.newReply(tid, getPid(button), topicName, username ? username + ' ' : ''); | 
					
						
							| 
									
										
										
										
											2014-04-03 18:07:31 -04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function onQuoteClicked(button, tid, topicName) { | 
					
						
							|  |  |  | 		var username = getUserName(button), | 
					
						
							|  |  |  | 			pid = getPid(button); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		socket.emit('posts.getRawPost', pid, function(err, post) { | 
					
						
							|  |  |  | 			if(err) { | 
					
						
							|  |  |  | 				return app.alertError(err.message); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			var quoted = ''; | 
					
						
							|  |  |  | 			if(post) { | 
					
						
							|  |  |  | 				quoted = '> ' + post.replace(/\n/g, '\n> ') + '\n\n'; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if($('.composer').length) { | 
					
						
							|  |  |  | 				composer.addQuote(tid, pid, topicName, username, quoted); | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2014-06-23 18:47:52 -04:00
										 |  |  | 				composer.newReply(tid, pid, topicName, '[[modules:composer.user_said, ' + username + ']]' + quoted); | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function favouritePost(button, pid) { | 
					
						
							|  |  |  | 		var method = button.attr('data-favourited') === 'false' ? 'posts.favourite' : 'posts.unfavourite'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		socket.emit(method, { | 
					
						
							|  |  |  | 			pid: pid, | 
					
						
							|  |  |  | 			room_id: app.currentRoom | 
					
						
							| 
									
										
										
										
											2014-04-09 20:55:49 -04:00
										 |  |  | 		}, function(err) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				app.alertError(err.message); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function toggleVote(button, className, method) { | 
					
						
							|  |  |  | 		var post = button.parents('.post-row'), | 
					
						
							|  |  |  | 			currentState = post.find(className).length; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		socket.emit(currentState ? 'posts.unvote' : method , { | 
					
						
							|  |  |  | 			pid: post.attr('data-pid'), | 
					
						
							|  |  |  | 			room_id: app.currentRoom | 
					
						
							| 
									
										
										
										
											2014-04-09 20:55:49 -04:00
										 |  |  | 		}, function(err) { | 
					
						
							|  |  |  | 			if (err) { | 
					
						
							|  |  |  | 				app.alertError(err.message); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 	function getPid(button) { | 
					
						
							|  |  |  | 		return button.parents('.post-row').attr('data-pid'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function getUserName(button) { | 
					
						
							|  |  |  | 		var username = '', | 
					
						
							|  |  |  | 			post = button.parents('li[data-pid]'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (post.length) { | 
					
						
							|  |  |  | 			username = '@' + post.attr('data-username').replace(/\s/g, '-'); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return username; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:04:56 -04:00
										 |  |  | 	function deletePost(button, tid) { | 
					
						
							|  |  |  | 		var pid = getPid(button), | 
					
						
							| 
									
										
										
										
											2014-06-10 14:24:50 -04:00
										 |  |  | 			postEl = $('#post-container li[data-pid="' + pid + '"]'), | 
					
						
							| 
									
										
										
										
											2014-03-19 15:04:56 -04:00
										 |  |  | 			action = !postEl.hasClass('deleted') ? 'delete' : 'restore'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-10 14:24:50 -04:00
										 |  |  | 		postAction(action, pid, tid); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function purgePost(button, tid) { | 
					
						
							|  |  |  | 		postAction('purge', getPid(button), tid); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function postAction(action, pid, tid) { | 
					
						
							| 
									
										
										
										
											2014-04-02 10:29:42 -04:00
										 |  |  | 		translator.translate('[[topic:post_' + action + '_confirm]]', function(msg) { | 
					
						
							|  |  |  | 			bootbox.confirm(msg, function(confirm) { | 
					
						
							| 
									
										
										
										
											2014-06-10 14:24:50 -04:00
										 |  |  | 				if (!confirm) { | 
					
						
							|  |  |  | 					return; | 
					
						
							| 
									
										
										
										
											2014-04-02 10:29:42 -04:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-06-10 14:24:50 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				socket.emit('posts.' + action, { | 
					
						
							|  |  |  | 					pid: pid, | 
					
						
							|  |  |  | 					tid: tid | 
					
						
							|  |  |  | 				}, function(err) { | 
					
						
							|  |  |  | 					if(err) { | 
					
						
							|  |  |  | 						app.alertError(err.message); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2014-04-02 10:29:42 -04:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2014-03-19 15:04:56 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 	function openMovePostModal(button) { | 
					
						
							|  |  |  | 		var moveModal = $('#move-post-modal'), | 
					
						
							|  |  |  | 			moveBtn = moveModal.find('#move_post_commit'), | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 			topicId = moveModal.find('#topicId'); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 		showMoveModal(); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		moveModal.find('.close,#move_post_cancel').on('click', function() { | 
					
						
							|  |  |  | 			moveModal.addClass('hide'); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		topicId.on('change', function() { | 
					
						
							|  |  |  | 			if(topicId.val().length) { | 
					
						
							|  |  |  | 				moveBtn.removeAttr('disabled'); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				moveBtn.attr('disabled', true); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		moveBtn.on('click', function() { | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 			movePost(button.parents('.post-row'), getPid(button), topicId.val()); | 
					
						
							| 
									
										
										
										
											2014-03-19 15:04:56 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:26:38 -04:00
										 |  |  | 	function showMoveModal() { | 
					
						
							|  |  |  | 		$('#move-post-modal').removeClass('hide') | 
					
						
							|  |  |  | 			.css("position", "fixed") | 
					
						
							|  |  |  | 			.css("left", Math.max(0, (($(window).width() - $($('#move-post-modal')).outerWidth()) / 2) + $(window).scrollLeft()) + "px") | 
					
						
							|  |  |  | 			.css("top", "0px") | 
					
						
							|  |  |  | 			.css("z-index", "2000"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:04:56 -04:00
										 |  |  | 	function movePost(post, pid, tid) { | 
					
						
							|  |  |  | 		socket.emit('topics.movePost', {pid: pid, tid: tid}, function(err) { | 
					
						
							|  |  |  | 			$('#move-post-modal').addClass('hide'); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:04:56 -04:00
										 |  |  | 			if(err) { | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 				$('#topicId').val(''); | 
					
						
							| 
									
										
										
										
											2014-03-19 15:04:56 -04:00
										 |  |  | 				return app.alertError(err.message); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:04:56 -04:00
										 |  |  | 			post.fadeOut(500, function() { | 
					
						
							|  |  |  | 				post.remove(); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2014-03-19 15:04:56 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			$('#topicId').val(''); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 17:01:27 -04:00
										 |  |  | 			app.alertSuccess('[[topic:post_moved]]'); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function flagPost(pid) { | 
					
						
							| 
									
										
										
										
											2014-04-02 08:18:28 -04:00
										 |  |  | 		translator.translate('[[topic:flag_confirm]]', function(message) { | 
					
						
							|  |  |  | 			bootbox.confirm(message, function(confirm) { | 
					
						
							|  |  |  | 				if (confirm) { | 
					
						
							|  |  |  | 					socket.emit('posts.flag', pid, function(err) { | 
					
						
							|  |  |  | 						if(err) { | 
					
						
							|  |  |  | 							return app.alertError(err.message); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2014-04-11 17:01:27 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 						app.alertSuccess('[[topic:flag_success]]'); | 
					
						
							| 
									
										
										
										
											2014-04-02 08:18:28 -04:00
										 |  |  | 					}); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2014-03-19 14:53:31 -04:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 15:56:22 -04:00
										 |  |  | 	function openChat(button) { | 
					
						
							|  |  |  | 		var post = button.parents('li.post-row'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		app.openChat(post.attr('data-username'), post.attr('data-uid')); | 
					
						
							|  |  |  | 		button.parents('.btn-group').find('.dropdown-toggle').click(); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-19 14:29:55 -04:00
										 |  |  | 	return PostTools; | 
					
						
							| 
									
										
										
										
											2014-04-10 20:31:57 +01:00
										 |  |  | }); |