plugged in inital action from dropdown, delete selected linitems. fetch distribution...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 26 Mar 2009 18:33:46 +0000 (18:33 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 26 Mar 2009 18:33:46 +0000 (18:33 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@12692 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/ui/default/acq/common/li_table.js
Open-ILS/web/templates/default/acq/common/li_table.tt2

index 3b547e6..1a1db2a 100644 (file)
@@ -6,6 +6,7 @@ dojo.require('openils.User');
 dojo.require('openils.Util');
 dojo.require('openils.acq.Lineitem');
 dojo.require('openils.widget.AutoFieldWidget');
+dojo.require('dojo.data.ItemFileReadStore');
 
 function AcqLiTable() {
 
@@ -20,6 +21,11 @@ function AcqLiTable() {
     this.copyRow = this.copyTbody.removeChild(dojo.byId('acq-lit-li-details-row'));
     this.copyBatchRow = dojo.byId('acq-lit-li-details-batch-row');
     this.copyBatchWidgets = {};
+    dojo.connect(acqLitLiActionsSelector, 'onChange', 
+        function() { 
+            self.applySelectedLiAction(this.attr('value')) 
+            acqLitLiActionsSelector.attr('value', '_');
+        });
 
     dojo.byId('acq-lit-select-toggle').onclick = function(){self.toggleSelect()};
     dojo.byId('acq-lit-info-back-button').onclick = function(){self.show('list')};
@@ -80,6 +86,7 @@ function AcqLiTable() {
         self.toggleState = !self.toggleState;
     };
 
+
     /** @param all If true, assume all are selected */
     this.getSelected = function(all) {
         var selected = [];
@@ -110,13 +117,22 @@ function AcqLiTable() {
             // XXX media prefix for added content
             dojo.query('[name=jacket]', row)[0].setAttribute('src', '/opac/extras/ac/jacket/small/' + isbn);
         }
-        dojo.query('[name=infolink]', row)[0].onclick = function() {self.drawInfo(li.id())};
+        //dojo.query('[name=infolink]', row)[0].onclick = function() {self.drawInfo(li.id())};
+        dojo.query('[attr=title]', row)[0].onclick = function() {self.drawInfo(li.id())};
         dojo.query('[name=copieslink]', row)[0].onclick = function() {self.drawCopies(li.id())};
         dojo.query('[name=count]', row)[0].appendChild(document.createTextNode(li.item_count()));
         self.tbody.appendChild(row);
         self.selectors.push(dojo.query('[name=selectbox]', row)[0]);
     };
 
+    this.removeLineitem = function(liId) {
+        console.log(liId);
+        console.log('[li='+liId+']');
+        console.log(dojo.query('[li='+liId+']', this.tbody)[0]);
+        this.tbody.removeChild(dojo.query('[li='+liId+']', this.tbody)[0]);
+        delete this.liCache[liId];
+    }
+
     this.drawInfo = function(liId) {
         this.show('info');
         openils.acq.Lineitem.fetchAttrDefs(
@@ -198,6 +214,41 @@ function AcqLiTable() {
         while(this.copyTbody.childNodes[0])
             this.copyTbody.removeChild(this.copyTbody.childNodes[0]);
 
+        this._drawBatchCopyWidgets();
+
+        this._fetchDistribFormulas(
+            function() {
+                openils.acq.Lineitem.fetchAttrDefs(
+                    function() { 
+                        self._fetchLineitem(liId, function(li){self._drawCopies(li);}); 
+                    } 
+                );
+            }
+        );
+    };
+
+    this._fetchDistribFormulas = function(onload) {
+        if(this.distribForms) {
+            onload();
+        } else {
+            var self = this;
+            fieldmapper.standardRequest(
+                ['open-ils.acq', 'open-ils.acq.distribution_formula.ranged.retrieve.atomic'],
+                {   async: true,
+                    params: [openils.User.authtoken],
+                    oncomplete: function(r) {
+                        self.distribForms = openils.Util.readResponse(r);
+                        self.distribFormulaStore = 
+                            new dojo.data.ItemFileReadStore(
+                                {data:acqdf.toStoreData(self.distribForms)});
+                        onload();
+                    }
+                }
+            );
+        }
+    }
+
+    this._drawBatchCopyWidgets = function() {
         var row = this.copyBatchRow;
         dojo.forEach(['fund', 'owning_lib', 'location'],
             function(field) {
@@ -217,13 +268,6 @@ function AcqLiTable() {
             }
         );
         this.copyBatchRowDrawn = true;
-
-
-        openils.acq.Lineitem.fetchAttrDefs(
-            function() { 
-                self._fetchLineitem(liId, function(li){self._drawCopies(li);}); 
-            } 
-        );
     };
 
     this.batchCopyUpdate = function() {
@@ -339,6 +383,30 @@ function AcqLiTable() {
             }
         );
     }
+
+    this.applySelectedLiAction = function(action) {
+        switch(action) {
+            case 'delete_selected':
+                self._deleteLiList(self.getSelected());
+                break;
+        }
+    }
+
+    this._deleteLiList = function(list, idx) {
+        if(idx == null) idx = 0;
+        if(idx >= list.length) return;
+        var liId = list[idx].id();
+        fieldmapper.standardRequest(
+            ['open-ils.acq', 'open-ils.acq.lineitem.delete'],
+            {   async: true,
+                params: [openils.User.authtoken, liId],
+                oncomplete: function(r) {
+                    self.removeLineitem(liId);
+                    self._deleteLiList(list, ++idx);
+                }
+            }
+        );
+    }
 }
 
 
index 52f112f..ad526af 100644 (file)
@@ -12,8 +12,9 @@
                             <td>
                                 <div style='width:100%;text-align:right;'>
                                     <span>
-                                        <select dojoType='dijit.form.FilteringSelect' value='_'>
+                                        <select dojoType='dijit.form.FilteringSelect' value='_' jsId='acqLitLiActionsSelector'>
                                             <option value='_'>--Actions--</option>
+                                            <option value='delete_selected'>Delete Selected Items</option>
                                             <option value='selector_ready'>Mark Ready for Selector</option>
                                             <option value='order_ready'>Mark Ready for Order</option>
                                             <option value='create_order'>Create Purchase Order</option>
                         <table style='width:100%;'>
                             <tbody>
                                 <tr>
-                                    <td rowspan='2'><img style='width:40px;height:65px;' name='jacket'/></td>
-                                    <td attr='title' style='width:70%;font-weight:bold;'/>
+                                    <td rowspan='2' style='width:43px;'><img style='width:40px;height:65px;' name='jacket'></img></td>
+                                    <td style='width:70%;font-weight:bold;'><a attr='title' href='javascript:void(0);'></a></td>
                                     <td rowspan='2' style='text-align:right'>
+                                        <!--
                                         <a name='infolink' href='javascript:void(0);' style='margin-right:10px;'>Details</a>
+                                        -->
                                         <a name='copieslink' href='javascript:void(0);' 
                                             style='margin-right:20px;'>Copies(<span name='count'></span>)</a>
                                     </td>
                     </td>
                 </tr>
             </tbody>
+            <!--
+            <tbody><tr>
+                <td colspan='0'>
+                    <a href='javascript:void(0);' 
+                        onclick='openils.Util.toggle("acq-lit-distrib-formula-tbody");'>Distribution Formulas</a>
+                </td>
+            </tr></tbody>
+            -->
+            <tbody id='acq-lit-distrib-formula-tbody' class='hidden'>
+                <tr id='acq-lit-distrib-form-row'>
+                    <td name='selector'/>
+                    <td name='setbutton'/>
+                </tr>
+            </tbody>
             <tbody><tr><td class='acq-lit-table-spacer' colspan='0'/></tr></tbody>
             <tbody style='font-weight:bold;'>
                 <tr>