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