create part button
authorJason Etheridge <jason@esilibrary.com>
Fri, 4 Mar 2011 07:29:56 +0000 (02:29 -0500)
committerJason Etheridge <jason@esilibrary.com>
Fri, 4 Mar 2011 17:23:05 +0000 (12:23 -0500)
Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js
Open-ILS/xul/staff_client/server/locale/en-US/cat.properties

index b468b0c..4c151c8 100644 (file)
@@ -115,11 +115,11 @@ function my_init() {
         get_contentWindow(summary).xulG = { 'docid' : g.doc_id };
 
         /***********************************************************************************************************/
-        /* Fetch the monographic parts for this bib */
+        /* Setup pcrud and fetch the monographic parts for this bib */
 
         dojo.require('openils.PermaCrud');
-        var pcrud = new openils.PermaCrud({'authtoken':ses()});
-        g.parts = pcrud.search('bmp',{'record':g.doc_id},{'order_by': { 'bmp' : 'label_sortkey' } });
+        g.pcrud = new openils.PermaCrud({'authtoken':ses()});
+        g.parts = g.pcrud.search('bmp',{'record':g.doc_id},{'order_by': { 'bmp' : 'label_sortkey' } });
 
         /***********************************************************************************************************/
         /* For the call number drop down */
@@ -364,16 +364,70 @@ g.render_callnumber_copy_count_entry = function(row,ou_id,count) {
 }
 
 g.render_part_menu = function() {
+    var hbox = document.createElement('hbox');
     var menulist = document.createElement('menulist');
-    menulist.setAttribute('editable','true');
+        menulist.setAttribute('editable','true');
+        hbox.appendChild(menulist);
+    var button = document.createElement('button');
+        button.setAttribute('label',$('catStrings').getString('staff.cat.volume_copy_creator.create_part.btn.label'));
+        button.hidden = true;
+        hbox.appendChild(button);
+
     var menupopup = document.createElement('menupopup');
-    menulist.appendChild(menupopup);
+        menulist.appendChild(menupopup);
+        g.render_part_menuitems(menupopup);
+
+    button.addEventListener(
+        'command',
+        function(ev) {
+            var new_part = new bmp();
+                new_part.isnew(1);
+                new_part.label(menulist.value);
+                new_part.record(g.doc_id);
+            g.pcrud.create(new_part);
+            // FIXME - is the following authoritative with a replicated database?
+            g.parts = g.pcrud.search('bmp',{'record':g.doc_id},{'order_by': { 'bmp' : 'label_sortkey' } });
+            g.render_part_menuitems(menupopup);
+            if (menulist.selectedItem) {
+                button.hidden = true;
+            }
+        },
+        false
+    );
+
+    menulist.addEventListener(
+        'change',
+        function(ev) {
+            if (! ev.target.selectedItem) {
+                button.hidden = false;
+            }
+        },
+        false
+    );
+    menulist.addEventListener(
+        'command',
+        function(ev) {
+            button.hidden = true;
+        },
+        false
+    );
+    return hbox;
+}
+
+g.render_part_menuitems = function(menupopup) {
+    util.widgets.remove_children(menupopup);
+    var menuitem = document.createElement('menuitem');
+    menuitem.setAttribute('label','');
+    menuitem.setAttribute('value','');
+    menupopup.appendChild(menuitem);
     for (var i = 0; i < g.parts.length; i++) {
         var menuitem = document.createElement('menuitem');
         menuitem.setAttribute('label',g.parts[i].label());
+        menuitem.setAttribute('value',g.parts[i].id());
         menupopup.appendChild(menuitem);
     }
-    return menulist;
+
 }
 
 g.render_barcode_entry = function(node,callnumber,count,ou_id) {
@@ -410,7 +464,7 @@ g.render_barcode_entry = function(node,callnumber,count,ou_id) {
             tb.setAttribute('ou_id',ou_id);
             tb.setAttribute('callnumber',callnumber);
             tb.setAttribute('rel_vert_pos','4');
-            part_menu.setAttribute('rel_vert_pos','5');
+            part_menu.firstChild.setAttribute('rel_vert_pos','5');
             if (!tb.value && g.org_label_existing_copy_map[ ou_id ]) {
                 tb.value = g.org_label_existing_copy_map[ ou_id ][ callnumber ][i].barcode();
                 tb.setAttribute('acp_id', g.org_label_existing_copy_map[ ou_id ][ callnumber ][i].id());
@@ -427,8 +481,8 @@ g.render_barcode_entry = function(node,callnumber,count,ou_id) {
                     function() { ready_to_create({'target':tb}); setTimeout(function(){util.widgets.vertical_tab(tb);},0); }
                 );
                 util.widgets.apply_vertical_tab_on_enter_handler(
-                    part_menu,
-                    function() { setTimeout(function(){util.widgets.vertical_tab(part_menu);},0); }
+                    part_menu.firstChild,
+                    function() { setTimeout(function(){util.widgets.vertical_tab(part_menu.firstChild);},0); }
                 );
                 tb.addEventListener('change', function(ev) {
                     var barcode = String( ev.target.value ).replace(/\s/g,'');
index 1195262..5228b6d 100644 (file)
@@ -392,6 +392,7 @@ staff.cat.util.mark_item_missing_pieces.circ_not_found=No circulation found for
 staff.cat.volume_buckets.window_tab_name=Volume Buckets
 staff.cat.volume_copy_creator.my_init.btn.label=Apply
 staff.cat.volume_copy_creator.my_init.btn.accesskey=A
+staff.cat.volume_copy_creator.create_part.btn.label=Create Part Designator
 staff.cat.volume_copy_creator.edit_then_create.btn.label=Edit then Create
 staff.cat.volume_copy_creator.edit_then_create.btn.accesskey=C
 staff.cat.volume_copy_creator.create_with_defaults.btn.label=Create with Defaults