Rip modal_xulG_stack out, replace with openDialog
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / 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="/xul/server/skin/global.css" type="text/css"?>
12 <?xml-stylesheet href="/xul/server/skin/simple_auth.css" type="text/css"?>
13
14 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
15 <!-- LOCALIZATION -->
16 <!DOCTYPE window PUBLIC "" ""[
17     <!--#include virtual="/opac/locale/${locale}/lang.dtd"-->
18 ]>
19
20 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
21 <!-- OVERLAYS -->
22 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
23
24 <window id="simple_auth_win" oils_persist="height width sizemode"
25     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
26     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
27
28     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
29     <!-- BEHAVIOR -->
30         <script type="text/javascript">
31         var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};
32     </script>
33         <scripts id="openils_util_scripts"/>
34
35     <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
36     <script>
37     <![CDATA[
38
39         var offlineStrings = document.getElementById('offlineStrings');
40
41         function my_init() {
42             try {
43                 if (typeof JSAN == 'undefined') { 
44                     throw( offlineStrings.getString('common.jsan.missing'));
45                 }
46                 JSAN.errorLevel = "die"; // none, warn, or die
47                 JSAN.addRepository('/xul/server/');
48                 JSAN.use('util.error'); g.error = new util.error();
49                 g.error.sdump('D_TRACE','my_init() for simple_auth.xul');
50
51                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
52                 g.data.temporary_session = ''; g.data.stash('temporary_session');
53
54                 $('server').value = g.data.server_unadorned;
55
56                 addCSSClass(document.documentElement,xul_param('login_type'))
57
58                 if (xul_param('desc_brief')) {
59                     $('desc').hidden = false;
60                     $('desc_brief').appendChild( document.createTextNode( xul_param('desc_brief') ) );
61                 }
62                 if (xul_param('desc_full')) {
63                     $('desc').hidden = false;
64                     $('desc_full').appendChild( document.createTextNode( xul_param('desc_full') ) );
65                 }
66
67                 $('username').focus();
68
69                 $('username').addEventListener('keypress',handle_keypress,false);
70                 $('password').addEventListener('keypress',handle_keypress,false);
71
72             } catch(E) {
73                 var err_msg =  offlineStrings.getFormattedString('common.exception', ['simple_auth.xul', E]);
74                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
75                 alert(err_msg);
76             }
77         }
78
79         function $(id) { return document.getElementById(id); }
80
81         function handle_keypress(ev) {
82             if ( (! ev.keyCode) || (ev.keyCode != 13) ) return;
83             switch(ev.target) {
84                 case $('username') : $('password').focus(); break;
85                 case $('password') : authorize(); break;
86                 default: break;
87             }
88         }
89
90         function authorize() {
91             try {
92                 JSAN.use('auth.session');
93                 g.session = new auth.session(
94                     {
95                         'name_prompt' : $('username'),
96                         'password_prompt' : $('password'),
97                         'server_prompt' : $('server'),
98                     },
99                     xul_param('login_type') || 'temp'
100                 );
101                 g.session.on_init = function() { 
102                     try {
103                         JSAN.use('util.network'); var n = new util.network();
104                         var staff = n.simple_request('FM_AU_RETRIEVE_VIA_SESSION',[ g.session.key ]);
105                         g.data.temporary_session = {  // old way because of local chrome still out there
106                             'key' : g.session.key, 
107                             'authtime' : g.session.authtime, 
108                             'usr' : js2JSON(staff)
109                         }
110                         g.data.stash('temporary_session');
111                         xulG.temporary_session = g.data.temporary_session;
112                         window.close();
113                     } catch(E) {
114                         g.error.standard_unexpected_error_alert('simple_auth.session.on_init',E);
115                     }
116                 }
117                 g.session.on_init_error = function() { 
118                     $('password').value = '';
119                     $('username').focus();
120                     $('username').select();
121                  }
122                 g.session.init();
123             } catch(E) {
124                 alert(E);
125             }
126         }
127
128     ]]>
129     </script>
130
131     <commandset id="simple_auth_cmds">
132         <command id="cmd_broken" />
133     </commandset>
134
135     <vbox id="simple_auth_main" flex="1">
136     <groupbox id="desc" hidden="true">
137         <caption label="&staff.main.simple_auth.exception.label;"/>
138         <description id="desc_brief" style="color: red"/>
139         <description id="desc_full"/>
140     </groupbox>
141     <groupbox>
142         <caption label="&staff.main.simple_auth.authorization.label;"/>
143         <grid>
144             <columns><column /><column /></columns>
145             <rows>
146                 <row>
147                     <label value="&common.username.label;" control="username" accesskey="&common.username.accesskey;"/>
148                     <textbox id="username" />
149                 </row>
150                 <row>
151                     <label value="&staff.auth.password_prompt;" control="password" accesskey="&staff.auth.password_prompt.accesskey;"/>
152                     <textbox id="password" type="password"/>
153                 </row>
154                 <row>
155                     <button label="&common.cancel;" accesskey="&common.cancel.accesskey;" oncommand="window.close()"/>
156                     <button label="&staff.main.simple_auth.authorize.label;" accesskey="&staff.main.simple_auth.authorize.accesskey;" oncommand="authorize()"/>
157                 </row>
158             </rows>
159         </grid>
160         <label id="server" hidden="true"/>
161     </groupbox>
162     <spacer flex="1"/>
163     </vbox>
164 </window>
165