643336ffc1674611122a9785906ed64515032184
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Resources / Public / JavaScript / FormEngine / Element / SelectTreeElement.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 * Initialization of the selectTree js component used e.g. for category tree rendering
16 */
17 define(['jquery', 'TYPO3/CMS/Backend/FormEngine/Element/SelectTree'],
18 function($, SelectTree) {
19 'use strict';
20
21 var SelectTreeElement = {};
22
23 SelectTreeElement.initialize = function() {
24 $(document).ready(function() {
25 $('.typo3-tceforms-tree .treeRecord').each(function(i, element) {
26
27 /**
28 * Hidden input field storing selected elements.
29 * Tree is initialized based on values stored in it's data attributes
30 *
31 * @type {*|jQuery|HTMLElement}
32 */
33 var $treeInput = $(element);
34 var dataParams = {
35 tableName: $treeInput.data('tablename'),
36 fieldName: $treeInput.data('fieldname'),
37 uid: $treeInput.data('uid'),
38 recordTypeValue: $treeInput.data('recordtypevalue'),
39 dataStructureIdentifier: $treeInput.data('datastructureidentifier'),
40 flexFormSheetName: $treeInput.data('flexformsheetname'),
41 flexFormFieldName: $treeInput.data('flexformfieldname'),
42 flexFormContainerName: $treeInput.data('flexformcontainername'),
43 flexFormContainerIdentifier: $treeInput.data('flexformcontaineridentifier'),
44 flexFormContainerFieldName: $treeInput.data('flexformcontainerfieldname'),
45 flexFormSectionContainerIsNew: $treeInput.data('flexformsectioncontainerisnew'),
46 command: $treeInput.data('command')
47 };
48 var $wrapper = $treeInput.parent().siblings('.svg-tree-wrapper');
49 var dataUrl = TYPO3.settings.ajaxUrls.record_tree_data + '&' + $.param(dataParams);
50 var tree = new SelectTree();
51 var initialized = tree.initialize($wrapper, {
52 dataUrl: dataUrl,
53 showIcons: true,
54 showCheckboxes: true,
55 readOnlyMode: $treeInput.data('read-only'),
56 input: $treeInput,
57 exclusiveNodesIdentifiers: $treeInput.data('tree-exclusive-keys'),
58 validation: $treeInput.data('formengine-validation-rules')[0],
59 expandUpToLevel: $treeInput.data('tree-expand-up-to-level')
60 });
61 if (!initialized) {
62 return;
63 }
64
65 tree.dispatch.on('nodeSelectedAfter.requestUpdate', window[$wrapper.attr('id')]);
66
67 if ($treeInput.data('tree-show-toolbar')) {
68 require(['TYPO3/CMS/Backend/FormEngine/Element/TreeToolbar'], function(TreeToolbar) {
69 var selectTreeToolbar = new TreeToolbar();
70 selectTreeToolbar.initialize($wrapper);
71 });
72 }
73 });
74 });
75 };
76
77 return SelectTreeElement;
78 });