]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/main/simple_auth.xul
xul_param and modal xulG conversion
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / main / simple_auth.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Example Template for remote xul -->
4
5 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
6 <!-- STYLESHEETS -->
7 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
8 <?xml-stylesheet href="/xul/server/skin/global.css" type="text/css"?>
9 <?xml-stylesheet href="/xul/server/skin/simple_auth.css" type="text/css"?>
10
11 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
12 <!-- LOCALIZATION -->
13 <!DOCTYPE window PUBLIC "" ""[
14         <!--#include virtual="/opac/locale/en-US/lang.dtd"-->
15 ]>
16
17 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
18 <!-- OVERLAYS -->
19 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
20
21 <window id="simple_auth_win" 
22         onload="try { my_init(); font_helper(); } catch(E) { alert(E); }"
23         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
24
25         <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
26         <!-- BEHAVIOR -->
27         <script type="text/javascript">
28                 var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};
29         </script>
30         <scripts id="openils_util_scripts"/>
31
32         <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
33         <script>
34         <![CDATA[
35                 function my_init() {
36                         try {
37                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
38                                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
39                                 JSAN.errorLevel = "die"; // none, warn, or die
40                                 JSAN.addRepository('/xul/server/');
41                                 JSAN.use('util.error'); g.error = new util.error();
42                                 g.error.sdump('D_TRACE','my_init() for simple_auth.xul');
43
44                                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
45                                 g.data.temporary_session = ''; g.data.stash('temporary_session');
46
47                                 $('server').value = g.data.server_unadorned;
48
49                                 addCSSClass(document.documentElement,xul_param('login_type',{'modal_xulG':true}))
50
51                                 if (xul_param('desc_brief',{'modal_xulG':true})) {
52                                         $('desc').hidden = false;
53                                         $('desc_brief').appendChild( document.createTextNode( xul_param('desc_brief',{'modal_xulG':true}) ) );
54                                 }
55                                 if (xul_param('desc_full',{'modal_xulG':true})) {
56                                         $('desc').hidden = false;
57                                         $('desc_full').appendChild( document.createTextNode( xul_param('desc_full',{'modal_xulG':true}) ) );
58                                 }
59
60                                 $('username').focus();
61
62                                 $('username').addEventListener('keypress',handle_keypress,false);
63                                 $('password').addEventListener('keypress',handle_keypress,false);
64
65                         } catch(E) {
66                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
67                                         "system administrator or software developer the following:\nquick_auth.xul\n" + E + '\n';
68                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
69                                 alert(err_msg);
70                         }
71                 }
72
73                 function $(id) { return document.getElementById(id); }
74
75                 function handle_keypress(ev) {
76                         if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
77                         switch(ev.target) {
78                                 case $('username') : $('password').focus(); break;
79                                 case $('password') : authorize(); break;
80                                 default: break;
81                         }
82                 }
83
84                 function authorize() {
85                         try {
86                                 JSAN.use('auth.session');
87                                 g.session = new auth.session(
88                                         {
89                                                 'name_prompt' : $('username'),
90                                                 'password_prompt' : $('password'),
91                                                 'server_prompt' : $('server'),
92                                         },
93                                         xul_param('login_type',{'modal_xulG':true}) || 'temp'
94                                 );
95                                 g.session.on_init = function() { 
96                                         try {
97                                                 JSAN.use('util.network'); var n = new util.network();
98                                                 var staff = n.simple_request('FM_AU_RETRIEVE_VIA_SESSION',[ g.session.key ]);
99                                                 g.data.temporary_session = {  // old way because of local chrome still out there
100                                                         'key' : g.session.key, 
101                                                         'authtime' : g.session.authtime, 
102                                                         'usr' : js2JSON(staff)
103                                                 }
104                                                 g.data.stash('temporary_session');
105                                                 var my_xulG = { // new way, to minimize the use of global spaces
106                                                         'temporary_session' : g.data.temporary_session
107                                                 };
108                                                 update_modal_xulG(my_xulG);
109                                                 window.close();
110                                         } catch(E) {
111                                                 g.error.standard_unexpected_error_alert('simple_auth.session.on_init',E);
112                                         }
113                                 }
114                                 g.session.on_init_error = function() { 
115                                         $('password').value = '';
116                                         $('username').focus();
117                                         $('username').select();
118                                  }
119                                 g.session.init();
120                         } catch(E) {
121                                 alert(E);
122                         }
123                 }
124
125         ]]>
126         </script>
127
128         <commandset id="simple_auth_cmds">
129                 <command id="cmd_broken" />
130         </commandset>
131
132         <vbox id="simple_auth_main" flex="1">
133         <groupbox id="desc" hidden="true">
134                 <caption label="Exception"/>
135                 <description id="desc_brief" style="color: red"/>
136                 <description id="desc_full"/>
137         </groupbox>
138         <groupbox>
139                 <caption label="Authorization"/>
140                 <grid>
141                         <columns><column /><column /></columns>
142                         <rows>
143                                 <row>
144                                         <label value="Username:" control="username" accesskey="U"/>
145                                         <textbox id="username" />
146                                 </row>
147                                 <row>
148                                         <label value="Password:" control="password" accesskey="P"/>
149                                         <textbox id="password" type="password"/>
150                                 </row>
151                                 <row>
152                                         <button label="Cancel" accesskey="C" oncommand="window.close()"/>
153                                         <button label="Authorize" accesskey="A" oncommand="authorize()"/>
154                                 </row>
155                         </rows>
156                 </grid>
157                 <label id="server" hidden="true"/>
158         </groupbox>
159         <spacer flex="1"/>
160         </vbox>
161 </window>
162