aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/admin/friends
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-09-09 22:16:51 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-09-09 22:16:51 +0200
commit4b2f33f3c6d109365090b08244d7f99ad4e69025 (patch)
tree700d3e8e14efc4172f754d75c041ec507100e897 /client/src/app/admin/friends
parentab32b0fc805b92c5a1d7ac5901cb1a38e94622ca (diff)
downloadPeerTube-4b2f33f3c6d109365090b08244d7f99ad4e69025.tar.gz
PeerTube-4b2f33f3c6d109365090b08244d7f99ad4e69025.tar.zst
PeerTube-4b2f33f3c6d109365090b08244d7f99ad4e69025.zip
Client: reactive forms
Diffstat (limited to 'client/src/app/admin/friends')
-rw-r--r--client/src/app/admin/friends/friend-add/friend-add.component.html6
-rw-r--r--client/src/app/admin/friends/friend-add/friend-add.component.ts15
2 files changed, 11 insertions, 10 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 5b8dc8d87..788f3b44d 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,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 (ngSubmit)="makeFriends()" [formGroup]="friendAddForm"> 5<form (ngSubmit)="makeFriends()" [formGroup]="form">
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 8
9 <div class="input-group"> 9 <div class="input-group">
10 <input 10 <input
11 type="text" class="form-control" placeholder="http://domain.com" 11 type="text" class="form-control" placeholder="http://domain.com"
12 [name]="'url-' + id" [id]="'url-' + id" [formControlName]="'url-' + id" [(ngModel)]="urls[id]" 12 [id]="'url-' + id" [formControlName]="'url-' + id"
13 /> 13 />
14 <span class="input-group-btn"> 14 <span class="input-group-btn">
15 <button *ngIf="displayAddField(id)" (click)="addField()" class="btn btn-default" type="button">+</button> 15 <button *ngIf="displayAddField(id)" (click)="addField()" class="btn btn-default" type="button">+</button>
@@ -17,7 +17,7 @@
17 </span> 17 </span>
18 </div> 18 </div>
19 19
20 <div [hidden]="friendAddForm.controls['url-' + id].valid || friendAddForm.controls['url-' + id].pristine" class="alert alert-warning"> 20 <div [hidden]="form.controls['url-' + id].valid || form.controls['url-' + id].pristine" class="alert alert-warning">
21 It should be a valid url. 21 It should be a valid url.
22 </div> 22 </div>
23 </div> 23 </div>
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 55aed9156..68363b482 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
@@ -11,19 +11,19 @@ import { FriendService } from '../shared';
11 styles: [ require('./friend-add.component.scss') ] 11 styles: [ require('./friend-add.component.scss') ]
12}) 12})
13export class FriendAddComponent implements OnInit { 13export class FriendAddComponent implements OnInit {
14 friendAddForm: FormGroup; 14 form: FormGroup;
15 urls = [ ]; 15 urls = [ ];
16 error: string = null; 16 error: string = null;
17 17
18 constructor(private router: Router, private friendService: FriendService) {} 18 constructor(private router: Router, private friendService: FriendService) {}
19 19
20 ngOnInit() { 20 ngOnInit() {
21 this.friendAddForm = new FormGroup({}); 21 this.form = new FormGroup({});
22 this.addField(); 22 this.addField();
23 } 23 }
24 24
25 addField() { 25 addField() {
26 this.friendAddForm.addControl(`url-${this.urls.length}`, new FormControl('', [ validateUrl ])); 26 this.form.addControl(`url-${this.urls.length}`, new FormControl('', [ validateUrl ]));
27 this.urls.push(''); 27 this.urls.push('');
28 } 28 }
29 29
@@ -42,7 +42,7 @@ export class FriendAddComponent implements OnInit {
42 isFormValid() { 42 isFormValid() {
43 // Do not check the last input 43 // Do not check the last input
44 for (let i = 0; i < this.urls.length - 1; i++) { 44 for (let i = 0; i < this.urls.length - 1; i++) {
45 if (!this.friendAddForm.controls[`url-${i}`].valid) return false; 45 if (!this.form.controls[`url-${i}`].valid) return false;
46 } 46 }
47 47
48 const lastIndex = this.urls.length - 1; 48 const lastIndex = this.urls.length - 1;
@@ -50,13 +50,13 @@ export class FriendAddComponent implements OnInit {
50 if (this.urls[lastIndex] === '' && lastIndex !== 0) { 50 if (this.urls[lastIndex] === '' && lastIndex !== 0) {
51 return true; 51 return true;
52 } else { 52 } else {
53 return this.friendAddForm.controls[`url-${lastIndex}`].valid; 53 return this.form.controls[`url-${lastIndex}`].valid;
54 } 54 }
55 } 55 }
56 56
57 removeField(index: number) { 57 removeField(index: number) {
58 // Remove the last control 58 // Remove the last control
59 this.friendAddForm.removeControl(`url-${this.urls.length - 1}`); 59 this.form.removeControl(`url-${this.urls.length - 1}`);
60 this.urls.splice(index, 1); 60 this.urls.splice(index, 1);
61 } 61 }
62 62
@@ -94,7 +94,8 @@ export class FriendAddComponent implements OnInit {
94 private getNotEmptyUrls() { 94 private getNotEmptyUrls() {
95 const notEmptyUrls = []; 95 const notEmptyUrls = [];
96 96
97 this.urls.forEach((url) => { 97 Object.keys(this.form.value).forEach((urlKey) => {
98 const url = this.form.value[urlKey];
98 if (url !== '') notEmptyUrls.push(url); 99 if (url !== '') notEmptyUrls.push(url);
99 }); 100 });
100 101