Permalink
Browse files

ajax version of enable and disable post

  • Loading branch information...
chemix committed Jun 23, 2014
1 parent 8681a2f commit c9b5a8fce0a63c3e0c3f69e11b0549d860d871db
Showing with 56 additions and 11 deletions.
  1. +19 −6 app/presenters/AdminPresenter.php
  2. +4 −5 app/templates/Admin/default.latte
  3. +4 −0 www/css/screen.css
  4. +29 −0 www/js/main.js
@@ -24,18 +24,31 @@ public function renderDefault()
public function actionEnablePost($postId)
{
if ($this->wallposts->enablePost($postId)){
$this->flashMessage('Post enabled');
if ($this->wallposts->enablePost($postId)) {
if ($this->isAjax()) {
$this->payload->message = 'Post enabled';
$this->sendPayload();
} else {
$this->flashMessage('Post enabled');
$this->redirect('default');
}
}
$this->redirect('default');
}
public function actionDisablePost($postId)
{
if ($this->wallposts->disablePost($postId)){
$this->flashMessage('Post disabled');
if ($this->wallposts->disablePost($postId)) {
if ($this->isAjax()) {
$this->payload->message = 'Post disabled';
$this->sendPayload();
} else {
$this->flashMessage('Post disabled');
$this->redirect('default');
}
}
$this->redirect('default');
}
}
@@ -28,11 +28,10 @@
{/ifset}
<li><small>{$post->id}</small></li>
<li><small>{$post->created_time}</small></li>
{if $post->status == '1'}
<li><a n:href="Admin:disablePost $post->id" class="button alert">disable</a></li>
{else}
<li><a n:href="Admin:enablePost $post->id" class="button">enable</a></li>
{/if}
<li n:class="disable, !$post->status ? hide"><a n:href="Admin:disablePost $post->id" class="ajax button alert">disable</a></li>
<li n:class="enable, $post->status ? hide"><a n:href="Admin:enablePost $post->id" class="ajax button">enable</a></li>
</ul>
</div>
</div>
View
@@ -50,3 +50,7 @@ html.js .jshidden {
.brick-container {
width: 0 auto;
}
.hide {
display: none !important;
}
View
@@ -8,4 +8,33 @@
});
});
// Ajax click in admin
$('body').on('click', 'a.ajax', function (event) {
event.preventDefault();
event.stopImmediatePropagation();
var link = $(this);
if (link.hasClass('disabled')) {
return false;
}
link.css('cursor', 'wait');
link.addClass('disabled');
$.post(this.href, function (data) {
if (data.message == 'Post disabled') {
link.parent().parent().find('.disable').addClass('hide');
link.parent().parent().find('.enable').removeClass('hide');
} else {
// enabled
link.parent().parent().find('.disable').removeClass('hide');
link.parent().parent().find('.enable').addClass('hide');
}
link.removeClass('disabled');
link.css('cursor', 'default');
});
});
})(jQuery);

0 comments on commit c9b5a8f

Please sign in to comment.