From 2373c3272264107891dfddd3a2440c546501604f Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 26 Apr 2016 14:45:20 -0400 Subject: [PATCH] CAT-51 Patron editor profile group sorting refactor Signed-off-by: Bill Erickson --- Open-ILS/web/js/ui/default/actor/user/register.js | 183 ++++++++-------------- 1 file changed, 68 insertions(+), 115 deletions(-) diff --git a/Open-ILS/web/js/ui/default/actor/user/register.js b/Open-ILS/web/js/ui/default/actor/user/register.js index a65d87c2b1..3f9b3e1ac2 100644 --- a/Open-ILS/web/js/ui/default/actor/user/register.js +++ b/Open-ILS/web/js/ui/default/actor/user/register.js @@ -1388,122 +1388,75 @@ function processStageUserValues() { } function trimGrpTree(autoWidget) { - var permArray = []; - var store = autoWidget.widget.store; - if(!store) return; - // remove all groups that this user are not allowed to edit, - // except the profile group of an existing user - var tree = autoWidget.widget.tree[0]; - function order_perms(treeNode) { - if (!treeNode) return; - dojo.forEach(treeNode.children(), function(node){ - - switch( node.id()){ - case 13: //Full Privileges - permArray[0] = node; - break; - case 17: //Limited Checkout - permArray[1] = node; - break; - case 26: //Online Registration - permArray[2] = node; - break; - case 90: //PC Only Ineligible - permArray[3] = node; - break; - case 15: //Recip Limit Holds - permArray[4] = node; - break; - case 23: //Recip Limit Holds & CKO - permArray[5] = node; - break; - case 25: //Recip Limit Holds No PC - permArray[6] = node; - break; - case 28: //Parental Limit 10 - permArray[7] = node; - break; - case 27: //Parental Limit 5 - permArray[8] = node; - break; - case 30: //Parental No - PC & CKO - permArray[9] = node; - break; - case 92: //One Year - Full - permArray[10] = node; - break; - case 93: //One Year - Limit Holds - permArray[11] = node; - break; - case 38: //KCLS Staff - permArray[12] = node; - break; - case 39: //Branch Work - var dupNode = node; - permArray[24] = node.a[0][0]; //CMS Recall - dupNode.a[0] = null; - permArray[13] = dupNode; - break; - case 16: //No CKO - permArray[14] = node; - break; - case 31: //Deceased - permArray[15] = node; - break; - case 32: //Summer Bus Student - permArray[16] = node; - break; - case 35: //Outreach Service - permArray[19] = node; - break; - case 34: //Outreach Staff Only - permArray[20] = node; - break; - case 901: //Student Ecard - permArray[21] = node; - break; - case 902: //Classroom Databases - permArray[22] = node; - break; - case 40: //ILL - permArray[23] = node; - break; - case 91: //Enumclaw Migration - permArray[25] = node; - break; - case 1001: //ADA - SC Approved - var copyNode = node; - permArray[17] = node.a[0][1]; //ADA Circ Limit Holds - permArray[18] = node.a[0][0]; //ADA Circulation - copyNode.a[0] = null; - permArray[26] = copyNode; - break; - case 74: //Data Review - permArray[27] = node; - break; - case 3: //Staff - permArray[28] = node; - break; - case 888: //SIP - permArray[29] = node; - break; - default: - } - order_perms(node); - }); - - tree.children([permArray[0], permArray[1], permArray[2], permArray[3], permArray[4], - permArray[5], permArray[6], permArray[7], permArray[8], permArray[9], - permArray[10], permArray[11], permArray[12], permArray[13], permArray[14], - permArray[15], permArray[16], permArray[17], permArray[18], permArray[19], - permArray[20], permArray[21], permArray[22], permArray[23], permArray[24], - permArray[25], permArray[26], permArray[27], permArray[28], permArray[29]]); - } - - order_perms(tree); - - autoWidget.widget.startup(); + var store = autoWidget.widget.store; + if(!store) return; + + // group ID by sorted position + var id_pos = [ + 13, //Full Privileges + 17, //Limited Checkout + 26, //Online Registration + 90, //PC Only Ineligible + 15, //Recip Limit Holds + 23, //Recip Limit Holds & CKO + 25, //Recip Limit Holds No PC + 28, //Parental Limit 10 + 27, //Parental Limit 5 + 30, //Parental No - PC & CKO + 92, //One Year - Full + 93, //One Year - Limit Holds + 38, //KCLS Staff + 39, //Branch Work + 16, //No CKO + 31, //Deceased + 32, //Summer Bus Student + 1002, //ADA Circ Limit Holds + 1003, //ADA Circulation + 35, //Outreach Service + 34, //Outreach Staff Only + 901, //Student Ecard + 902, //Classroom Databases + 40, //ILL + 89, //CMS Recall 89 + 91, //Enumclaw Migration + 1001, //ADA - SC Approved + 74, //Data Review + 3, //Staff + 888 //SIP + ]; + + // avoid removing the child nodes for these groups, since + // we are displaying them as-is (unsorted). + var keep_children = { + 3 : true, + 888 : true + }; + + var sorted_groups = []; + function sort_groups(node) { + if (!node) return; + + dojo.forEach(node.children(), function(child) { + var idx = id_pos.indexOf(Number(child.id())); + + if (idx > -1) { // custom sorting applied + var cloned = child.clone(); + sorted_groups[idx] = cloned; + if (!keep_children[cloned.id()]) + cloned.children([]); + } + sort_groups(child); + }); + } + + var tree = autoWidget.widget.tree[0]; + sort_groups(tree); + tree.children(sorted_groups); + + autoWidget.widget.startup(); + // remove all groups that this user are not allowed to edit, + // except the profile group of an existing user store.fetch({onItem : function(item) { if(!checkGrpAppPerm(item.id[0]) && patron.profile() != item.id[0]) -- 2.11.0