patron edit; plug in editor xulG handlers
authorBill Erickson <berick@esilibrary.com>
Tue, 15 Jul 2014 16:01:05 +0000 (12:01 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 15 Jul 2014 16:01:05 +0000 (12:01 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/circ/patron/index.tt2
Open-ILS/src/templates/staff/circ/patron/t_edit.tt2
Open-ILS/web/js/ui/default/actor/user/register.js
Open-ILS/web/js/ui/default/staff/circ/patron/app.js
Open-ILS/web/js/ui/default/staff/circ/patron/register.js
Open-ILS/web/js/ui/default/staff/services/env.js
Open-ILS/web/js/ui/default/staff/services/lframe.js

index 82b6283..4f38659 100644 (file)
@@ -9,6 +9,7 @@
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/grid.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/ui.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/user.js"></script>
+<script src="[% ctx.media_prefix %]/js/ui/default/staff/services/lframe.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/circ/services/billing.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/circ/services/circ.js"></script>
 [% INCLUDE 'staff/circ/share/circ_strings.tt2' %]
index 02e2e0a..379444a 100644 (file)
@@ -1,6 +1,3 @@
-<div class="row pad-vert">
-  <div class="col-md-10 col-md-offset-1">
-    <div class="alert alert-warning">[% l('EDIT Development Pending') %]</div>
-  </div>
-</div>
+<!-- insert the patron registration UI -->
+<eg-legacy-frame url="patron_edit_url" handlers="funcs"></eg-legacy-frame>
 
index fe5f0c9..6100a9b 100644 (file)
@@ -2010,6 +2010,7 @@ function uEditFinishSave(newPatron, doClone) {
 
                if(xulG && typeof xulG.spawn_editor == 'function' && !patron.isnew() ) {
             window.xulG.spawn_editor({ses:openils.User.authtoken,clone:cloneUser});
+            return;
             uEditRefresh();
 
                } else {
index 20f1f96..b150528 100644 (file)
@@ -226,7 +226,8 @@ function($q , $timeout , $location , egCore,  egUser , $locale) {
 
     // shortcut to force-reload the current primary
     service.refreshPrimary = function() {
-        return service.setPrimary(null, service.current, true);
+        if (!service.current) return $q.when();
+        return service.setPrimary(service.current.id(), null, true);
     }
 
     // sets the primary display user, fetching data as necessary.
@@ -1111,9 +1112,23 @@ function($scope , $q , $routeParams,  egCore , $modal , patronSvc) {
  * Link to patron edit UI
  */
 .controller('PatronEditCtrl',
-       ['$scope','$routeParams','egCore',
-function($scope,  $routeParams,  egCore) {
+       ['$scope','$routeParams','$location','egCore','patronSvc',
+function($scope,  $routeParams,  $location , egCore , patronSvc) {
     $scope.initTab('edit', $routeParams.id);
+
+    var url = $location.absUrl().replace(/\/staff.*/, '/actor/user/register');
+
+    // since we don't store auth cookies, pass the ses via URL
+    url += '?ses=' + egCore.auth.token();
+    url += '&usr=' + encodeURIComponent($routeParams.id);
+
+    $scope.funcs = {
+        on_save : function() {
+            patronSvc.refreshPrimary();
+        }
+    }
+
+    $scope.patron_edit_url = url;
 }])
 
 /**
index 0550be5..a74b023 100644 (file)
@@ -66,6 +66,7 @@ function($scope , $routeParams , $location , $filter , egCore) {
         url += '&clone=' + encodeURIComponent($routeParams.clone_id);
     }
 
+    // pass the reg URL into the scope, thus into the 
     $scope.reg_url = url;
 }])
  
index b8ddd7b..fb1e120 100644 (file)
@@ -1,9 +1,22 @@
 /**
  * Core Service - egEnv
  *
- * Manages startup data loading.  All registered loaders run 
- * simultaneously.  When all promises are resolved, the promise
- * returned by egEnv.load() is resolved.
+ * Manages startup data loading and data caching.  
+ * All registered loaders run * simultaneously.  When all promises 
+ * are resolved, the promise * returned by egEnv.load() is resolved.
+ *
+ * There are two main uses cases for egEnv:
+ *
+ * 1. When loading a variety of objects on page load, having them
+ * loaded with egEnv ensures that the load will happen in parallel
+ * and that it will complete before egStartup completes, which is 
+ * generally before page controllers run.
+ *
+ * 2. When loading generic IDL data across different services,
+ * having them all stash the data in egEnv means they each have
+ * an agreed-upon cache mechanism.
+ *
+ * It's also a good place to stash other environmental tidbits...
  *
  * Generic and class-based loaders are supported.  
  *
@@ -41,6 +54,14 @@ function($q,  $window , egAuth,  egPCRUD,  egIDL) {
         loaders : []
     };
 
+
+    // <base href="<basePath>"/> from the current index page
+    // Currently defaults to /eg/staff for all pages.
+    // Use $location.path() to jump around within an app.
+    // Use egEnv.basePath to create URLs to new apps.
+    service.basePath = 
+        $window.document.getElementsByTagName('base')[0].getAttribute('href');
+
     /* returns a promise, loads all of the specified classes */
     service.load = function() {
         // always assume the user is logged in
index 053cb45..26adcdd 100644 (file)
@@ -8,20 +8,34 @@ angular.module('egCoreMod')
         restrict : 'AE',
         replace : true,
         scope : {
-            url : '='
+            // URL to load in the legacy iframe
+            url : '=',
+
+            // optional hash of functions which augment or override 
+            // the stock xulG functions defined below.
+            handlers : '='
         },
 
         template : '<iframe src="{{url}}" onload="egLegacyFrameLoader(this)" '
             + 'class="eg-legacy-frame" style="height:{{height}}px"></iframe>',
 
         controller : 
-                   ['$scope','$window','$location', 
-            function($scope , $window , $location) {
+                   ['$scope','$window','$location','egCore',
+            function($scope , $window , $location , egCore) {
 
             // Set the iframe height to just under the window height.
             // leave room for the navbar, padding, margins, etc.
             $scope.height = $window.outerHeight - 250;
 
+            // $location has functions for modifying paths and search,
+            // but they all assume you are staying within the angular
+            // app, which we are not.  Build the URLs by hand.
+            function open_tab(path) {
+                var url = 'https://' + $window.location.hostname + 
+                    egCore.env.basePath + path;
+                console.debug('egLegacyFrame opening tab ' + url);
+                $window.open(url, '_blank').focus();
+            }
 
             // define our own xulG functions to be inserted into the
             // iframe.  NOTE: window-level functions are bad.  Though
@@ -31,17 +45,51 @@ angular.module('egCoreMod')
             // for porting dojo, etc. apps to angular apps and should
             // eventually go away.
             $window.egLegacyFrameLoader = function(iframe) {
+
+                // tell the iframe'd window its inside the staff client
+                iframe.contentWindow.IAMXUL = true;
+
+                // also tell it it's inside the browser client, which 
+                // may be needed in a few special cases.
+                iframe.contentWindow.IAMBROWSER = true;
+
+                // define a few commonly used stock xulG handlers. 
                 
                 iframe.contentWindow.xulG = {
-
                     // patron search
                     spawn_search : function(search) {
-                        $window.open(
-                            $location.path('/circ/patron/search').
-                                search({search : js2JSON(search)}).absUrl(),
-                            '_blank'
-                        ).focus();
-                    }
+                        open_tab('/circ/patron/search?search=' 
+                            + encodeURIComponent(js2JSON(search)));
+                    },
+
+                    // edit an existing user
+                    spawn_editor : function(info) {
+                        if (info.usr) {
+                            open_tab('/circ/patron/register/edit/' + info.usr);
+                        
+                        } else if (info.clone) {
+                            // FIXME: The save-and-clone operation in the
+                            // patron editor results in this action.  
+                            // For some reason, this specific function results
+                            // in a new browser window opening instead of a 
+                            // browser tab.  Possibly this is caused by the 
+                            // fact that the action occurs as a result of a
+                            // button click instead of an href.  *shrug*.
+                            // It's obnoxious.
+                            open_tab('/circ/patron/register/clone/' + info.clone);
+                        } 
+                    },
+
+                    // open a user account
+                    new_patron_tab : function(tab_info, usr_info) {
+                        open_tab('/circ/patron/' + usr_info.id + '/checkout');
+                    }  
+                }
+
+                if ($scope.handlers) {
+                    angular.forEach($scope.handlers, function(val, key) {
+                        iframe.contentWindow.xulG[key] = val;
+                    });
                 }
             }
         }]