Bug 21964: Update two-column templates with Bootstrap grid: Patrons part 2
[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 [% Asset.css("css/treeview/jquery.treeview.css") | $raw %]
9 [% INCLUDE 'doc-head-close.inc' %]
10 </head>
11
12 <body id="pat_member-flags" class="pat">
13 [% INCLUDE 'header.inc' %]
14 [% INCLUDE 'patron-search.inc' %]
15
16 <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>
17
18 <div class="main container-fluid">
19     <div class="row">
20         <div class="col-sm-10 col-sm-push-2">
21             <main>
22
23 [% INCLUDE 'members-toolbar.inc' %]
24
25 <form method="post" action="/cgi-bin/koha/members/member-flags.pl">
26     <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
27     <input type="hidden" name="member" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
28     <input type="hidden" name="newflags" value="1" />
29     <h1>Set permissions for [% patron.surname | html %], [% patron.firstname | html %]</h1>
30     <!-- <ul id="permissionstree"><li class="root">All privileges<ul> -->
31     <ul id="permissionstree" class="treeview-grey">
32         <!-- <li class="folder-close">One level down<ul> -->
33     [% FOREACH loo IN loop %]
34         [% IF ( loo.expand ) %]
35         <li class="open">
36         [% ELSE %]
37         <li>
38         [% END %]
39                         [% IF ( loo.checked ) %]
40           [% IF disable_superlibrarian_privs && loo.bit == 0 %]
41               <input type="checkbox" disabled="disabled" class="flag parent superlib" id="flag-[% loo.bit | html %]_disabled" name="flag" value="[% loo.flag | html %]" checked="checked" title="The system preference ProtectSuperlibrarianPrivileges is enabled" />
42               <input type="hidden" id="flag-[% loo.bit | html %]" name="flag" value="[% loo.flag | html %]" >
43           [% ELSE %]
44               <input type="checkbox" class="flag parent" id="flag-[% loo.bit | html %]" name="flag" value="[% loo.flag | html %]" checked="checked" />
45           [% END %]
46                         [% ELSE %]
47           [% IF disable_superlibrarian_privs && loo.bit == 0 %]
48               <input type="checkbox" disabled="disabled" class="flag parent" id="flag-[% loo.bit | html %]_disabled" name="flag" value="[% loo.flag | html %]" title="The system preference ProtectSuperlibrarianPrivileges is enabled" />
49           [% ELSE %]
50               <input type="checkbox" class="flag parent" id="flag-[% loo.bit | html %]" name="flag" value="[% loo.flag | html %]" />
51           [% END %]
52                         [% END %]
53                 <label class="permissioncode" for="flag-[% loo.bit | html %]">[% loo.flag | html %]</label>
54                 <span class="permissiondesc">[% PROCESS main_permissions name=loo.flag %]</span>
55             [% IF ( loo.sub_perm_loop ) %]
56                 <ul id="flag-[% loo.bit | html %]-children">
57                     [% FOREACH sub_perm_loo IN loo.sub_perm_loop %]
58                         <li>
59                                     [% IF ( sub_perm_loo.checked ) %]
60                             <input type="checkbox" class="flag child" id="[% sub_perm_loo.id | html %]" name="flag" value="[% sub_perm_loo.perm | html %]" checked="checked" />
61                                     [% ELSE %]
62                             <input type="checkbox" class="flag child" id="[% sub_perm_loo.id | html %]" name="flag" value="[% sub_perm_loo.perm | html %]" />
63                                     [% END %]
64                     <label class="permissioncode" for="[% sub_perm_loo.id | html %]">[% sub_perm_loo.code | html %]</label>
65                              <span class="permissiondesc">[% PROCESS sub_permissions name=sub_perm_loo.code %]</span>
66                         </li>
67                     [% END %]
68                 </ul>
69                 </li>
70             [% ELSE %]
71                 </li>
72                         [% END %]
73     [% END %]
74         <!-- </ul></li> -->
75     <!-- </ul></li></ul> -->
76     </ul>
77
78 <fieldset class="action"><input type="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a></fieldset>
79
80 </form>
81
82             </main>
83         </div> <!-- /.col-sm-10.col-sm-push-2 -->
84
85         <div class="col-sm-2 col-sm-pull-10">
86             <aside>
87                 [% INCLUDE 'circ-menu.inc' %]
88             </aside>
89         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
90     </div> <!-- /.row -->
91
92 [% MACRO jsinclude BLOCK %]
93     [% INCLUDE 'str/members-menu.inc' %]
94     [% Asset.js("js/members-menu.js") | $raw %]
95     [% Asset.js("lib/jquery/plugins/jquery.treeview.pack.js") | $raw %]
96     <!-- set up tree -->
97     <script>
98         $(document).ready(function() {
99             $("#permissionstree").treeview({animated: "fast", collapsed: true});
100
101             // Enforce Superlibrarian Privilege Mutual Exclusivity
102             if( $('input[id="flag-0"]:checked').length || $(".superlib:checked").length ){
103                 if ($('input[name="flag"]:checked').length > 1){
104                     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."));
105                 }
106
107                 $('input[name="flag"]').each(function() {
108                     if($(this).attr('id') != "flag-0" && !$(this).hasClass('superlib') ){
109                         $(this).prop('disabled', true);
110                         $(this).prop('checked', false);
111                     }
112                 });
113             }
114
115             $('input#flag-0').click(function() {
116                 if( $('input[id="flag-0"]:checked').length || $(".superlib:checked").length ){
117                     $('input[name="flag"]').each(function() {
118                         if($(this).attr('id') != "flag-0" && !$(this).hasClass('superlib') ){
119                             $(this).prop('disabled', true);
120                             $(this).prop('checked', false);
121                         }
122                     });
123                 }
124                 else {
125                     $('input[name="flag"]').each(function() {
126                         $(this).prop('disabled', false);
127                     });
128                 }
129             });
130
131             $(".flag").on("change",function(){
132                 if( $(this).hasClass("parent") ){
133                     toggleChildren(this);
134                 } else {
135                     toggleParent(this);
136                 }
137             });
138
139         });
140
141         // manage checking/unchecking parent permissions
142         var originalChildStates = {}; /* keep track of subpermission checkbox values
143                                          so that user can recover from accidentally
144                                          toggling a parent/module permission */
145         function selectChildren(parentInput) {
146             var childListId = parentInput.id + '-children';
147             var list = document.getElementById(childListId);
148             var children = [];
149             if (list) {
150                 var inputs = list.getElementsByTagName('input');
151                 for (var i = 0; i < inputs.length; i++) {
152                     if (inputs[i].type == 'checkbox') {
153                         children.push(inputs[i]);
154                     }
155                 }
156             }
157             return children;
158         }
159
160         function toggleChildren(parentInput) {
161             var children = selectChildren(parentInput);
162             if (children.length == 0) {
163                 return;
164             }
165             var checked = parentInput.checked;
166             if (checked && parentInput.parentNode.className == 'expandable') {
167                 /* expand the tree */
168                 $(".hitarea", parentInput.parentNode).click();
169             }
170             for (var i = 0; i < children.length; i++) {
171                 if (checked) {
172                     originalChildStates[children[i].id] = children[i].checked;
173                     children[i].checked = checked;
174                 } else {
175                     if (children[i].id in originalChildStates) {
176                         children[i].checked = originalChildStates[children[i].id];
177                     } else {
178                         children[i].checked = checked;
179                     }
180                 }
181             }
182         }
183
184         function toggleParent(childInput) {
185             originalChildStates[childInput.id] = childInput.checked;
186             if (childInput.checked) {
187                 return;
188             }
189             var parentId = childInput.parentNode.parentNode.id.replace(/-children$/, '');;
190             var parentInput = document.getElementById(parentId);
191             if (parentInput) {
192                 parentInput.checked = false;
193             }
194         }
195
196     </script>
197 [% END %]
198
199 [% INCLUDE 'intranet-bottom.inc' %]