Add content selection before removing content
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / WoltLabSuite / Core / Acp / Ui / User / Content / Remove / Handler.js
1 /**
2 * Provides the trophy icon designer.
3 *
4 * @author Joshua Ruesweg
5 * @copyright 2001-2018 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/Acp/User/Content/Remove/Handler
8 * @since 3.2
9 */
10 define(['Ajax', 'Language', 'Ui/Dialog', 'WoltLabSuite/Core/Acp/Ui/Worker'], function (Ajax, Language, UiDialog, Worker) {
11 "use strict";
12
13 /**
14 * Creates a new worker instance.
15 * @constructor
16 */
17 function Handler(element, userId) { this.init(element, userId); }
18 Handler.prototype = {
19 /**
20 * Initializes the content remove handler.
21 */
22 init: function (element, userId) {
23 element.addEventListener(WCF_CLICK_EVENT, this._click.bind(this));
24 this._userId = userId;
25 },
26
27 /**
28 * Click on the remove content button.
29 *
30 * @param {object} event click event
31 */
32 _click: function (event) {
33 event.preventDefault();
34
35 Ajax.api(this);
36 },
37
38 /**
39 * Executes the remove content worker.
40 *
41 * @param {Array} objectTypes
42 */
43 _executeWorker: function (objectTypes) {
44 new Worker({
45 // dialog
46 dialogId: 'removeContentWorker',
47 dialogTitle: Language.get('wcf.acp.user.content.removeContent'),
48
49 // ajax
50 className: '\\wcf\\system\\worker\\UserContentRemoveWorker',
51 parameters: {
52 userID: this._userId,
53 contentProvider: objectTypes
54 }
55 });
56 },
57
58 /**
59 * Handles a click on the submit button in the overlay.
60 */
61 _submit: function () {
62 var objectTypeInputs = elBySelAll('input.contentProviderObjectType', UiDialog.getDialog('userRemoveContentHandler-' + this._userId).content);
63 var objectTypes = [];
64
65 for (var i = 0, length = objectTypeInputs.length; i < length; i++) {
66 if (objectTypeInputs[i].checked) {
67 objectTypes.push(objectTypeInputs[i].name);
68 }
69 }
70
71 if (objectTypes.length > 0) {
72 this._executeWorker(objectTypes);
73 }
74 },
75
76 _ajaxSuccess: function (data) {
77 UiDialog.open(this, data.returnValues.template);
78
79 elBySel('input[type="submit"]', UiDialog.getDialog('userRemoveContentHandler-' + this._userId).content).addEventListener(WCF_CLICK_EVENT, this._submit.bind(this));
80 },
81
82 _ajaxSetup: function () {
83 return {
84 data: {
85 actionName: 'prepareRemoveContent',
86 className: 'wcf\\data\\user\\UserAction',
87 parameters: {
88 userID: this._userId
89 }
90 }
91 };
92 },
93
94 _dialogSetup: function() {
95 return {
96 id: 'userRemoveContentHandler-' + this._userId,
97 options: {
98 title: Language.get('wcf.acp.user.content.removeContent')
99 },
100 source: null
101 };
102 }
103 };
104
105 return Handler;
106 });