Jak na výpis komentářů a jejich mazání pomocí Ajaxu?

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
Tirus91
Člen | 199
+
0
-

Projel jsem si v dokumentaci jak na ajax, ale moc jsem to asi nepobral.

Momentálně článek jako takový vypisuju takto

presenter

public function renderView($id, $title) {
  if (!$this->user->isAllowed('Story', 'view')) {
    $this->error($this->translator->translate('messages.error.sufficientPermissions'), \Nette\Http\IResponse::S403_FORBIDDEN);
  }
  $story = $this->story->fetchById($id);
  $story->loadTopic($this->topic->fetchById($story->article_topic_id));
  $comment = $this->comment->fetchAllByStoryId($story->id);
  $vp = new \VisualPaginator\VisualPaginator($this, 'commentsPaginator');
  $paginator = $vp->getPaginator();
  $paginator->itemsPerPage = $this->systemInformation->number_posts_view;
  $paginator->itemCount = $comment->count;
  $comment->values = $comment->values->fetchAll($paginator->offset, $paginator->itemsPerPage);
  $story->author = $this->adminUserManagerModel->getUserInformation($story->security_users_id);
  foreach ($comment->values as $row => $com) {
    $comment->values[$row]->author = $this->adminUserManagerModel->getUserInformation($com->user_id);
  }
  $story->loadComments($comment);
  $this->template->story = $story;
}

A komentář má jen toto html

 {snippet comments}
<div class="row" n:foreach="$story->comments->values as $comment">

        <div class="col-md-7">
            <div class="panel panel-info">
                <div class="panel-heading">
                    <p><a n:href=":Front:Account:Profile">{$comment->author->login}</a> napsal dne {$comment->created_at|date:'F j, Y H:i:s'}:</p>
                </div>
                <div class="panel-body">
                    <p>{$comment->content|striptags}</p>
                </div>
                {if $user->isAllowed('Comment','delete')}
                    <div class="panel-footer">
                        <p><a n:href="commentdelete! $comment->id,$story->id,$story->title" class="ajax btn btn-xs btn-danger">{_system.button.delete}</a></p>
                    </div>
                {/if}
            </div>
        </div>

    </div>
{/snippet}

Mazání jsem udělal následovně

if (!$this->user->isLoggedIn()) {
      $this->redirect(':Front:Sign:in', array('backlink' => $this->storeRequest()));
    }
    if (!$this->user->isAllowed('Comment', 'delete')) {
      $this->error($this->translator->translate('messages.error.sufficientPermissions'), \Nette\Http\IResponse::S403_FORBIDDEN);
    }
    $result = $this->comment->delete($commentId);
    if (!$result) {
      $this->flashMessage($this->translator->translate('article.error.deleteComment'), 'error');
    } else {
      $this->flashMessage($this->translator->translate('article.success.deleteComment'), 'success');
      if ($this->isAjax()) {
        $comment = $this->comment->fetchAllByStoryId($id);
        $vp = new \VisualPaginator\VisualPaginator($this, 'commentsPaginator');
        $paginator = $vp->getPaginator();
        $paginator->itemsPerPage = $this->systemInformation->number_posts_view;
        $paginator->itemCount = $comment->count;
        $comment->values = $comment->values->fetchAll($paginator->offset, $paginator->itemsPerPage);
        foreach ($comment->values as $row => $com) {
          $comment->values[$row]->author = $this->adminUserManagerModel->getUserInformation($com->user_id);
        }
        $this->template->comments = $comment;
        $this->invalidateControl('comments');
      }
    }
    if (!$this->isAjax()) {
      $this->redirect('Story:view#comments', $id, $title);
    }

Pochopil jsem, že tam musím zavěst snippety a vše dělat přes signály, ovšem asi jen moc nepobral zbytek. Mohl by mne jen někdo nakopnout nějakým směrem?

Neustále po kliknutí na button to není ajax request

Editoval Tirus91 (19. 4. 2014 18:07)

Tirus91
Člen | 199
+
0
-

Obdržený snippet se mi již překreslí, ovšem již se mi neodešle invalidovaný snippet z beforeRender v BasePresenteru

Také nevím kde mohu mít chybu, ale po odeslání ajax requestu mi již další linky nefungují pomocí ajaxu, ale pouze normálně skrze redirect

Editoval Tirus91 (19. 4. 2014 22:59)