.then(yes => {
if (!yes) { return; }
- return this.net.request('open-ils.cat',
- 'open-ils.cat.biblio.record_entry.delete',
- this.auth.token(), this.record.id).toPromise()
-
- .then(resp => {
-
- const evt = this.evt.parse(resp);
- if (evt) {
- if (evt.textcode === 'RECORD_NOT_EMPTY') {
- return this.cannotDelete.open().toPromise();
- } else {
- console.error(evt);
- return alert(evt);
- }
- }
- return this.fromId(this.record.id)
- .then(_ => this.recordSaved.emit(
- {marcXml: this.record.toXml(), recordId: this.recordId}));
+ let promise;
+ if (this.recordType === 'authority') {
+ promise = this.deleteAuthorityRecord();
+ } else {
+ promise = this.deleteBibRecord();
+ }
+
+ return promise.then(ok => {
+ if (!ok) { return; }
+
+ return this.fromId(this.record.id).then(_ => {
+ this.recordSaved.emit({
+ marcXml: this.record.toXml(),
+ recordId: this.recordId
+ });
+ });
});
});
}
+ deleteAuthorityRecord(): Promise<boolean> {
+ return this.pcrud.retrieve('are', this.record.id).toPromise()
+ .then(rec => this.pcrud.remove(rec).toPromise())
+ .then(resp => resp !== null);
+ }
+
+ deleteBibRecord(): Promise<boolean> {
+
+ return this.net.request('open-ils.cat',
+ 'open-ils.cat.biblio.record_entry.delete',
+ this.auth.token(), this.record.id).toPromise()
+
+ .then(resp => {
+
+ const evt = this.evt.parse(resp);
+ if (evt) {
+ if (evt.textcode === 'RECORD_NOT_EMPTY') {
+ return this.cannotDelete.open().toPromise()
+ .then(_ => false);
+ } else {
+ console.error(evt);
+ alert(evt);
+ return false;
+ }
+ }
+
+ return true;
+ });
+ }
+
undeleteRecord(): Promise<any> {
return this.confirmUndelete.open().toPromise()
.then(yes => {
if (!yes) { return; }
- return this.net.request('open-ils.cat',
- 'open-ils.cat.biblio.record_entry.undelete',
- this.auth.token(), this.record.id).toPromise()
-
- .then(resp => {
-
- const evt = this.evt.parse(resp);
- if (evt) { console.error(evt); return alert(evt); }
+ let promise;
+ if (this.recordType === 'authority') {
+ promise = this.undeleteAuthorityRecord();
+ } else {
+ promise = this.undeleteBibRecord();
+ }
+ return promise.then(ok => {
+ if (!ok) { return; }
return this.fromId(this.record.id)
- .then(_ => this.recordSaved.emit(
- {marcXml: this.record.toXml(), recordId: this.recordId}));
+ .then(_ => {
+ this.recordSaved.emit({
+ marcXml: this.record.toXml(),
+ recordId: this.recordId
+ });
+ });
});
});
}
+ undeleteAuthorityRecord(): Promise<any> {
+ return this.pcrud.retrieve('are', this.record.id).toPromise()
+ .then(rec => {
+ rec.deleted('f');
+ return this.pcrud.update(rec).toPromise();
+ }).then(resp => resp !== null);
+ }
+
+ undeleteBibRecord(): Promise<any> {
+
+ return this.net.request('open-ils.cat',
+ 'open-ils.cat.biblio.record_entry.undelete',
+ this.auth.token(), this.record.id).toPromise()
+
+ .then(resp => {
+
+ const evt = this.evt.parse(resp);
+ if (evt) {
+ console.error(evt);
+ alert(evt);
+ return false;
+ }
+
+ return true;
+ });
+ }
+
// Spawns the copy editor with the requested barcode and
// call number label. Called after our record is saved.
fastAdd() {