1 import {Component, Input, ViewChild, OnInit} from '@angular/core';
2 import {Location} from '@angular/common';
3 import {FormatService} from '@eg/core/format.service';
4 import {AdminPageComponent} from '@eg/staff/share/admin-page/admin-page.component';
5 import {ActivatedRoute} from '@angular/router';
6 import {IdlService, IdlObject} from '@eg/core/idl.service';
7 import {ToastService} from '@eg/share/toast/toast.service';
8 import {PcrudService} from '@eg/core/pcrud.service';
9 import {OrgService} from '@eg/core/org.service';
10 import {PermService} from '@eg/core/perm.service';
11 import {AuthService} from '@eg/core/auth.service';
12 import {NetService} from '@eg/core/net.service';
13 import {StringComponent} from '@eg/share/string/string.component';
16 templateUrl: './admin-carousel.component.html'
19 export class AdminCarouselComponent extends AdminPageComponent implements OnInit {
24 refreshSelected: (idlThings: IdlObject[]) => void;
25 createNew: () => void;
26 deleteSelected: (idlThings: IdlObject[]) => void;
28 @ViewChild('refreshString', { static: true }) refreshString: StringComponent;
29 @ViewChild('refreshErrString', { static: true }) refreshErrString: StringComponent;
32 route: ActivatedRoute,
34 format: FormatService,
41 private net: NetService
43 super(route, ngLocation, format, idl, org, auth, pcrud, perm, toast);
49 this.classLabel = this.idlClassDef.label;
50 this.includeOrgDescendants = true;
53 this.createNew = () => {
57 this.deleteSelected = (idlThings: IdlObject[]) => {
58 super.deleteSelected(idlThings);
61 this.refreshSelected = (idlThings: IdlObject[]) => {
62 idlThings.forEach(cc => {
63 if (cc.type().automatic() === 't') {
66 'open-ils.actor.carousel.refresh',
67 this.auth.token(), cc.id()
68 ).toPromise(); // fire and forget, as this could take a couple minutes
69 this.refreshString.current({ name: cc.name() }).then(str => this.toast.success(str));
71 this.refreshErrString.current({ name: cc.name() }).then(str => this.toast.warning(str));
77 mungeCarousel(editMode: string, rec: IdlObject) {
78 if (editMode === 'create') {
79 rec.creator(this.auth.user().id());
81 rec.editor(this.auth.user().id());
84 // convert empty string to nulls as needed
86 if (rec.owning_lib_filter() === '') {
87 rec.owning_lib_filter(null);
89 if (rec.copy_location_filter() === '') {
90 rec.copy_location_filter(null);
94 postSave(rec: IdlObject) {
95 if (rec._isfieldmapper) {
96 // if we got an actual IdlObject back, the
97 // record had just been created, not just
98 // edited. therefore, we probably need
99 if (rec.bucket() == null) {
100 const bucket = this.idl.create('cbreb');
101 bucket.owner(this.auth.user().id());
102 bucket.name('System-generated bucket for carousel: ' + rec.id()); // FIXME I18N
103 bucket.btype('carousel');
105 bucket.owning_lib(rec.owner());
109 'open-ils.actor.container.create',
110 this.auth.token(), 'biblio', bucket
113 const ccou = this.idl.create('ccou');
114 ccou.carousel(rec.id());
115 ccou.org_unit(rec.owner());
117 rec.bucket(newBucket);
118 this.pcrud.create(ccou).subscribe(
120 this.pcrud.update(rec).subscribe(
121 ok2 => console.debug('updated'),
122 err => console.error(err),
123 () => { this.grid.reload(); }
126 err => console.error(err),
127 () => { this.grid.reload(); }