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