diff options
Diffstat (limited to 'client/src/app/videos/video-add/video-add.component.ts')
-rw-r--r-- | client/src/app/videos/video-add/video-add.component.ts | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/client/src/app/videos/video-add/video-add.component.ts b/client/src/app/videos/video-add/video-add.component.ts index 6eab54f7e..1e700ae48 100644 --- a/client/src/app/videos/video-add/video-add.component.ts +++ b/client/src/app/videos/video-add/video-add.component.ts | |||
@@ -30,6 +30,10 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
30 | currentTag: VIDEO_TAGS.MESSAGES | 30 | currentTag: VIDEO_TAGS.MESSAGES |
31 | }; | 31 | }; |
32 | 32 | ||
33 | // Special error messages | ||
34 | tagsError = ''; | ||
35 | fileError = ''; | ||
36 | |||
33 | constructor( | 37 | constructor( |
34 | private authService: AuthService, | 38 | private authService: AuthService, |
35 | private elementRef: ElementRef, | 39 | private elementRef: ElementRef, |
@@ -57,30 +61,6 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
57 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); | 61 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); |
58 | } | 62 | } |
59 | 63 | ||
60 | getInvalidFieldsTitle() { | ||
61 | let title = ''; | ||
62 | const nameControl = this.form.controls['name']; | ||
63 | const descriptionControl = this.form.controls['description']; | ||
64 | |||
65 | if (!nameControl.valid) { | ||
66 | title += 'A name is required\n'; | ||
67 | } | ||
68 | |||
69 | if (this.tags.length === 0) { | ||
70 | title += 'At least one tag is required\n'; | ||
71 | } | ||
72 | |||
73 | if (this.filename === null) { | ||
74 | title += 'A file is required\n'; | ||
75 | } | ||
76 | |||
77 | if (!descriptionControl.valid) { | ||
78 | title += 'A description is required\n'; | ||
79 | } | ||
80 | |||
81 | return title; | ||
82 | } | ||
83 | |||
84 | ngOnInit() { | 64 | ngOnInit() { |
85 | this.uploader = new FileUploader({ | 65 | this.uploader = new FileUploader({ |
86 | authToken: this.authService.getRequestHeaderValue(), | 66 | authToken: this.authService.getRequestHeaderValue(), |
@@ -104,6 +84,24 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
104 | this.buildForm(); | 84 | this.buildForm(); |
105 | } | 85 | } |
106 | 86 | ||
87 | checkForm() { | ||
88 | this.forceCheck(); | ||
89 | |||
90 | if (this.tags.length === 0) { | ||
91 | this.tagsError = 'You have 0 tags'; | ||
92 | } | ||
93 | |||
94 | if (this.filename === null) { | ||
95 | this.fileError = 'You did not add a file.'; | ||
96 | } | ||
97 | |||
98 | return this.form.valid === true && this.tagsError === '' && this.fileError === ''; | ||
99 | } | ||
100 | |||
101 | fileChanged() { | ||
102 | this.fileError = ''; | ||
103 | } | ||
104 | |||
107 | onTagKeyPress(event: KeyboardEvent) { | 105 | onTagKeyPress(event: KeyboardEvent) { |
108 | const currentTag = this.form.value['currentTag']; | 106 | const currentTag = this.form.value['currentTag']; |
109 | 107 | ||
@@ -121,6 +119,8 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
121 | if (this.tags.length >= 3) { | 119 | if (this.tags.length >= 3) { |
122 | this.form.get('currentTag').disable(); | 120 | this.form.get('currentTag').disable(); |
123 | } | 121 | } |
122 | |||
123 | this.tagsError = ''; | ||
124 | } | 124 | } |
125 | } | 125 | } |
126 | } | 126 | } |
@@ -135,6 +135,10 @@ export class VideoAddComponent extends FormReactive implements OnInit { | |||
135 | } | 135 | } |
136 | 136 | ||
137 | upload() { | 137 | upload() { |
138 | if (this.checkForm() === false) { | ||
139 | return; | ||
140 | } | ||
141 | |||
138 | const item = this.uploader.queue[0]; | 142 | const item = this.uploader.queue[0]; |
139 | // TODO: wait for https://github.com/valor-software/ng2-file-upload/pull/242 | 143 | // TODO: wait for https://github.com/valor-software/ng2-file-upload/pull/242 |
140 | item.alias = 'videofile'; | 144 | item.alias = 'videofile'; |