Bug 11375: Improve patrons permissions display
[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             <div class="btn-group pull-right">
35                 Filter: <input type="text" name="permissions_filter" id="permissions_filter" size="20" />
36                 <a href="#" id="clear_filter" style="display:none"><i class="fa fa-remove"></i></a>
37             </div>
38         </div>
39         <div class="permissions">
40             [% FOREACH loo IN loop %]
41                 [% IF ( loo.expand ) %]
42                     <div id="parent-flag-[% loo.flag | html %]" class="open parent">
43                 [% ELSE %]
44                     <div id="parent-flag-[% loo.flag | html %]" class="parent">
45                 [% END %]
46                 [% IF ( loo.checked ) %]
47                     [% IF disable_superlibrarian_privs && loo.bit == 0 %]
48                         <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" />
49                         <input type="hidden" id="flag-[% loo.bit | html %]" name="flag" value="[% loo.flag | html %]" >
50                     [% ELSE %]
51                           <input type="checkbox" data-bit="[% loo.bit | html %]" id="flag-[% loo.bit | html %]" class="parent flag" name="flag" value="[% loo.flag | html %]" checked="checked" />
52                     [% END %]
53                 [% ELSE %]
54                     [% IF disable_superlibrarian_privs && loo.bit == 0 %]
55                         <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" />
56                     [% ELSE %]
57                         <input type="checkbox" class="flag parent" data-bit="[% loo.bit | html %]" id="flag-[% loo.bit | html %]" name="flag" value="[% loo.flag | html %]" />
58                     [% END %]
59                 [% END # /IF loo.checked %]
60                     <label class="permissiondesc" for="flag-[% loo.bit | html %]">
61                         [% PROCESS main_permissions name=loo.flag %]
62                     </label>
63                     [% 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 %]
64                 [% IF ( loo.sub_perm_loop ) %]
65                     <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>
66                     <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>
67                     <div class="children" id="flag-[% loo.bit | html %]-children">
68                         [% FOREACH sub_perm_loo IN loo.sub_perm_loop %]
69                             <div class="child-flags">
70                                 [% IF ( sub_perm_loo.checked ) %]
71                                     <input type="checkbox" id="[% sub_perm_loo.id | html %]" class="child flag" name="flag" value="[% sub_perm_loo.perm | html %]" checked="checked" />
72                                 [% ELSE %]
73                                     <input type="checkbox" id="[% sub_perm_loo.id | html %]" class="child flag" name="flag" value="[% sub_perm_loo.perm | html %]" />
74                                 [% END %]
75                                 <label class="permissiondesc" for="[% sub_perm_loo.id | html %]">
76                                     [% PROCESS sub_permissions name=sub_perm_loo.code %]
77                                 </label>
78                             </div>
79                         [% END %]
80                     </div> <!-- /#flag-[% loo.bit | html %]-children -->
81                 [% END # /IF loo.sub_perm_loop %]
82                 </div> <!-- /.parent -->
83             [% END # /FOREACH loo %]
84         </div>
85     </div> <!-- /#permissionstree -->
86 </form>
87
88             </main>
89         </div> <!-- /.col-sm-10.col-sm-push-2 -->
90
91         <div class="col-sm-2 col-sm-pull-10">
92             <aside>
93                 [% INCLUDE 'circ-menu.inc' %]
94             </aside>
95         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
96     </div> <!-- /.row -->
97
98 [% MACRO jsinclude BLOCK %]
99     [% INCLUDE 'str/members-menu.inc' %]
100     [% Asset.js("js/members-menu.js") | $raw %]
101     [% Asset.js("lib/hc-sticky.js") | $raw %]
102     <script>
103         var Sticky;
104         $(document).ready(function() {
105
106             Sticky = $("#permissions_toolbar");
107             Sticky.hcSticky({
108                 stickTo: "#permissionstree",
109                 stickyClass: "floating"
110             });
111
112             $(".open div").show();
113
114             $("#permissions_filter").on("keyup", function(){
115                 $("#clear_filter").css("display","inline-block");
116                 $("a[class^=toggle-]").hide();
117                 var string = $(this).val();
118                 var divs = $("div[id!='parent-flag-superlibrarian']", ".permissions");
119                 if( string != "" && string.length > 3 ){
120                     divs.each(function(){
121                         if ( $(this).text().search(new RegExp( string, "i")) < 0 ) {
122                             $(this).hide();
123                         } else {
124                             $(this).show();
125                         }
126                     });
127                 } else {
128                     divs.show();
129                 }
130             });
131
132             $("#clear_filter").on("click", function(){
133                 $(".togglechildren_off").show();
134                 $("#permissions_filter").val("");
135                 $("div", "#permissionstree").show();
136                 $(this).css("display","none");
137             });
138
139             // Enforce Superlibrarian Privilege Mutual Exclusivity
140             if( $('input[id="flag-0"]:checked').length || $(".superlib:checked").length ){
141                 if ($('input[name="flag"]:checked').length > 1){
142                     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."));
143                 }
144
145                 $('input[name="flag"]').each(function() {
146                     if($(this).attr('id') != "flag-0" && !$(this).hasClass('superlib') ){
147                         $(this).prop('disabled', true);
148                         $(this).prop('checked', false);
149                     }
150                 });
151             }
152
153             $('input#flag-0').click(function() {
154                 if( $('input[id="flag-0"]:checked').length || $(".superlib:checked").length ){
155                     $('input[name="flag"]').each(function() {
156                         if($(this).attr('id') != "flag-0" && !$(this).hasClass('superlib') ){
157                             $(this).prop('disabled', true);
158                             $(this).prop('checked', false);
159                         }
160                     });
161                 }
162                 else {
163                     $('input[name="flag"]').each(function() {
164                         $(this).prop('disabled', false);
165                     });
166                 }
167             });
168
169             $(".togglechildren_off, .togglechildren_on").on('click', function(e) {
170                 e.preventDefault();
171                 var bit = $(this).data("bit");
172                 $("#flag-" + bit + "-children").toggle();
173                 $(".toggle-" + bit).toggle();
174             });
175
176             $(".togglechildren_off, .togglechildren_on").hover( function(){
177                 $(this).parent().addClass("permission-highlight");
178             }, function(){
179                 $(this).parent().removeClass("permission-highlight");
180             });
181
182             $(".flag").on("change",function(e){
183                 e.preventDefault();
184                 var bit = $(this).data("bit");
185                 if( $(this).is(":checked") ){
186                     $("#flag-" + bit + "-children").show().find(".flag").prop("checked", true);
187                     $(".toggle-" + bit + ".togglechildren_on").hide();
188                     $(".toggle-" + bit + ".togglechildren_off").show();
189                 } else {
190                     $("#flag-" + bit + "-children").show().find(".flag").prop("checked", false);
191                 }
192             });
193
194         });
195     </script>
196 [% END %]
197
198 [% INCLUDE 'intranet-bottom.inc' %]