]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/volume_copy_editor.js
Improve Firefox/XULRunner Support
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / cat / volume_copy_editor.js
1 var error;
2 var g = {};
3
4 function my_init() {
5     try {
6         if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
7         JSAN.errorLevel = "die"; // none, warn, or die
8         JSAN.addRepository('/xul/server/');
9         JSAN.use('util.error'); error = new util.error();
10         error.sdump('D_TRACE','my_init() for main_test.xul');
11
12         /*if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
13             try { window.xulG.set_tab_name('Test'); } catch(E) { alert(E); }
14         }*/
15
16         // Both interfaces look for this
17         xulG.unified_interface = true;
18
19         // Item Attribute Editor looks for these
20         xulG.not_modal = true;
21         xulG.edit = true;
22
23         // Volume Creator looks for these
24         xulG.no_bib_summary = true;
25         xulG.volume_ui_callback_for_unified_interface = function() {
26             on_volume_pane_load();
27         };
28
29         // Spawn the volume/copy creator
30         JSAN.use('util.browser');
31         var volume_pane = new util.browser();
32         volume_pane.init(
33             {
34                 'url' : urls.XUL_VOLUME_COPY_CREATOR_ORIGINAL,
35                 'push_xulG' : true,
36                 'alt_print' : false,
37                 'browser_id' : 'volume_pane',
38                 'passthru_content_params' : xulG
39             }
40         );
41
42         setup_templates();
43
44         // Spawn the item attribute editor
45         var item_pane = new util.browser();
46         item_pane.init(
47             {
48                 'url' : urls.XUL_COPY_EDITOR,
49                 'push_xulG' : true,
50                 'alt_print' : false,
51                 'browser_id' : 'item_pane',
52                 'passthru_content_params' : xulG,
53                 'on_url_load' : g.clone_template_bar // from setup_templates()
54             }
55         );
56
57     } catch(E) {
58         alert('Error in volume_copy_editor.js, my_init(): ' + E);
59     }
60 }
61
62 function setup_templates() {
63     try {
64         JSAN.use('util.widgets'); JSAN.use('util.functional');
65
66         // Once the item attribute editor is loaded, clone and import its template menu to this window with this callback
67         g.clone_template_bar = function() {
68             var item_editor_template_bar = get_contentWindow( $('item_pane') ).document.getElementById('template_bar');
69             $('template_bar_holder').appendChild(
70                 document.importNode(
71                     item_editor_template_bar,
72                     true // children
73                 )
74             );
75             item_editor_template_bar.hidden = true;
76             g.apply_template = function() {
77                 xulG.update_item_editor_template_selection( $('template_menu').value );
78                 xulG.item_editor_apply_template();
79             };
80             g.delete_template = function() {
81                 xulG.update_item_editor_template_selection( $('template_menu').value );
82                 xulG.item_editor_delete_template();
83             };
84             g.save_template = function() { xulG.item_editor_save_template(); };
85             g.import_templates = function() { xulG.item_editor_import_templates(); };
86             g.export_templates = function() { xulG.item_editor_export_templates(); };
87             g.reset = function() { xulG.item_editor_reset(); };
88
89             // just do this once; not sure if on_url_load could fire multiple times
90             g.clone_template_bar = function() {};
91         }
92
93         // callback for populating the list of templates
94         xulG.update_unified_template_list = function(list) {
95             try {
96                 util.widgets.remove_children('template_placeholder');
97                 g.template_menu = util.widgets.make_menulist( list );
98                 g.template_menu.setAttribute('id','template_menu');
99                 $('template_placeholder').appendChild(g.template_menu);
100                 g.template_menu.addEventListener(
101                     'command',
102                     function() {
103                         xulG.update_item_editor_template_selection( g.template_menu.value );
104                     },
105                     false
106                 );
107             } catch(E) {
108                 alert('Error in volume_copy_editor.js, xulG.update_unified_template_list(): ' + E);
109             }
110         };
111
112         // used for loading default template selection
113         xulG.update_unified_template_selection = function(value) {
114             g.template_menu.setAttribute('value', value);
115             g.template_menu.value = value;
116         };
117
118     } catch(E) {
119         alert('Error in volume_copy_editor.js, setup_templates(): ' + E);
120     }
121 }
122
123 function on_volume_pane_load() {
124     try {
125         var f_content = get_contentWindow( $('volume_pane' ) );
126
127         // horizontal UI variant has its own create button
128         if ($('Create')) {
129             var original_btn = f_content.document.getElementById('Create');
130             original_btn.hidden = true;
131             $('Create').setAttribute(
132                 'label',
133                 $('catStrings').getString('staff.cat.volume_copy_creator.create.btn.label')
134             );
135             $('Create').setAttribute(
136                 'accesskey',
137                 $('catStrings').getString('staff.cat.volume_copy_creator.create.btn.accesskey')
138             );
139             g.stash_and_close = function(p) {
140                 // Wire up the method for the replacement button
141                 f_content.g.stash_and_close(p);
142             }
143         }
144
145         // load the bib summary pane
146         var sb = document.getElementById('summary_box');
147         while(sb.firstChild) sb.removeChild(sb.lastChild);
148         var summary = document.createElement('iframe'); sb.appendChild(summary);
149         summary.setAttribute('src',urls.XUL_BIB_BRIEF);
150         summary.setAttribute('flex','1');
151         get_contentWindow(summary).xulG = { 'docid' : f_content.g.doc_id };
152         dump('f_content.g.doc_id = ' + f_content.g.doc_id + '\n');
153     } catch(E) {
154         alert('Error in volume_copy_editor.js, on_volume_pane_load(): ' + E);
155     }
156 }