df23291447f9617ff41048f99756a8276e558f9c
[Packages/TYPO3.CMS.git] / typo3 / sysext / wizard_crpages / Resources / Public / JavaScript / WizardCreatePages.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 * JavaScript functions for creating multiple pages
16 */
17 define(['jquery'], function($) {
18 'use strict';
19
20 var WizardCreatePages = {
21 lineCounter: 5,
22 containerSelector: '.t3js-wizardcrpages-container',
23 addMoreFieldsButtonSelector: '.t3js-wizardcrpages-createnewfields',
24 doktypeSelector: '.t3js-wizardcrpages-select-doktype'
25 };
26
27 WizardCreatePages.createNewFormFields = function() {
28 for (var i = 0; i < 5; i++) {
29 var label = this.lineCounter + i + 1;
30 var line = tpl
31 .replace(/\{0\}/g, (this.lineCounter + i))
32 .replace(/\{1\}/g, label);
33
34 $(line).appendTo(this.containerSelector);
35 }
36 WizardCreatePages.lineCounter += 5;
37 };
38
39 WizardCreatePages.actOnTypeSelectChange = function($selectElement) {
40 var $optionElement = $selectElement.find(':selected');
41 var $target = $($selectElement.data('target'));
42 $target.html($optionElement.data('icon'));
43 };
44
45 /**
46 * Register listeners
47 */
48 WizardCreatePages.initializeEvents = function() {
49 $(this.addMoreFieldsButtonSelector).on('click', function() {
50 WizardCreatePages.createNewFormFields();
51 });
52
53 $(document).on('change', this.doktypeSelector, function() {
54 WizardCreatePages.actOnTypeSelectChange($(this));
55 });
56 };
57
58 $(WizardCreatePages.initializeEvents);
59
60 return WizardCreatePages;
61 });