Permalink
Browse files

refactor handleDisable and handleEnable

  • Loading branch information...
chemix committed Jun 25, 2014
1 parent d4e73de commit 8cc54bf7e2898fffa6512ccb89be3ebd12ab722a
Showing with 14 additions and 22 deletions.
  1. +14 −22 app/presenters/AdminPresenter.php
@@ -24,41 +24,33 @@ public function renderDefault()
}
}
public function handleEnablePost($postId)
protected function afterTogglePostStatus($status, $postId, $message)
{
if ($this->wallposts->enablePost($postId)) {
if ($status) {
$this->template->wallPosts = $this->isAjax()
? array($this->wallposts->getOne($postId))
: $this->wallposts->getAllPosts();
$this->flashMessage('Post enabled');
$this->flashMessage($message);
$this->redrawControl('flashes');
$this->redrawControl('wallposts');
// F5 protection without JS
if (!$this->isAjax()){
$this->redirect('this');
}
}
// F5 protection without JS
if (!$this->isAjax()){
$this->redirect('this');
}
}
public function handleEnablePost($postId)
{
$status = $this->wallposts->enablePost($postId);
$this->afterTogglePostStatus($status, $postId, 'Post enabled');
}
public function handleDisablePost($postId)
{
if ($this->wallposts->disablePost($postId)) {
$this->template->wallPosts = $this->isAjax()
? array($this->wallposts->getOne($postId))
: $this->wallposts->getAllPosts();
$this->flashMessage('Post disabled');
$this->redrawControl('flashes');
$this->redrawControl('wallposts');
// F5 protection
if (!$this->isAjax()){
$this->redirect('this');
}
}
$status = $this->wallposts->disablePost($postId);
$this->afterTogglePostStatus($status, $postId, 'Post disabled');
}
}

0 comments on commit 8cc54bf

Please sign in to comment.