]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/cat/volcopy/config.component.ts
LP1959048: manual ng lint fixes
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / cat / volcopy / config.component.ts
1 import {Component, Input, OnInit, DoCheck} from '@angular/core';
2 import {Router, ActivatedRoute} from '@angular/router';
3 import {IdlService} from '@eg/core/idl.service';
4 import {VolCopyContext} from './volcopy';
5 import {VolCopyService} from './volcopy.service';
6
7 @Component({
8   selector: 'eg-volcopy-config',
9   templateUrl: 'config.component.html'
10 })
11 export class VolCopyConfigComponent implements OnInit, DoCheck {
12
13     @Input() context: VolCopyContext;
14
15     defaultsCopy: any;
16
17     constructor(
18         private router: Router,
19         private route: ActivatedRoute,
20         private idl: IdlService,
21         public  volcopy: VolCopyService
22     ) {}
23
24     ngOnInit() {
25         console.debug('DEFAULTS', this.volcopy.defaults);
26
27         // Not an IDL object, but clones just the same
28         this.defaultsCopy = this.idl.clone(this.volcopy.defaults);
29     }
30
31     // Watch for changes in the form and auto-save them.
32     ngDoCheck() {
33         const hidden = this.volcopy.defaults.hidden;
34         for (const key in hidden) {
35             if (hidden[key] !== this.defaultsCopy.hidden[key]) {
36                 this.save();
37                 return;
38             }
39         }
40
41         const values = this.volcopy.defaults.values;
42         for (const key in values) {
43             if (values[key] !== this.defaultsCopy.values[key]) {
44                 this.save();
45                 return;
46             }
47         }
48     }
49
50     save() {
51         this.volcopy.saveDefaults().then(_ =>
52             this.defaultsCopy = this.idl.clone(this.volcopy.defaults)
53         );
54     }
55 }
56
57