public function onShowFlashMsg()
 {
     $msg = \Flash::all();
     if ($msg) {
         $res['msgs'] = $msg;
         if ($this->property('configuration')) {
             $data = FlashConfigur::find($this->property('configuration'))->toArray();
             $conf = $this->combineSettings($data);
             $res['options'] = $conf['options'];
             $res['settings'] = $conf['settings'];
         } else {
             $res['options'] = [];
             $res['settings'] = [];
         }
         return $res;
     }
 }
Example #2
0
 /**
  * @return \Symfony\Component\HttpFoundation\Response
  */
 protected function ajaxAction()
 {
     if ($this->request->header('X-Remote') && $this->request->wantsJson()) {
         try {
             $responseContents = [];
             $result = call_user_func_array([$this, $this->action], $this->params);
             $responseContents['success'] = true;
             if (is_array($result)) {
                 $responseContents = array_merge($responseContents, $result);
             } elseif (is_string($result)) {
                 $responseContents['result'] = $result;
             }
             if ($result instanceof RedirectResponse) {
                 $responseContents['REDIRECT'] = $result->getTargetUrl();
             } elseif (\Flash::check()) {
                 $types = ['success', 'info', 'error', 'warning'];
                 foreach (\Flash::all() as $type => $message) {
                 }
                 if (\Flash::get('success')) {
                     $responseContents['FLASH']['success'] = \Flash::first('success');
                 }
                 if (\Flash::get('info')) {
                     $responseContents['FLASH']['info'] = \Flash::first('info');
                 }
                 if (\Flash::get('error')) {
                     $responseContents['FLASH']['danger'] = \Flash::first('error');
                 }
                 if (\Flash::get('warning')) {
                     $responseContents['FLASH']['warning'] = \Flash::first('warning');
                 }
             }
             return response()->make()->setContent($responseContents);
         } catch (ValidationException $ex) {
             \Flash::error($ex->getMessage());
             $responseContents = [];
             $responseContents['success'] = false;
             $responseContents['FLASH']['danger'] = \Flash::first('error');
             $responseContents['ERROR_FIELDS'] = $ex->getFields();
             return response()->make()->setContent($responseContents);
         }
     }
 }