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