1295714c7e3e7f3a6c5b353e18271a23abf97fed
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Resources / Public / JavaScript / Modules / ChangeInstallToolPassword.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/Severity',
21 'TYPO3/CMS/Install/PasswordStrength',
22 'TYPO3/CMS/Backend/Notification'
23 ], function($, Router, Severity, PasswordStrength, Notification) {
24 'use strict';
25
26 return {
27 selectorModalBody: '.t3js-modal-body',
28 selectorModuleContent: '.t3js-module-content',
29 selectorChangeTrigger: '.t3js-changeInstallToolPassword-change',
30 selectorOutputContainer: '.t3js-changeInstallToolPassword-output',
31 currentModal: {},
32
33 initialize: function(currentModal) {
34 var self = this;
35 this.currentModal = currentModal;
36 this.getData();
37
38 currentModal.on('click', this.selectorChangeTrigger, function(e) {
39 e.preventDefault();
40 self.change();
41 });
42 currentModal.on('click', '.t3-install-form-password-strength', function(e) {
43 PasswordStrength.initialize('.t3-install-form-password-strength');
44 });
45 },
46
47 getData: function() {
48 var modalContent = this.currentModal.find(this.selectorModalBody);
49 $.ajax({
50 url: Router.getUrl('changeInstallToolPasswordGetData'),
51 cache: false,
52 success: function(data) {
53 if (data.success === true) {
54 modalContent.empty().append(data.html);
55 } else {
56 Notification.error('Something went wrong');
57 }
58 },
59 error: function(xhr) {
60 Router.handleAjaxError(xhr, modalContent);
61 }
62 });
63 },
64
65 change: function() {
66 var self = this;
67 var modalContent = this.currentModal.find(this.selectorModalBody);
68 var executeToken = this.currentModal.find(this.selectorModuleContent).data('install-tool-token');
69 $.ajax({
70 url: Router.getUrl(),
71 method: 'POST',
72 data: {
73 'install': {
74 'action': 'changeInstallToolPassword',
75 'token': executeToken,
76 'password': self.currentModal.find('.t3js-changeInstallToolPassword-password').val(),
77 'passwordCheck': self.currentModal.find('.t3js-changeInstallToolPassword-password-check').val()
78 }
79 },
80 cache: false,
81 success: function(data) {
82 if (data.success === true && Array.isArray(data.status)) {
83 data.status.forEach(function(element) {
84 Notification.showMessage('', element.message, element.severity);
85 });
86 } else {
87 Notification.error('Something went wrong');
88 }
89 },
90 error: function(xhr) {
91 Router.handleAjaxError(xhr, modalContent);
92 },
93 complete: function() {
94 self.currentModal.find('.t3js-changeInstallToolPassword-password,.t3js-changeInstallToolPassword-password-check').val('')
95 }
96 });
97 }
98 };
99 });