banWizard.js
3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
angular.module('footyroom').component('banWizard', {
template: /* html */`
<div fr-litelay="$ctrl.isSaving || $ctrl.isLoading">
<div class="modal-body">
<div ng-if="!$ctrl.isLoading">
<div ng-if="!$ctrl.isRequestingPermaban">
<div ng-if="$ctrl.warning" ng-bind-html="$ctrl.warning"></div>
<span>Ban this user from commenting for </span>
<select class="ban-duration" ng-model="$ctrl.duration" ng-change="onDurationChange()">
<option value="600">10 minutes</option>
<option value="3600">1 hour</option>
<option value="36000">10 hours</option>
<option value="86400">1 day</option>
<option value="172800">2 days</option>
<option value="604800">1 week</option>
<option value="2592000">1 month</option>
</select>
</div>
<div ng-if="$ctrl.isRequestingPermaban">
<textarea ng-model="$ctrl.explanation" class="form-control" rows="10" placeholder="Please give some explanation why you think this user deserves a permanent ban"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<div class="pull-left">
<button ng-click="$ctrl.isRequestingPermaban = true" ng-if="!$ctrl.isRequestingPermaban" class="btn btn-default">Request Permaban</button>
<button ng-click="$ctrl.isRequestingPermaban = false" ng-if="$ctrl.isRequestingPermaban" class="btn btn-default">Ban Temporarily</button>
</div>
<div class="pull-right">
<button class="btn btn-default" ng-click="$ctrl.dismiss()">Cancel</button>
<button class="btn btn-primary" ng-click="$ctrl.ban()" ng-if="!$ctrl.isRequestingPermaban">Ban</button>
<button class="btn btn-primary" ng-click="$ctrl.permaban()" ng-if="$ctrl.isRequestingPermaban">Send Request</button>
</div>
</div>
</div>
`,
bindings: {
userId: '<',
dismiss: '&',
},
/**
* @param {ng.IHttpService} $http
* @param {ng.ISCEService} $sce
*/
controller: ['$http', '$sce', function ($http, $sce) {
const vm = this;
vm.ban = ban;
vm.permaban = permaban;
vm.duration = '600';
vm.isLoading = true;
$http.get('/bans/active-pagelet', { params: { userId: vm.userId, type: 'comment' } })
.then((response) => {
vm.warning = $sce.trustAsHtml(response.data);
})
.finally(() => {
vm.isLoading = false;
});
function ban() {
confirm('/bans', {
entity: 'user_id',
value: vm.userId,
type: 'comment',
duration: vm.duration,
});
}
function permaban() {
confirm('/bans/request-permaban', {
userId: vm.userId,
explanation: vm.explanation,
});
}
function confirm(action, data) {
vm.isSaving = true;
return $http.post(action, data)
.then(() => vm.dismiss())
.catch((response) => { alert(response.data.errors); })
.finally(() => {
vm.isSaving = false;
});
}
}],
});