54119958f8b6b05cbab2183ec14e2748d5075575
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Resources / Public / JavaScript / Modules / CreateAdmin.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/Install/CreateAdmin
16 */
17 define([
18 'jquery',
19 'TYPO3/CMS/Install/Router',
20 'TYPO3/CMS/Install/FlashMessage',
21 'TYPO3/CMS/Install/ProgressBar',
22 'TYPO3/CMS/Install/InfoBox',
23 'TYPO3/CMS/Install/Severity',
24 'TYPO3/CMS/Install/PasswordStrength',
25 'TYPO3/CMS/Backend/Notification'
26 ], function($, Router, FlashMessage, ProgressBar, InfoBox, Severity, PasswordStrength, Notification) {
27 'use strict';
28
29 return {
30 selectorModalBody: '.t3js-modal-body',
31 selectorModuleContent: '.t3js-module-content',
32 selectorCreateForm: '#t3js-createAdmin-form',
33 selectorCreateTrigger: '.t3js-createAdmin-create',
34 selectorOutputContainer: '.t3js-createAdmin-output',
35 currentModal: {},
36
37 initialize: function(currentModal) {
38 var self = this;
39 this.currentModal = currentModal;
40 this.getData();
41
42 currentModal.on('click', this.selectorCreateTrigger, function(e) {
43 e.preventDefault();
44 self.create();
45 });
46
47 currentModal.on('click', '.t3-install-form-password-strength', function(e) {
48 PasswordStrength.initialize('.t3-install-form-password-strength');
49 });
50 },
51
52 getData: function() {
53 var modalContent = this.currentModal.find(this.selectorModalBody);
54 $.ajax({
55 url: Router.getUrl('createAdminGetData'),
56 cache: false,
57 success: function(data) {
58 if (data.success === true) {
59 modalContent.empty().append(data.html);
60 } else {
61 Notification.error('Something went wrong');
62 }
63 },
64 error: function(xhr) {
65 Router.handleAjaxError(xhr, modalContent);
66 }
67 });
68 },
69
70 create: function() {
71 var self = this;
72 var modalContent = this.currentModal.find(this.selectorModalBody);
73 var executeToken = this.currentModal.find(this.selectorModuleContent).data('create-admin-token');
74 $.ajax({
75 url: Router.getUrl(),
76 method: 'POST',
77 data: {
78 'install': {
79 'action': 'createAdmin',
80 'token': executeToken,
81 'userName': self.currentModal.find('.t3js-createAdmin-user').val(),
82 'userPassword': self.currentModal.find('.t3js-createAdmin-password').val(),
83 'userPasswordCheck': self.currentModal.find('.t3js-createAdmin-password-check').val(),
84 'userSystemMaintainer': (self.currentModal.find('.t3js-createAdmin-system-maintainer').is(':checked')) ? 1 : 0
85 }
86 },
87 cache: false,
88 success: function(data) {
89 if (data.success === true && Array.isArray(data.status)) {
90 data.status.forEach(function(element) {
91 if (element.severity == 2) {
92 Notification.error(element.message);
93 }
94 else {
95 Notification.success(element.title);
96 }
97 });
98 } else {
99 Notification.error('Something went wrong');
100 }
101 },
102 error: function(xhr) {
103 Router.handleAjaxError(xhr, modalContent);
104 }
105 });
106 this.currentModal.find('.t3js-createAdmin-user').val('');
107 this.currentModal.find('.t3js-createAdmin-password').val('');
108 this.currentModal.find('.t3js-createAdmin-password-check').val('');
109 this.currentModal.find('.t3js-createAdmin-system-maintainer').prop('checked', false);
110 }
111 };
112 });