Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. import { Component } from '@angular/core';
  2. import { IonicPage, ViewController, NavParams } from 'ionic-angular';
  3. import { FormBuilder, FormGroup, Validators } from '@angular/forms';
  4. import { UUID } from 'angular2-uuid';
  5.  
  6. import { WorkItem, Task } from '../../commons/types';
  7. import { TaskModel } from '../../models/task-model';
  8.  
  9. @IonicPage()
  10. @Component({
  11. selector: 'page-task',
  12. templateUrl: 'task.html',
  13. })
  14. export class TaskPage {
  15. workitem: WorkItem;
  16. task: Task;
  17. title: string;
  18. taskForm: FormGroup;
  19.  
  20. constructor(public viewCtrl: ViewController, public navParams: NavParams, public formBuilder: FormBuilder) {
  21. this.task = this.navParams.get('task');
  22. this.workitem = this.navParams.get('workitem');
  23.  
  24. this.title = this.task ? this.task.title : 'New Task';
  25.  
  26. this.taskForm = formBuilder.group({
  27. title: [this.task ? this.task.title : '', Validators.required],
  28. detail: [this.task ? this.task.detail : ''],
  29. completed: [this.task ? this.task.completed : false]
  30. });
  31. }
  32.  
  33. saveForm() {
  34. if (this.task) {
  35. this.task.update(this.taskForm.value.title, this.taskForm.value.detail, this.taskForm.value.completed);
  36. }
  37. else {
  38. let task = new TaskModel(UUID.UUID(), this.taskForm.value.title, this.taskForm.value.detail, [], [], this.taskForm.value.completed);
  39. this.workitem.addTask(task);
  40. }
  41. this.viewCtrl.dismiss();
  42. }
  43.  
  44. close() {
  45. this.viewCtrl.dismiss();
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement