You are here

public function ForenaController::ajaxReport in Forena Reports 8

Ajax callback handler for ajax requests.

Parameters

String $report: Name of Report.

String $js_mode: Either nojs to imply disabled javascript or ajax to perform replacement.

string $command: Type of replacement that is to be performed.

string $id: ID to replace.

Return value

\Drupal\Core\Ajax\AjaxResponse|array

1 string reference to 'ForenaController::ajaxReport'
forena.routing.yml in ./forena.routing.yml
forena.routing.yml

File

src/Controller/ForenaController.php, line 67

Class

ForenaController

Namespace

Drupal\forena\Controller

Code

public function ajaxReport($report, $js_mode, $id = 'report', $command = 'html') {
  $report = $this
    ->report($report);
  if ($js_mode == 'ajax') {
    $reponse = new AjaxResponse();
    $commands = Frx::instance()
      ->getDocument()
      ->getAjaxCommands();
    if (isset($commands['pre'])) {
      foreach ($commands['pre'] as $cmd) {
        $reponse
          ->addCommand($cmd);
      }
    }
    switch ($command) {
      case 'after':
        $reponse
          ->addCommand(new AfterCommand("#{$id}", $report));
        break;
      case 'append':
        $reponse
          ->addCommand(new AppendCommand("#{$id}", $report));
        break;
      case 'modal':
        $reponse
          ->addCommand(new OpenModalDialogCommand($report['title'], $report));
        break;
      case 'before':
        $reponse
          ->addCommand(new BeforeCommand("#{$id}", $report));
        break;
      case 'html':
        $reponse
          ->addCommand(new HtmlCommand("#{$id}", $report));
        break;
      case 'replace':
        $reponse
          ->addCommand(new ReplaceCommand("#{$id}", $report));
        break;
    }
    if (isset($commands['post'])) {
      foreach ($commands['post'] as $cmd) {
        $reponse
          ->addCommand($cmd);
      }
    }
    return $reponse;
  }
  else {
    return $report;
  }
}