Can now delete lineitem detail records from a lineitem in a picklist
authordjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 23 May 2008 00:27:22 +0000 (00:27 +0000)
committerdjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 23 May 2008 00:27:22 +0000 (00:27 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9682 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/acq/Lineitems.js
Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js
Open-ILS/web/oilsweb/oilsweb/templates/oils/default/common/jubgrid.html

index 729f744..62dc8c5 100644 (file)
@@ -85,32 +85,26 @@ openils.acq.Lineitems.createStore = function(li_id, onComplete) {
        });
 };
 
-openils.acq.Lineitems.obj2Str = function(obj) {
-    var str = "";
-    for (var prop in item) {
-       str += prop + " = " + item[prop] + "\n";
-    }
-    return(str);
-}
-
 openils.acq.Lineitems.alertOnSet = function(griditem, attr, oldVal, newVal) {
     var item;
     var updateDone = function(r) {
        var stat = r.recv().content();
        // XXX Check for Event
-//     alert("updateDone");
     }
+
     if (oldVal == newVal) {
-//     alert("value edited, but not changed. skipping");
        return;
     }
 
-//     console.dir(griditem);
     item = openils.acq.Lineitems.acqlidCache[griditem.id];
     
-//     console.log("alertOnSet: newVal = "+newVal);
-//     console.dir(item) 
-    item.fund(newVal);
+    if (attr == "fund") {
+       item.fund(newVal);
+    } else {
+       alert("Unexpected attr in Lineitems.alertOnSet: '"+attr+"'");
+       return;
+    }
+
     fieldmapper.standardRequest(
        ["open-ils.acq", "open-ils.acq.lineitem_detail.update"],
        { params: [openils.User.authtoken, item],
@@ -118,6 +112,19 @@ openils.acq.Lineitems.alertOnSet = function(griditem, attr, oldVal, newVal) {
        });
 };
 
+openils.acq.Lineitems.deleteLID = function(id, onComplete) {
+    fieldmapper.standardRequest(
+        ['open-ils.acq', 'open-ils.acq.lineitem_detail.delete'],
+        {   async: true,
+            params: [openils.User.authtoken, id],
+            oncomplete: function(r) {
+                msg = r.recv()
+                stat = msg.content();
+               onComplete();
+            }
+    });
+};
+
 openils.acq.Lineitems.loadGrid = function(domNode, id, layout) {
     if (!openils.acq.Lineitems.ModelCache[id]) {
        openils.acq.Lineitems.createStore(id,
@@ -126,7 +133,8 @@ openils.acq.Lineitems.loadGrid = function(domNode, id, layout) {
                    var model = new dojox.grid.data.DojoData(null, store,
                        {rowsPerPage: 20, clientSort:true, query:{id:'*'}});
 
-                   dojo.connect(store, "onSet", openils.acq.Lineitems.alertOnSet);
+                   dojo.connect(store, "onSet",
+                                openils.acq.Lineitems.alertOnSet);
                    openils.acq.Lineitems.ModelCache[id] = model;
 
                    domNode.setStructure(layout);
@@ -138,6 +146,4 @@ openils.acq.Lineitems.loadGrid = function(domNode, id, layout) {
        domNode.update();
     }
 };
-
-
 }
index 3b4ab93..cbbdcdd 100644 (file)
@@ -47,9 +47,9 @@ var JUBGrid = {
         var data = JUBGrid.jubDetailGrid.model.getRow(rowIndex);
         if (!data || !data.fund) return;
         try {
-        return openils.acq.Fund.retrieve(data.fund).name();
+            return openils.acq.Fund.retrieve(data.fund).name();
         } catch (evt) {
-        return data.fund;
+            return data.fund;
         }
     },
     getLIDLibName : function(rowIndex) {
@@ -63,10 +63,42 @@ var JUBGrid = {
         JUBGrid.jubGrid.setModel(model);
         dojo.connect(gridWidget, "onRowClick", 
             function(evt) {
-             openils.acq.Lineitems.loadGrid(
-                 JUBGrid.jubDetailGrid, 
+               JUBGrid.jubDetailGrid.lineitemID = model.getRow(evt.rowIndex).id;
+               openils.acq.Lineitems.loadGrid(
+                    JUBGrid.jubDetailGrid, 
                     JUBGrid.jubGrid.model.getRow(evt.rowIndex).id, JUBGrid.jubDetailGridLayout);
             });
         gridWidget.update();
-    }
+    },
+    deleteLID: function(evt) {
+       var list =[];
+       var selected = JUBGrid.jubDetailGrid.selection.getSelected();
+       for (var idx = 0; idx < selected.length; idx++) {
+           var rowIdx = selected[idx];
+           var lid = JUBGrid.jubDetailGrid.model.getRow(rowIdx);
+           var deleteFromStore = function () {
+               var deleteItem = function(item, rq) {
+                   JUBGrid.jubDetailGrid.model.store.deleteItem(item);
+               };
+               JUBGrid.jubDetailGrid.model.store.fetch({query:{id:lid.id},
+                                                        onItem: deleteItem});
+           };
+
+           openils.acq.Lineitems.deleteLID(lid.id, deleteFromStore);
+           JUBGrid.jubDetailGrid.update();
+
+           var updateCount = function(item) {
+               var newval = JUBGrid.jubGrid.model.store.getValue(item, "item_count");
+               JUBGrid.jubGrid.model.store.setValue(item, "item_count", newval-1);
+               JubGrid.jubGrid.update();
+           };
+
+           JUBGrid.jubGrid.model.store.fetch({query:{id:JUBGrid.jubDetailGrid.lineitemID},
+                                              onItem: updateCount});
+       }
+    },
+    createLID: function(evt) {
+       console.dir(evt);
+    },
 };
+
index 79af846..e079971 100644 (file)
@@ -10,11 +10,11 @@ model for the set of JUBs, then place the following lines in your
 HTML where you want the display to appear:
 
     <%namespace file='/oils/default/common/jubgrid.html' name='jubgrid'/>
-    ${jubgrid.jubgrid('dom_prefix', 'grid_js_id')}
+    ${jubgrid.jubgrid('dom_prefix', 'grid_jsid')}
 
 where 'dom_prefix' is a string that will be used as the prefix
 for the DOM notes that are created by this template, and
-'grid_js_id' is a valid JavaScript identifier that will name the
+'grid_jsid' is a valid JavaScript identifier that will name the
 DOM node to which the list of JUBs will be attached.  For example
 
     ${jubgrid.jubgrid('oils-acq-picklist', 'pickListGrid')}
@@ -29,9 +29,9 @@ and a jsid of
 
 To fill the grid with data, call the javascript function
 
-    populateJUBGrid(grid_js_id, model)
+    populateJUBGrid(grid_jsid, model)
 
-'grid_js_id' is the same javascript id that was used to
+'grid_jsid' is the same javascript id that was used to
 instantiate the template, and model is a javascript variable
 pointing to the JUB model (and store) that you have created.
 
@@ -42,7 +42,7 @@ pointing to the JUB model (and store) that you have created.
      activeSizing="1" layoutAlign="client">
 
     <script src='${c.oils.core.media_prefix.value}/ui_js/oils/default/common/jubgrid.js'> </script>
-    <script>
+    <script type="text/javascript">
     JUBGrid.jubGridLayout = [{
         cells: [[
             {name: "ID", field: 'id'},
@@ -74,6 +74,16 @@ pointing to the JUB model (and store) that you have created.
             dojoType='dojox.Grid' id="${domprefix + '-JUB-grid'}"> </div>
     </div>
     <div dojoType="dijit.layout.ContentPane" sizeMin="20" sizeShare="50">
+       <div jsid="lineItemButtonbar" dojoType="dijit.layout.ContentPane"
+            id=${domprefix+"-details-buttonbar"}>
+           <button dojoType='dijit.form.Button'
+                   onclick='JUBGrid.createLID'>
+               ${_('Add Copy')}
+           </button>
+           <button dojotype='dijit.form.Button' onclick='JUBGrid.deleteLID'>
+               ${_('Delete Selected Copy')}
+           </button>
+       </div>
         <div structure='JUBGrid.jubDetailGridLayout' jsid="JUBGrid.jubDetailGrid" dojoType="dojox.Grid"
             id='${domprefix + "-details-grid"}'>
         </div>