]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/marc_new.xul
Improve Firefox/XULRunner Support
[Evergreen.git] / Open-ILS / xul / staff_client / server / cat / marc_new.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Example Template for remote xul -->
4 <!--
5     vim:et: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
13 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
14 <!-- LOCALIZATION -->
15 <!DOCTYPE window PUBLIC "" ""[
16     <!--#include virtual="/opac/locale/${locale}/lang.dtd"-->
17 ]>
18
19 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
20 <!-- OVERLAYS -->
21 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
22
23 <window id="example_template_win" 
24     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
25     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
26
27     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
28     <!-- BEHAVIOR -->
29         <script type="text/javascript">
30         var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};
31     </script>
32         <scripts id="openils_util_scripts"/>
33
34     <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
35     <script>
36     <![CDATA[
37         var catStrings;
38
39         function $(id) { return document.getElementById(id); }
40
41         function my_init() {
42             try {
43                 /* load translatable strings for cataloging interfaces */
44                 catStrings = document.getElementById('catStrings');
45
46                 if (typeof JSAN == 'undefined') { 
47                     throw( $('commonStrings').getString('common.jsan.missing') );
48                 }
49                 JSAN.errorLevel = "die"; // none, warn, or die
50                 JSAN.addRepository('/xul/server/');
51                 JSAN.use('util.error'); g.error = new util.error();
52                 g.error.sdump('D_TRACE','my_init() for example_template.xul');
53
54                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
55                     try { window.xulG.set_tab_name(catStrings.getString('staff.cat.marc_new.tab_name')); } catch(E) { alert(E); }
56                 }
57
58                 JSAN.use('util.network'); g.network = new util.network();
59                 JSAN.use('util.widgets');
60                 JSAN.use('util.functional');
61                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
62
63                 var templates = g.network.simple_request('MARC_XML_TEMPLATE_LIST',[]);
64                 if (typeof templates.ilsevent != 'undefined') throw(templates);
65                 var default_template;
66                 g.prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
67                 var default_template_key = 'oils.marc_new.default_template.' + window.location.hostname;
68                 if(g.data.last_marc_template) default_template = g.data.last_marc_template;
69                 if(!default_template) {
70                     var has_key = g.prefs.prefHasUserValue(default_template_key);
71                     if(has_key) default_template = g.prefs.getCharPref(default_template_key);
72                 }
73                 var ml = util.widgets.make_menulist(
74                     util.functional.map_list(
75                         templates.sort(),
76                         function(el) {
77                             return [ el /* The menu entry label */, el /* The menu entry value */ ];
78                         }
79                     ), default_template
80                 );
81                 $('menu_placeholder').appendChild(ml);
82
83                 $('load').addEventListener(
84                     'command',
85                     function(ev) {
86
87                         var template_name;
88                         try {
89
90                             template_name = $('menu_placeholder').firstChild.value;
91                             var marc = g.network.simple_request(
92                                 'MARC_XML_TEMPLATE_RETRIEVE',
93                                 [ template_name ]
94                             );
95                             if (typeof marc.ilsevent != 'undefined') throw(marc);
96
97                             g.data.stash_retrieve();
98                             g.data.last_marc_template = template_name;
99                             g.data.stash('last_marc_template');
100
101                             var url = urls.XUL_MARC_EDIT;
102                             var params = {
103                                 'record' : { 'marc' : marc },
104                                 'marc_control_number_identifier': g.data.hash.aous['cat.marc_control_number_identifier'] || 'Set cat.marc_control_number_identifier in Library Settings',
105                                 'fast_add_item' : function(doc_id,cn_label,cp_barcode) {
106                                     try {
107                                         JSAN.use('cat.util'); return cat.util.fast_item_add(doc_id,cn_label,cp_barcode);
108                                     } catch(E) {
109                                         alert(E);
110                                     }
111                                 },
112                                 'save' : {
113                                     'label' : catStrings.getString('staff.cat.marc_new.create_record.label'),
114                                     'func' : function(new_marcxml) {
115                                         try {
116                                             var robj = g.network.simple_request(
117                                                 'MARC_XML_RECORD_IMPORT',
118                                                 [ ses(), new_marcxml, catStrings.getString('staff.cat.marc_new.system_local.label'), 1 ]
119                                             );
120                                             if (typeof robj.ilsevent != 'undefined') throw(robj);
121
122                                             /* Replace tab with OPAC-view of record */
123
124                                             var opac_url = xulG.url_prefix('opac_rdetail') + robj.id();
125                                             var content_params = {
126                                                 'session' : ses(),
127                                                 'authtime' : ses('authtime'),
128                                                 'opac_url' : opac_url
129                                             };
130                                             return { 
131                                                 'id' : robj.id(), 
132                                                 'on_complete' : function() {
133                                                     try {
134                                                         xulG.set_tab(
135                                                             xulG.url_prefix('XUL_OPAC_WRAPPER'),
136                                                             {'tab_name': catStrings.getString('staff.cat.marc_new.retrieving.label')},
137                                                             content_params
138                                                         );
139                                                     } catch(E) {
140                                                         alert(E);
141                                                     } 
142                                                 }
143                                             };
144
145                                         } catch(E) {
146                                             g.error.standard_unexpected_error_alert(
147                                                 catStrings.getString('staff.cat.marc_new.creating_record.error'), E
148                                             );
149                                         }
150                                     }
151                                 },
152                                 'lock_tab' : xulG.lock_tab,
153                                 'unlock_tab' : xulG.unlock_tab
154                             };
155                             var marc_editor = document.createElement('iframe');
156                             $('marc_editor_box').appendChild(marc_editor);
157                             marc_editor.setAttribute('flex','1');
158                             marc_editor.setAttribute('src',url);
159                             get_contentWindow(marc_editor).xulG = params;
160
161                             /* hide template widgets */
162                             $('actions').hidden = true;
163
164                             window.xulG.set_tab_name(template_name);
165
166                         } catch(E) {
167                             g.error.standard_unexpected_error_alert(
168                                 catStrings.getFormattedString('staff.cat.marc_new.loading_template.error', [template_name]), E
169                             );
170                         }
171
172                     },
173                     false
174                 );
175
176                 $('set_default').addEventListener(
177                     'command',
178                     function(ev) {
179                         var template_name;
180                         try {
181                             template_name = $('menu_placeholder').firstChild.value;
182                             g.prefs.setCharPref(default_template_key, template_name);
183                             alert(catStrings.getFormattedString('staff.cat.marc_new.set_default.success', [template_name]));
184                         } catch (E) {
185                             g.error.standard_unexpected_error_alert(
186                                 catStrings.getFormattedString('staff.cat.marc_new.set_default.error', [template_name]), E
187                             );
188                         }
189                     },
190                     false
191                 );
192
193             } catch(E) {
194                 g.error.standard_unexpected_error_alert('cat/marc_new.xul',E);
195             }
196         }
197
198     ]]>
199     </script>
200
201     <messagecatalog id="catStrings" src="/xul/server/locale/<!--#echo var='locale'-->/cat.properties" />
202     <messagecatalog id="circStrings" src="/xul/server/locale/<!--#echo var='locale'-->/circ.properties" />
203
204     <vbox id="marc_editor_box" flex="1">
205         <hbox id="actions">
206             <hbox id="menu_placeholder" />
207             <button id="load" label="&staff.cat.marc_new.load.label;" accesskey="&staff.cat.marc_new.load.accesskey;"/>
208             <button id="set_default" label="&staff.cat.marc_new.set_default.label;" accesskey="&staff.cat.marc_new.set_default.accesskey;"/>
209         </hbox>
210     </vbox>
211
212 </window>
213