1 import { Component, OnInit } from '@angular/core'
2 import { FormBuilder, FormGroup } from '@angular/forms'
3 import { Router } from '@angular/router'
5 import { NotificationsService } from 'angular2-notifications'
7 import { UserService } from '../shared'
13 } from '../../../shared'
14 import { ServerService } from '../../../core'
15 import { UserCreate } from '../../../../../../shared'
16 import { UserEdit } from './user-edit'
19 selector: 'my-user-add',
20 templateUrl: './user-edit.component.html',
21 styleUrls: [ './user-edit.component.scss' ]
23 export class UserAddComponent extends UserEdit implements OnInit {
33 validationMessages = {
34 'username': USER_USERNAME.MESSAGES,
35 'email': USER_EMAIL.MESSAGES,
36 'password': USER_PASSWORD.MESSAGES,
37 'videoQuota': USER_VIDEO_QUOTA.MESSAGES
41 protected serverService: ServerService,
42 private formBuilder: FormBuilder,
43 private router: Router,
44 private notificationsService: NotificationsService,
45 private userService: UserService
51 this.form = this.formBuilder.group({
52 username: [ '', USER_USERNAME.VALIDATORS ],
53 email: [ '', USER_EMAIL.VALIDATORS ],
54 password: [ '', USER_PASSWORD.VALIDATORS ],
55 videoQuota: [ '-1', USER_VIDEO_QUOTA.VALIDATORS ]
58 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
66 this.error = undefined
68 const userCreate: UserCreate = this.form.value
70 // A select in HTML is always mapped as a string, we convert it to number
71 userCreate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
73 this.userService.addUser(userCreate).subscribe(
75 this.notificationsService.success('Success', `User ${userCreate.username} created.`)
76 this.router.navigate([ '/admin/users/list' ])
79 err => this.error = err
87 getFormButtonTitle () {