Exemple #1
0
    /**
     * Registers the needed JavaScript.
     */
    public function registerClientScript()
    {
        $view = $this->getView();
        PNotifyAsset::register($view);
        $flashes = Json::encode(Yii::$app->session->getAllFlashes(true));
        $clientOptions = Json::encode($this->clientOptions);
        $js = <<<JS
            var flashes = {$flashes}, clientOptions = {$clientOptions};
            for (var key in flashes) {
                if (flashes[key]) {
                    if (flashes[key] instanceof Array) {
                        for (var i = 0; i < flashes[key].length; i++) {
                            new PNotify(\$.extend({}, clientOptions, {
                                type: key,
                                text: flashes[key][i],
                            }));
                        }
                    } else {
                        new PNotify(\$.extend({}, clientOptions, {
                            type: key,
                            text: flashes[key],
                        }));
                    }
                }
            }
JS;
        $view->registerJs($js);
    }
Exemple #2
0
 /**
  * Registers the needed JavaScript.
  */
 public function registerClientScript()
 {
     $view = $this->getView();
     PNotifyAsset::register($view);
 }