LP#1452950 Patron reg secondary groups part 1
authorBill Erickson <berickxx@gmail.com>
Thu, 19 Nov 2015 15:04:10 +0000 (10:04 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 25 Feb 2016 22:31:58 +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/t_edit.tt2
Open-ILS/src/templates/staff/circ/patron/t_patron_groups_dialog.tt2 [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/circ/patron/app.js
Open-ILS/web/js/ui/default/staff/circ/patron/regctl.js

index a35e9e4..6e08117 100644 (file)
     </div>
   </div>
   <div class="col-md-3">
-    <button class="btn btn-default">[% l('Secondary Groups') %]</button>
+    <button class="btn btn-default" ng-click="secondary_groups_dialog()">
+        [% l('Secondary Groups') %]
+    </button>
   </div> 
 </div>
 
diff --git a/Open-ILS/src/templates/staff/circ/patron/t_patron_groups_dialog.tt2 b/Open-ILS/src/templates/staff/circ/patron/t_patron_groups_dialog.tt2
new file mode 100644 (file)
index 0000000..7cdd889
--- /dev/null
@@ -0,0 +1,46 @@
+<form ng-submit="ok(args)" role="form">
+    <div class="modal-header">
+      <button type="button" class="close" ng-click="cancel()" 
+        aria-hidden="true">&times;</button>
+      <h4 class="modal-title">[% l('Secondary Permission Groups') %]</h4>
+    </div>
+    <div class="modal-body patron-reg-barcodes">
+      <div class="row pad-all">
+      [% | l %]
+Assign additional permission groups to users here.  
+This does not affect circulation policy.
+      [% END %]
+      </div>
+      <div class="row header">
+        <div class="col-md-6">
+          <label>[% l('Group') %]</label>
+        </div>
+        <div class="col-md-6">
+          <label>[% l('Action') %]</label>
+        </div>
+      </div>
+      <div class="row pad-all-min" ng-repeat="grp in args.linked_groups">
+        <div class="col-md-6">{{grp.name()}}</div>
+        <div class="col-md-6">
+            <button class="btn btn-default" ng-click="unlink_group($event, grp)">
+                [% l('Delete') %]
+            </button>
+        </div>
+      </div>
+      <div class="row pad-all-min">
+        <div class="col-md-6">
+            <!-- group selector -->
+        </div>
+        <div class="col-md-6">
+            <button class="btn btn-default" ng-click="link_group($event, grp)">
+                [% l('Add') %]
+            </button>
+        </div>
+      </div>
+    </div>
+    <div class="modal-footer">
+      <input type="submit" class="btn btn-primary" value="[% l('Apply Changes') %]"/>
+      <button class="btn btn-warning" ng-click="cancel()">[% l('Cancel') %]</button>
+    </div>
+  </div> <!-- modal-content -->
+</form>
index 117d8f8..2cd7d9d 100644 (file)
@@ -47,7 +47,8 @@ angular.module('egPatronApp', ['ngRoute', 'ui.bootstrap',
                 'net_access_level',
                 'ident_type',
                 'ident_type2',
-                'cards'
+                'cards',
+                'groups'
             ]);
         }
 
index dca92a8..54eb55c 100644 (file)
@@ -7,6 +7,7 @@ angular.module('egCoreMod')
     var service = {
         field_doc : {},            // config.idl_field_doc
         profiles : [],             // permission groups
+        no_edit_profiles : [],     // perm groups we cannot modify
         sms_carriers : [],
         user_settings : {},        // applied user settings
         user_setting_types : {},   // config.usr_setting_type
@@ -32,6 +33,51 @@ angular.module('egCoreMod')
         ]);
     };
 
