Bug 34531: Fix template logic to not hide patron restrictions
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / member-flags.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Branches %]
4 [% PROCESS 'i18n.inc' %]
5 [% SET footerjs = 1 %]
6 [% PROCESS 'permissions.inc' %]
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>[% FILTER collapse %]
9     [% t("Set permissions for") | html %] [% INCLUDE 'patron-title.inc' no_html = 1 %] &rsaquo;
10     [% t("Patrons") | html %] &rsaquo;
11     [% t("Koha") | html %]
12 [% END %]</title>
13 [% INCLUDE 'doc-head-close.inc' %]
14 </head>
15
16 <body id="pat_member-flags" class="pat">
17 [% WRAPPER 'header.inc' %]
18     [% INCLUDE 'patron-search-header.inc' %]
19 [% END %]
20
21 [% WRAPPER 'sub-header.inc' %]
22     [% WRAPPER breadcrumbs %]
23         [% WRAPPER breadcrumb_item %]
24             <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>
25         [% END %]
26         [% WRAPPER breadcrumb_item %]
27             <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | uri %]">[% INCLUDE 'patron-title.inc' %]</a>
28         [% END %]
29         [% WRAPPER breadcrumb_item bc_active= 1 %]
30             <span>Set permissions</span>
31         [% END %]
32     [% END #/ WRAPPER breadcrumbs %]
33 [% END #/ WRAPPER sub-header.inc %]
34
35 <div class="main container-fluid">
36     <div class="row">
37         <div class="col-sm-10 col-sm-push-2">
38             <main>
39
40 [% INCLUDE 'members-toolbar.inc' %]
41
42 <form id="flag_form" method="post" action="/cgi-bin/koha/members/member-flags.pl">
43     <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
44     <input type="hidden" name="member" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
45     <input type="hidden" name="newflags" value="1" />
46     <h1>Set permissions for [% INCLUDE 'patron-title.inc' no_html = 1 %]</h1>
47
48     <div id="permissionstree">
49         <div id="permissions_toolbar" class="btn-toolbar">
50             <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Save</button>
51             <a class="btn btn-default" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | html %]"><i class="fa fa-times"></i> Cancel</a>
52             <a class="toggleall toggleall_on btn btn-link" href="#"><i class="fa-solid fa-square-plus"></i> Show all</a>
53             <a class="toggleall toggleall_off btn btn-link" href="#"><i class="fa-solid fa-square-minus"></i> Hide all</a>
54             <a id="CheckAllFlags" class="btn btn-link" href="#">
55                 <i class="fa fa-check"></i> Select all
56             </a>
57             <a id="UncheckAllFlags" class="btn btn-link" href="#">
58                 <i class="fa fa-times"></i> Clear all
59             </a>
60             <div class="btn-group pull-right">
61                 Filter: <input type="text" name="permissions_filter" id="permissions_filter" size="20" />
62                 <a href="#" id="clear_filter" style="display:none"><i class="fa fa-times"></i></a>
63             </div>
64         </div>
65         <div class="permissions">
66             [% FOREACH loo IN loop %]
67                 [% IF ( loo.expand ) %]
68                     <div id="parent-flag-[% loo.flag | html %]" class="open parent">
69                 [% ELSE %]
70                     <div id="parent-flag-[% loo.flag | html %]" class="parent">
71                 [% END %]
72                 [% IF ( loo.checked ) %]
73                     [% IF disable_superlibrarian_privs && loo.bit == 0 %]
74                         <input type="checkbox" disabled="disabled" data-bit="0" id="flag-0" class="parent flag superlib" name="flag" value="[% loo.flag | html %]" checked="checked" title="The system preference ProtectSuperlibrarianPrivileges is enabled" />
75                         <input type="hidden" id="flag-0" name="flag" value="[% loo.flag | html %]" >
76                     [% ELSE %]
77                           <input type="checkbox" data-bit="[% loo.bit | html %]" id="flag-[% loo.bit | html %]" class="parent flag" name="flag" value="[% loo.flag | html %]" checked="checked" />
78                     [% END %]
79                 [% ELSE %]
80                     [% IF disable_superlibrarian_privs && loo.bit == 0 %]
81                         <input type="checkbox" disabled="disabled" class="flag parent" data-bit="0" id="flag-0" name="flag" value="[% loo.flag | html %]" title="The system preference ProtectSuperlibrarianPrivileges is enabled" />
82                     [% ELSE %]
83                         <input type="checkbox" class="flag parent" data-bit="[% loo.bit | html %]" id="flag-[% loo.bit | html %]" name="flag" value="[% loo.flag | html %]" />
84                     [% END %]
85                 [% END # /IF loo.checked %]
86                     <label class="permissiondesc" for="flag-[% loo.bit | html %]">
87                         [% PROCESS main_permissions name=loo.flag %]
88                     </label>
89                     [% 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 %]
90                 [% IF ( loo.sub_perm_loop ) %]
91                     <a class="toggle-[% loo.bit | html %] togglechildren_off" href="#" data-bit="[% loo.bit | html %]"><i class="fa-solid fa-square-minus"></i> Hide details</a>
92                     <a class="toggle-[% loo.bit | html %] togglechildren_on" href="#" data-bit="[% loo.bit | html %]"><i class="fa-solid fa-square-plus"></i> Show details</a>
93                     <div class="children" id="flag-[% loo.bit | html %]-children">
94                         [% FOREACH sub_perm_loo IN loo.sub_perm_loop %]
95                             <div class="child-flags">
96                                 [% IF ( sub_perm_loo.checked ) %]
97                                     <input type="checkbox" id="[% sub_perm_loo.id | html %]" class="child flag" name="flag" value="[% sub_perm_loo.perm | html %]" checked="checked" />
98                                 [% ELSE %]
99                                     <input type="checkbox" id="[% sub_perm_loo.id | html %]" class="child flag" name="flag" value="[% sub_perm_loo.perm | html %]" />
100                                 [% END %]
101                                 <label class="permissiondesc" for="[% sub_perm_loo.id | html %]">
102                                     [% PROCESS sub_permissions name=sub_perm_loo.code %]
103                                 </label>
104                             </div>
105                         [% END %]
106                     </div> <!-- /#flag-[% loo.bit | html %]-children -->
107                 [% END # /IF loo.sub_perm_loop %]
108                 </div> <!-- /.parent -->
109             [% END # /FOREACH loo %]
110         </div>
111     </div> <!-- /#permissionstree -->
112 </form>
113
114             </main>
115         </div> <!-- /.col-sm-10.col-sm-push-2 -->
116
117         <div class="col-sm-2 col-sm-pull-10">
118             <aside>
119                 [% INCLUDE 'circ-menu.inc' %]
120             </aside>
121         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
122     </div> <!-- /.row -->
123
124 [% MACRO jsinclude BLOCK %]
125     [% INCLUDE 'str/members-menu.inc' %]
126     [% Asset.js("js/members-menu.js") | $raw %]
127     [% Asset.js("lib/hc-sticky.js") | $raw %]
128     <script>
129         var Sticky;
130         $(document).ready(function() {
131
132             [% IF disable_superlibrarian_privs && patron.is_superlibrarian %]
133                 $("#CheckAllFlags,#UncheckAllFlags")
134                     .attr("disabled", true)
135                     .attr("title", _("The system preference ProtectSuperlibrarian is enabled"))
136                     .on("click", function(e){e.preventDefault()});
137             [% ELSE %]
138                 $("#CheckAllFlags").on("click",function(){
139                     $(".flag").attr("disabled", false);
140                     $(".flag").prop("checked", true);
141                     $("#flag-0").prop("checked", false);
142                     [% IF disable_superlibrarian_privs %]
143                         $("#flag-0").prop("disabled", true);
144                     [% END %]
145                     return false;
146                 });
147                 $("#UncheckAllFlags").on("click",function(){
148                     $(".flag").attr("disabled", false);
149                     [% IF disable_superlibrarian_privs %]
150                         $("#flag-0").prop("disabled", true);
151                     [% END %]
152                     $(".flag").prop("checked", false);
153                     return false;
154                 });
155                 $(".flag").change(function(){
156                     if(!$(this).is(':checked')){
157                         $("input#flag-0").prop("checked", false);
158                     }
159                 });
160             [% END %]
161
162             Sticky = $("#permissions_toolbar");
163             Sticky.hcSticky({
164                 stickTo: "#permissionstree",
165                 stickyClass: "floating"
166             });
167
168             $(".open div").show();
169
170             $("#permissions_filter").on("keyup", function(){
171                 $("#clear_filter").css("display","inline-block");
172                 $("a[class^=toggle-]").hide();
173                 var string = $(this).val();
174                 var divs = $("div[id!='parent-flag-superlibrarian']", ".permissions");
175                 if( string != "" && string.length > 3 ){
176                     divs.each(function(){
177                         if ( $(this).text().search(new RegExp( string, "i")) < 0 ) {
178                             $(this).hide();
179                         } else {
180                             $(this).show();
181                         }
182                     });
183                 } else {
184                     divs.show();
185                 }
186             });
187
188             $("#clear_filter").on("click", function(){
189                 $(".togglechildren_off").show();
190                 $("#permissions_filter").val("");
191                 $("div", "#permissionstree").show();
192                 $(this).css("display","none");
193             });
194
195             // Enforce Superlibrarian Privilege Mutual Exclusivity
196             if( $('input[id="flag-0"]:checked').length || $(".superlib:checked").length ){
197                 if ($('input[name="flag"]:checked').length > 1){
198                     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."));
199                 }
200
201                 setLibrarian();
202             }
203
204             $('input#flag-0').click(function() {
205                 if( $('input[id="flag-0"]:checked').length || $(".superlib:checked").length ){
206                     $('input[name="flag"]').each(function() {
207                         if($(this).attr('id') != "flag-0" && !$(this).hasClass('superlib') ){
208                             $(this).prop('disabled', true);
209                             $(this).prop('checked', false);
210                         }
211                     });
212                 }
213                 else {
214                     $('input[name="flag"]').each(function() {
215                         $(this).prop('disabled', false);
216                     });
217                 }
218             });
219
220
221             $(".toggleall_off, .toggleall_on").on('click', function(e) {
222                 e.preventDefault();
223                 if( $(this).hasClass("toggleall_on")){
224                     $(".children,.togglechildren_off").show();
225                     $(".togglechildren_on").hide();
226                 } else {
227                     $(".children,.togglechildren_off").hide();
228                     $(".togglechildren_on").show();
229                 }
230             });
231
232             $(".togglechildren_off, .togglechildren_on").on('click', function(e) {
233                 e.preventDefault();
234                 var bit = $(this).data("bit");
235                 $("#flag-" + bit + "-children").toggle();
236                 $(".toggle-" + bit).toggle();
237             });
238
239             $(".togglechildren_off, .togglechildren_on").hover( function(){
240                 $(this).parent().addClass("permission-highlight");
241             }, function(){
242                 $(this).parent().removeClass("permission-highlight");
243             });
244
245             $(".flag").on("change",function(e){
246                 e.preventDefault();
247                 if( $(this).hasClass("child") ){
248                     if( $(this).prop("checked") ){
249                         // If this is the last of all the child boxes to be checked the parent should be checked too
250                         var unchecked = 0;
251                         $(this).closest(".children").find(".child").each(function(){
252                             if( !$(this).prop("checked") ){
253                                 // There are still unchecked checkboxes in this group
254                                 unchecked = 1;
255                             }
256                         });
257                         if( unchecked === 0 ){
258                             $(this).closest(".parent").find(".flag.parent").prop("checked", true);
259                         }
260                     } else {
261                         $(this).closest(".parent").find(".flag.parent").prop("checked", false);
262                     }
263                 } else {
264                     var bit = $(this).data("bit");
265                     if( $(this).is(":checked") ){
266                         $("#flag-" + bit + "-children").show().find(".flag").prop("checked", true);
267                         $(".toggle-" + bit + ".togglechildren_on").hide();
268                         $(".toggle-" + bit + ".togglechildren_off").show();
269                     } else {
270                         $("#flag-" + bit + "-children").show().find(".flag").prop("checked", false);
271                     }
272                 }
273             });
274         });
275
276         function setLibrarian(){
277             $('input[name="flag"]').each(function() {
278                 if($(this).attr('id') != "flag-0" && !$(this).hasClass('superlib') ){
279                     $(this).prop('disabled', true);
280                     $(this).prop('checked', false);
281                 }
282             });
283         }
284
285     </script>
286 [% END %]
287
288 [% INCLUDE 'intranet-bottom.inc' %]