have the unified wrapper present template controls but let the item attribute editor...
authorJason Etheridge <jason@esilibrary.com>
Mon, 28 Feb 2011 18:24:29 +0000 (13:24 -0500)
committerJason Etheridge <jason@esilibrary.com>
Wed, 2 Mar 2011 15:20:57 +0000 (10:20 -0500)
Open-ILS/xul/staff_client/server/cat/copy_editor.js
Open-ILS/xul/staff_client/server/cat/copy_editor.xul
Open-ILS/xul/staff_client/server/cat/volume_copy_editor.js
Open-ILS/xul/staff_client/server/cat/volume_copy_editor.xul

index 26f8770..1b8f5aa 100644 (file)
@@ -214,6 +214,25 @@ g.retrieve_templates = function() {
             function() { g.copy_editor_prefs[ 'template_menu' ] = { 'value' : g.template_menu.value }; g.save_attributes(); },
             false
         );
+
+        if (xulG.unified_interface) {
+            if (typeof xulG.update_unified_template_list == 'function') {
+                xulG.update_unified_template_list(list);
+                // functions the unified wrapper should use to let the item attribute editor do the heavy lifting for templates
+                xulG.update_item_editor_template_selection = function(new_value) {
+                    g.template_menu.value = new_value;
+                    g.copy_editor_prefs[ 'template_menu' ] = { 'value' : g.template_menu.value };
+                    g.save_attributes();
+                }
+                xulG.item_editor_apply_template = function() { g.apply_template(); };
+                xulG.item_editor_delete_template = function() { g.delete_template(); };
+                xulG.item_editor_save_template = function() { g.save_template(); };
+                xulG.item_editor_import_templates = function() { g.import_templates(); };
+                xulG.item_editor_export_templates = function() { g.export_templates(); };
+                xulG.item_editor_reset = function() { g.reset(); };
+            }
+        }
+
     } catch(E) {
         g.error.standard_unexpected_error_alert($('catStrings').getString('staff.cat.copy_editor.retrieve_templates.error'), E);
     }
index 100617f..62edc31 100644 (file)
@@ -42,7 +42,7 @@
         <caption id="caption" label="&staff.cat.copy_editor.groupbox1.label;"/>
 
         <hbox id="top_nav">
-            <hbox style="background: grey">
+            <hbox id="template_bar" style="background: grey" flex="1">
                 <vbox><spacer flex="1"/><label value="&staff.cat.copy_editor.templates.label;" style="font-weight: bold"/><spacer flex="1"/></vbox>
                 <hbox id="template_placeholder"/>
                 <button id="apply_template" label="&staff.cat.copy_editor.templates.apply_template.label;" accesskey="&staff.cat.copy_editor.templates.apply_template.accesskey;" oncommand="g.apply_template()"/>
@@ -50,9 +50,9 @@
                 <button id="import_templates" label="&staff.cat.copy_editor.templates.import_template.label;" oncommand="g.import_templates()"/>
                 <button id="export_templates" label="&staff.cat.copy_editor.templates.export_template.label;" oncommand="g.export_templates()"/>
                 <button id="save_template" label="&staff.cat.copy_editor.templates.save_template.label;" oncommand="g.save_template()"/>
+                <spacer flex="1"/>
+                <button label="&staff.cat.copy_editor.templates.reset.label;" accesskey="&staff.cat.copy_editor.templates.reset.accesskey;" oncommand="g.reset()"/>
             </hbox>
-            <spacer flex="1"/>
-            <button label="&staff.cat.copy_editor.templates.reset.label;" accesskey="&staff.cat.copy_editor.templates.reset.accesskey;" oncommand="g.reset()"/>
         </hbox>
 
         <hbox flex="1" style="overflow: scroll">
index 46db75f..cc3408c 100644 (file)
@@ -1,4 +1,5 @@
 var error;
+var g = {};
 
 function my_init() {
     try {
@@ -20,7 +21,7 @@ function my_init() {
         xulG.not_modal = true;
         xulG.edit = true;
 
-        // Spawn the two interfaces
+        // Spawn the volume/copy creator
         JSAN.use('util.browser');
         var volume_pane = new util.browser();
         volume_pane.init(
@@ -33,6 +34,9 @@ function my_init() {
             }
         );
 
+        setup_templates();
+
+        // Spawn the item attribute editor
         var item_pane = new util.browser();
         item_pane.init(
             {
@@ -40,14 +44,62 @@ function my_init() {
                 'push_xulG' : true,
                 'alt_print' : false,
                 'browser_id' : 'item_pane',
-                'passthru_content_params' : xulG
+                'passthru_content_params' : xulG,
+                'on_url_load' : g.clone_template_bar // from setup_templates()
             }
         );
 
-
     } catch(E) {
-        try { error.standard_unexpected_error_alert('main/test.xul',E); } catch(F) { alert(E); }
+        alert('Error in volume_copy_editor.js, my_init(): ' + E);
     }
 }
 
+function setup_templates() {
+    try {
+        JSAN.use('util.widgets'); JSAN.use('util.functional');
+
+        // Once the item attribute editor is loaded, clone and import its template menu to this window with this callback
+        g.clone_template_bar = function() {
+            var item_editor_template_bar = get_contentWindow( $('item_pane') ).document.getElementById('template_bar');
+            $('template_bar_holder').appendChild(
+                document.importNode(
+                    item_editor_template_bar,
+                    true // children
+                )
+            );
+            item_editor_template_bar.hidden = true;
+            g.apply_template = function() { xulG.item_editor_apply_template(); };
+            g.delete_template = function() { xulG.item_editor_delete_template(); };
+            g.save_template = function() { xulG.item_editor_save_template(); };
+            g.import_templates = function() { xulG.item_editor_import_templates(); };
+            g.export_templates = function() { xulG.item_editor_apply_templates(); };
+            g.reset = function() { xulG.item_editor_reset(); };
+
+            // just do this once; not sure if on_url_load could fire multiple times
+            g.clone_template_bar = function() {};
+        }
+
+        // callback for populating the list of templates
+        xulG.update_unified_template_list = function(list) {
+            try {
+                util.widgets.remove_children('template_placeholder');
+                g.template_menu = util.widgets.make_menulist( list );
+                g.template_menu.setAttribute('id','template_menu');
+                $('template_placeholder').appendChild(g.template_menu);
+                g.template_menu.addEventListener(
+                    'command',
+                    function() {
+                        xulG.update_item_editor_template_selection( g.template_menu.value );
+                    },
+                    false
+                );
+            } catch(E) {
+                alert('Error in volume_copy_editor.js, xulG.update_unified_template_list(): ' + E);
+            }
+        };
+
+    } catch(E) {
+        alert('Error in volume_copy_editor.js, setup_templates(): ' + E);
+    }
+}
 
index 521babf..f69355b 100644 (file)
@@ -32,6 +32,7 @@
     <script type="text/javascript" src="volume_copy_editor.js"/>
 
     <vbox flex="1">
+        <hbox id="template_bar_holder"/>
         <browser id="volume_pane" flex="1" />
         <splitter resizeafter="flex" resizebefore="flex"><grippy/></splitter>
         <browser id="item_pane" flex="1" />