]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/util/widget_prompt.js
internal: an alternative to default_focus
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / util / widget_prompt.js
1 var widget;
2
3 function my_init() {
4     try {
5         if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
6         JSAN.errorLevel = "die"; // none, warn, or die
7         JSAN.addRepository('/xul/server/');
8         JSAN.use('util.error'); g.error = new util.error();
9         g.error.sdump('D_TRACE','my_init() for widget_prompt.xul');
10
11         widget = xul_param('widget');
12         if (widget) {
13             $('widget_prompt_main').appendChild(widget);
14         }
15
16         if (typeof offlineStrings == 'undefined') {
17             offlineStrings = $('offlineStrings');
18         }
19
20         var ok_label = xul_param('ok_label') || offlineStrings.getString('common.ok.label');
21         $('ok_btn').setAttribute('label',ok_label);
22
23         var ok_accesskey = xul_param('ok_accesskey') || offlineStrings.getString('common.ok.accesskey');
24         $('ok_btn').setAttribute('accesskey',ok_accesskey);
25
26         var cancel_label = xul_param('cancel_label') || offlineStrings.getString('common.cancel.label');
27         $('cancel_btn').setAttribute('label',cancel_label);
28
29         var cancel_accesskey = xul_param('cancel_accesskey') || offlineStrings.getString('common.cancel.accesskey');
30         $('cancel_btn').setAttribute('accesskey',cancel_accesskey);
31
32         var desc = xul_param('desc');
33         if (desc) {
34             $('desc').appendChild( document.createTextNode( desc ) );
35         }
36
37         $('ok_btn').addEventListener('command',widget_save,false);
38         $('cancel_btn').addEventListener('command',function(ev) { window.close(); },false);
39
40         if (xul_param('title')) {
41             try { window.title = xul_param('title'); } catch(E) {}
42             try { document.title = xul_param('title'); } catch(E) {}
43         }
44
45         xulG[ 'status' ] = 'incomplete';
46
47         try { widget.focus(); } catch(E) {}
48
49     } catch(E) {
50         alert('Error in widget_prompt.js, my_init(): ' + E);
51     }
52 }
53
54 function widget_save(ev) {
55     try {
56         if (widget) {
57             switch( xul_param('access') ) {
58                 case 'method' :
59                     xulG[ 'value' ] = xulG[ 'method' ]();
60                 break;
61                 case 'attribute':
62                     xulG[ 'value' ] = widget.getAttribute('value');
63                 break;
64                 case 'property':
65                 default:
66                     xulG[ 'value'  ] = widget.value;
67                 break;
68             }
69         }
70         xulG[ 'status' ] = 'complete';
71
72         window.close();
73     } catch(E) {
74         alert('Error in widget_prompt.js, widget_save(): ' + E);
75     }
76 }
77