added the ability to save selected search results and save results to an existing...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 11 Jul 2008 22:53:32 +0000 (22:53 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 11 Jul 2008 22:53:32 +0000 (22:53 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@10018 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/acq/picklist/bib_search.js
Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/picklist/bib_search.html

index c916c36..d14874f 100644 (file)
@@ -6,10 +6,13 @@ dojo.require('dijit.form.TextBox');
 dojo.require('dijit.form.NumberSpinner');
 dojo.require('openils.Event');
 dojo.require('openils.acq.Picklist');
+dojo.require('openils.acq.Lineitems');
 dojo.require('openils.User');
 
 var searchFields = [];
 var resultPicklist;
+var resultLIs;
+var selectedLIs;
 var recvCount = 0;
 var sourceCount = 0; // how many sources are we searching
 var user = new openils.User();
@@ -112,6 +115,7 @@ function handleResult(r) {
 function viewResults(plId) {
     var plist = new openils.acq.Picklist(plId,
         function(model) {
+            resultLIs = plist._items;
             dojo.style('oils-acq-pl-search-results', 'visibility', 'visible');
             JUBGrid.populate(plResultGrid, model, plist._items);
         },
@@ -120,12 +124,73 @@ function viewResults(plId) {
     resultPicklist = plist._plist;
 }
 
+function loadPLSelect() {
+    var plList = [];
+    function handleResponse(r) {
+        plList.push(r.recv().content());
+    }
+    var method = 'open-ils.acq.picklist.user.retrieve';
+    fieldmapper.standardRequest(
+        ['open-ils.acq', method],
+        {   async: true,
+            params: [openils.User.authtoken],
+            onresponse: handleResponse,
+            oncomplete: function() {
+                plAddExistingSelect.store = 
+                    new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(plList)});
+                plAddExistingSelect.setValue();
+            }
+        }
+    );
+}
+
+
 function saveResults(values) {
-    if(!values.name) return;
-    resultPicklist.name(values.name); 
-    openils.acq.Picklist.update(resultPicklist,
-        function(stat) {
-            location.href = 'view/' + resultPicklist.id(); 
+    selectedLIs = resultLIs;
+
+    if(values.which == 'selected') {
+        selectedLIs = [];
+        var selected = plResultGrid.selection.getSelected();
+        for(var idx = 0; idx < selected.length; idx++) {
+            var rowIdx = selected[idx];
+            var id = plResultGrid.model.getRow(rowIdx).id;
+            for(var i = 0; i < resultLIs.length; i++) {
+                var pl = resultLIs[i];
+                if(pl.id() == id) {
+                    selectedLIs.push(pl);
+                }
+            }
+        }
+    }
+        
+    if(values.new_name && values.new_name != '') {
+        // XXX create a new PL and copy LIs over
+        /*
+        if(values.which = 'selected') {
+            resultPicklist = new acqpl();
+            resultPicklist.owner(user.user.id())
+        } 
+        */
+        resultPicklist.name(values.new_name); 
+        openils.acq.Picklist.update(resultPicklist,
+            function(stat) {
+                location.href = 'view/' + resultPicklist.id(); 
+            }
+        );
+    } else if(values.existing_pl) {
+        updateLiList(values.existing_pl, selectedLIs, 0, 
+            function(){location.href = 'view/' + values.existing_pl});
+    }
+}
+
+function updateLiList(pl, list, idx, oncomplete) {
+    if(idx >= list.length)
+        return oncomplete();
+    var li = selectedLIs[idx];
+    li.picklist(pl);
+    new openils.acq.Lineitems({lineitem:li}).update(
+        function(r) {
+            updateLiList(pl, list, ++idx, oncomplete);
         }
     );
 }
index e17fe80..bfd2200 100644 (file)
             <span>${('Save Results')}</span>
             <div dojoType="dijit.TooltipDialog" execute="saveResults(arguments[0]);">
                 <script type='dojo/connect' event='onOpen'>
+                    loadPLSelect(); 
                 </script>
                 <table class='dijitTooltipTable'>
                     <tr>
-                        <td><label for="name">${_('Save as picklist:')} </label></td>
-                        <td><input dojoType="dijit.form.TextBox" name="name"></td>
+                        <td colspan='2'>
+                            <input dojoType="dijit.form.RadioButton" name="which" type='radio' checked='checked' value='selected'/>
+                            <label for="name">${_('Save selected')}</label>
+                            <input dojoType="dijit.form.RadioButton" name="which" type='radio' value='all'/>
+                            <label for="name">${_('Save all')}</label>
+                        </td>
+                    </tr>
+                    <tr><td colspan='2'><hr/></td></tr>
+                    <tr>
+                        <td><label for="new_name">${_('Save as picklist:')} </label></td>
+                        <td><input dojoType="dijit.form.TextBox" name="new_name"/></td>
+                    </tr>
+                    <tr>
+                        <td><label for="existing_pl">${_('Add to picklist:')} </label></td>
+                        <td>
+                            <input jsId='plAddExistingSelect' dojoType="dijit.form.FilteringSelect" 
+                                name="existing_pl" searchAttr='name' displayAttr='name'/>
+                        </td>
                     </tr>
                     <tr>
                         <td colspan='2' align='center'>