f698da186a9694c8ce00317051a8b6913639c4fc
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Resources / Public / JavaScript / Backend / FormEditor / Mediator.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13
14 /**
15 * Module: TYPO3/CMS/Form/Backend/FormEditor/Mediator
16 */
17 define(['jquery',
18 'TYPO3/CMS/Form/Backend/FormEditor/Helper'
19 ], function($, Helper) {
20 'use strict';
21
22 return (function($, Helper) {
23
24 /**
25 * @private
26 *
27 * @var object
28 */
29 var _formEditorApp = null;
30
31 /**
32 * @private
33 *
34 * @var object
35 */
36 var _viewModel = null;
37
38 /* *************************************************************
39 * Private Methodes
40 * ************************************************************/
41
42 /**
43 * @private
44 *
45 * @return void
46 * @throws 1478268638
47 */
48 function _helperSetup() {
49 assert('function' === $.type(Helper.bootstrap),
50 'The view model helper does not implement the method "bootstrap"',
51 1478268638
52 );
53 Helper.bootstrap(getFormEditorApp());
54 };
55
56 /**
57 * @private
58 *
59 * @return object
60 */
61 function getFormEditorApp() {
62 return _formEditorApp;
63 };
64
65 /**
66 * @private
67 *
68 * @return object
69 */
70 function getViewModel() {
71 return _viewModel;
72 };
73
74 /**
75 * @private
76 *
77 * @return object
78 */
79 function getUtility() {
80 return getFormEditorApp().getUtility();
81 };
82
83 /**
84 * @private
85 *
86 * @param mixed test
87 * @param string message
88 * @param int messageCode
89 * @return void
90 */
91 function assert(test, message, messageCode) {
92 return getFormEditorApp().assert(test, message, messageCode);
93 };
94
95 /**
96 * @private
97 *
98 * @param object
99 * @return object
100 */
101 function getHelper(configuration) {
102 if (getUtility().isUndefinedOrNull(configuration)) {
103 return Helper.setConfiguration(getViewModel().getConfiguration());
104 }
105 return Helper.setConfiguration(configuration);
106 };
107
108 /**
109 * @private
110 *
111 * @return object
112 */
113 function getCurrentlySelectedFormElement() {
114 return getFormEditorApp().getCurrentlySelectedFormElement();
115 };
116
117 /**
118 * @private
119 *
120 * @return object
121 */
122 function getPublisherSubscriber() {
123 return getFormEditorApp().getPublisherSubscriber();
124 };
125
126 /**
127 * @private
128 *
129 * @return object
130 */
131 function getRootFormElement() {
132 return getFormEditorApp().getRootFormElement();
133 };
134
135 /**
136 * @private
137 *
138 * @return void
139 */
140 function _subscribeEvents() {
141
142 /* *********************************************************
143 * Misc
144 * ********************************************************/
145
146 /**
147 * @private
148 *
149 * @return string
150 */
151 window.onbeforeunload = function(e) {
152 if (!getFormEditorApp().getUnsavedContent()) {
153 return;
154 }
155 e = e || window.event;
156 if (e) {
157 e.returnValue = getFormEditorApp().getFormElementDefinition(getRootFormElement(), 'modalCloseDialogMessage');
158 }
159 return getFormEditorApp().getFormElementDefinition(getRootFormElement(), 'modalCloseDialogTitle');
160 };
161
162 /**
163 * @private
164 *
165 * @param string
166 * @param array
167 * @return void
168 * @subscribe view/ready
169 */
170 getPublisherSubscriber().subscribe('view/ready', function(topic, args) {
171 getViewModel().onViewReadyBatch();
172 });
173
174 /**
175 * @private
176 *
177 * @param string
178 * @param array
179 * args[0] = applicationState
180 * args[1] = stackPointer
181 * args[2] = stackSize
182 * @return void
183 * @subscribe core/applicationState/add
184 */
185 getPublisherSubscriber().subscribe('core/applicationState/add', function(topic, args) {
186 getViewModel().disableButton($(getHelper().getDomElementDataIdentifierSelector('buttonHeaderRedo')));
187 if (args[2] > 1 && args[1] <= args[2]) {
188 getViewModel().enableButton($(getHelper().getDomElementDataIdentifierSelector('buttonHeaderUndo')));
189 } else {
190 getViewModel().disableButton($(getHelper().getDomElementDataIdentifierSelector('buttonHeaderUndo')));
191 }
192 });
193
194 /* *********************************************************
195 * Ajax
196 * ********************************************************/
197
198 /**
199 * @private
200 *
201 * @param string
202 * @param array
203 * args[0] = html
204 * @return void
205 * @subscribe core/ajax/saveFormDefinition/success
206 */
207 getPublisherSubscriber().subscribe('core/ajax/saveFormDefinition/success', function(topic, args) {
208 getFormEditorApp().setUnsavedContent(false);
209 getViewModel().showSaveSuccessMessage();
210 });
211
212 /**
213 * @private
214 *
215 * @param string
216 * @param array
217 * args[0] = object
218 * @return void
219 * @subscribe core/ajax/saveFormDefinition/error
220 */
221 getPublisherSubscriber().subscribe('core/ajax/saveFormDefinition/error', function(topic, args) {
222 getViewModel().showSaveErrorMessage(args[0]);
223 });
224
225 /**
226 * @private
227 *
228 * @param string
229 * @param array
230 * args[0] = html
231 * args[1] = pageIndex
232 * @return void
233 * @subscribe core/ajax/renderFormDefinitionPage/success
234 */
235 getPublisherSubscriber().subscribe('core/ajax/renderFormDefinitionPage/success', function(topic, args) {
236 getViewModel().renderPreviewStageArea(args[0]);
237 });
238
239 /**
240 * @private
241 *
242 * @param string
243 * @param array
244 * args[0] = jqXHR
245 * args[1] = textStatus
246 * args[2] = errorThrown
247 * @return void
248 * @subscribe core/ajax/saveFormDefinition/error
249 */
250 getPublisherSubscriber().subscribe('core/ajax/error', function(topic, args) {
251 if (args[0].status !== 0) {
252 getViewModel().showErrorFlashMessage(args[1], args[2]);
253 getViewModel().renderPreviewStageArea(args[0].responseText);
254 }
255 });
256
257 /**
258 * @private
259 *
260 * @param string
261 * @param array
262 * @return void
263 * @subscribe ajax/beforeSend
264 */
265 getPublisherSubscriber().subscribe('ajax/beforeSend', function(topic, args) {
266 getViewModel().showSaveButtonSpinnerIcon();
267 });
268
269 /**
270 * @private
271 *
272 * @param string
273 * @param array
274 * @return void
275 * @subscribe ajax/complete
276 */
277 getPublisherSubscriber().subscribe('ajax/complete', function(topic, args) {
278 getViewModel().showSaveButtonSaveIcon();
279 });
280
281 /* *********************************************************
282 * Header
283 * ********************************************************/
284
285 /**
286 * @private
287 *
288 * @param string
289 * @param array
290 * @return void
291 * @subscribe view/header/button/save/clicked
292 */
293 getPublisherSubscriber().subscribe('view/header/button/save/clicked', function(topic, args) {
294 if (getFormEditorApp().validationResultsHasErrors(getFormEditorApp().validateFormElementRecursive(getRootFormElement(), true))) {
295 getViewModel().showValidationErrorsModal();
296 } else {
297 getFormEditorApp().saveFormDefinition();
298 }
299 });
300
301 /**
302 * @private
303 *
304 * @param string
305 * @param array
306 * @return void
307 * @subscribe view/header/formSettings/clicked
308 */
309 getPublisherSubscriber().subscribe('view/header/formSettings/clicked', function(topic, args) {
310 getViewModel().addStructureRootElementSelection();
311 getFormEditorApp().setCurrentlySelectedFormElement(getRootFormElement());
312 getViewModel().renderAbstractStageArea();
313 getViewModel().renewStructure();
314 getViewModel().renderPagination();
315 getViewModel().renderInspectorEditors();
316 });
317
318 /**
319 * @private
320 *
321 * @param string
322 * @param array
323 * args[0] = targetEvent
324 * @return void
325 * @subscribe view/header/button/newPage/clicked
326 */
327 getPublisherSubscriber().subscribe('view/header/button/newPage/clicked', function(topic, args) {
328 if (getFormEditorApp().isRootFormElementSelected()) {
329 getViewModel().selectPageBatch(0);
330 }
331 getViewModel().showInsertPagesModal(args[0]);
332 });
333
334 /**
335 * @private
336 *
337 * @param string
338 * @param array
339 * @return void
340 * @subscribe view/header/button/close/clicked
341 */
342 getPublisherSubscriber().subscribe('view/header/button/close/clicked', function(topic, args) {
343 getViewModel().showCloseConfirmationModal();
344 });
345
346 /**
347 * @private
348 *
349 * @param string
350 * @param array
351 * @return void
352 * @subscribe view/undoButton/clicked
353 */
354 getPublisherSubscriber().subscribe('view/undoButton/clicked', function(topic, args) {
355 getViewModel().disableButton($(getHelper().getDomElementDataIdentifierSelector('buttonHeaderUndo')));
356 getViewModel().disableButton($(getHelper().getDomElementDataIdentifierSelector('buttonHeaderRedo')));
357 getFormEditorApp().undoApplicationState();
358
359 if (getViewModel().getPreviewMode()) {
360 getFormEditorApp().renderCurrentFormPage();
361 } else {
362 getViewModel().renderAbstractStageArea();
363 }
364 getFormEditorApp().setUnsavedContent(true);
365
366 getViewModel().renewStructure();
367 getViewModel().renderPagination();
368 getViewModel().renderInspectorEditors();
369 });
370
371 /**
372 * @private
373 *
374 * @param string
375 * @param array
376 * @return void
377 * @subscribe view/redoButton/clicked
378 */
379 getPublisherSubscriber().subscribe('view/redoButton/clicked', function(topic, args) {
380 getViewModel().disableButton($(getHelper().getDomElementDataIdentifierSelector('buttonHeaderUndo')));
381 getViewModel().disableButton($(getHelper().getDomElementDataIdentifierSelector('buttonHeaderRedo')));
382 getFormEditorApp().redoApplicationState();
383
384 if (getViewModel().getPreviewMode()) {
385 getFormEditorApp().renderCurrentFormPage();
386 } else {
387 getViewModel().renderAbstractStageArea();
388 }
389 getFormEditorApp().setUnsavedContent(true);
390
391 getViewModel().renewStructure();
392 getViewModel().renderPagination();
393 getViewModel().renderInspectorEditors();
394 });
395
396 /* *********************************************************
397 * Stage
398 * ********************************************************/
399
400 /**
401 * @private
402 *
403 * @param string
404 * @param array
405 * args[0] = formElementIdentifierPath
406 * @return void
407 * @subscribe view/stage/element/clicked
408 */
409 getPublisherSubscriber().subscribe('view/stage/element/clicked', function(topic, args) {
410 if (getCurrentlySelectedFormElement().get('__identifierPath') !== args[0]) {
411 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
412 getViewModel().renewStructure();
413 getViewModel().refreshSelectedElementItemsBatch();
414 getViewModel().addAbstractViewValidationResults();
415 getViewModel().renderInspectorEditors();
416 }
417 });
418
419 /**
420 * @private
421 *
422 * @param string
423 * @param array
424 * args[0] = targetEvent
425 * args[1] = configuration
426 * @return void
427 * @subscribe view/stage/abstract/elementToolbar/button/newElement/clicked
428 */
429 getPublisherSubscriber().subscribe('view/stage/abstract/elementToolbar/button/newElement/clicked', function(topic, args) {
430 if (getFormEditorApp().isRootFormElementSelected()) {
431 getViewModel().selectPageBatch(0);
432 }
433 getViewModel().showInsertElementsModal(args[0], args[1]);
434 });
435
436 /**
437 * @private
438 *
439 * @param string
440 * @param array
441 * args[0] = targetEvent
442 * args[1] = configuration
443 * @return void
444 * @subscribe view/newElementButton/clicked
445 */
446 getPublisherSubscriber().subscribe('view/stage/abstract/button/newElement/clicked', function(topic, args) {
447 if (getFormEditorApp().isRootFormElementSelected()) {
448 getViewModel().selectPageBatch(0);
449 }
450 getViewModel().showInsertElementsModal(args[0], args[1]);
451 });
452
453 /**
454 * @private
455 *
456 * @param string
457 * @param array
458 * args[0] = draggedFormElementDomElement
459 * args[1] = draggedFormPlaceholderDomElement
460 * @return void
461 * @subscribe view/stage/abstract/dnd/start
462 */
463 getPublisherSubscriber().subscribe('view/stage/abstract/dnd/start', function(topic, args) {
464 getViewModel().onAbstractViewDndStartBatch(args[0], args[1]);
465 });
466
467 /**
468 * @private
469 *
470 * @param string
471 * @param array
472 * args[0] = draggedFormElementIdentifierPath
473 * @return void
474 * @subscribe view/stage/abstract/dnd/stop
475 */
476 getPublisherSubscriber().subscribe('view/stage/abstract/dnd/stop', function(topic, args) {
477 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
478 getViewModel().renewStructure();
479 getViewModel().renderAbstractStageArea(false, false);
480 getViewModel().refreshSelectedElementItemsBatch();
481 getViewModel().addAbstractViewValidationResults();
482 getViewModel().renderInspectorEditors();
483 });
484
485 /**
486 * @private
487 *
488 * @param string
489 * @param array
490 * args[0] = placeholderDomElement
491 * args[1] = parentFormElementIdentifierPath
492 * args[2] = enclosingCompositeFormElement
493 * @return void
494 * @subscribe view/stage/abstract/dnd/change
495 */
496 getPublisherSubscriber().subscribe('view/stage/abstract/dnd/change', function(topic, args) {
497 getViewModel().onAbstractViewDndChangeBatch(args[0], args[1], args[2]);
498 });
499
500 /**
501 * @private
502 *
503 * @param string
504 * @param array
505 * args[0] = movedDomElement
506 * args[1] = movedFormElementIdentifierPath
507 * args[2] = previousFormElementIdentifierPath
508 * args[3] = nextFormElementIdentifierPath
509 * @return void
510 * @subscribe view/stage/abstract/dnd/update
511 */
512 getPublisherSubscriber().subscribe('view/stage/abstract/dnd/update', function(topic, args) {
513 getViewModel().onAbstractViewDndUpdateBatch(args[0], args[1], args[2], args[3]);
514 });
515
516 /**
517 * @private
518 *
519 * @param string
520 * @param array
521 * @return void
522 * @subscribe view/viewModeButton/abstract/clicked
523 */
524 getPublisherSubscriber().subscribe('view/viewModeButton/abstract/clicked', function(topic, args) {
525 if (getViewModel().getPreviewMode()) {
526 getViewModel().setPreviewMode(false);
527 getViewModel().renderAbstractStageArea();
528 }
529 });
530
531 /**
532 * @private
533 *
534 * @param string
535 * @param array
536 * @return void
537 * @subscribe view/viewModeButton/preview/clicked
538 */
539 getPublisherSubscriber().subscribe('view/viewModeButton/preview/clicked', function(topic, args) {
540 if (!getViewModel().getPreviewMode()) {
541 getViewModel().setPreviewMode(true);
542 getFormEditorApp().renderCurrentFormPage();
543 }
544 });
545
546 /**
547 * @private
548 *
549 * @param string
550 * @param array
551 * @return void
552 * @subscribe view/paginationPrevious/clicked
553 */
554 getPublisherSubscriber().subscribe('view/paginationPrevious/clicked', function(topic, args) {
555 getViewModel().selectPageBatch(getFormEditorApp().getCurrentlySelectedPageIndex() - 1);
556 if (getViewModel().getPreviewMode()) {
557 getFormEditorApp().renderCurrentFormPage();
558 } else {
559 getViewModel().renderAbstractStageArea();
560 }
561 });
562
563 /**
564 * @private
565 *
566 * @param string
567 * @param array
568 * @return void
569 * @subscribe view/paginationNext/clicked
570 */
571 getPublisherSubscriber().subscribe('view/paginationNext/clicked', function(topic, args) {
572 getViewModel().selectPageBatch(getFormEditorApp().getCurrentlySelectedPageIndex() + 1);
573 if (getViewModel().getPreviewMode()) {
574 getFormEditorApp().renderCurrentFormPage();
575 } else {
576 getViewModel().renderAbstractStageArea();
577 }
578 });
579
580 /**
581 * @private
582 *
583 * @param string
584 * @param array
585 * @return void
586 * @subscribe view/stage/abstract/render/postProcess
587 */
588 getPublisherSubscriber().subscribe('view/stage/abstract/render/postProcess', function(topic, args) {
589 getViewModel().renderUndoRedo();
590 });
591
592 /**
593 * @private
594 *
595 * @param string
596 * @param array
597 * @return void
598 * @subscribe view/stage/preview/render/postProcess
599 */
600 getPublisherSubscriber().subscribe('view/stage/preview/render/postProcess', function(topic, args) {
601 getViewModel().renderUndoRedo();
602 });
603
604 /* *********************************************************
605 * Structure
606 * ********************************************************/
607
608 /**
609 * @private
610 *
611 * @param string
612 * @param array
613 * args[0] = formElementIdentifierPath
614 * @return void
615 * @subscribe view/tree/node/clicked
616 */
617 getPublisherSubscriber().subscribe('view/tree/node/clicked', function(topic, args) {
618 var oldPageIndex;
619 if (getCurrentlySelectedFormElement().get('__identifierPath') !== args[0]) {
620 oldPageIndex = getFormEditorApp().getCurrentlySelectedPageIndex();
621 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
622 if (oldPageIndex !== getFormEditorApp().getCurrentlySelectedPageIndex()) {
623 getViewModel().renderAbstractStageArea();
624 } else {
625 getViewModel().renderAbstractStageArea(false);
626 }
627 getViewModel().renderPagination();
628 getViewModel().renderInspectorEditors();
629 }
630 });
631
632 /**
633 * @private
634 *
635 * @param string
636 * @param array
637 * @return void
638 * @subscribe view/structure/root/selected
639 */
640 getPublisherSubscriber().subscribe('view/structure/root/selected', function(topic, args) {
641 if (!getFormEditorApp().isRootFormElementSelected()) {
642 getViewModel().addStructureRootElementSelection();
643 getFormEditorApp().setCurrentlySelectedFormElement(getRootFormElement());
644 getViewModel().renderAbstractStageArea();
645 getViewModel().renewStructure();
646 getViewModel().renderPagination();
647 getViewModel().renderInspectorEditors();
648 }
649 });
650
651 /**
652 * @private
653 *
654 * @param string
655 * @param array
656 * args[0] = targetEvent
657 * @return void
658 * @subscribe view/header/button/newPage/clicked
659 */
660 getPublisherSubscriber().subscribe('view/structure/button/newPage/clicked', function(topic, args) {
661 if (getFormEditorApp().isRootFormElementSelected()) {
662 getViewModel().selectPageBatch(0);
663 }
664 getViewModel().showInsertPagesModal(args[0]);
665 });
666
667 /**
668 * @private
669 *
670 * @param string
671 * @param array
672 * args[0] = draggedFormElementIdentifierPath
673 * @return void
674 * @subscribe view/tree/dnd/stop
675 */
676 getPublisherSubscriber().subscribe('view/tree/dnd/stop', function(topic, args) {
677 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
678 getViewModel().renewStructure();
679 getViewModel().renderPagination();
680 getViewModel().renderAbstractStageArea();
681 getViewModel().renderInspectorEditors();
682 });
683
684 /**
685 * @private
686 *
687 * @param string
688 * @param array
689 * args[0] = placeholderDomElement
690 * args[1] = parentFormElementIdentifierPath
691 * args[2] = enclosingCompositeFormElement
692 * @return void
693 * @subscribe view/tree/dnd/change
694 */
695 getPublisherSubscriber().subscribe('view/tree/dnd/change', function(topic, args) {
696 getViewModel().onStructureDndChangeBatch(args[0], args[1], args[2]);
697 });
698
699 /**
700 * @private
701 *
702 * @param string
703 * @param array
704 * args[0] = movedDomElement
705 * args[1] = movedFormElementIdentifierPath
706 * args[2] = previousFormElementIdentifierPath
707 * args[3] = nextFormElementIdentifierPath
708 * @return void
709 * @subscribe view/tree/dnd/update
710 */
711 getPublisherSubscriber().subscribe('view/tree/dnd/update', function(topic, args) {
712 getViewModel().onStructureDndUpdateBatch(args[0], args[1], args[2], args[3]);
713 });
714
715 /**
716 * @private
717 *
718 * @param string
719 * @param array
720 * @return void
721 * @subscribe view/structure/renew/postProcess
722 */
723 getPublisherSubscriber().subscribe('view/structure/renew/postProcess', function(topic, args) {
724 getViewModel().addStructureValidationResults();
725 });
726
727 /* *********************************************************
728 * Inspector
729 * ********************************************************/
730
731 /**
732 * @private
733 *
734 * @param string
735 * @param array
736 * args[0] = collectionElementIdentifier
737 * args[1] = collectionName
738 * args[2] = formElement
739 * @return void
740 * @subscribe view/inspector/removeCollectionElement/perform
741 */
742 getPublisherSubscriber().subscribe('view/inspector/removeCollectionElement/perform', function(topic, args) {
743 getViewModel().removePropertyCollectionElement(args[0], args[1], args[2]);
744 });
745
746 /**
747 * @private
748 *
749 * @param string
750 * @param array
751 * args[0] = collectionElementIdentifier
752 * args[1] = collectionName
753 * @return void
754 * @subscribe view/inspector/collectionElement/selected
755 */
756 getPublisherSubscriber().subscribe('view/inspector/collectionElement/new/selected', function(topic, args) {
757 getViewModel().createAndAddPropertyCollectionElement(args[0], args[1]);
758 });
759
760 /**
761 * @private
762 *
763 * @param string
764 * @param array
765 * args[0] = collectionElementIdentifier
766 * args[1] = collectionName
767 * @return void
768 * @subscribe view/inspector/collectionElement/selected
769 */
770 getPublisherSubscriber().subscribe('view/inspector/collectionElement/existing/selected', function(topic, args) {
771 getViewModel().renderInspectorCollectionElementEditors(args[1], args[0]);
772 });
773
774 /**
775 * @private
776 *
777 * @param string
778 * @param array
779 * args[0] = movedCollectionElementIdentifier
780 * args[1] = previousCollectionElementIdentifier
781 * args[2] = nextCollectionElementIdentifier
782 * args[3] = collectionName
783 * @return void
784 * @subscribe view/inspector/collectionElements/dnd/update
785 * @throws 1477407673
786 */
787 getPublisherSubscriber().subscribe('view/inspector/collectionElements/dnd/update', function(topic, args) {
788 if (args[2]) {
789 getViewModel().movePropertyCollectionElement(args[0], 'before', args[2], args[3]);
790 } else if (args[1]) {
791 getViewModel().movePropertyCollectionElement(args[0], 'after', args[1], args[3]);
792 } else {
793 assert(false, 'Next element or previous element need to be set.', 1477407673);
794 }
795 });
796
797 /* *********************************************************
798 * Form element
799 * ********************************************************/
800
801 /**
802 * @private
803 *
804 * @param string
805 * @param array
806 * args[0] = propertyPath
807 * args[1] = value
808 * args[2] = oldValue
809 * args[3] = formElementIdentifierPath
810 * @return void
811 * @subscribe core/formElement/somePropertyChanged
812 */
813 getPublisherSubscriber().subscribe('core/formElement/somePropertyChanged', function(topic, args) {
814 var hasError, validationElement, validationResults;
815
816 validationResults = [];
817 if ('renderables' !== args[0]) {
818 if (!getFormEditorApp().isRootFormElementSelected() && 'label' === args[0]) {
819 getViewModel().getStructure().setTreeNodeTitle();
820 getViewModel().setInspectorFormElementHeaderEditorContent();
821 } else if (!getFormEditorApp().getUtility().isUndefinedOrNull(args[3]) && getRootFormElement().get('__identifierPath') === args[3]) {
822 getViewModel().setStructureRootElementTitle();
823 getViewModel().setStageHeadline();
824 getViewModel().setInspectorFormElementHeaderEditorContent();
825 }
826
827 if (getViewModel().getPreviewMode()) {
828 getFormEditorApp().renderCurrentFormPage();
829 } else {
830 getViewModel().renderAbstractStageArea(false, false);
831 }
832 getViewModel().addStructureValidationResults();
833 }
834
835 getFormEditorApp().setUnsavedContent(true);
836 });
837
838 /**
839 * @private
840 *
841 * @param string
842 * @param array
843 * args[0] = parentFormElement
844 * @return void
845 * @subscribe view/formElement/removed
846 */
847 getPublisherSubscriber().subscribe('view/formElement/removed', function(topic, args) {
848 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
849 getViewModel().renewStructure();
850 getViewModel().renderAbstractStageArea();
851 getViewModel().renderPagination();
852 getViewModel().renderInspectorEditors();
853 });
854
855 /**
856 * @private
857 *
858 * @param string
859 * @param array
860 * args[0] = newFormElement
861 * @return void
862 * @subscribe view/formElement/inserted
863 */
864 getPublisherSubscriber().subscribe('view/formElement/inserted', function(topic, args) {
865 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
866 getViewModel().renewStructure();
867 getViewModel().renderAbstractStageArea();
868 getViewModel().renderPagination();
869 getViewModel().renderInspectorEditors();
870 });
871
872 /**
873 * @private
874 *
875 * @param string
876 * @param array
877 * args[0] = collectionElementIdentifier
878 * args[1] = collectionName
879 * args[2] = formElement
880 * args[3] = collectionElementConfiguration
881 * args[4] = referenceCollectionElementIdentifier
882 * @return void
883 * @subscribe view/collectionElement/new/added
884 */
885 getPublisherSubscriber().subscribe('view/collectionElement/new/added', function(topic, args) {
886 getViewModel().renderInspectorEditors();
887 });
888
889 /**
890 * @private
891 *
892 * @param string
893 * @param array
894 * args[0] = movedCollectionElementIdentifier
895 * args[1] = previousCollectionElementIdentifier
896 * args[2] = nextCollectionElementIdentifier
897 * args[3] = collectionName
898 * @return void
899 * @subscribe view/collectionElement/moved
900 * @throws 1477407673
901 */
902 getPublisherSubscriber().subscribe('view/collectionElement/moved', function(topic, args) {
903 getViewModel().renderInspectorEditors(undefined, false);
904 });
905
906 /**
907 * @private
908 *
909 * @param string
910 * @param array
911 * args[0] = collectionElementIdentifier
912 * args[1] = collectionName
913 * args[2] = formElement
914 * @return void
915 * @subscribe view/collectionElement/removed
916 */
917 getPublisherSubscriber().subscribe('view/collectionElement/removed', function(topic, args) {
918 getViewModel().renderInspectorEditors(undefined, false);
919 });
920
921 /**
922 * @private
923 *
924 * @param string
925 * @param array
926 * args[0] = formElementType
927 * @return void
928 * @subscribe view/insertElements/perform/bottom
929 */
930 getPublisherSubscriber().subscribe('view/insertElements/perform/bottom', function(topic, args) {
931 var lastRenderable;
932
933 lastRenderable = getFormEditorApp().getLastTopLevelElementOnCurrentPage();
934 if (!lastRenderable) {
935 getViewModel().createAndAddFormElement(args[0], getFormEditorApp().getCurrentlySelectedPage());
936 } else {
937 if (
938 !getFormEditorApp().getFormElementDefinition(lastRenderable, '_isTopLevelFormElement')
939 && getFormEditorApp().getFormElementDefinition(lastRenderable, '_isCompositeFormElement')
940 ) {
941 getViewModel().createAndAddFormElement(args[0], getFormEditorApp().getCurrentlySelectedPage());
942 } else {
943 getViewModel().createAndAddFormElement(args[0], lastRenderable);
944 }
945 }
946 });
947
948 /**
949 * @private
950 *
951 * @param string
952 * @param array
953 * args[0] = formElementType
954 * @return void
955 * @publish view/formElement/inserted
956 * @subscribe view/insertElements/perform/after
957 */
958 getPublisherSubscriber().subscribe('view/insertElements/perform/after', function(topic, args) {
959 var newFormElement;
960 newFormElement = getViewModel().createAndAddFormElement(args[0], undefined, true);
961 newFormElement = getViewModel().moveFormElement(newFormElement, 'after', getFormEditorApp().getCurrentlySelectedFormElement());
962 getPublisherSubscriber().publish('view/formElement/inserted', [newFormElement]);
963 });
964
965 /**
966 * @private
967 *
968 * @param string
969 * @param array
970 * args[0] = formElementType
971 * @return void
972 * @subscribe view/insertElements/perform/inside
973 */
974 getPublisherSubscriber().subscribe('view/insertElements/perform/inside', function(topic, args) {
975 getViewModel().createAndAddFormElement(args[0]);
976 });
977
978 /**
979 * @private
980 *
981 * @param string
982 * @param array
983 * args[0] = formElementType
984 * @return void
985 * @subscribe view/insertElements/perform/after
986 */
987 getPublisherSubscriber().subscribe('view/insertPages/perform', function(topic, args) {
988 getViewModel().createAndAddFormElement(args[0]);
989 });
990
991 /* *********************************************************
992 * Modals
993 * ********************************************************/
994
995 /**
996 * @private
997 *
998 * @param string
999 * @param array
1000 * @return void
1001 * @subscribe view/modal/close/perform
1002 */
1003 getPublisherSubscriber().subscribe('view/modal/close/perform', function(topic, args) {
1004 getFormEditorApp().setUnsavedContent(false);
1005 getViewModel().closeEditor();
1006 });
1007
1008 /**
1009 * @private
1010 *
1011 * @param string
1012 * @param array
1013 * args[0] = formElement
1014 * @return void
1015 * @subscribe view/modal/removeFormElement/perform
1016 */
1017 getPublisherSubscriber().subscribe('view/modal/removeFormElement/perform', function(topic, args) {
1018 getViewModel().removeFormElement(args[0]);
1019 });
1020
1021 /**
1022 * @private
1023 *
1024 * @param string
1025 * @param array
1026 * args[0] = collectionElementIdentifier
1027 * args[1] = collectionName
1028 * args[2] = formElement
1029 * @return void
1030 * @subscribe view/modal/removeCollectionElement/perform
1031 */
1032 getPublisherSubscriber().subscribe('view/modal/removeCollectionElement/perform', function(topic, args) {
1033 getViewModel().removePropertyCollectionElement(args[0], args[1], args[2]);
1034 });
1035
1036 /**
1037 * @private
1038 *
1039 * @param string
1040 * @param array
1041 * args[0] = formElementIdentifierPath
1042 * @return void
1043 * @subscribe view/modal/validationErrors/element/clicked
1044 */
1045 getPublisherSubscriber().subscribe('view/modal/validationErrors/element/clicked', function(topic, args) {
1046 var oldPageIndex;
1047 if (getCurrentlySelectedFormElement().get('__identifierPath') !== args[0]) {
1048 oldPageIndex = getFormEditorApp().getCurrentlySelectedPageIndex();
1049 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
1050
1051 if (getViewModel().getPreviewMode()) {
1052 getViewModel().setPreviewMode(false);
1053 }
1054
1055 if (oldPageIndex !== getFormEditorApp().getCurrentlySelectedPageIndex()) {
1056 getViewModel().renderAbstractStageArea();
1057 } else {
1058 getViewModel().renderAbstractStageArea(false);
1059 }
1060
1061 getViewModel().renderPagination();
1062 getViewModel().renderInspectorEditors();
1063 }
1064 });
1065 };
1066
1067 /**
1068 * @public
1069 *
1070 * @param object
1071 * @param object
1072 * @return void
1073 */
1074 function bootstrap(formEditorApp, viewModel) {
1075 _formEditorApp = formEditorApp;
1076 _viewModel = viewModel;
1077 _helperSetup();
1078 _subscribeEvents();
1079 };
1080
1081 /**
1082 * Implements the "Revealing Module Pattern".
1083 */
1084 return {
1085 /**
1086 * Publish the public methods.
1087 */
1088 bootstrap: bootstrap
1089 };
1090 })($, Helper);
1091 });