Bug 20538: Remove the need of writing [% KOHA_VERSION %] everywhere
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / member-flags.tt
blobd380187b6583ba9542f5eb03fa6097e707cbbd9a
1 [% USE Asset %]
2 [% USE Branches %]
3 [% SET footerjs = 1 %]
4 [% PROCESS 'permissions.inc' %]
5 [% INCLUDE 'doc-head-open.inc' %]
6 <title>Koha &rsaquo; Patrons &rsaquo; Set permissions for [% patron.surname %], [% patron.firstname %]</title>
7 [% Asset.css("css/treeview/jquery.treeview.css") %]
8 [% INCLUDE 'doc-head-close.inc' %]
9 </head>
11 <body id="pat_member-flags" class="pat">
12 [% INCLUDE 'header.inc' %]
13 [% INCLUDE 'patron-search.inc' %]
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 %], [% patron.firstname %]</div>
17 <div id="doc3" class="yui-t2">
18    
19    <div id="bd">
20         <div id="yui-main">
21         <div class="yui-b">
22 [% INCLUDE 'members-toolbar.inc' %]
24 <form method="post" action="/cgi-bin/koha/members/member-flags.pl">
25     <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
26     <input type="hidden" name="member" id="borrowernumber" value="[% patron.borrowernumber %]" />
27     <input type="hidden" name="newflags" value="1" />
28     <h1>Set permissions for [% patron.surname %], [% patron.firstname %]</h1>
29     <!-- <ul id="permissionstree"><li class="root">All privileges<ul> -->
30     <ul id="permissionstree" class="treeview-grey">
31         <!-- <li class="folder-close">One level down<ul> -->
32     [% FOREACH loo IN loop %]
33         [% IF ( loo.expand ) %]
34         <li class="open">
35         [% ELSE %]
36         <li>
37         [% END %]
38                         [% IF ( loo.checked ) %]
39                 <input type="checkbox" class="flag parent" id="flag-[% loo.bit %]" name="flag" value="[% loo.flag %]" checked="checked" />
40                         [% ELSE %]
41                 <input type="checkbox" class="flag parent" id="flag-[% loo.bit %]" name="flag" value="[% loo.flag %]" />
42                         [% END %]
43                 <label class="permissioncode" for="flag-[% loo.bit %]">[% loo.flag %]</label>
44                 <span class="permissiondesc">[% PROCESS main_permissions name=loo.flag %]</span>
45             [% IF ( loo.sub_perm_loop ) %]
46                 <ul id="flag-[% loo.bit %]-children">
47                     [% FOREACH sub_perm_loo IN loo.sub_perm_loop %]
48                         <li>
49                                     [% IF ( sub_perm_loo.checked ) %]
50                             <input type="checkbox" class="flag child" id="[% sub_perm_loo.id %]" name="flag" value="[% sub_perm_loo.perm %]" checked="checked" />
51                                     [% ELSE %]
52                             <input type="checkbox" class="flag child" id="[% sub_perm_loo.id %]" name="flag" value="[% sub_perm_loo.perm %]" />
53                                     [% END %]
54                     <label class="permissioncode" for="[% sub_perm_loo.id %]">[% sub_perm_loo.code %]</label>
55                              <span class="permissiondesc">[% PROCESS sub_permissions name=sub_perm_loo.code %]</span>
56                         </li>
57                     [% END %]
58                 </ul>
59                 </li>
60             [% ELSE %]
61                 </li>
62                         [% END %]
63     [% END %]
64         <!-- </ul></li> -->
65     <!-- </ul></li></ul> -->
66     </ul>
68 <fieldset class="action"><input type="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a></fieldset>
70 </form>
71 </div>
72 </div>
74 <div class="yui-b">
75 [% INCLUDE 'circ-menu.inc' %]
76 </div>
77 </div>
79 [% MACRO jsinclude BLOCK %]
80     [% Asset.js("js/members-menu.js") %]
81     [% Asset.js("lib/jquery/plugins/jquery.treeview.pack.js") %]
82     <!-- set up tree -->
83     <script type="text/javascript">
84         $(document).ready(function() {
85             $("#permissionstree").treeview({animated: "fast", collapsed: true});
87             // Enforce Superlibrarian Privilege Mutual Exclusivity
88             if($('input[id="flag-0"]:checked').length){
89                 if ($('input[name="flag"]:checked').length > 1){
90                     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."));
91                 }
93                 $('input[name="flag"]').each(function() {
94                     if($(this).attr('id') != "flag-0"){
95                         $(this).prop('disabled', true);
96                         $(this).prop('checked', false);
97                     }
98                 });
99             }
101             $('input#flag-0').click(function() {
102                 if($('input[id="flag-0"]:checked').length){
103                     $('input[name="flag"]').each(function() {
104                         if($(this).attr('id') != "flag-0"){
105                             $(this).prop('disabled', true);
106                             $(this).prop('checked', false);
107                         }
108                     });
109                 }
110                 else {
111                     $('input[name="flag"]').each(function() {
112                         $(this).prop('disabled', false);
113                     });
114                 }
115             });
117             $(".flag").on("change",function(){
118                 if( $(this).hasClass("parent") ){
119                     toggleChildren(this);
120                 } else {
121                     toggleParent(this);
122                 }
123             });
125         });
127         // manage checking/unchecking parent permissions
128         var originalChildStates = {}; /* keep track of subpermission checkbox values
129                                          so that user can recover from accidentally
130                                          toggling a parent/module permission */
131         function selectChildren(parentInput) {
132             var childListId = parentInput.id + '-children';
133             var list = document.getElementById(childListId);
134             var children = [];
135             if (list) {
136                 var inputs = list.getElementsByTagName('input');
137                 for (var i = 0; i < inputs.length; i++) {
138                     if (inputs[i].type == 'checkbox') {
139                         children.push(inputs[i]);
140                     }
141                 }
142             }
143             return children;
144         }
146         function toggleChildren(parentInput) {
147             var children = selectChildren(parentInput);
148             if (children.length == 0) {
149                 return;
150             }
151             var checked = parentInput.checked;
152             if (checked && parentInput.parentNode.className == 'expandable') {
153                 /* expand the tree */
154                 $(".hitarea", parentInput.parentNode).click();
155             }
156             for (var i = 0; i < children.length; i++) {
157                 if (checked) {
158                     originalChildStates[children[i].id] = children[i].checked;
159                     children[i].checked = checked;
160                 } else {
161                     if (children[i].id in originalChildStates) {
162                         children[i].checked = originalChildStates[children[i].id];
163                     } else {
164                         children[i].checked = checked;
165                     }
166                 }
167             }
168         }
170         function toggleParent(childInput) {
171             originalChildStates[childInput.id] = childInput.checked;
172             if (childInput.checked) {
173                 return;
174             }
175             var parentId = childInput.parentNode.parentNode.id.replace(/-children$/, '');;
176             var parentInput = document.getElementById(parentId);
177             if (parentInput) {
178                 parentInput.checked = false;
179             }
180         }
182     </script>
183 [% END %]
185 [% INCLUDE 'intranet-bottom.inc' %]