1 import {Component, Input, ViewChild, TemplateRef, OnInit} from '@angular/core';
2 import {DialogComponent} from '@eg/share/dialog/dialog.component';
3 import {NgForm} from '@angular/forms';
4 import {IdlService, IdlObject} from '@eg/core/idl.service';
5 import {EventService} from '@eg/core/event.service';
6 import {NetService} from '@eg/core/net.service';
7 import {AuthService} from '@eg/core/auth.service';
8 import {PcrudService} from '@eg/core/pcrud.service';
9 import {GridDataSource} from '@eg/share/grid/grid';
10 import {Pager} from '@eg/share/util/pager';
11 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
12 import {StringComponent} from '@eg/share/string/string.component';
13 import {ToastService} from '@eg/share/toast/toast.service';
14 import {PermService} from '@eg/core/perm.service';
15 import {ComboboxComponent} from '@eg/share/combobox/combobox.component';
16 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
17 import {Observable} from 'rxjs';
18 import {map} from 'rxjs/operators';
21 selector: 'eg-fund-transfer-dialog',
22 templateUrl: './fund-transfer-dialog.component.html'
25 export class FundTransferDialogComponent
26 extends DialogComponent implements OnInit {
28 @Input() sourceFund: IdlObject;
31 @ViewChild('successString', { static: true }) successString: StringComponent;
32 @ViewChild('updateFailedString', { static: false }) updateFailedString: StringComponent;
33 @ViewChild('fundSelector', { static: false }) tagSelector: ComboboxComponent;
35 fundDataSource: (term: string) => Observable<ComboboxEntry>;
36 destFund: ComboboxEntry = null;
41 private idl: IdlService,
42 private evt: EventService,
43 private net: NetService,
44 private auth: AuthService,
45 private pcrud: PcrudService,
46 private perm: PermService,
47 private toast: ToastService,
48 private modal: NgbModal
55 this.onOpen$.subscribe(() => this._initRecord());
56 this.fundDataSource = term => {
59 const extra_args = { order_by : {} };
60 args[field] = {'ilike': `%${term}%`}; // could -or search on label
62 extra_args['order_by']['acqf'] = field;
63 extra_args['limit'] = 100;
64 extra_args['flesh'] = 1;
65 const flesh_fields: Object = {};
66 flesh_fields['acqf'] = ['org'];
67 extra_args['flesh_fields'] = flesh_fields;
68 return this.pcrud.search('acqf', args, extra_args).pipe(map(data => {
72 + ' (' + data.year() + ')'
73 + ' (' + data.org().shortname() + ')',
80 private _initRecord() {
81 this.doneLoading = false;
82 this.destFund = { id: null }; // destFund is a ComoboxEntry, so
83 // we need to clear it like this
84 this.sourceAmount = null;
86 this.doneLoading = true;
92 'open-ils.acq.funds.transfer_money',
101 this.successString.current()
102 .then(str => this.toast.success(str));
106 this.updateFailedString.current()
107 .then(str => this.toast.danger(str));