[open-ils-commits] r11703 - in trunk/Open-ILS/web: js/ui/default/acq/picklist templates/default/acq/picklist

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Dec 29 18:14:13 EST 2008


Author: erickson
Date: 2008-12-29 18:14:08 -0500 (Mon, 29 Dec 2008)
New Revision: 11703

Modified:
   trunk/Open-ILS/web/js/ui/default/acq/picklist/view_list.js
   trunk/Open-ILS/web/templates/default/acq/picklist/list.tt2
Log:
implemented inline update for picklist names.  shorter default date format

Modified: trunk/Open-ILS/web/js/ui/default/acq/picklist/view_list.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/picklist/view_list.js	2008-12-29 23:12:14 UTC (rev 11702)
+++ trunk/Open-ILS/web/js/ui/default/acq/picklist/view_list.js	2008-12-29 23:14:08 UTC (rev 11703)
@@ -4,10 +4,12 @@
 dojo.require('dijit.form.Button');
 dojo.require('dijit.form.TextBox');
 dojo.require('dijit.form.Button');
+dojo.require('dojox.grid.cells.dijit');
 dojo.require('openils.acq.Picklist');
 dojo.require('openils.Util');
 
 var listAll = false;
+var plCache = {};
 
 function loadGrid() {
     var method = 'open-ils.acq.picklist.user.retrieve';
@@ -17,21 +19,30 @@
     var store = new dojo.data.ItemFileWriteStore({data:acqpl.initStoreData()});
     plListGrid.setStore(store);
     plListGrid.render();
+    dojo.connect(store, 'onSet', plGridChanged);
 
     fieldmapper.standardRequest(
         ['open-ils.acq', method],
 
         {   async: true,
             params: [openils.User.authtoken, 
-                {flesh_lineitem_count:1, flesh_username:1}],
+                {flesh_lineitem_count:1, flesh_owner:1}],
 
             onresponse : function(r) {
-                if(pl = openils.Util.readResponse(r)) 
+                if(pl = openils.Util.readResponse(r)) {
+                    plCache[pl.id()] = pl;
                     store.newItem(acqpl.itemToStoreData(pl));
+                }
             }
         }
     );
 }
+function getOwnerName(rowIndex, item) {
+    if(!item) return ''; 
+    var id= this.grid.store.getValue(item, 'id'); 
+    var pl = plCache[id];
+    return pl.owner().usrname();
+}
 
 function createPL(fields) {
     if(fields.name == '') return;
@@ -55,7 +66,54 @@
         }
     );
 }
+function plGridChanged(item, attr, oldVal, newVal) {
+    var pl = plCache[plListGrid.store.getValue(item, 'id')];
+    console.log("changing pl " + pl.id() + " object: " + attr + " = " + newVal);
+    pl[attr](newVal);
+    pl.ischanged(true);
+    plSaveButton.setDisabled(false);
+}
+function saveChanges() {
+    plListGrid.doclick(0);   
+    var changedObjects = [];
+    for(var i in plCache){
+        var pl = plCache[i];
+        if(pl.ischanged())
+            changedObjects.push(pl);
+    }   
+    _saveChanges(changedObjects, 0);
+}
+function _saveChanges(changedObjects, idx) {
+    
+    if(idx >= changedObjects.length) {
+        // we've made it through the list
+        plSaveButton.setDisabled(true);
+        return;
+    }
 
+    var pl = changedObjects[idx];
+    var owner = pl.owner();
+    pl.owner(owner.id()); // un-flesh the owner object
+
+    fieldmapper.standardRequest(
+        ['open-ils.acq', 'open-ils.acq.picklist.update'],
+        {   async: true,
+            params: [openils.User.authtoken, pl],
+            oncomplete: function(r) {
+                if(stat = openils.Util.readResponse(r)) {
+                    _saveChanges(changedObjects, ++idx);
+                }
+            }
+        }
+    );
+}
+
+function getDateTimeField(rowIndex, item) {
+    if(!item) return '';
+    var data = this.grid.store.getValue(item, this.field);
+    var date = dojo.date.stamp.fromISOString(data);
+    return dojo.date.locale.format(date, {formatLength:'short'});
+}
 function deleteFromGrid() {
     var list = []
     var selected = plListGrid.selection.getSelected();

Modified: trunk/Open-ILS/web/templates/default/acq/picklist/list.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/acq/picklist/list.tt2	2008-12-29 23:12:14 UTC (rev 11702)
+++ trunk/Open-ILS/web/templates/default/acq/picklist/list.tt2	2008-12-29 23:14:08 UTC (rev 11703)
@@ -20,15 +20,25 @@
         dojo.style('oils-acq-picklist-all-list-header', 'display', 'none');
     }
 </script>
