Add multiple permission groups editor to user registration form
authorJames Fournie <jfournie@sitka.bclibraries.ca>
Wed, 4 Jan 2012 19:55:19 +0000 (11:55 -0800)
committerBen Shum <bshum@biblio.org>
Fri, 8 Aug 2014 01:51:58 +0000 (21:51 -0400)
This makes use of permission.usr_grp_perm_map which grants secondary
permission groups.  It does not affect the 'profile' ie: circulation policy.

Signed-off-by: James Fournie <jfournie@sitka.bclibraries.ca>
Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Signed-off-by: Ben Shum <bshum@biblio.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/templates/actor/user/register.tt2
Open-ILS/src/templates/actor/user/register_table.tt2
Open-ILS/web/js/dojo/openils/actor/nls/register.js
Open-ILS/web/js/ui/default/actor/user/register.js

index 7580733..4dd3c01 100644 (file)
@@ -2953,6 +2953,7 @@ sub user_retrieve_fleshed_by_id {
     $fields ||= [
         "cards",
         "card",
+        "groups",
         "standing_penalties",
         "addresses",
         "billing_address",
index 2f76450..13797aa 100644 (file)
     </div>
 </div>
 
+<!-- SECONDARY GROUPS DIALOG -->
+<div class='hidden'>
+    <span id='true' style='color:green;'>&#x2713;</span>
+    <span id='false' style='color:red;'>&#x2717;</span>
+    <div dojoType='dijit.Dialog' jsId='secondaryGroupsDialog'>
+        <table class='oils-generic-table' style='margin:10px;'>
+            <thead>
+                <tr>
+                    <th>[% l('Secondary Permission Groups') %]</th>
+                    <th/>
+                </tr>
+            </thead>
+            <tbody>
+                <tr>
+                  <td colspan="2">
+                    [% l('Assign additional permission groups to users here.<br/>This does not affect circulation policy.') %]
+                  </td>
+                </tr>
+            </tbody>
+            <tbody id='uedit-secondary-groups-tbody'>
+                <tr id='uedit-secondary-groups-tr-template'>
+                    <td><div name='groupname'></div></td>
+                    <td><div name='groupeditbutton'></div></td>
+                </tr>
+            </tbody>
+            <tbody>
+                <tr>
+                   <td style='text-align:center;'>
+                       <button dojoType='dijit.form.Button' onClick='saveSecondaryGroups' scrollOnFocus='false'>[% l('Save') %]</button>
+                    </td>
+                    <td/>
+                </tr>
+            </tbody>
+        </table>
+    </div>
+</div>
+
 
 [% END %]
 
index cdb5fa3..d3f19a0 100644 (file)
     <tr fmclass='au' fmfield='evening_phone'/>
     <tr fmclass='au' fmfield='other_phone'/>
     <tr fmclass='au' fmfield='home_ou' required='required'/>
-    <tr fmclass='au' fmfield='profile' required='required'/>
+    <tr fmclass='au' fmfield='profile' required='required'>
+        <td/><td/><td/>
+        <td>
+            <span class="hidden" id="ueditSecondaryGrpButton">
+                <button dojoType='dijit.form.Button' jsId='secondaryGroupsButton' scrollOnFocus='false' tabIndex='-1'>[% l('Secondary Groups') %]</button>
+            </span>
+        </td>
+    </tr>
     <tr fmclass='au' fmfield='expire_date' required='required'>
         <td/><td/><td/>
         <td>
index d6dbd71..ebca55d 100644 (file)
     "HOLD_NOTIFY_EMAIL": "Email: ",
     "HOLD_NOTIFY_SMS": "SMS: ",
     "REQUESTING_USER" : "Account requested by ${0} ${1}",
-    "UPDATE_EXPIRE_DATE": "Update Expire Date"
+    "UPDATE_EXPIRE_DATE": "Update Expire Date",
+    "DELETE": "Delete",
+    "ADD": "Add",
+    "SECONDARY_GROUP_NOT_ALLOWED": "You do not have permission to add this group.",
+    "SECONDARY_GROUP_IS_PROFILE": "That is already the primary profile group for this patron.",
+    "SECONDARY_GROUP_EXISTS": "This group is on the list already.",
+    "SECONDARY_GROUP_ERROR": "Error saving secondary groups."
+
+
 }
index fe5f0c9..7577e3f 100644 (file)
@@ -10,6 +10,7 @@ dojo.require('openils.PermaCrud');
 dojo.require('openils.widget.AutoGrid');
 dojo.require('openils.widget.AutoFieldWidget');
 dojo.require('openils.widget.ProgressDialog');
+dojo.require('openils.widget.PermGrpFilteringSelect');
 dojo.require('dijit.form.CheckBox');
 dojo.require('dijit.form.Button');
 dojo.require('dojo.date');
@@ -46,6 +47,8 @@ var cloneUserObj;
 var stageUser;
 var optInSettings;
 var allCardsTemplate;
+var secondaryGroupsTemplate;
+var secondaryGroupsChanged = false;
 var uEditCloneCopyAddr; // if true, copy addrs on clone instead of link
 var homeOuTypes = {};
 var holdPickupTypes = {};
@@ -262,6 +265,9 @@ function load() {
 
     dojo.connect(replaceBarcode, 'onClick', replaceCardHandler);
     dojo.connect(allCards, 'onClick', drawAllCards);
+    checkSecondaryGroupsPerm();
+    dojo.connect(secondaryGroupsButton, 'onClick', drawSecondaryGroups);
+
     if(patron.isnew()) {
         dojo.addClass(dojo.byId('uedit-all-barcodes'), 'hidden');
     } else if(checkGrpAppPerm(patron.profile())) {
@@ -432,6 +438,104 @@ function drawAllCards() {
     allCardsDialog.show();
 }
 
+/* Additional group editor */
+function drawSecondaryGroups() {
+    var tbody = dojo.byId('uedit-secondary-groups-tbody');
+
+    // create a template for each row we add
+    if(!secondaryGroupsTemplate) {
+        secondaryGroupsTemplate = tbody.removeChild(dojo.byId('uedit-secondary-groups-tr-template'));
+    } else {
+        while(tbody.childNodes[0])
+            tbody.removeChild(tbody.childNodes[0]);
+    }
+
+    // for each of the groups, add the group name and a delete button to the dialog
+    dojo.forEach(patron.groups(),
+        function(group) {
+            if(!group.isdeleted()){
+              var row = secondaryGroupsTemplate.cloneNode(true);
+              getByName(row, 'groupname').innerHTML = group.name();
+              var act = new dijit.form.ToggleButton({label:localeStrings.DELETE, onClick: function() {deleteSecondaryGroup(group.id());} },"deleteButton");
+              getByName(row, 'groupeditbutton').appendChild(act.domNode);
+              tbody.appendChild(row);
+            }
+        }
+    );
+
+    //add a blank row with a selector and an "add" button for adding new groups
+    var row = secondaryGroupsTemplate.cloneNode(true);
+    var editbox = new openils.widget.AutoFieldWidget({fmClass:"pgt",selfReference:true, parentNode:getByName(row,'groupname')});
+    editbox.build(function(w, ww){ trimGrpTree(ww)} );
+    var act = new dijit.form.ToggleButton({label:localeStrings.ADD, onClick: function() {addSecondaryGroup(editbox.widget.value)} },"addButton");
+    getByName(row, 'groupeditbutton').appendChild(act.domNode);
+
+    tbody.appendChild(row);
+
+    secondaryGroupsChanged = true;
+
+    secondaryGroupsDialog.show();
+}
+
+
+function deleteSecondaryGroup(id){
+    // filter out the selected group from our patron.groups()
+    var myGroups = dojo.filter( patron.groups(), function(g){
+        return (g.id() != id )
+        }
+    );
+    patron.groups(myGroups);
+    // redraw dialog
+    drawSecondaryGroups();
+}
+
+function addSecondaryGroup(id){
+    var myGroups = patron.groups() || [];
+    // check if we allowed to add requested group
+    if (!checkGrpAppPerm(id)){
+        alert(localeStrings.SECONDARY_GROUP_NOT_ALLOWED);
+        return;
+    }
+    // check if group is profile
+    if(id == patron.profile()){
+        alert(localeStrings.SECONDARY_GROUP_IS_PROFILE);
+        return;
+    }
+
+    // check if the group exists
+    var old = myGroups.filter(function(c){return ( c.id() == id )})[0];
+    if(old){
+        alert(localeStrings.SECONDARY_GROUP_EXISTS);
+        drawSecondaryGroups();
+        return;
+    }
+
+    // fetch the group from the pgt table
+    dojo.forEach(permGroups,function(newgrp){
+        // add it to our groups list
+        if(newgrp.id() == id){
+            if (!myGroups) { grps = []; }
+            newgrp.isnew(1);
+            myGroups.push(newgrp);
+        }
+    });
+    patron.groups(myGroups);
+    // redraw the dialog
+    drawSecondaryGroups();
+}
+
+function saveSecondaryGroups(){
+    var groupids = dojo.map( patron.groups(), function(grp){ if(!grp.isdeleted()){ return grp.id()} } );
+    var data = fieldmapper.standardRequest(
+        ['open-ils.actor', 'open-ils.actor.user.set_groups'],
+        { params : [openils.User.authtoken, patron.id(), groupids ] }
+    );
+    if(!data){
+        alert(localeStrings.SECONDARY_GROUP_ERROR);
+    }
+    secondaryGroupsDialog.hide()
+}
+
 function applyCardChanges() {
     var cardrows = dojo.query('[cardid]', allCardsDialog.domNode);
     var changed = false;
@@ -1235,6 +1339,21 @@ function checkClaimsReturnCountPerm() {
     );
 }
 
+function checkSecondaryGroupsPerm() {
+    new openils.User().getPermOrgList(
+        'CREATE_USER_GROUP_LINK',
+        function(orgList) {
+            if(orgList.indexOf(patron.home_ou()) == -1) {
+                dojo.addClass(dojo.byId('ueditSecondaryGrpButton'), 'hidden');
+                secondaryGroupsChanged = false;
+            } else {
+                dojo.removeClass(dojo.byId('ueditSecondaryGrpButton'), 'hidden');
+            }
+        },
+        true,
+        true
+    );
+}
 
 function checkClaimsNoCheckoutCountPerm() {
     new openils.User().getPermOrgList(
@@ -1948,6 +2067,9 @@ function _uEditSave(doClone) {
             }
         }
     );
+    if(secondaryGroupsChanged){
+        saveSecondaryGroups();
+    }
 }
 
 function uUpdateContactInvalidators() {