From 5769e1db8d3d5a1e3baa8dff23090cfe93d48a50 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 27 Jan 2017 16:54:44 +0100 Subject: Client: better confirm box for a beautiful world --- .../friends/friend-add/friend-add.component.ts | 22 +++++--- .../friends/friend-list/friend-list.component.ts | 21 +++++--- .../+admin/users/user-list/user-list.component.ts | 26 +++++---- client/src/app/app.component.html | 1 + client/src/app/core/confirm/confirm.component.html | 20 +++++++ client/src/app/core/confirm/confirm.component.ts | 61 ++++++++++++++++++++++ client/src/app/core/confirm/confirm.service.ts | 15 ++++++ client/src/app/core/confirm/index.ts | 2 + client/src/app/core/core.module.ts | 13 ++++- client/src/app/core/index.ts | 2 + .../videos/video-list/video-miniature.component.ts | 18 ++++--- .../videos/video-watch/video-report.component.ts | 14 ++--- 12 files changed, 176 insertions(+), 39 deletions(-) create mode 100644 client/src/app/core/confirm/confirm.component.html create mode 100644 client/src/app/core/confirm/confirm.component.ts create mode 100644 client/src/app/core/confirm/confirm.service.ts create mode 100644 client/src/app/core/confirm/index.ts (limited to 'client') diff --git a/client/src/app/+admin/friends/friend-add/friend-add.component.ts b/client/src/app/+admin/friends/friend-add/friend-add.component.ts index a271970ae..12c46e5cd 100644 --- a/client/src/app/+admin/friends/friend-add/friend-add.component.ts +++ b/client/src/app/+admin/friends/friend-add/friend-add.component.ts @@ -4,6 +4,7 @@ import { Router } from '@angular/router'; import { NotificationsService } from 'angular2-notifications'; +import { ConfirmService } from '../../../core'; import { validateHost } from '../../../shared'; import { FriendService } from '../shared'; @@ -20,6 +21,7 @@ export class FriendAddComponent implements OnInit { constructor( private router: Router, private notificationsService: NotificationsService, + private confirmService: ConfirmService, private friendService: FriendService ) {} @@ -84,16 +86,20 @@ export class FriendAddComponent implements OnInit { return; } - const confirmMessage = 'Are you sure to make friends with:\n - ' + notEmptyHosts.join('\n - '); - if (!confirm(confirmMessage)) return; + const confirmMessage = 'Are you sure to make friends with:
- ' + notEmptyHosts.join('
- '); + this.confirmService.confirm(confirmMessage, 'Make friends').subscribe( + res => { + if (res === false) return; - this.friendService.makeFriends(notEmptyHosts).subscribe( - status => { - this.notificationsService.success('Sucess', 'Make friends request sent!'); - this.router.navigate([ '/admin/friends/list' ]); - }, + this.friendService.makeFriends(notEmptyHosts).subscribe( + status => { + this.notificationsService.success('Sucess', 'Make friends request sent!'); + this.router.navigate([ '/admin/friends/list' ]); + }, - err => this.notificationsService.error('Error', err.text) + err => this.notificationsService.error('Error', err.text) + ); + } ); } diff --git a/client/src/app/+admin/friends/friend-list/friend-list.component.ts b/client/src/app/+admin/friends/friend-list/friend-list.component.ts index 700ea7a69..175ad9cba 100644 --- a/client/src/app/+admin/friends/friend-list/friend-list.component.ts +++ b/client/src/app/+admin/friends/friend-list/friend-list.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { NotificationsService } from 'angular2-notifications'; +import { ConfirmService } from '../../../core'; import { Friend, FriendService } from '../shared'; @Component({ @@ -14,6 +15,7 @@ export class FriendListComponent implements OnInit { constructor( private notificationsService: NotificationsService, + private confirmService: ConfirmService, private friendService: FriendService ) { } @@ -22,16 +24,21 @@ export class FriendListComponent implements OnInit { } quitFriends() { - if (!confirm('Are you sure?')) return; + const confirmMessage = 'Do you really want to quit your friends? All their videos will be deleted.'; + this.confirmService.confirm(confirmMessage, 'Quit friends').subscribe( + res => { + if (res === false) return; - this.friendService.quitFriends().subscribe( - status => { - this.notificationsService.success('Sucess', 'Friends left!'); + this.friendService.quitFriends().subscribe( + status => { + this.notificationsService.success('Sucess', 'Friends left!'); - this.getFriends(); - }, + this.getFriends(); + }, - err => this.notificationsService.error('Error', err.text) + err => this.notificationsService.error('Error', err.text) + ); + } ); } diff --git a/client/src/app/+admin/users/user-list/user-list.component.ts b/client/src/app/+admin/users/user-list/user-list.component.ts index ca08ed305..baefb7064 100644 --- a/client/src/app/+admin/users/user-list/user-list.component.ts +++ b/client/src/app/+admin/users/user-list/user-list.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { NotificationsService } from 'angular2-notifications'; +import { ConfirmService } from '../../../core'; import { User } from '../../../shared'; import { UserService } from '../shared'; @@ -16,6 +17,7 @@ export class UserListComponent implements OnInit { constructor( private notificationsService: NotificationsService, + private confirmService: ConfirmService, private userService: UserService ) {} @@ -36,15 +38,19 @@ export class UserListComponent implements OnInit { removeUser(user: User) { - if (confirm('Are you sure?')) { - this.userService.removeUser(user).subscribe( - () => { - this.notificationsService.success('Success', `User ${user.username} deleted.`); - this.getUsers(); - }, - - err => this.notificationsService.error('Error', err.text) - ); - } + this.confirmService.confirm('Do you really want to delete this user?', 'Delete').subscribe( + res => { + if (res === false) return; + + this.userService.removeUser(user).subscribe( + () => { + this.notificationsService.success('Success', `User ${user.username} deleted.`); + this.getUsers(); + }, + + err => this.notificationsService.error('Error', err.text) + ); + } + ); } } diff --git a/client/src/app/app.component.html b/client/src/app/app.component.html index 95a025832..9f2661e12 100644 --- a/client/src/app/app.component.html +++ b/client/src/app/app.component.html @@ -23,6 +23,7 @@ +