summaryrefslogtreecommitdiff
path: root/src/web/_views/modal/new_post.php
blob: 50b9b847e76f1f3c977849ba8e082bffa8ea5333 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php /* Copyright (c) 2024 Freya Murphy */ ?>
<?php /* vi: syntax=php */ ?>
<?php
	$user = $this->main->user();
?>
<form id="new-post-form">
<div class="modal-content new-post-modal">
	<div class="row">
		<?php $this->view('template/pfp', array('user' => $user))?>
		<div class="col ml">
			<strong><?=$user['first_name'] . ' ' . $user['last_name']?></strong>
				<span class="dim"><?=lang('now')?></span>
		</div>
	</div>
	<textarea
		type="text"
		name="content"
		id="new-post-content"
		placeholder="<?=lang('action_new_post_text', sub: [$user['first_name']])?>"
	></textarea>
</div>
<div class="modal-footer">
		<?=ilang('action_submit',
			id: 'new-post-submit',
			class: 'btn btn-wide btn-submit',
			attrs: array('type' => 'submit'),
			button: TRUE
		)?>
</div>
</form>
<script>
	$('#new-post-form').submit(function(e) {
		e.preventDefault();
		let content = $('#new-post-content').val();
		let me = $(this);

		const getPost = function(data) {
			if (data) {
				$('#post-container').prepend(data);
			}
			me.closest('.modal-container').remove();
		}

		const onPost = function(data) {
			let id = data[0].id;
			$.get({
				url: '/_util/post/post?id=' + id,
				success: getPost
			});
		}

		$.ajax({
			url: '/api/post',
			method: 'POST',
			data: JSON.stringify({ content }),
			success: onPost
		});
	});
</script>