Permalink
Browse files

use snippets and nette.ajax.js

  • Loading branch information...
chemix committed Jun 25, 2014
1 parent a1728c3 commit 151202a775d65adeccb6a8a991fc759545d935c7
Showing with 530 additions and 94 deletions.
  1. +6 −20 app/presenters/AdminPresenter.php
  2. +4 −2 app/templates/@layout.latte
  3. +35 −33 app/templates/Admin/default.latte
  4. +3 −39 www/js/main.js
  5. +482 −0 www/js/nette.ajax.js
@@ -25,33 +25,19 @@ public function renderDefault()
public function handleEnablePost($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 {
$this->flashMessage('Post enabled');
$this->redirect('default');
}
$this->flashMessage('Post enabled');
$this->redrawControl('flashes');
$this->redrawControl('wallposts');
}
}
public function handleDisablePost($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 {
$this->flashMessage('Post disabled');
$this->redirect('default');
}
$this->flashMessage('Post disabled');
$this->redrawControl('flashes');
$this->redrawControl('wallposts');
}
}
@@ -20,8 +20,9 @@
<body>
<script> document.documentElement.className+=' js' </script>
<div n:foreach="$flashes as $flash" class="flash {$flash->type}">{$flash->message}</div>
{snippet flashes}
<div n:foreach="$flashes as $flash" class="flash {$flash->type}">{$flash->message}</div>
{/snippet}
<div class="row">
<div class="column">
@@ -64,6 +65,7 @@
<script src="{$basePath}/js/jquery.js"></script>
<script src="{$basePath}/js/masonry.pkgd.min.js"></script>
<script src="{$basePath}/js/netteForms.js"></script>
<script src="{$basePath}/js/nette.ajax.js"></script>
<script src="{$basePath}/js/main.js"></script>
{/block}
</body>
@@ -3,40 +3,42 @@
<div class="row">
<div class="column">
{foreach $wallPosts as $post}
<div class="row">
<div class="large-2 columns small-3">
{if $post->picture}
<img src="{$post->picture}">
{/if}
{snippet wallposts}
{foreach $wallPosts as $post}
<div class="row">
<div class="large-2 columns small-3">
{if $post->picture}
<img src="{$post->picture}">
{/if}
</div>
<div class="large-10 columns">
{ifset $post->name}
<h3>{$post->name}</h3>
{/ifset}
{ifset $post->message}
<p>{$post->message} </p>
{/ifset}
<ul class="inline-list">
<li><strong>{$post->type}</strong></li>
{ifset $post->link}
<li><a href="{$post->link}">{$post->link}</a></li>
{/ifset}
<li><small>{$post->id}</small></li>
<li><small>{$post->created_time}</small></li>
<li n:if="$post->status"><a n:href="disablePost! $post->id" class="ajax button alert">disable</a></li>
<li n:if="!$post->status"><a n:href="enablePost! $post->id" class="ajax button">enable</a></li>
</ul>
</div>
</div>
<div class="large-10 columns">
{ifset $post->name}
<h3>{$post->name}</h3>
{/ifset}
{ifset $post->message}
<p>{$post->message} </p>
{/ifset}
<ul class="inline-list">
<li><strong>{$post->type}</strong></li>
{ifset $post->link}
<li><a href="{$post->link}">{$post->link}</a></li>
{/ifset}
<li><small>{$post->id}</small></li>
<li><small>{$post->created_time}</small></li>
<li n:class="disable, !$post->status ? hide"><a n:href="disablePost! $post->id" class="ajax button alert">disable</a></li>
<li n:class="enable, $post->status ? hide"><a n:href="enablePost! $post->id" class="ajax button">enable</a></li>
</ul>
</div>
</div>
<hr>
{/foreach}
<hr>
{/foreach}
{/snippet}
</div>
</div>
View
@@ -6,46 +6,10 @@
itemSelector: '.brick',
columnWidth: 320
});
});
var flashMessage = function(message)
{
$($('body')[0]).prepend($('<div class="flash info">'+message+'</div>'));
}
// 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 (payload) {
if (payload.action == 'disable' && payload.status == '1') {
// disabled
link.parent().parent().find('.disable').addClass('hide');
link.parent().parent().find('.enable').removeClass('hide');
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');
});
// Init Nette Ajax
$.nette.init();
});
})(jQuery);
Oops, something went wrong.

0 comments on commit 151202a

Please sign in to comment.