Finish of the new discussion post add

- flips to the page where the post was added
- scrolls to the last post
pull/762/head
Iglocska 2015-12-06 00:44:57 +01:00
parent d66d26d383
commit 1584ddfc48
3 changed files with 23 additions and 10 deletions

View File

@ -164,10 +164,11 @@ class PostsController extends AppController {
$thread = $this->Thread->read(null, $target_thread_id);
$this->Thread->updateAfterPostChange(true);
if (!$this->request->is('ajax')) $this->Session->setFlash(__('Post added'));
$this->Post->sendPostsEmailRouter($this->Auth->user('id'), $this->Post->getId(), $event_id, $title, $this->request->data['Post']['message']);
$post_id = $this->Post->getId();
$this->Post->sendPostsEmailRouter($this->Auth->user('id'), $post_id, $event_id, $title, $this->request->data['Post']['message']);
$pageNr = (count($thread['Post']) != 0 ? ceil((count($thread['Post']) / 10)) : 1);
if ($target_type == 'event') $this->view($target_id, 'event', $pageNr);
else $this->view($target_thread_id, 'thread', $pageNr);
if ($target_type == 'event') $this->view($target_id, 'event', $pageNr, $this->Post->id);
else $this->view($target_thread_id, 'thread', $pageNr, $post_id);
return true;
} else {
$this->Session->setFlash('The post could not be added.');
@ -248,14 +249,14 @@ class PostsController extends AppController {
// Views the proper context for the post
public function view($id, $context = 'thread', $pageNr = 1) {
public function view($id, $context = 'thread', $pageNr = 1, $post_id) {
// We don't know what the context was, so let's try to guess what the user wants to see!
// If the post belongs to an event's discussion thread, redirect the user to the event's view
if ($context == 'event') {
$this->redirect(array('controller' => 'threads', 'action' => 'view', $id, true, 'page:' . $pageNr));
$this->redirect(array('controller' => 'threads', 'action' => 'view', $id, true, 'page:' . $pageNr, 'post_id:' . $post_id));
} else {
//Otherwise send the user to the thread's index.
$this->redirect(array('controller' => 'threads', 'action' => 'view', $id, 'page:' . $pageNr));
$this->redirect(array('controller' => 'threads', 'action' => 'view', $id, false, 'page:' . $pageNr, 'post_id:' . $post_id));
}
return true;
}
@ -265,7 +266,6 @@ class PostsController extends AppController {
$this->Post->read();
return $this->Post->data;
}
}
?>

View File

@ -87,6 +87,8 @@ class ThreadsController extends AppController {
public function view($thread_id, $eventView = false) {
$post_id = false;
if (isset($this->passedArgs['post_id'])) $post_id = $this->passedArgs['post_id'];
if ($eventView) {
$id = $thread_id;
$this->loadModel('Event');
@ -183,13 +185,14 @@ class ThreadsController extends AppController {
}
}
$this->set('posts', $posts);
$this->set('post_id', $post_id);
$this->set('thread_id', $thread_id);
$this->set('myuserid', $this->Auth->user('id'));
$this->set('thread_title', $thread['Thread']['title']);
if ($this->request->is('ajax')) {
$this->layout = 'ajax';
$this->render('/Elements/eventdiscussion');
}
if ($eventView) $this->render('/Elements/eventdiscussion');
}
public function index() {

View File

@ -22,6 +22,7 @@
<?php
foreach ($posts as $post) {
?>
<a name="message_<?php echo h($post['Post']['id']);?>"></a>
<table class="discussionBox" id=<?php echo '"' . h($post['Post']['id']) . '"';?> >
<tr>
<td class="discussionBoxTD discussionBoxTDtop" colspan="2">
@ -128,7 +129,11 @@
</div>
<?php endif; ?>
<div class="comment">
<?php echo $this->Form->create('Post', array('url' => '/posts/add/event/' . $currentEvent));?>
<?php
if (isset($currentEvent)) $url = '/posts/add/event/' . $currentEvent;
else $url = '/posts/add/thread/' . $thread_id;
echo $this->Form->create('Post', array('url' => $url));
?>
<fieldset>
<div class="input clear">
<button type="button" title="Insert a quote - just paste your quote between the [quote][/quote] tags." class="toggle-left btn btn-inverse qet" id = "quote" onclick="insertQuote()">Quote</button>
@ -150,7 +155,7 @@
'success'=>$this->Js->get('#loading')->effect('fadeOut'),
'update'=>'#top',
'class'=>'btn btn-primary',
'url' => '/posts/add/event/' . $currentEvent
'url' => $url
));
echo $this->Form->end();
?>
@ -166,5 +171,10 @@
function insertThread() {
document.getElementById("PostMessage").value+="[Thread][/Thread]";
}
<?php if ($post_id): ?>
$(document).ready(function() {
location.hash = "#message_<?php echo h($post_id); ?>";
});
<?php endif; ?>
</script>
<?php echo $this->Js->writeBuffer();?>