ff staff web : generate org selector by perms
authorBill Erickson <berick@esilibrary.com>
Mon, 28 Oct 2013 13:11:40 +0000 (09:11 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 28 Oct 2013 13:11:40 +0000 (09:11 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/fulfillment/index.tt2
Open-ILS/web/js/ui/default/staff/fulfillment/app.js

index be86b3f..ce0c312 100644 (file)
     </div>
   </body>
   [% INCLUDE "staff/t_base_js.tt2" %]
+  <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/user.js"></script>
   <script src="[% ctx.media_prefix %]/js/ui/default/staff/fulfillment/app.js"></script>
 </html>
index 2ed28fe..78db9fb 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 
-angular.module('ffMain', ['ngRoute', 'egCoreMod', 'egUiMod'])
+angular.module('ffMain', ['ngRoute', 'egCoreMod', 'egUiMod', 'egUserMod'])
 
 .config(function($routeProvider, $locationProvider) {
 
@@ -48,9 +48,13 @@ angular.module('ffMain', ['ngRoute', 'egCoreMod', 'egUiMod'])
 ['$rootScope', 'egOrg', 'egAuth', 
 function($rootScope, egOrg, egAuth) {
     return {
-        orgList : function() {
-            // we want all orgs
-            return egOrg.list();
+        orgList : function(newList) {
+            if (newList) {
+                this._orgList = newList;
+            } else if (!this._orgList) {
+                this._orgList = egOrg.list();
+            } 
+            return this._orgList;
         },
 
         // currently selected org unit
@@ -78,12 +82,22 @@ function($rootScope, egOrg, egAuth) {
  * selector.
  */
 .controller('FFMainCtrl', 
-['$scope', '$route', 'egStartup', 'ffService', 'egAuth',
-function ($scope, $route, egStartup, ffService, egAuth) {
+['$scope', '$route', 'egStartup', 'ffService', 'egAuth', 'egUser',
+function ($scope, $route, egStartup, ffService, egAuth, egUser) {
 
     // run after startup so we can guarantee access to org units
     egStartup.go().then(function() {
-        $scope.ffService = ffService;
+        // after startup, we want to fetch the perm orgs for our 
+        // logged in user.  From there, we can drive the org selector
+        // TODO: we need an FF-specific perm, since login perms are 
+        // all or none.
+        egUser.hasPermAt('STAFF_LOGIN') 
+        .then(function(orgList) {
+            console.log('setting login list at ' + 
+                orgList.map(function(org) { return org.shortname() }));
+            ffService.orgList(orgList);
+            $scope.ffService = ffService;
+        });
     });
 
     // change the selected org unit and re-draw the page