webstaff: new egShareDepthSelector directive
authorGalen Charlton <gmc@equinoxinitiative.org>
Tue, 9 May 2017 18:56:04 +0000 (14:56 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 9 May 2017 18:56:04 +0000 (14:56 -0400)
This directive implements a selector for OU-sharing depths; depths
and names come from the actor.org_unit_type table. If there are
multiple types defined for a given depth, the display value in
the selector is the concatenation of their names.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/staff/share/t_share_depth_selector.tt2 [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/services/ui.js

diff --git a/Open-ILS/src/templates/staff/share/t_share_depth_selector.tt2 b/Open-ILS/src/templates/staff/share/t_share_depth_selector.tt2
new file mode 100644 (file)
index 0000000..2633eac
--- /dev/null
@@ -0,0 +1,4 @@
+<select
+  ng-options="item.id as item.name for item in values"
+  ng-model="ngModel"
+</select>
index 7328e7d..cef719e 100644 (file)
@@ -793,6 +793,42 @@ function($window , egStrings) {
     }
 })
 
+/*
+ *  egShareDepthSelector - widget for selecting a share depth
+ */
+.directive('egShareDepthSelector', function() {
+    return {
+        restrict : 'E',
+        transclude : true,
+        scope : {
+            ngModel : '=',
+        },
+        require: 'ngModel',
+        templateUrl : './share/t_share_depth_selector',
+        controller : ['$scope','egCore', function($scope , egCore) {
+            $scope.values = [];
+            egCore.pcrud.search('aout',
+                { id : {'!=' : null} },
+                { order_by : {aout : ['depth', 'name']} },
+                { atomic : true }
+            ).then(function(list) {
+                var scratch = [];
+                angular.forEach(list, function(aout) {
+                    var depth = parseInt(aout.depth());
+                    if (depth in scratch) {
+                        scratch[depth].push(aout.name());
+                    } else {
+                        scratch[depth] = [ aout.name() ]
+                    }
+                });
+                scratch.forEach(function(val, idx) {
+                    $scope.values.push({ id : idx,  name : scratch[idx].join(' / ') });
+                });
+            });
+        }]
+    }
+})
+
 .factory('egWorkLog', ['egCore', function(egCore) {
     var service = {};