Created
October 7, 2014 07:38
-
-
Save morontt/476d097e377b6402dc34 to your computer and use it in GitHub Desktop.
Preview action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class QuestionController extends BaseController | |
| { | |
| /** | |
| * @param Request $request | |
| * @return JsonResponse | |
| */ | |
| public function saveSessionAction(Request $request) | |
| { | |
| $question = new Question(); | |
| $form = $this->createForm(new QuestionType(), $question); | |
| $form->submit($request); | |
| $result = false; | |
| if ($form->isValid()) { | |
| $questionArray = $question->toArray(); | |
| $this->getSession()->set('question', $questionArray); | |
| $result = true; | |
| } | |
| return new JsonResponse($result); | |
| } | |
| /** | |
| * @Template() | |
| * | |
| * @return array | |
| */ | |
| public function previewAction() | |
| { | |
| return [ | |
| 'question' => $this->getSession()->get('question'), | |
| ]; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(function () { | |
| var other_window = false; | |
| $('button.preview').click(function () { | |
| $.ajax({ | |
| url: 'path/to/question_save_session', | |
| data: $('form.question-form').serialize(), | |
| dataType: 'json', | |
| type: 'POST', | |
| success: function (data) { | |
| if (data) { | |
| if (other_window) { | |
| other_window.location.reload(true); | |
| } else { | |
| other_window = window.open('/path/to/question_preview'); | |
| } | |
| } | |
| } | |
| }); | |
| return false; | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment