diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-08-23 14:37:49 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-08-23 14:37:49 +0200 |
commit | 0f6da32b148c0f4146b2ae9ad1add9a9f00cc339 (patch) | |
tree | 1272a5892e357aa0a0d370545effa6800092d568 /client/src/app/admin | |
parent | 39f87cb21689a912559d0498641db7d2de4a784d (diff) | |
download | PeerTube-0f6da32b148c0f4146b2ae9ad1add9a9f00cc339.tar.gz PeerTube-0f6da32b148c0f4146b2ae9ad1add9a9f00cc339.tar.zst PeerTube-0f6da32b148c0f4146b2ae9ad1add9a9f00cc339.zip |
Client: update to new form api
Diffstat (limited to 'client/src/app/admin')
4 files changed, 22 insertions, 18 deletions
diff --git a/client/src/app/admin/friends/friend-add/friend-add.component.html b/client/src/app/admin/friends/friend-add/friend-add.component.html index a52965e8f..d8bb740b4 100644 --- a/client/src/app/admin/friends/friend-add/friend-add.component.html +++ b/client/src/app/admin/friends/friend-add/friend-add.component.html | |||
@@ -2,11 +2,11 @@ | |||
2 | 2 | ||
3 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> | 3 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> |
4 | 4 | ||
5 | <form role="form" (ngSubmit)="makeFriends()"> | 5 | <form (ngSubmit)="makeFriends()"> |
6 | <div class="form-group" *ngFor="let url of urls; let id = index; trackBy:customTrackBy"> | 6 | <div class="form-group" *ngFor="let url of urls; let id = index; trackBy:customTrackBy"> |
7 | <label for="username">Url</label> | 7 | <label for="username">Url</label> |
8 | <div class="input-group"> | 8 | <div class="input-group"> |
9 | <input type="text" class="form-control" name="url" id="url" placeholder="http://domain.com" [(ngModel)]="urls[id]" /> | 9 | <input type="text" class="form-control" [name]="'url-' + id" [id]="'url-' + id" placeholder="http://domain.com" [(ngModel)]="urls[id]" /> |
10 | <span class="input-group-btn"> | 10 | <span class="input-group-btn"> |
11 | <button *ngIf="displayAddField(id)" (click)="addField()" class="btn btn-default" type="button">+</button> | 11 | <button *ngIf="displayAddField(id)" (click)="addField()" class="btn btn-default" type="button">+</button> |
12 | <button *ngIf="displayRemoveField(id)" (click)="removeField(index)" class="btn btn-default" type="button">-</button> | 12 | <button *ngIf="displayRemoveField(id)" (click)="removeField(index)" class="btn btn-default" type="button">-</button> |
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 30dbf4d36..07888a781 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 | |||
@@ -53,7 +53,7 @@ export class FriendAddComponent { | |||
53 | return; | 53 | return; |
54 | } | 54 | } |
55 | 55 | ||
56 | const confirmMessage = 'Are you sure to make friends with:\n - ' + this.urls.join('\n - '); | 56 | const confirmMessage = 'Are you sure to make friends with:\n - ' + notEmptyUrls.join('\n - '); |
57 | if (!confirm(confirmMessage)) return; | 57 | if (!confirm(confirmMessage)) return; |
58 | 58 | ||
59 | this.friendService.makeFriends(notEmptyUrls).subscribe( | 59 | this.friendService.makeFriends(notEmptyUrls).subscribe( |
diff --git a/client/src/app/admin/users/user-add/user-add.component.html b/client/src/app/admin/users/user-add/user-add.component.html index aa102358a..09219893b 100644 --- a/client/src/app/admin/users/user-add/user-add.component.html +++ b/client/src/app/admin/users/user-add/user-add.component.html | |||
@@ -2,14 +2,14 @@ | |||
2 | 2 | ||
3 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> | 3 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> |
4 | 4 | ||
5 | <form role="form" (ngSubmit)="addUser(username.value, password.value)" #addUserForm="ngForm"> | 5 | <form role="form" (ngSubmit)="addUser()" [formGroup]="userAddForm"> |
6 | <div class="form-group"> | 6 | <div class="form-group"> |
7 | <label for="username">Username</label> | 7 | <label for="username">Username</label> |
8 | <input | 8 | <input |
9 | type="text" class="form-control" name="username" id="username" placeholder="Username" required | 9 | type="text" class="form-control" name="username" id="username" placeholder="Username" |
10 | ngControl="username" #username="ngForm" | 10 | [(ngModel)]="username" |
11 | > | 11 | > |
12 | <div [hidden]="username.valid || username.pristine" class="alert alert-danger"> | 12 | <div [hidden]="userAddForm.controls.username.valid || userAddForm.controls.username.pristine" class="alert alert-danger"> |
13 | Username is required with a length >= 3 and <= 20 | 13 | Username is required with a length >= 3 and <= 20 |
14 | </div> | 14 | </div> |
15 | </div> | 15 | </div> |
@@ -17,13 +17,13 @@ | |||
17 | <div class="form-group"> | 17 | <div class="form-group"> |
18 | <label for="password">Password</label> | 18 | <label for="password">Password</label> |
19 | <input | 19 | <input |
20 | type="password" class="form-control" name="password" id="password" placeholder="Password" required | 20 | type="password" class="form-control" name="password" id="password" placeholder="Password" |
21 | ngControl="password" #password="ngForm" | 21 | [(ngModel)]="password" |
22 | > | 22 | > |
23 | <div [hidden]="password.valid || password.pristine" class="alert alert-danger"> | 23 | <div [hidden]="userAddForm.controls.password.valid || userAddForm.controls.password.pristine" class="alert alert-danger"> |
24 | Password is required with a length >= 6 | 24 | Password is required with a length >= 6 |
25 | </div> | 25 | </div> |
26 | </div> | 26 | </div> |
27 | 27 | ||
28 | <input type="submit" value="Add user" class="btn btn-default" [disabled]="!addUserForm.form.valid"> | 28 | <input type="submit" value="Add user" class="btn btn-default" [disabled]="!userAddForm.valid"> |
29 | </form> | 29 | </form> |
diff --git a/client/src/app/admin/users/user-add/user-add.component.ts b/client/src/app/admin/users/user-add/user-add.component.ts index 30ca947a0..b7efd3a80 100644 --- a/client/src/app/admin/users/user-add/user-add.component.ts +++ b/client/src/app/admin/users/user-add/user-add.component.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { Control, ControlGroup, Validators } from '@angular/common'; | 1 | import { Validators } from '@angular/common'; |
2 | import { Component, OnInit } from '@angular/core'; | 2 | import { Component, OnInit } from '@angular/core'; |
3 | import { FormGroup, FormControl, REACTIVE_FORM_DIRECTIVES } from '@angular/forms'; | ||
3 | import { Router } from '@angular/router'; | 4 | import { Router } from '@angular/router'; |
4 | 5 | ||
5 | import { UserService } from '../shared'; | 6 | import { UserService } from '../shared'; |
@@ -7,24 +8,27 @@ import { UserService } from '../shared'; | |||
7 | @Component({ | 8 | @Component({ |
8 | selector: 'my-user-add', | 9 | selector: 'my-user-add', |
9 | template: require('./user-add.component.html'), | 10 | template: require('./user-add.component.html'), |
11 | directives: [ REACTIVE_FORM_DIRECTIVES ] | ||
10 | }) | 12 | }) |
11 | export class UserAddComponent implements OnInit { | 13 | export class UserAddComponent implements OnInit { |
12 | userAddForm: ControlGroup; | 14 | userAddForm: FormGroup; |
13 | error: string = null; | 15 | error: string = null; |
16 | username = ''; | ||
17 | password = ''; | ||
14 | 18 | ||
15 | constructor(private router: Router, private userService: UserService) {} | 19 | constructor(private router: Router, private userService: UserService) {} |
16 | 20 | ||
17 | ngOnInit() { | 21 | ngOnInit() { |
18 | this.userAddForm = new ControlGroup({ | 22 | this.userAddForm = new FormGroup({ |
19 | username: new Control('', Validators.compose([ Validators.required, Validators.minLength(3), Validators.maxLength(20) ])), | 23 | username: new FormControl('', [ <any>Validators.required, <any>Validators.minLength(3), <any>Validators.maxLength(20) ]), |
20 | password: new Control('', Validators.compose([ Validators.required, Validators.minLength(6) ])), | 24 | password: new FormControl('', [ <any>Validators.required, <any>Validators.minLength(6) ]), |
21 | }); | 25 | }); |
22 | } | 26 | } |
23 | 27 | ||
24 | addUser(username: string, password: string) { | 28 | addUser() { |
25 | this.error = null; | 29 | this.error = null; |
26 | 30 | ||
27 | this.userService.addUser(username, password).subscribe( | 31 | this.userService.addUser(this.username, this.password).subscribe( |
28 | ok => this.router.navigate([ '/admin/users/list' ]), | 32 | ok => this.router.navigate([ '/admin/users/list' ]), |
29 | 33 | ||
30 | err => this.error = err | 34 | err => this.error = err |