CAT-206 Update Date performs pcrud
authorKyle Huckins <khuckins@catalyte.io>
Tue, 26 Feb 2019 18:14:40 +0000 (18:14 +0000)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:51:45 +0000 (15:51 -0400)
- Modify Update Date functionality to perform pcrud
update of cataloging_date

Signed-off-by: Kyle Huckins <khuckins@catalyte.io>
 Changes to be committed:
modified:   Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js

Open-ILS/web/js/ui/default/staff/cat/services/marcedit.js

index 63310ff..83c1e37 100644 (file)
@@ -1194,7 +1194,7 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                         $scope.flat_text_marc = $scope.record.toBreaker();
 
                         if ($scope.record_type == 'bre') {
-                            $scope.cataloging_date = new Date(rec.cataloging_date()) || new Date();
+                            $scope.cataloging_date = Date.parse(rec.cataloging_date()) || new Date();
                         }
                         if ($scope.record_type == 'bre' && !$scope.brandNewRecord) {
                             $scope.bib_source.id = $scope.bibSource = rec.source(); //$scope.Record().source();
@@ -1261,15 +1261,32 @@ angular.module('egMarcMod', ['egCoreMod', 'ui.bootstrap'])
                 };
 
                 $scope.updateDate = function(cataloging_date) {
-                    if (cataloging_date instanceof Date && !isNaN(cataloging_date)) {
-                        $scope.Record().cataloging_date(new Date(cataloging_date).toISOString());
-                    } else if (!cataloging_date) {
-                        $scope.Record.cataloging_date(null);
-                    } else {
-                        return;
+                    if (cataloging_date != $scope.Record().cataloging_date()) {
+                        if (cataloging_date instanceof Date && !isNaN(cataloging_date)) {
+                            saveDate($scope.Record().cataloging_date(), cataloging_date);
+                            $scope.Record().cataloging_date(new Date(cataloging_date).toISOString());
+                        } else if (!cataloging_date) {
+                            saveDate($scope.Record().cataloging_date(), cataloging_date);
+                            $scope.Record().cataloging_date(null);
+                        } else {
+                            return;
+                        }
                     }
                 }
 
+                var saveDate = function(orig_date, new_date) {
+                    egCore.pcrud.retrieve(
+                        $scope.record_type, $scope.Record().id()
+                    ).then(function(rec) {
+                        if (new_date) {
+                            rec.cataloging_date(new Date(new_date).toISOString());
+                        } else {
+                            rec.cataloging_date(null);
+                        }
+                        egCore.pcrud.update(rec);
+                    });
+                }
+
                 $scope.processRedo = function () {
                     if ($scope.record_redo_stack.length) {
                         $scope.in_redo = true;