webstaff: Provide hooks for on-save callback for marc edit to, for instance, refresh...
authorMike Rylander <mrylander@gmail.com>
Tue, 15 Sep 2015 21:32:41 +0000 (17:32 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 16 Sep 2015 17:23:55 +0000 (13:23 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/staff/cat/catalog/t_catalog.tt2
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js
Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js

index 62db3ca..8437ee8 100644 (file)
@@ -76,7 +76,7 @@
       <eg-embed-frame save-space="300" frame="opac_iframe" url="catalog_url" handlers="handlers" onchange="handle_page"></eg-embed-frame>
     </div>
     <div ng-show="record_tab == 'marc_edit'">
-      <eg-marc-edit-record dirty-flag="stop_unload" record-id="record_id"/>
+      <eg-marc-edit-record on-save="refresh_record_callback" dirty-flag="stop_unload" record-id="record_id"/>
     </div>
     <!-- ng-if the remaining tabs so they can be instantiated on demand -->
     <div ng-if="record_tab == 'marc_html'">
index f60abf3..80423a1 100644 (file)
@@ -233,6 +233,7 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
 
     // set record ID on page load if available...
     $scope.record_id = $routeParams.record_id;
+    $scope.summary_pane_record;
 
     if ($routeParams.record_id) $scope.from_route = true;
     else $scope.from_route = false;
@@ -325,6 +326,20 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
     if ($scope.record_id)
         egCore.hatch.setLocalItem("eg.cat.last_record_retrieved", $scope.record_id);
 
+    $scope.refresh_record_callback = function (record_id) {
+        egCore.pcrud.retrieve('bre', record_id, {
+            flesh : 1,
+            flesh_fields : {
+                bre : ['simple_record','creator','editor']
+            }
+        }).then(function(rec) {
+            rec.owner(egCore.org.get(rec.owner()));
+            $scope.summary_pane_record = rec;
+        });
+
+        return record_id;
+    }
+
     // also set it when the iframe changes to a new record
     $scope.handle_page = function(url) {
 
index 26a1e6c..d4686eb 100644 (file)
@@ -521,6 +521,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
             dirtyFlag : '=',
             recordId : '=',
             marcXml : '=',
+            onSave : '=',
             // in-place mode means that the editor is being
             // used just to munge some MARCXML client-side, rather
             // than to (immediately) update the database
@@ -545,6 +546,11 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
         controller : ['$timeout','$scope','$q','$window','egCore', 'egTagTable',
             function ( $timeout , $scope , $q,  $window , egCore ,  egTagTable ) {
 
+
+                $scope.onSaveCallback = $scope.onSave;
+                if (typeof $scope.onSaveCallback !== 'undefined' && !angular.isArray($scope.onSaveCallback))
+                    $scope.onSaveCallback = [ $scope.onSaveCallback ];
+
                 MARC21.Record.delimiter = '$';
 
                 $scope.enable_fast_add = false;
@@ -1074,10 +1080,23 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                     });
                 }
 
+                processOnSaveCallbacks = function() {
+                    var deferred = $q.defer();
+                    if (typeof $scope.onSaveCallback !== 'undefined') {
+                        var promise = deferred.promise;
+
+                        angular.forEach($scope.onSaveCallback, function (f) {
+                            if (angular.isFunction(f)) promise = promise.then(f);
+                        });
+
+                    }
+                    return deferred.resolve($scope.recordId)
+                };
+
                 $scope.saveRecord = function () {
                     if ($scope.inPlaceMode) {
                         $scope.marcXml = $scope.record.toXmlString();
-                        return;
+                        return processOnSaveCallbacks();
                     }
                     $scope.mangle_005();
                     $scope.Record().editor(egCore.auth.user().id());
@@ -1110,7 +1129,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                                     }
                                 });
                             }
-                        }).then(loadRecord);
+                        }).then(loadRecord).then(processOnSaveCallbacks);
                     } else {
                         $scope.Record().creator(egCore.auth.user().id());
                         $scope.Record().create_date('now');
@@ -1140,7 +1159,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                                     }
                                 });
                             }
-                        }).then(loadRecord);
+                        }).then(loadRecord).then(processOnSaveCallbacks);
                     }