8d8b6fe77f5c4e0c6fee1ea266a1a8d30ee4b9b7
[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] = response
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 getFormEditorApp().setFormDefinition(args[0]['formDefinition']);
212
213 getViewModel().addStructureRootElementSelection();
214 getFormEditorApp().setCurrentlySelectedFormElement(getRootFormElement());
215 getViewModel().setStructureRootElementTitle();
216 getViewModel().setStageHeadline();
217 getViewModel().renderAbstractStageArea();
218 getViewModel().renewStructure();
219 getViewModel().renderPagination();
220 getViewModel().renderInspectorEditors();
221 });
222
223 /**
224 * @private
225 *
226 * @param string
227 * @param array
228 * args[0] = object
229 * @return void
230 * @subscribe core/ajax/saveFormDefinition/error
231 */
232 getPublisherSubscriber().subscribe('core/ajax/saveFormDefinition/error', function(topic, args) {
233 getViewModel().showSaveErrorMessage(args[0]);
234 });
235
236 /**
237 * @private
238 *
239 * @param string
240 * @param array
241 * args[0] = html
242 * args[1] = pageIndex
243 * @return void
244 * @subscribe core/ajax/renderFormDefinitionPage/success
245 */
246 getPublisherSubscriber().subscribe('core/ajax/renderFormDefinitionPage/success', function(topic, args) {
247 getViewModel().renderPreviewStageArea(args[0]);
248 });
249
250 /**
251 * @private
252 *
253 * @param string
254 * @param array
255 * args[0] = jqXHR
256 * args[1] = textStatus
257 * args[2] = errorThrown
258 * @return void
259 * @subscribe core/ajax/saveFormDefinition/error
260 */
261 getPublisherSubscriber().subscribe('core/ajax/error', function(topic, args) {
262 if (args[0].status !== 0) {
263 getViewModel().showErrorFlashMessage(args[1], args[2]);
264 getViewModel().renderPreviewStageArea(args[0].responseText);
265 }
266 });
267
268 /**
269 * @private
270 *
271 * @param string
272 * @param array
273 * @return void
274 * @subscribe ajax/beforeSend
275 */
276 getPublisherSubscriber().subscribe('ajax/beforeSend', function(topic, args) {
277 getViewModel().showSaveButtonSpinnerIcon();
278 });
279
280 /**
281 * @private
282 *
283 * @param string
284 * @param array
285 * @return void
286 * @subscribe ajax/complete
287 */
288 getPublisherSubscriber().subscribe('ajax/complete', function(topic, args) {
289 getViewModel().showSaveButtonSaveIcon();
290 });
291
292 /* *********************************************************
293 * Header
294 * ********************************************************/
295
296 /**
297 * @private
298 *
299 * @param string
300 * @param array
301 * @return void
302 * @subscribe view/header/button/save/clicked
303 */
304 getPublisherSubscriber().subscribe('view/header/button/save/clicked', function(topic, args) {
305 if (getFormEditorApp().validationResultsHasErrors(getFormEditorApp().validateFormElementRecursive(getRootFormElement(), true))) {
306 getViewModel().showValidationErrorsModal();
307 } else {
308 getFormEditorApp().saveFormDefinition();
309 }
310 });
311
312 /**
313 * @private
314 *
315 * @param string
316 * @param array
317 * @return void
318 * @subscribe view/header/formSettings/clicked
319 */
320 getPublisherSubscriber().subscribe('view/header/formSettings/clicked', function(topic, args) {
321 getViewModel().addStructureRootElementSelection();
322 getFormEditorApp().setCurrentlySelectedFormElement(getRootFormElement());
323 getViewModel().renderAbstractStageArea();
324 getViewModel().renewStructure();
325 getViewModel().renderPagination();
326 getViewModel().renderInspectorEditors();
327 });
328
329 /**
330 * @private
331 *
332 * @param string
333 * @param array
334 * args[0] = targetEvent
335 * @return void
336 * @subscribe view/header/button/newPage/clicked
337 */
338 getPublisherSubscriber().subscribe('view/header/button/newPage/clicked', function(topic, args) {
339 if (getFormEditorApp().isRootFormElementSelected()) {
340 getViewModel().selectPageBatch(0);
341 }
342 getViewModel().showInsertPagesModal(args[0]);
343 });
344
345 /**
346 * @private
347 *
348 * @param string
349 * @param array
350 * @return void
351 * @subscribe view/header/button/close/clicked
352 */
353 getPublisherSubscriber().subscribe('view/header/button/close/clicked', function(topic, args) {
354 getViewModel().showCloseConfirmationModal();
355 });
356
357 /**
358 * @private
359 *
360 * @param string
361 * @param array
362 * @return void
363 * @subscribe view/undoButton/clicked
364 */
365 getPublisherSubscriber().subscribe('view/undoButton/clicked', function(topic, args) {
366 getViewModel().disableButton($(getHelper().getDomElementDataIdentifierSelector('buttonHeaderUndo')));
367 getViewModel().disableButton($(getHelper().getDomElementDataIdentifierSelector('buttonHeaderRedo')));
368 getFormEditorApp().undoApplicationState();
369
370 if (getViewModel().getPreviewMode()) {
371 getFormEditorApp().renderCurrentFormPage();
372 } else {
373 getViewModel().renderAbstractStageArea();
374 }
375 getFormEditorApp().setUnsavedContent(true);
376
377 getViewModel().renewStructure();
378 getViewModel().renderPagination();
379 getViewModel().renderInspectorEditors();
380 });
381
382 /**
383 * @private
384 *
385 * @param string
386 * @param array
387 * @return void
388 * @subscribe view/redoButton/clicked
389 */
390 getPublisherSubscriber().subscribe('view/redoButton/clicked', function(topic, args) {
391 getViewModel().disableButton($(getHelper().getDomElementDataIdentifierSelector('buttonHeaderUndo')));
392 getViewModel().disableButton($(getHelper().getDomElementDataIdentifierSelector('buttonHeaderRedo')));
393 getFormEditorApp().redoApplicationState();
394
395 if (getViewModel().getPreviewMode()) {
396 getFormEditorApp().renderCurrentFormPage();
397 } else {
398 getViewModel().renderAbstractStageArea();
399 }
400 getFormEditorApp().setUnsavedContent(true);
401
402 getViewModel().renewStructure();
403 getViewModel().renderPagination();
404 getViewModel().renderInspectorEditors();
405 });
406
407 /* *********************************************************
408 * Stage
409 * ********************************************************/
410
411 /**
412 * @private
413 *
414 * @param string
415 * @param array
416 * args[0] = formElementIdentifierPath
417 * @return void
418 * @subscribe view/stage/element/clicked
419 */
420 getPublisherSubscriber().subscribe('view/stage/element/clicked', function(topic, args) {
421 if (getCurrentlySelectedFormElement().get('__identifierPath') !== args[0]) {
422 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
423 getViewModel().renewStructure();
424 getViewModel().refreshSelectedElementItemsBatch();
425 getViewModel().addAbstractViewValidationResults();
426 getViewModel().renderInspectorEditors();
427 }
428 });
429
430 /**
431 * @private
432 *
433 * @param string
434 * @param array
435 * args[0] = targetEvent
436 * args[1] = configuration
437 * @return void
438 * @subscribe view/stage/abstract/elementToolbar/button/newElement/clicked
439 */
440 getPublisherSubscriber().subscribe('view/stage/abstract/elementToolbar/button/newElement/clicked', function(topic, args) {
441 if (getFormEditorApp().isRootFormElementSelected()) {
442 getViewModel().selectPageBatch(0);
443 }
444 getViewModel().showInsertElementsModal(args[0], args[1]);
445 });
446
447 /**
448 * @private
449 *
450 * @param string
451 * @param array
452 * args[0] = targetEvent
453 * args[1] = configuration
454 * @return void
455 * @subscribe view/newElementButton/clicked
456 */
457 getPublisherSubscriber().subscribe('view/stage/abstract/button/newElement/clicked', function(topic, args) {
458 if (getFormEditorApp().isRootFormElementSelected()) {
459 getViewModel().selectPageBatch(0);
460 }
461 getViewModel().showInsertElementsModal(args[0], args[1]);
462 });
463
464 /**
465 * @private
466 *
467 * @param string
468 * @param array
469 * args[0] = draggedFormElementDomElement
470 * args[1] = draggedFormPlaceholderDomElement
471 * @return void
472 * @subscribe view/stage/abstract/dnd/start
473 */
474 getPublisherSubscriber().subscribe('view/stage/abstract/dnd/start', function(topic, args) {
475 getViewModel().onAbstractViewDndStartBatch(args[0], args[1]);
476 });
477
478 /**
479 * @private
480 *
481 * @param string
482 * @param array
483 * args[0] = draggedFormElementIdentifierPath
484 * @return void
485 * @subscribe view/stage/abstract/dnd/stop
486 */
487 getPublisherSubscriber().subscribe('view/stage/abstract/dnd/stop', function(topic, args) {
488 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
489 getViewModel().renewStructure();
490 getViewModel().renderAbstractStageArea(false, false);
491 getViewModel().refreshSelectedElementItemsBatch();
492 getViewModel().addAbstractViewValidationResults();
493 getViewModel().renderInspectorEditors();
494 });
495
496 /**
497 * @private
498 *
499 * @param string
500 * @param array
501 * args[0] = placeholderDomElement
502 * args[1] = parentFormElementIdentifierPath
503 * args[2] = enclosingCompositeFormElement
504 * @return void
505 * @subscribe view/stage/abstract/dnd/change
506 */
507 getPublisherSubscriber().subscribe('view/stage/abstract/dnd/change', function(topic, args) {
508 getViewModel().onAbstractViewDndChangeBatch(args[0], args[1], args[2]);
509 });
510
511 /**
512 * @private
513 *
514 * @param string
515 * @param array
516 * args[0] = movedDomElement
517 * args[1] = movedFormElementIdentifierPath
518 * args[2] = previousFormElementIdentifierPath
519 * args[3] = nextFormElementIdentifierPath
520 * @return void
521 * @subscribe view/stage/abstract/dnd/update
522 */
523 getPublisherSubscriber().subscribe('view/stage/abstract/dnd/update', function(topic, args) {
524 getViewModel().onAbstractViewDndUpdateBatch(args[0], args[1], args[2], args[3]);
525 });
526
527 /**
528 * @private
529 *
530 * @param string
531 * @param array
532 * @return void
533 * @subscribe view/viewModeButton/abstract/clicked
534 */
535 getPublisherSubscriber().subscribe('view/viewModeButton/abstract/clicked', function(topic, args) {
536 if (getViewModel().getPreviewMode()) {
537 getViewModel().setPreviewMode(false);
538 getViewModel().renderAbstractStageArea();
539 }
540 });
541
542 /**
543 * @private
544 *
545 * @param string
546 * @param array
547 * @return void
548 * @subscribe view/viewModeButton/preview/clicked
549 */
550 getPublisherSubscriber().subscribe('view/viewModeButton/preview/clicked', function(topic, args) {
551 if (!getViewModel().getPreviewMode()) {
552 getViewModel().setPreviewMode(true);
553 getFormEditorApp().renderCurrentFormPage();
554 }
555 });
556
557 /**
558 * @private
559 *
560 * @param string
561 * @param array
562 * @return void
563 * @subscribe view/paginationPrevious/clicked
564 */
565 getPublisherSubscriber().subscribe('view/paginationPrevious/clicked', function(topic, args) {
566 getViewModel().selectPageBatch(getFormEditorApp().getCurrentlySelectedPageIndex() - 1);
567 if (getViewModel().getPreviewMode()) {
568 getFormEditorApp().renderCurrentFormPage();
569 } else {
570 getViewModel().renderAbstractStageArea();
571 }
572 });
573
574 /**
575 * @private
576 *
577 * @param string
578 * @param array
579 * @return void
580 * @subscribe view/paginationNext/clicked
581 */
582 getPublisherSubscriber().subscribe('view/paginationNext/clicked', function(topic, args) {
583 getViewModel().selectPageBatch(getFormEditorApp().getCurrentlySelectedPageIndex() + 1);
584 if (getViewModel().getPreviewMode()) {
585 getFormEditorApp().renderCurrentFormPage();
586 } else {
587 getViewModel().renderAbstractStageArea();
588 }
589 });
590
591 /**
592 * @private
593 *
594 * @param string
595 * @param array
596 * @return void
597 * @subscribe view/stage/abstract/render/postProcess
598 */
599 getPublisherSubscriber().subscribe('view/stage/abstract/render/postProcess', function(topic, args) {
600 getViewModel().renderUndoRedo();
601 });
602
603 /**
604 * @private
605 *
606 * @param string
607 * @param array
608 * @return void
609 * @subscribe view/stage/preview/render/postProcess
610 */
611 getPublisherSubscriber().subscribe('view/stage/preview/render/postProcess', function(topic, args) {
612 getViewModel().renderUndoRedo();
613 });
614
615 /* *********************************************************
616 * Structure
617 * ********************************************************/
618
619 /**
620 * @private
621 *
622 * @param string
623 * @param array
624 * args[0] = formElementIdentifierPath
625 * @return void
626 * @subscribe view/tree/node/clicked
627 */
628 getPublisherSubscriber().subscribe('view/tree/node/clicked', function(topic, args) {
629 var oldPageIndex;
630 if (getCurrentlySelectedFormElement().get('__identifierPath') !== args[0]) {
631 oldPageIndex = getFormEditorApp().getCurrentlySelectedPageIndex();
632 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
633 if (oldPageIndex !== getFormEditorApp().getCurrentlySelectedPageIndex()) {
634 getViewModel().renderAbstractStageArea();
635 } else {
636 getViewModel().renderAbstractStageArea(false);
637 }
638 getViewModel().renderPagination();
639 getViewModel().renderInspectorEditors();
640 }
641 });
642
643 /**
644 * @private
645 *
646 * @param string
647 * @param array
648 * @return void
649 * @subscribe view/structure/root/selected
650 */
651 getPublisherSubscriber().subscribe('view/structure/root/selected', function(topic, args) {
652 if (!getFormEditorApp().isRootFormElementSelected()) {
653 getViewModel().addStructureRootElementSelection();
654 getFormEditorApp().setCurrentlySelectedFormElement(getRootFormElement());
655 getViewModel().renderAbstractStageArea();
656 getViewModel().renewStructure();
657 getViewModel().renderPagination();
658 getViewModel().renderInspectorEditors();
659 }
660 });
661
662 /**
663 * @private
664 *
665 * @param string
666 * @param array
667 * args[0] = targetEvent
668 * @return void
669 * @subscribe view/header/button/newPage/clicked
670 */
671 getPublisherSubscriber().subscribe('view/structure/button/newPage/clicked', function(topic, args) {
672 if (getFormEditorApp().isRootFormElementSelected()) {
673 getViewModel().selectPageBatch(0);
674 }
675 getViewModel().showInsertPagesModal(args[0]);
676 });
677
678 /**
679 * @private
680 *
681 * @param string
682 * @param array
683 * args[0] = draggedFormElementIdentifierPath
684 * @return void
685 * @subscribe view/tree/dnd/stop
686 */
687 getPublisherSubscriber().subscribe('view/tree/dnd/stop', function(topic, args) {
688 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
689 getViewModel().renewStructure();
690 getViewModel().renderPagination();
691 getViewModel().renderAbstractStageArea();
692 getViewModel().renderInspectorEditors();
693 });
694
695 /**
696 * @private
697 *
698 * @param string
699 * @param array
700 * args[0] = placeholderDomElement
701 * args[1] = parentFormElementIdentifierPath
702 * args[2] = enclosingCompositeFormElement
703 * @return void
704 * @subscribe view/tree/dnd/change
705 */
706 getPublisherSubscriber().subscribe('view/tree/dnd/change', function(topic, args) {
707 getViewModel().onStructureDndChangeBatch(args[0], args[1], args[2]);
708 });
709
710 /**
711 * @private
712 *
713 * @param string
714 * @param array
715 * args[0] = movedDomElement
716 * args[1] = movedFormElementIdentifierPath
717 * args[2] = previousFormElementIdentifierPath
718 * args[3] = nextFormElementIdentifierPath
719 * @return void
720 * @subscribe view/tree/dnd/update
721 */
722 getPublisherSubscriber().subscribe('view/tree/dnd/update', function(topic, args) {
723 getViewModel().onStructureDndUpdateBatch(args[0], args[1], args[2], args[3]);
724 });
725
726 /**
727 * @private
728 *
729 * @param string
730 * @param array
731 * @return void
732 * @subscribe view/structure/renew/postProcess
733 */
734 getPublisherSubscriber().subscribe('view/structure/renew/postProcess', function(topic, args) {
735 getViewModel().addStructureValidationResults();
736 });
737
738 /* *********************************************************
739 * Inspector
740 * ********************************************************/
741
742 /**
743 * @private
744 *
745 * @param string
746 * @param array
747 * args[0] = collectionElementIdentifier
748 * args[1] = collectionName
749 * args[2] = formElement
750 * @return void
751 * @subscribe view/inspector/removeCollectionElement/perform
752 */
753 getPublisherSubscriber().subscribe('view/inspector/removeCollectionElement/perform', function(topic, args) {
754 getViewModel().removePropertyCollectionElement(args[0], args[1], args[2]);
755 });
756
757 /**
758 * @private
759 *
760 * @param string
761 * @param array
762 * args[0] = collectionElementIdentifier
763 * args[1] = collectionName
764 * @return void
765 * @subscribe view/inspector/collectionElement/selected
766 */
767 getPublisherSubscriber().subscribe('view/inspector/collectionElement/new/selected', function(topic, args) {
768 getViewModel().createAndAddPropertyCollectionElement(args[0], args[1]);
769 });
770
771 /**
772 * @private
773 *
774 * @param string
775 * @param array
776 * args[0] = collectionElementIdentifier
777 * args[1] = collectionName
778 * @return void
779 * @subscribe view/inspector/collectionElement/selected
780 */
781 getPublisherSubscriber().subscribe('view/inspector/collectionElement/existing/selected', function(topic, args) {
782 getViewModel().renderInspectorCollectionElementEditors(args[1], args[0]);
783 });
784
785 /**
786 * @private
787 *
788 * @param string
789 * @param array
790 * args[0] = movedCollectionElementIdentifier
791 * args[1] = previousCollectionElementIdentifier
792 * args[2] = nextCollectionElementIdentifier
793 * args[3] = collectionName
794 * @return void
795 * @subscribe view/inspector/collectionElements/dnd/update
796 * @throws 1477407673
797 */
798 getPublisherSubscriber().subscribe('view/inspector/collectionElements/dnd/update', function(topic, args) {
799 if (args[2]) {
800 getViewModel().movePropertyCollectionElement(args[0], 'before', args[2], args[3]);
801 } else if (args[1]) {
802 getViewModel().movePropertyCollectionElement(args[0], 'after', args[1], args[3]);
803 } else {
804 assert(false, 'Next element or previous element need to be set.', 1477407673);
805 }
806 });
807
808 /* *********************************************************
809 * Form element
810 * ********************************************************/
811
812 /**
813 * @private
814 *
815 * @param string
816 * @param array
817 * args[0] = propertyPath
818 * args[1] = value
819 * args[2] = oldValue
820 * args[3] = formElementIdentifierPath
821 * @return void
822 * @subscribe core/formElement/somePropertyChanged
823 */
824 getPublisherSubscriber().subscribe('core/formElement/somePropertyChanged', function(topic, args) {
825 if ('renderables' !== args[0]) {
826 if (!getFormEditorApp().isRootFormElementSelected() && 'label' === args[0]) {
827 getViewModel().getStructure().setTreeNodeTitle();
828 getViewModel().setInspectorFormElementHeaderEditorContent();
829 } else if (!getFormEditorApp().getUtility().isUndefinedOrNull(args[3]) && getRootFormElement().get('__identifierPath') === args[3]) {
830 getViewModel().setStructureRootElementTitle();
831 getViewModel().setStageHeadline();
832 getViewModel().setInspectorFormElementHeaderEditorContent();
833 }
834
835 if (getViewModel().getPreviewMode()) {
836 getFormEditorApp().renderCurrentFormPage();
837 } else {
838 getViewModel().renderAbstractStageArea(false, false);
839 }
840 getViewModel().addStructureValidationResults();
841 }
842
843 getFormEditorApp().setUnsavedContent(true);
844 });
845
846 /**
847 * @private
848 *
849 * @param string
850 * @param array
851 * args[0] = parentFormElement
852 * @return void
853 * @subscribe view/formElement/removed
854 */
855 getPublisherSubscriber().subscribe('view/formElement/removed', function(topic, args) {
856 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
857 getViewModel().renewStructure();
858 getViewModel().renderAbstractStageArea();
859 getViewModel().renderPagination();
860 getViewModel().renderInspectorEditors();
861 });
862
863 /**
864 * @private
865 *
866 * @param string
867 * @param array
868 * args[0] = newFormElement
869 * @return void
870 * @subscribe view/formElement/inserted
871 */
872 getPublisherSubscriber().subscribe('view/formElement/inserted', function(topic, args) {
873 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
874 getViewModel().renewStructure();
875 getViewModel().renderAbstractStageArea();
876 getViewModel().renderPagination();
877 getViewModel().renderInspectorEditors();
878 });
879
880 /**
881 * @private
882 *
883 * @param string
884 * @param array
885 * args[0] = collectionElementIdentifier
886 * args[1] = collectionName
887 * args[2] = formElement
888 * args[3] = collectionElementConfiguration
889 * args[4] = referenceCollectionElementIdentifier
890 * @return void
891 * @subscribe view/collectionElement/new/added
892 */
893 getPublisherSubscriber().subscribe('view/collectionElement/new/added', function(topic, args) {
894 getViewModel().renderInspectorEditors();
895 });
896
897 /**
898 * @private
899 *
900 * @param string
901 * @param array
902 * args[0] = movedCollectionElementIdentifier
903 * args[1] = previousCollectionElementIdentifier
904 * args[2] = nextCollectionElementIdentifier
905 * args[3] = collectionName
906 * @return void
907 * @subscribe view/collectionElement/moved
908 * @throws 1477407673
909 */
910 getPublisherSubscriber().subscribe('view/collectionElement/moved', function(topic, args) {
911 getViewModel().renderInspectorEditors(undefined, false);
912 });
913
914 /**
915 * @private
916 *
917 * @param string
918 * @param array
919 * args[0] = collectionElementIdentifier
920 * args[1] = collectionName
921 * args[2] = formElement
922 * @return void
923 * @subscribe view/collectionElement/removed
924 */
925 getPublisherSubscriber().subscribe('view/collectionElement/removed', function(topic, args) {
926 getViewModel().renderInspectorEditors(undefined, false);
927 });
928
929 /**
930 * @private
931 *
932 * @param string
933 * @param array
934 * args[0] = formElementType
935 * @return void
936 * @subscribe view/insertElements/perform/bottom
937 */
938 getPublisherSubscriber().subscribe('view/insertElements/perform/bottom', function(topic, args) {
939 var lastRenderable;
940
941 lastRenderable = getFormEditorApp().getLastTopLevelElementOnCurrentPage();
942 if (!lastRenderable) {
943 getViewModel().createAndAddFormElement(args[0], getFormEditorApp().getCurrentlySelectedPage());
944 } else {
945 if (
946 !getFormEditorApp().getFormElementDefinition(lastRenderable, '_isTopLevelFormElement')
947 && getFormEditorApp().getFormElementDefinition(lastRenderable, '_isCompositeFormElement')
948 ) {
949 getViewModel().createAndAddFormElement(args[0], getFormEditorApp().getCurrentlySelectedPage());
950 } else {
951 getViewModel().createAndAddFormElement(args[0], lastRenderable);
952 }
953 }
954 });
955
956 /**
957 * @private
958 *
959 * @param string
960 * @param array
961 * args[0] = formElementType
962 * @return void
963 * @publish view/formElement/inserted
964 * @subscribe view/insertElements/perform/after
965 */
966 getPublisherSubscriber().subscribe('view/insertElements/perform/after', function(topic, args) {
967 var newFormElement;
968 newFormElement = getViewModel().createAndAddFormElement(args[0], undefined, true);
969 newFormElement = getViewModel().moveFormElement(newFormElement, 'after', getFormEditorApp().getCurrentlySelectedFormElement());
970 getPublisherSubscriber().publish('view/formElement/inserted', [newFormElement]);
971 });
972
973 /**
974 * @private
975 *
976 * @param string
977 * @param array
978 * args[0] = formElementType
979 * @return void
980 * @subscribe view/insertElements/perform/inside
981 */
982 getPublisherSubscriber().subscribe('view/insertElements/perform/inside', function(topic, args) {
983 getViewModel().createAndAddFormElement(args[0]);
984 });
985
986 /**
987 * @private
988 *
989 * @param string
990 * @param array
991 * args[0] = formElementType
992 * @return void
993 * @subscribe view/insertElements/perform/after
994 */
995 getPublisherSubscriber().subscribe('view/insertPages/perform', function(topic, args) {
996 getViewModel().createAndAddFormElement(args[0]);
997 });
998
999 /* *********************************************************
1000 * Modals
1001 * ********************************************************/
1002
1003 /**
1004 * @private
1005 *
1006 * @param string
1007 * @param array
1008 * @return void
1009 * @subscribe view/modal/close/perform
1010 */
1011 getPublisherSubscriber().subscribe('view/modal/close/perform', function(topic, args) {
1012 getFormEditorApp().setUnsavedContent(false);
1013 getViewModel().closeEditor();
1014 });
1015
1016 /**
1017 * @private
1018 *
1019 * @param string
1020 * @param array
1021 * args[0] = formElement
1022 * @return void
1023 * @subscribe view/modal/removeFormElement/perform
1024 */
1025 getPublisherSubscriber().subscribe('view/modal/removeFormElement/perform', function(topic, args) {
1026 getViewModel().removeFormElement(args[0]);
1027 });
1028
1029 /**
1030 * @private
1031 *
1032 * @param string
1033 * @param array
1034 * args[0] = collectionElementIdentifier
1035 * args[1] = collectionName
1036 * args[2] = formElement
1037 * @return void
1038 * @subscribe view/modal/removeCollectionElement/perform
1039 */
1040 getPublisherSubscriber().subscribe('view/modal/removeCollectionElement/perform', function(topic, args) {
1041 getViewModel().removePropertyCollectionElement(args[0], args[1], args[2]);
1042 });
1043
1044 /**
1045 * @private
1046 *
1047 * @param string
1048 * @param array
1049 * args[0] = formElementIdentifierPath
1050 * @return void
1051 * @subscribe view/modal/validationErrors/element/clicked
1052 */
1053 getPublisherSubscriber().subscribe('view/modal/validationErrors/element/clicked', function(topic, args) {
1054 var oldPageIndex;
1055 if (getCurrentlySelectedFormElement().get('__identifierPath') !== args[0]) {
1056 oldPageIndex = getFormEditorApp().getCurrentlySelectedPageIndex();
1057 getFormEditorApp().setCurrentlySelectedFormElement(args[0]);
1058
1059 if (getViewModel().getPreviewMode()) {
1060 getViewModel().setPreviewMode(false);
1061 }
1062
1063 if (oldPageIndex !== getFormEditorApp().getCurrentlySelectedPageIndex()) {
1064 getViewModel().renderAbstractStageArea();
1065 } else {
1066 getViewModel().renderAbstractStageArea(false);
1067 }
1068
1069 getViewModel().renderPagination();
1070 getViewModel().renderInspectorEditors();
1071 }
1072 });
1073 };
1074
1075 /**
1076 * @public
1077 *
1078 * @param object
1079 * @param object
1080 * @return void
1081 */
1082 function bootstrap(formEditorApp, viewModel) {
1083 _formEditorApp = formEditorApp;
1084 _viewModel = viewModel;
1085 _helperSetup();
1086 _subscribeEvents();
1087 };
1088
1089 /**
1090 * Implements the "Revealing Module Pattern".
1091 */
1092 return {
1093 /**
1094 * Publish the public methods.
1095 */
1096 bootstrap: bootstrap
1097 };
1098 })($, Helper);
1099 });