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