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