integrate batch drop downs with templating
authorJason Etheridge <jason@esilibrary.com>
Fri, 11 Mar 2011 11:57:15 +0000 (06:57 -0500)
committerJason Etheridge <jason@esilibrary.com>
Fri, 11 Mar 2011 11:57:15 +0000 (06:57 -0500)
Open-ILS/xul/staff_client/server/cat/copy_editor.js
Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js
Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul

index 38fb418..7daa37c 100644 (file)
@@ -189,6 +189,9 @@ function my_init() {
             xulG.unlock_copy_editor = function() {
                 oils_unlock_page();
             };
+            xulG.notify_of_templatable_field_change = function(id,v) {
+                g.changed[ 'volume_copy_creator.'+id ] = { 'type' : 'volume_copy_creator', 'field' : id, 'value' : v };
+            }
         }
 
     } catch(E) {
@@ -280,6 +283,11 @@ g._apply_template = function(name) {
                     case 'owning_lib' :
                         g.apply_owning_lib(template[i].value);
                     break;
+                    case 'volume_copy_creator' :
+                        if (xulG.unified_interface) {
+                            xulG.apply_template_to_batch(template[i].field,template[i].value);
+                        }
+                    break;
                 }
             }
         }
@@ -451,6 +459,9 @@ g.reset = function() {
     g.render();
     g.check_for_unmet_required_fields();
     oils_unlock_page();
+    if (xulG.unified_interface) {
+        xulG.reset_batch_menus();
+    }
 }
 
 /******************************************************************************************************/
index fc2d39a..9ded72c 100644 (file)
@@ -33,6 +33,26 @@ function my_init() {
 
         if (xulG.unified_interface) {
             $('non_unified_buttons').hidden = true;
+            xulG.reset_batch_menus = function() {
+                $('batch_class_menulist').value = false;
+                util.widgets.dispatch('command',$('batch_class_menulist'));
+                $('batch_prefix_menulist').value = false;
+                util.widgets.dispatch('command',$('batch_prefix_menulist'));
+                $('batch_suffix_menulist').value = false;
+                util.widgets.dispatch('command',$('batch_suffix_menulist'));
+            }
+            xulG.apply_template_to_batch = function(id,value) {
+                if (!isNaN(Number(value))) {
+                    $(id).value = value;
+                    util.widgets.dispatch('command',$(id));
+                }
+                setTimeout(
+                    function() {
+                        // TODO:  Only apply batch to columns that haven't been adjusted manually?
+                        util.widgets.dispatch('command',$('batch_button'));
+                    },0
+                );
+            }
         } else {
             $('Create').hidden = true;
         }
@@ -1290,6 +1310,21 @@ g.list_classes = function() {
             )
         )
     ); hbox.appendChild(ml);
+    ml.setAttribute('id','batch_class_menulist');
+    ml.addEventListener(
+        'command',
+        function() {
+            if (!isNaN(Number(ml.value))) {
+                addCSSClass(hbox,'copy_editor_field_changed');
+                if (xulG.unified_interface) {
+                    xulG.notify_of_templatable_field_change('batch_class_menulist',ml.value);
+                }
+            } else {
+                removeCSSClass(hbox,'copy_editor_field_changed');
+            }
+        },
+        false
+    );
 }
 
 g.list_prefixes = function() {
@@ -1302,6 +1337,21 @@ g.list_prefixes = function() {
     for (var i = 0; i < g.common_ancestor_ou_ids.length; i++) {
         g.render_prefix_menu_items(ml.firstChild,g.common_ancestor_ou_ids[i]);
     }
+    ml.setAttribute('id','batch_prefix_menulist');
+    ml.addEventListener(
+        'command',
+        function() {
+            if (!isNaN(Number(ml.value))) {
+                addCSSClass(hbox,'copy_editor_field_changed');
+                if (xulG.unified_interface) {
+                    xulG.notify_of_templatable_field_change('batch_prefix_menulist',ml.value);
+                }
+            } else {
+                removeCSSClass(hbox,'copy_editor_field_changed');
+            }
+        },
+        false
+    );
 }
 
 g.list_suffixes = function() {
@@ -1314,11 +1364,27 @@ g.list_suffixes = function() {
     for (var i = 0; i < g.common_ancestor_ou_ids.length; i++) {
         g.render_suffix_menu_items(ml.firstChild,g.common_ancestor_ou_ids[i]);
     }
+    ml.setAttribute('id','batch_suffix_menulist');
+    ml.addEventListener(
+        'command',
+        function() {
+            if (!isNaN(Number(ml.value))) {
+                addCSSClass(hbox,'copy_editor_field_changed');
+                if (xulG.unified_interface) {
+                    xulG.notify_of_templatable_field_change('batch_suffix_menulist',ml.value);
+                }
+            } else {
+                removeCSSClass(hbox,'copy_editor_field_changed');
+            }
+        },
+        false
+    );
 }
 
 g.render_batch_button = function() {
-    var hbox = $('batch_button');
+    var hbox = $('batch_button_box');
     var btn = document.createElement('button');
+    btn.setAttribute('id','batch_button');
     btn.setAttribute('label',$('catStrings').getString('staff.cat.volume_copy_creator.my_init.btn.label'));
     btn.setAttribute('accesskey',$('catStrings').getString('staff.cat.volume_copy_creator.my_init.btn.accesskey'));
     btn.setAttribute('image','/xul/server/skin/media/images/down_arrow.gif');
@@ -1341,7 +1407,7 @@ g.render_batch_button = function() {
             for (var i = 0; i < nl.length; i++) {
                 /* classification */
                 if (nl[i].getAttribute('rel_vert_pos')==rel_vert_pos_call_number_classification && !nl[i].disabled) {
-                    var value =  $('batch_class').firstChild.value;
+                    var value =  $('batch_class_menulist').value;
                     if (!isNaN( Number(value) )) {
                         nl[i].value = value;
                         util.widgets.dispatch('command',nl[i]);
@@ -1349,7 +1415,7 @@ g.render_batch_button = function() {
                 }
                 /* prefix */
                 if (nl[i].getAttribute('rel_vert_pos')==rel_vert_pos_call_number_prefix && !nl[i].disabled) {
-                    var value =  $('batch_prefix').firstChild.value;
+                    var value =  $('batch_prefix_menulist').value;
                     if (!isNaN( Number(value) )) {
                         nl[i].value = value;
                         util.widgets.dispatch('command',nl[i]);
@@ -1357,7 +1423,7 @@ g.render_batch_button = function() {
                 }
                 /* suffix */
                 if (nl[i].getAttribute('rel_vert_pos')==rel_vert_pos_call_number_suffix && !nl[i].disabled) {
-                    var value =  $('batch_suffix').firstChild.value;
+                    var value =  $('batch_suffix_menulist').value;
                     if (!isNaN( Number(value) )) {
                         nl[i].value = value;
                         util.widgets.dispatch('command',nl[i]);
index 0d4338f..88559f3 100644 (file)
@@ -6,6 +6,7 @@
 <!-- STYLESHEETS -->
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <?xml-stylesheet href="/xul/server/skin/global.css" type="text/css"?>
+<?xml-stylesheet href="/xul/server/skin/cat.css" type="text/css"?>
 
 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
 <!-- LOCALIZATION -->
@@ -56,7 +57,7 @@
                 <hbox id="marc_cn"/>
                 <label value="Suffix:"/>
                 <hbox id="batch_suffix"/>
-                <hbox id="batch_button"/>
+                <hbox id="batch_button_box"/>
             </hbox>
             <spacer flex="1" />
         </hbox>