[open-ils-commits] r14340 - in trunk/Open-ILS/web: js/ui/default/acq/common templates/default/acq/common (erickson)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Oct 9 15:48:04 EDT 2009


Author: erickson
Date: 2009-10-09 15:47:59 -0400 (Fri, 09 Oct 2009)
New Revision: 14340

Modified:
   trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js
   trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2
Log:
initial support for applying distribution formulas to a set of lineitem_details.  TODO: need to clean up the styling, support formula chains (appying multiples), storing which formula was used (somehwere)

Modified: trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js	2009-10-09 19:30:27 UTC (rev 14339)
+++ trunk/Open-ILS/web/js/ui/default/acq/common/li_table.js	2009-10-09 19:47:59 UTC (rev 14340)
@@ -501,6 +501,7 @@
 
         this._fetchDistribFormulas(
             function() {
+                self._addDistribFormulaRow();
                 openils.acq.Lineitem.fetchAttrDefs(
                     function() { 
                         self._fetchLineitem(liId, function(li){self._drawCopies(li);}); 
@@ -510,6 +511,106 @@
         );
     };
 
+    /**
+     * Insert a new row into the distribution formula selection form
+     */
+    this._addDistribFormulaRow = function() {
+        var self = this;
+
+        if(!self.distribFormulaStore) {
+            // no formulas, hide the form
+            openils.Util.hide('acq-lit-distrib-formula-tbody');
+            return;
+        }
+
+        if(!this.distribFormulaTemplate) 
+            this.distribFormulaTemplate = 
+                dojo.byId('acq-lit-distrib-formula-tbody').removeChild(dojo.byId('acq-lit-distrib-form-row'));
+
+        var row = dojo.byId('acq-lit-distrib-formula-tbody').appendChild(this.distribFormulaTemplate.cloneNode(true));
+
+        var selector = new dijit.form.FilteringSelect(
+            {store : self.distribFormulaStore}, 
+            nodeByName('selector', row)
+        );
+
+        var apply = new dijit.form.Button(
+            {label : 'Apply'},  // TODO i18n
+            nodeByName('set_button', row)
+        ); 
+
+        var release = new dijit.form.Button(
+            {label : 'Release', disabled: true}, // TODO i18n
+            nodeByName('rel_button', row)  
+        );
+
+        dojo.connect(apply, 'onClick', 
+            function() {
+                var form_id = selector.attr('value');
+                if(!form_id) return;
+                apply.attr('disabled', true);
+                release.attr('disabled', false);
+                self._applyDistribFormula(form_id);
+            }
+        );
+
+        dojo.connect(release, 'onClick', 
+            function() {
+                apply.attr('disabled', false);
+                release.attr('disabled', true);
+            }
+        );
+    };
+
+    /**
+     * Applies a distrib formula to the current set of copies
+     */
+    this._applyDistribFormula = function(formula) {
+        if(!formula) return;
+
+        formula = this.distribForms.filter(
+            function(form) {
+                return form.id() == formula;
+            }
+        )[0];
+
+        var copyRows = dojo.query('tr', self.copyTbody);
+
+        for(var rowIndex = 0; rowIndex < copyRows.length; rowIndex++) {
+            
+            var row = copyRows[rowIndex];
+            var copy_id = row.getAttribute('copy_id');
+            var copyWidgets = this.copyWidgetCache[copy_id];
+            var entryIndex = 0;
+            var entry = null;
+
+            // find the correct entry for the current row
+            dojo.forEach(formula.entries(), 
+                function(e) {
+                    if(!entry) {
+                        entryIndex += e.item_count();
+                        if(entryIndex > rowIndex)
+                            entry = e;
+                    }
+                }
+            );
+
+            if(entry) {
+                
+                //console.log("rowIndex = " + rowIndex + ", entry = " + entry.id() + ", entryIndex=" + 
+                //  entryIndex + ", owning_lib = " + entry.owning_lib() + ", location = " + entry.location());
+    
+                dojo.forEach(
+                    ['owning_lib', 'location'], 
+                    function(field) {
+                        if(entry[field]()) 
+                            copyWidgets[field].attr('value', (entry[field]()));
+                    }
+                );
+            }
+        }
+    };
+
     this._fetchDistribFormulas = function(onload) {
         if(this.distribForms) {
             onload();

Modified: trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2	2009-10-09 19:30:27 UTC (rev 14339)
+++ trunk/Open-ILS/web/templates/default/acq/common/li_table.tt2	2009-10-09 19:47:59 UTC (rev 14340)
@@ -202,20 +202,20 @@
                     </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'>
+
+            <tbody><tr><td class='acq-lit-table-spacer' colspan='0'/></tr></tbody>
+
+            <tbody id='acq-lit-distrib-formula-tbody'>
                 <tr id='acq-lit-distrib-form-row'>
-                    <td name='selector'/>
-                    <td name='setbutton'/>
+                    <td colspan='0'>
+                        <span>Distribution Formulas</span>
+                        <div name='selector'></div>
+                        <div name='set_button'></div>
+                        <div name='rel_button'></div>
+                    </td>
                 </tr>
             </tbody>
+
             <tbody><tr><td class='acq-lit-table-spacer' colspan='0'/></tr></tbody>
             <tbody style='font-weight:bold;'>
                 <tr>



More information about the open-ils-commits mailing list