LP1956790 Support applying item alerts via templates
authorBill Erickson <berickxx@gmail.com>
Fri, 8 Jul 2022 15:17:51 +0000 (11:17 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Tue, 12 Jul 2022 13:54:59 +0000 (09:54 -0400)
Fixes an issue where item alerts contained within copy templates failed
to apply when using the new Angular holdings editor.

Testing note: if you add an item alert by applying a template, it currently
will not be displayed in the item alerts dialog until you save the item.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts

index 51621ae..805f888 100644 (file)
@@ -528,9 +528,38 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
 
             if (field === 'statcats') {
                 Object.keys(value).forEach(catId => {
-                    this.statCatValues[+catId] = value[+catId];
-                    this.statCatChanged(+catId);
+                    if (value[+catId] !== null) {
+                        this.statCatValues[+catId] = value[+catId];
+                        this.statCatChanged(+catId);
+                    }
+                });
+                return;
+            }
+
+            // Copy alerts are stored as hashes of the bits we need.
+            // Templates can be used to create alerts, but not edit them.
+            if (field === 'copy_alerts' && Array.isArray(value)) {
+                value.forEach(a => {
+                    this.context.copyList().forEach(copy => {
+                        const newAlert = this.idl.create('aca');
+                        newAlert.isnew(true);
+                        newAlert.copy(copy.id());
+                        newAlert.alert_type(a.alert_type);
+                        newAlert.temp(a.temp);
+                        newAlert.note(a.note);
+                        newAlert.create_staff(this.auth.user().id());
+                        newAlert.create_time('now');
+
+                        if (Array.isArray(copy.copy_alerts())) {
+                            copy.copy_alerts().push(newAlert);
+                        } else {
+                            copy.copy_alerts([newAlert]);
+                        }
+
+                        copy.ischanged(true);
+                    });
                 });
+
                 return;
             }
 
index 1d42d97..400825e 100644 (file)
@@ -226,6 +226,7 @@ export class VolCopyService {
         copy.parts([]);
         copy.tags([]);
         copy.notes([]);
+        copy.copy_alerts([]);
         copy.stat_cat_entries([]);
 
         return copy;