LP#1452950 patron reg initial save operation
authorBill Erickson <berickxx@gmail.com>
Mon, 14 Sep 2015 02:03:47 +0000 (22:03 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 25 Feb 2016 22:31:56 +0000 (17:31 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/templates/staff/circ/patron/reg_actions.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js

index 12aa57f..a35b949 100644 (file)
@@ -23,7 +23,8 @@
 <div class="flex-cell"></div>
 <div>
   <span class="pad-all-min">
-    <button type="button" class="btn btn-default">[% l('Save') %]</button>
+    <button type="button" class="btn btn-default" 
+      ng-click="edit_passthru.save()">[% l('Save') %]</button>
   </span>
   <span class="pad-all-min">
     <button type="button" class="btn btn-default">[% l('Save & Clone') %]</button>
index 5fd2273..c88dbee 100644 (file)
@@ -299,7 +299,7 @@ angular.module('egCoreMod')
         );
 
         angular.forEach(patron.cards, function(card) {
-            card.active = card.active == 't'
+            card.active = card.active == 't';
             if (card.id == patron.card.id)
                 card._primary = 'on';
         });
@@ -329,6 +329,74 @@ angular.module('egCoreMod')
         };
     }
 
+    // translate the patron back into IDL form
+    service.save_patron = function(phash) {
+
+        var patron = new egCore.idl.au();
+
+        for (var key in phash) {
+            if (typeof patron[key] == 'function')
+                patron[key](phash[key]);
+        }
+
+        patron.home_ou(patron.home_ou().id());
+        patron.expire_date(
+            patron.expire_date().toISOString().replace(/T.*/,''));
+        patron.dob(patron.dob().toISOString().replace(/T.*/,''));
+        patron.profile(patron.profile().id());
+        patron.net_access_level(patron.net_access_level().id());
+        patron.ident_type(patron.ident_type().id());
+
+        angular.forEach(
+            ['juvenile', 'barred', 'active', 'master_account'],
+            function(field) { patron[field](phash[field] ? 't' : 'f'); }
+        );
+
+        var card_hashes = patron.cards();
+        patron.cards([]);
+        angular.forEach(card_hashes, function(chash) {
+            var card = new egCore.idl.ac();
+            patron.cards().push(card);
+            for (var key in chash) {
+                if (typeof card[key] == 'function') 
+                    card[key](chash[key]);
+            }
+            card.usr(patron.id());
+            card.active(chash.active ? 't' : 'f');
+
+            if (chash._primary) {
+                patron.card(card);
+            }
+        });
+
+        var addr_hashes = patron.addresses();
+        patron.addresses([]);
+        angular.forEach(addr_hashes, function(addr_hash) {
+            var addr = new egCore.idl.aua();
+            patron.addresses().push(addr);
+            for (var key in addr_hash) {
+                if (typeof addr[key] == 'function') 
+                    addr[key](addr_hash[key]);
+            }
+
+            addr.valid(addr.valid() ? 't' : 'f');
+            addr.within_city_limits(addr.within_city_limits() ? 't' : 'f');
+            if (addr_hash._is_mailing) patron.mailing_address(addr);
+            if (addr_hash._is_billing) patron.billing_address(addr);
+        });
+
+        egCore.net.request(
+            'open-ils.actor', 
+            'open-ils.actor.patron.update',
+            egCore.auth.token(), patron)
+        .then(function(resp) {
+            // TODO: see original
+            console.log(js2JSON(resp));
+        });
+
+        console.log(js2JSON(patron));
+    }
+
     return service;
 }]);
 
@@ -542,6 +610,10 @@ function PatronRegCtrl($scope, $routeParams,
         );
     }
 
+    $scope.edit_passthru.save = function() {
+        patronRegSvc.save_patron($scope.patron);        
+    }
+
 }