89b54407e186bd6de7eb3867ecdcd06549500246
[working/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  vim:noet:sw=4:ts=4:
6 -->
7
8 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
9 <!-- STYLESHEETS -->
10 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
11 <?xml-stylesheet href="chrome://open_ils_staff_client/skin/global.css" type="text/css"?>
12 <?xml-stylesheet href="chrome://open_ils_staff_client/skin/auth.css" type="text/css"?>
13
14 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
15 <!-- LOCALIZATION -->
16 <!DOCTYPE window SYSTEM "chrome://open_ils_staff_client/locale/lang.dtd">
17
18 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
19 <!-- OVERLAYS -->
20 <?xul-overlay href="chrome://open_ils_staff_client/OpenILS/content/util_overlay_chrome.xul"?>
21
22 <window id="simple_auth_win" 
23     onload="try { my_init(); font_helper(); } catch(E) { alert(E); }"
24     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
25
26     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
27     <!-- BEHAVIOR -->
28         <script type="text/javascript">
29         var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};
30     </script>
31         <scripts id="openils_util_scripts"/>
32
33     <script>
34     <![CDATA[
35         function my_init() {
36             try {
37                 if (typeof JSAN == 'undefined') { 
38                     throw( offlineStrings.getString('common.jsan.missing'));
39                 }
40                 JSAN.errorLevel = "die"; // none, warn, or die
41                 JSAN.addRepository('..');
42                 JSAN.use('util.error'); g.error = new util.error();
43                 g.error.sdump('D_TRACE','my_init() for simple_auth.xul');
44
45                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
46                 g.data.temporary_session = ''; g.data.stash('temporary_session');
47
48                 $('server').value = g.data.server_unadorned;
49
50                 addCSSClass(document.documentElement,xul_param('login_type',{'modal_xulG':true}))
51
52                 if (xul_param('desc_brief',{'modal_xulG':true})) {
53                     $('desc').hidden = false;
54                     $('desc_brief').appendChild( document.createTextNode( xul_param('desc_brief',{'modal_xulG':true}) ) );
55                 }
56                 if (xul_param('desc_full',{'modal_xulG':true})) {
57                     $('desc').hidden = false;
58                     $('desc_full').appendChild( document.createTextNode( xul_param('desc_full',{'modal_xulG':true}) ) );
59                 }
60
61                 $('username').focus();
62
63                 $('username').addEventListener('keypress',handle_keypress,false);
64                 $('password').addEventListener('keypress',handle_keypress,false);
65
66             } catch(E) {
67                 var err_msg =  offlineStrings.getFormattedString('common.exception', ['simple_auth.xul', E]);
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="&staff.main.simple_auth.exception.label;"/>
135         <description id="desc_brief" style="color: red"/>
136         <description id="desc_full"/>
137     </groupbox>
138     <groupbox>
139         <caption label="&staff.main.simple_auth.authorization.label;"/>
140         <grid>
141             <columns><column /><column /></columns>
142             <rows>
143                 <row>
144                     <label value="&common.username.label;" control="username" accesskey="&common.username.accesskey;"/>
145                     <textbox id="username" />
146                 </row>
147                 <row>
148                     <label value="&staff.auth.password_prompt;" control="password" accesskey="&staff.auth.password_prompt.accesskey;"/>
149                     <textbox id="password" type="password"/>
150                 </row>
151                 <row>
152                     <button label="&staff.main.simple_auth.authorize.label;" accesskey="&staff.main.simple_auth.authorize.accesskey;" oncommand="authorize()"/>
153                     <button label="&common.cancel;" accesskey="&common.cancel.accesskey;" oncommand="window.close()"/>
154                 </row>
155             </rows>
156         </grid>
157         <label id="server" hidden="true"/>
158     </groupbox>
159     <spacer flex="1"/>
160     </vbox>
161 </window>
162