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