Bug 22553: Unchecking a subpermission does not uncheck the top level permission
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / member-flags.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Branches %]
4 [% SET footerjs = 1 %]
5 [% PROCESS 'permissions.inc' %]
6 [% INCLUDE 'doc-head-open.inc' %]
7 <title>Koha &rsaquo; Patrons &rsaquo; Set permissions for [% patron.surname | html %], [% patron.firstname | html %]</title>
8 [% INCLUDE 'doc-head-close.inc' %]
9 </head>
10
11 <body id="pat_member-flags" class="pat">
12 [% INCLUDE 'header.inc' %]
13 [% INCLUDE 'patron-search.inc' %]
14
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 | html %], [% patron.firstname | html %]</div>
16
17 <div class="main container-fluid">
18     <div class="row">
19         <div class="col-sm-10 col-sm-push-2">
20             <main>
21
22 [% INCLUDE 'members-toolbar.inc' %]
23
24 <form method="post" action="/cgi-bin/koha/members/member-flags.pl">
25     <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
26     <input type="hidden" name="member" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
27     <input type="hidden" name="newflags" value="1" />
28     <h1>Set permissions for [% patron.surname | html %], [% patron.firstname | html %]</h1>
29
30     <div id="permissionstree">
31         <div id="permissions_toolbar" class="btn-toolbar">
32             <button type="submit" class="btn btn-sm btn-default"><i class="fa fa-save"></i> Save</button>
33             <a class="btn btn-sm btn-default" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | html %]"><i class="fa fa-remove"></i> Cancel</a>
34             <a class="toggleall toggleall_on btn btn-link" href="#"><i class="fa fa-plus-square-o"></i> Show all</a>
35             <a class="toggleall toggleall_off btn btn-link" href="#"><i class="fa fa-minus-square-o"></i> Hide all</a>
36             <div class="btn-group pull-right">
37                 Filter: <input type="text" name="permissions_filter" id="permissions_filter" size="20" />
38                 <a href="#" id="clear_filter" style="display:none"><i class="fa fa-remove"></i></a>
39             </div>
40         </div>
41         <div class="permissions">
42             [% FOREACH loo IN loop %]
43                 [% IF ( loo.expand ) %]
44                     <div id="parent-flag-[% loo.flag | html %]" class="open parent">
45                 [% ELSE %]
46                     <div id="parent-flag-[% loo.flag | html %]" class="parent">
47                 [% END %]
48                 [% IF ( loo.checked ) %]
49                     [% IF disable_superlibrarian_privs && loo.bit == 0 %]
50                         <input type="checkbox" disabled="disabled" data-bit="[% loo.bit | html %]" id="flag-[% loo.bit | html %]_disabled" class="parent flag superlib" name="flag" value="[% loo.flag | html %]" checked="checked" title="The system preference ProtectSuperlibrarianPrivileges is enabled" />
51                         <input type="hidden" id="flag-[% loo.bit | html %]" name="flag" value="[% loo.flag | html %]" >
52                     [% ELSE %]
53                           <input type="checkbox" data-bit="[% loo.bit | html %]" id="flag-[% loo.bit | html %]" class="parent flag" name="flag" value="[% loo.flag | html %]" checked="checked" />
54                     [% END %]
55                 [% ELSE %]
56                     [% IF disable_superlibrarian_privs && loo.bit == 0 %]
57                         <input type="checkbox" disabled="disabled" class="flag parent" data-bit="[% loo.bit | html %]" id="flag-[% loo.bit | html %]_disabled" name="flag" value="[% loo.flag | html %]" title="The system preference ProtectSuperlibrarianPrivileges is enabled" />
58                     [% ELSE %]
59                         <input type="checkbox" class="flag parent" data-bit="[% loo.bit | html %]" id="flag-[% loo.bit | html %]" name="flag" value="[% loo.flag | html %]" />
60                     [% END %]
61                 [% END # /IF loo.checked %]
62                     <label class="permissiondesc" for="flag-[% loo.bit | html %]">
63                         [% PROCESS main_permissions name=loo.flag %]
64                     </label>
65                     [% IF ( loo.flag == "superlibrarian" ) %]<div class="hint superlibrarian-hint">This permission grants access to all areas. If selected, specific sub-permissions cannot be selected.</div>[% END %]
66                 [% IF ( loo.sub_perm_loop ) %]
67                     <a class="toggle-[% loo.bit | html %] togglechildren_off" href="#" data-bit="[% loo.bit | html %]"><i class="fa fa-minus-square-o"></i> Hide details</a>
68                     <a class="toggle-[% loo.bit | html %] togglechildren_on" href="#" data-bit="[% loo.bit | html %]"><i class="fa fa-plus-square-o"></i> Show details</a>
69                     <div class="children" id="flag-[% loo.bit | html %]-children">
70                         [% FOREACH sub_perm_loo IN loo.sub_perm_loop %]
71                             <div class="child-flags">
72                                 [% IF ( sub_perm_loo.checked ) %]
73                                     <input type="checkbox" id="[% sub_perm_loo.id | html %]" class="child flag" name="flag" value="[% sub_perm_loo.perm | html %]" checked="checked" />
74                                 [% ELSE %]
75                                     <input type="checkbox" id="[% sub_perm_loo.id | html %]" class="child flag" name="flag" value="[% sub_perm_loo.perm | html %]" />
76                                 [% END %]
77                                 <label class="permissiondesc" for="[% sub_perm_loo.id | html %]">
78                                     [% PROCESS sub_permissions name=sub_perm_loo.code %]
79                                 </label>
80                             </div>
81                         [% END %]
82                     </div> <!-- /#flag-[% loo.bit | html %]-children -->
83                 [% END # /IF loo.sub_perm_loop %]
84                 </div> <!-- /.parent -->
85             [% END # /FOREACH loo %]
86         </div>
87     </div> <!-- /#permissionstree -->
88 </form>
89
90             </main>
91         </div> <!-- /.col-sm-10.col-sm-push-2 -->
92
93         <div class="col-sm-2 col-sm-pull-10">
94             <aside>
95                 [% INCLUDE 'circ-menu.inc' %]
96             </aside>
97         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
98     </div> <!-- /.row -->
99
100 [% MACRO jsinclude BLOCK %]
101     [% INCLUDE 'str/members-menu.inc' %]
102     [% Asset.js("js/members-menu.js") | $raw %]
103     [% Asset.js("lib/hc-sticky.js") | $raw %]
104     <script>
105         var Sticky;
106         $(document).ready(function() {
107
108             Sticky = $("#permissions_toolbar");
109             Sticky.hcSticky({
110                 stickTo: "#permissionstree",
111                 stickyClass: "floating"
112             });
113
114             $(".open div").show();
115
116             $("#permissions_filter").on("keyup", function(){
117                 $("#clear_filter").css("display","inline-block");
118                 $("a[class^=toggle-]").hide();
119                 var string = $(this).val();
120                 var divs = $("div[id!='parent-flag-superlibrarian']", ".permissions");
121                 if( string != "" && string.length > 3 ){
122                     divs.each(function(){
123                         if ( $(this).text().search(new RegExp( string, "i")) < 0 ) {
124                             $(this).hide();
125                         } else {
126                             $(this).show();
127                         }
128                     });
129                 } else {
130                     divs.show();
131                 }
132             });
133
134             $("#clear_filter").on("click", function(){
135                 $(".togglechildren_off").show();
136                 $("#permissions_filter").val("");
137                 $("div", "#permissionstree").show();
138                 $(this).css("display","none");
139             });
140
141             // Enforce Superlibrarian Privilege Mutual Exclusivity
142             if( $('input[id="flag-0"]:checked').length || $(".superlib:checked").length ){
143                 if ($('input[name="flag"]:checked').length > 1){
144                     alert(_("Inconsistency detected!") + "\n\n" + _("The superlibrarian privilege is mutually exclusive of other privileges, as it includes them all.") + "\n\n" + _("This patron's privileges will now be reset to include only superlibrarian."));
145                 }
146
147                 $('input[name="flag"]').each(function() {
148                     if($(this).attr('id') != "flag-0" && !$(this).hasClass('superlib') ){
149                         $(this).prop('disabled', true);
150                         $(this).prop('checked', false);
151                     }
152                 });
153             }
154
155             $('input#flag-0').click(function() {
156                 if( $('input[id="flag-0"]:checked').length || $(".superlib:checked").length ){
157                     $('input[name="flag"]').each(function() {
158                         if($(this).attr('id') != "flag-0" && !$(this).hasClass('superlib') ){
159                             $(this).prop('disabled', true);
160                             $(this).prop('checked', false);
161                         }
162                     });
163                 }
164                 else {
165                     $('input[name="flag"]').each(function() {
166                         $(this).prop('disabled', false);
167                     });
168                 }
169             });
170
171
172             $(".toggleall_off, .toggleall_on").on('click', function(e) {
173                 e.preventDefault();
174                 if( $(this).hasClass("toggleall_on")){
175                     $(".children,.togglechildren_off").show();
176                     $(".togglechildren_on").hide();
177                 } else {
178                     $(".children,.togglechildren_off").hide();
179                     $(".togglechildren_on").show();
180                 }
181             });
182
183             $(".togglechildren_off, .togglechildren_on").on('click', function(e) {
184                 e.preventDefault();
185                 var bit = $(this).data("bit");
186                 $("#flag-" + bit + "-children").toggle();
187                 $(".toggle-" + bit).toggle();
188             });
189
190             $(".togglechildren_off, .togglechildren_on").hover( function(){
191                 $(this).parent().addClass("permission-highlight");
192             }, function(){
193                 $(this).parent().removeClass("permission-highlight");
194             });
195
196             $(".flag").on("change",function(e){
197                 e.preventDefault();
198                 if( $(this).hasClass("child") ){
199                     $(this).closest(".parent").find(".flag.parent").prop("checked", false);
200                 } else {
201                     var bit = $(this).data("bit");
202                     if( $(this).is(":checked") ){
203                         $("#flag-" + bit + "-children").show().find(".flag").prop("checked", true);
204                         $(".toggle-" + bit + ".togglechildren_on").hide();
205                         $(".toggle-" + bit + ".togglechildren_off").show();
206                     } else {
207                         $("#flag-" + bit + "-children").show().find(".flag").prop("checked", false);
208                     }
209                 }
210             });
211
212         });
213     </script>
214 [% END %]
215
216 [% INCLUDE 'intranet-bottom.inc' %]