+    //service.check_grp_app_perm = function(grp_id) {
+
+    // determine which user groups our user is not allowed to modify
+    service.set_no_edit_profiles = function() {
+        var all_app_perms = [];
+        var failed_perms = [];
+
+        // extract the application permissions
+        angular.forEach(service.profiles, function(grp) {
+            if (grp.application_perm())
+                all_app_perms.push(grp.application_perm());
+        }); 
+
+        // fill in service.no_edit_profiles by inspecting failed_perms
+        function traverse_grp_tree(grp, failed) {
+            failed = failed || 
+                failed_perms.indexOf(grp.application_perm()) > -1;
+
+            if (failed) service.no_edit_profiles.push(grp.id());
+
+            angular.forEach(
+                service.profiles.filter( // children of grp
+                    function(p) { return p.parent() == grp.id() }),
+                function(child) {traverse_grp_tree(child, failed)}
+            );
+        }
+
+        return egCore.perm.hasPermAt(all_app_perms, true).then(
+            function(perm_orgs) {
+
+                angular.forEach(all_app_perms, function(p) {
+                    if (perm_orgs[p].length == 0)
+                        failed_perms.push(p);
+                });
+
+                traverse_grp_tree(egCore.env.pgt.tree);
+                console.log('User is not allowed to edit profiles: ' 
+                    + service.no_edit_profiles);
+            }
+        );
+    }
+
+    service.group_link_perms = function() {
+    }
+
     service.get_surveys = function() {
         var org_ids = egCore.org.fullPath(egCore.auth.user().ws_ou(), true);
 
@@ -221,7 +267,7 @@ angular.module('egCoreMod')
     service.get_perm_groups = function() {
         if (egCore.env.pgt) {
             service.profiles = egCore.env.pgt.list;
-            return $q.when();
+            return service.set_no_edit_profiles();
         } else {
             return egCore.pcrud.search('pgt', {parent : null}, 
                 {flesh : -1, flesh_fields : {pgt : ['children']}}
@@ -229,6 +275,7 @@ angular.module('egCoreMod')
                 function(tree) {
                     egCore.env.absorbTree(tree, 'pgt')
                     service.profiles = egCore.env.pgt.list;
+                    return service.set_no_edit_profiles();
                 }
             );
         }
@@ -345,6 +392,7 @@ angular.module('egCoreMod')
         patron.profile = current.profile(); // pre-hash version
         patron.net_access_level = current.net_access_level();
         patron.ident_type = current.ident_type();
+        patron.groups = current.groups(); // pre-hash
 
         angular.forEach(
             ['juvenile', 'barred', 'active', 'master_account'],
@@ -645,7 +693,6 @@ function PatronRegCtrl($scope, $routeParams,
             set_new_patron_defaults(prs);
 
         $scope.page_data_loaded = true;
-        console.log('here with ' + $scope.page_data_loaded);
     });
 
     // update the currently displayed field documentation
@@ -892,6 +939,43 @@ function PatronRegCtrl($scope, $routeParams,
         $scope.user_settings['opac.hold_notify'] = hold_notify;
     }
 
+    $scope.secondary_groups_dialog = function() {
+        $modal.open({
+            templateUrl: './circ/patron/t_patron_groups_dialog',
+            controller: 
+                   ['$scope','$modalInstance','linked_groups',
+            function($scope , $modalInstance , linked_groups) {
+                // scope here is the modal-level scope
+                $scope.link_group = function(grp) {
+                    $scope.args.linked_groups.push(grp);
+                    $event.preventDefault(); // avoid close
+                }
+                $scope.unlink_group = function($event, grp) {
+                    $scope.args.linked_groups = 
+                        $scope.args.linked_groups.filter(function(g) {
+                        return g.id() != grp.id()
+                    });
+                    $event.preventDefault(); // avoid close
+                }
+                $scope.args = {linked_groups : linked_groups};
+                $scope.ok = function() { $modalInstance.close($scope.args) }
+                $scope.cancel = function () { $modalInstance.dismiss() }
+            }],
+            resolve : {
+                linked_groups : function() {
+                    // scope here is the controller-level scope
+                    return $scope.patron.groups;
+                }
+            }
+        }).result.then(
+            function(args) {
+                angular.forEach(args.linked_groups, function(grp) {
+                    // TODO add/remove linked groups
+                });
+            }
+        );
+    }
+
     function extract_hold_notify() {
         notify = $scope.user_settings['opac.hold_notify'];
         if (!notify) return;