-
+<script>
+    function formatName(inDatum) {
+        for(var i in plCache){
+            var pl = plCache[i];
+            var id = pl.id();
+            if (inDatum  == pl.name()){
+                return '<a href="[% ctx.base_uri %]/acq/picklist/view/'+id+'">'+inDatum+'</a>';
+            }
+        }
+    }
+</script>
 <div class='oils-acq-actions-div'>
-    <div dojoType="dijit.form.DropDownButton">
-        <span>New Selection List</span>
-        <div dojoType="dijit.TooltipDialog" execute="createPL(arguments[0]);">
-            <table class='dijitTooltipTable'>
-                <tr>
-                    <td><label for="name">Name:</label></td>
-                    <td><input dojoType="dijit.form.TextBox" name="name"/></td>
+  <div dojoType="dijit.form.DropDownButton">
+    <span>New Selection List</span>
+    <div dojoType="dijit.TooltipDialog" execute="createPL(arguments[0]);">
+      <table class='dijitTooltipTable'>
+        <tr>
+          <td><label for="name">Name:</label></td>
+          <td><input dojoType="dijit.form.TextBox" name="name"/></td>
                 </tr>
                 <tr>
                     <td colspan='2' align='center'>
@@ -37,35 +47,29 @@
                 </tr>
             </table>
         </div>
-    </div> 
+    </div>
+    <button dojoType='dijit.form.Button' onclick="saveChanges();" disabled='disabled' jsId="plSaveButton">Save Changes</button>
     <button dojoType="dijit.form.Button" onclick="deleteFromGrid();">
         Delete Selected
     </button>
 </div>
 
-
-<script>
-    function getName(rowIndex, item) {
-        if(!item) return '';
-        var name = this.grid.store.getValue(item, 'name');
-        var id = this.grid.store.getValue(item, 'id');
-        return '<a href="[% ctx.base_uri %]/acq/picklist/view/'+id+'">'+name+'</a>';
-    }
-</script>
 <div dojoType="dijit.layout.ContentPane" layoutAlign="top">
     <div dojoType="dijit.layout.ContentPane" layoutAlign="client" style='height:600px;'>
         <table jsId="plListGrid" dojoType="dojox.grid.DataGrid" query="{id: '*'}" rowSelector='20px'>
             <thead>
                 <tr>
                     <th field="id">ID</th>
-                    <th field="name" width='auto' get='getName'>Name</th>
-                    <th field="owner">Selector</th>
-                    <th field="create_time">Create Time</th>
-                    <th field="edit_time">Edit Time</th>
+                    <th field="name" width='auto' editable='true'
+                        cellType='dojox.grid.cells._Widget'
+                        widgetClass='dijit.form.TextBox' formatter='formatName'>Name</th>
+                    <th field="owner" get='getOwnerName'>Selector</th>
+                    <th field="create_time" width='auto' get='getDateTimeField'>Create Time</th>
+                    <th field="edit_time" width='auto' get='getDateTimeField'>Edit Time</th>
                     <th field="entry_count">Entry Count</th>
                 </tr>
             </thead>
-        </table>    
+        </table>
     </div>
 </div>
 



More information about the open-ils-commits mailing list