1 import {Component, Input, ViewChild, OnInit} from '@angular/core';
2 import {AdminPageComponent} from '@eg/staff/share/admin-page/admin-page.component';
3 import {ActivatedRoute} from '@angular/router';
4 import {IdlService, IdlObject} from '@eg/core/idl.service';
5 import {ToastService} from '@eg/share/toast/toast.service';
6 import {PcrudService} from '@eg/core/pcrud.service';
7 import {OrgService} from '@eg/core/org.service';
8 import {PermService} from '@eg/core/perm.service';
9 import {AuthService} from '@eg/core/auth.service';
10 import {NetService} from '@eg/core/net.service';
11 import {StringComponent} from '@eg/share/string/string.component';
14 templateUrl: './admin-carousel.component.html'
17 export class AdminCarouselComponent extends AdminPageComponent implements OnInit {
22 refreshSelected: (idlThings: IdlObject[]) => void;
23 createNew: () => void;
24 deleteSelected: (idlThings: IdlObject[]) => void;
26 @ViewChild('refreshString', { static: true }) refreshString: StringComponent;
27 @ViewChild('refreshErrString', { static: true }) refreshErrString: StringComponent;
30 route: ActivatedRoute,
37 private net: NetService
39 super(route, idl, org, auth, pcrud, perm, toast);
45 this.classLabel = this.idlClassDef.label;
46 this.includeOrgDescendants = true;
49 this.createNew = () => {
53 this.deleteSelected = (idlThings: IdlObject[]) => {
54 super.deleteSelected(idlThings);
57 this.refreshSelected = (idlThings: IdlObject[]) => {
58 idlThings.forEach(cc => {
59 if (cc.type().automatic() === 't') {
62 'open-ils.actor.carousel.refresh',
63 this.auth.token(), cc.id()
64 ).toPromise(); // fire and forget, as this could take a couple minutes
65 this.refreshString.current({ name: cc.name() }).then(str => this.toast.success(str));
67 this.refreshErrString.current({ name: cc.name() }).then(str => this.toast.warning(str));
73 mungeCarousel(editMode: string, rec: IdlObject) {
74 if (editMode === 'create') {
75 rec.creator(this.auth.user().id());
77 rec.editor(this.auth.user().id());
80 // convert empty string to nulls as needed
82 if (rec.owning_lib_filter() === '') {
83 rec.owning_lib_filter(null);
85 if (rec.copy_location_filter() === '') {
86 rec.copy_location_filter(null);
90 postSave(rec: IdlObject) {
91 if (rec._isfieldmapper) {
92 // if we got an actual IdlObject back, the
93 // record had just been created, not just
94 // edited. therefore, we probably need
95 if (rec.bucket() == null) {
96 const bucket = this.idl.create('cbreb');
97 bucket.owner(this.auth.user().id());
98 bucket.name('System-generated bucket for carousel: ' + rec.id()); // FIXME I18N
99 bucket.btype('carousel');
101 bucket.owning_lib(rec.owner());
105 'open-ils.actor.container.create',
106 this.auth.token(), 'biblio', bucket
109 const ccou = this.idl.create('ccou');
110 ccou.carousel(rec.id());
111 ccou.org_unit(rec.owner());
113 rec.bucket(newBucket);
114 this.pcrud.create(ccou).subscribe(
116 this.pcrud.update(rec).subscribe(
117 ok2 => console.debug('updated'),
118 err => console.error(err),
119 () => { this.grid.reload(); }
122 err => console.error(err),
123 () => { this.grid.reload(); }