Bug 20100: Explain why the checkbox is disabled
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / member-flags.tt
blob4d40e0acce2ea289487b627518a59783d5e4e0dc
1 [% USE Asset %]
2 [% USE Branches %]
3 [% SET footerjs = 1 %]
4 [% PROCESS 'permissions.inc' %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>Koha &rsaquo; Patrons &rsaquo; Set permissions for [% patron.surname %], [% patron.firstname %]</title>
7 [% Asset.css("css/treeview/jquery.treeview.css") %]
8 [% INCLUDE 'doc-head-close.inc' %]
9 </head>
11 <body id="pat_member-flags" class="pat">
12 [% INCLUDE 'header.inc' %]
13 [% INCLUDE 'patron-search.inc' %]
15 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; Set permissions for [% patron.surname %], [% patron.firstname %]</div>
17 <div id="doc3" class="yui-t2">
18    
19    <div id="bd">
20         <div id="yui-main">
21         <div class="yui-b">
22 [% INCLUDE 'members-toolbar.inc' %]
24 <form method="post" action="/cgi-bin/koha/members/member-flags.pl">
25     <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
26     <input type="hidden" name="member" id="borrowernumber" value="[% patron.borrowernumber %]" />
27     <input type="hidden" name="newflags" value="1" />
28     <h1>Set permissions for [% patron.surname %], [% patron.firstname %]</h1>
29     <!-- <ul id="permissionstree"><li class="root">All privileges<ul> -->
30     <ul id="permissionstree" class="treeview-grey">
31         <!-- <li class="folder-close">One level down<ul> -->
32     [% FOREACH loo IN loop %]
33         [% IF ( loo.expand ) %]
34         <li class="open">
35         [% ELSE %]
36         <li>
37         [% END %]
38                         [% IF ( loo.checked ) %]
39           [% IF disable_superlibrarian_privs && loo.bit == 0 %]
40               <input type="checkbox" disabled="disabled" class="flag parent superlib" id="flag-[% loo.bit %]_disabled" name="flag" value="[% loo.flag %]" checked="checked" title="The system preference ProtectSuperlibrarianPrivileges is enabled" />
41               <input type="hidden" id="flag-[% loo.bit %]" name="flag" value="[% loo.flag %]" >
42           [% ELSE %]
43               <input type="checkbox" class="flag parent" id="flag-[% loo.bit %]" name="flag" value="[% loo.flag %]" checked="checked" />
44           [% END %]
45                         [% ELSE %]
46           [% IF disable_superlibrarian_privs && loo.bit == 0 %]
47               <input type="checkbox" disabled="disabled" class="flag parent" id="flag-[% loo.bit %]_disabled" name="flag" value="[% loo.flag %]" title="The system preference ProtectSuperlibrarianPrivileges is enabled" />
48           [% ELSE %]
49               <input type="checkbox" class="flag parent" id="flag-[% loo.bit %]" name="flag" value="[% loo.flag %]" />
50           [% END %]
51                         [% END %]
52                 <label class="permissioncode" for="flag-[% loo.bit %]">[% loo.flag %]</label>
53                 <span class="permissiondesc">[% PROCESS main_permissions name=loo.flag %]</span>
54             [% IF ( loo.sub_perm_loop ) %]
55                 <ul id="flag-[% loo.bit %]-children">
56                     [% FOREACH sub_perm_loo IN loo.sub_perm_loop %]
57                         <li>
58                                     [% IF ( sub_perm_loo.checked ) %]
59                             <input type="checkbox" class="flag child" id="[% sub_perm_loo.id %]" name="flag" value="[% sub_perm_loo.perm %]" checked="checked" />
60                                     [% ELSE %]
61                             <input type="checkbox" class="flag child" id="[% sub_perm_loo.id %]" name="flag" value="[% sub_perm_loo.perm %]" />
62                                     [% END %]
63                     <label class="permissioncode" for="[% sub_perm_loo.id %]">[% sub_perm_loo.code %]</label>
64                              <span class="permissiondesc">[% PROCESS sub_permissions name=sub_perm_loo.code %]</span>
65                         </li>
66                     [% END %]
67                 </ul>
68                 </li>
69             [% ELSE %]
70                 </li>
71                         [% END %]
72     [% END %]
73         <!-- </ul></li> -->
74     <!-- </ul></li></ul> -->
75     </ul>
77 <fieldset class="action"><input type="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a></fieldset>
79 </form>
80 </div>
81 </div>
83 <div class="yui-b">
84 [% INCLUDE 'circ-menu.inc' %]
85 </div>
86 </div>
88 [% MACRO jsinclude BLOCK %]
89     [% Asset.js("js/members-menu.js") %]
90     [% Asset.js("lib/jquery/plugins/jquery.treeview.pack.js") %]
91     <!-- set up tree -->
92     <script type="text/javascript">
93         $(document).ready(function() {
94             $("#permissionstree").treeview({animated: "fast", collapsed: true});
96             // Enforce Superlibrarian Privilege Mutual Exclusivity
97             if( $('input[id="flag-0"]:checked').length || $(".superlib:checked").length ){
98                 if ($('input[name="flag"]:checked').length > 1){
99                     alert(_("Inconsistency detected! The superlibrarian privilege is mutually exclusive of other privileges, as it includes them all. This patron's privileges will now be reset to include only superlibrarian."));
100                 }
102                 $('input[name="flag"]').each(function() {
103                     if($(this).attr('id') != "flag-0" && !$(this).hasClass('superlib') ){
104                         $(this).prop('disabled', true);
105                         $(this).prop('checked', false);
106                     }
107                 });
108             }
110             $('input#flag-0').click(function() {
111                 if( $('input[id="flag-0"]:checked').length || $(".superlib:checked").length ){
112                     $('input[name="flag"]').each(function() {
113                         if($(this).attr('id') != "flag-0" && !$(this).hasClass('superlib') ){
114                             $(this).prop('disabled', true);
115                             $(this).prop('checked', false);
116                         }
117                     });
118                 }
119                 else {
120                     $('input[name="flag"]').each(function() {
121                         $(this).prop('disabled', false);
122                     });
123                 }
124             });
126             $(".flag").on("change",function(){
127                 if( $(this).hasClass("parent") ){
128                     toggleChildren(this);
129                 } else {
130                     toggleParent(this);
131                 }
132             });
134         });
136         // manage checking/unchecking parent permissions
137         var originalChildStates = {}; /* keep track of subpermission checkbox values
138                                          so that user can recover from accidentally
139                                          toggling a parent/module permission */
140         function selectChildren(parentInput) {
141             var childListId = parentInput.id + '-children';
142             var list = document.getElementById(childListId);
143             var children = [];
144             if (list) {
145                 var inputs = list.getElementsByTagName('input');
146                 for (var i = 0; i < inputs.length; i++) {
147                     if (inputs[i].type == 'checkbox') {
148                         children.push(inputs[i]);
149                     }
150                 }
151             }
152             return children;
153         }
155         function toggleChildren(parentInput) {
156             var children = selectChildren(parentInput);
157             if (children.length == 0) {
158                 return;
159             }
160             var checked = parentInput.checked;
161             if (checked && parentInput.parentNode.className == 'expandable') {
162                 /* expand the tree */
163                 $(".hitarea", parentInput.parentNode).click();
164             }
165             for (var i = 0; i < children.length; i++) {
166                 if (checked) {
167                     originalChildStates[children[i].id] = children[i].checked;
168                     children[i].checked = checked;
169                 } else {
170                     if (children[i].id in originalChildStates) {
171                         children[i].checked = originalChildStates[children[i].id];
172                     } else {
173                         children[i].checked = checked;
174                     }
175                 }
176             }
177         }
179         function toggleParent(childInput) {
180             originalChildStates[childInput.id] = childInput.checked;
181             if (childInput.checked) {
182                 return;
183             }
184             var parentId = childInput.parentNode.parentNode.id.replace(/-children$/, '');;
185             var parentInput = document.getElementById(parentId);
186             if (parentInput) {
187                 parentInput.checked = false;
188             }
189         }
191     </script>
192 [% END %]
194 [% INCLUDE 'intranet-bottom.inc' %]