Permalink
Browse files

better payload status and javascript behaviour

  • Loading branch information...
chemix committed Jun 24, 2014
1 parent 5901b40 commit a13d6a0c37667278b0acfcd0a712683fb4afe0a0
Showing with 21 additions and 4 deletions.
  1. +4 −0 app/presenters/AdminPresenter.php
  2. +17 −4 www/js/main.js
@@ -27,6 +27,8 @@ public function actionEnablePost($postId)
if ($this->wallposts->enablePost($postId)) {
if ($this->isAjax()) {
$this->payload->message = 'Post enabled';
$this->payload->action = 'enable';
$this->payload->status = '1';
$this->sendPayload();
} else {
@@ -42,6 +44,8 @@ public function actionDisablePost($postId)
if ($this->wallposts->disablePost($postId)) {
if ($this->isAjax()) {
$this->payload->message = 'Post disabled';
$this->payload->action = 'disable';
$this->payload->status = '1';
$this->sendPayload();
} else {
View
@@ -1,13 +1,20 @@
(function ($, undefined) {
// When Ready
$(function() {
$(function () {
$('#wall').masonry({
itemSelector: '.brick',
columnWidth: 320
});
});
var flashMessage = function(message)
{
console.log(message)
console.log($('body')[0])
$($('body')[0]).prepend($('<div class="flash info">'+message+'</div>'));
}
// Ajax click in admin
$('body').on('click', 'a.ajax', function (event) {
@@ -23,14 +30,20 @@
link.css('cursor', 'wait');
link.addClass('disabled');
$.post(this.href, function (data) {
if (data.message == 'Post disabled') {
$.post(this.href, function (payload) {
if (payload.action == 'disable' && payload.status == '1') {
// disabled
link.parent().parent().find('.disable').addClass('hide');
link.parent().parent().find('.enable').removeClass('hide');
} else {
flashMessage(payload.message);
} else if (payload.action == 'enable' && payload.status == '1') {
// enabled
link.parent().parent().find('.disable').removeClass('hide');
link.parent().parent().find('.enable').addClass('hide');
flashMessage(payload.message);
} else {
// error ? refresh...
window.location.href = window.location.href + '?refresh=' + Date.now();
}
link.removeClass('disabled');
link.css('cursor', 'default');

0 comments on commit a13d6a0

Please sign in to comment.