From 4e60f2a4c78053c2bc43722b09b38c34e477d699 Mon Sep 17 00:00:00 2001 From: djfiander Date: Fri, 23 May 2008 00:27:22 +0000 Subject: [PATCH] Can now delete lineitem detail records from a lineitem in a picklist 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 | 40 ++++++++++++--------- .../media/ui_js/oils/default/common/jubgrid.js | 42 +++++++++++++++++++--- .../templates/oils/default/common/jubgrid.html | 20 ++++++++--- 3 files changed, 75 insertions(+), 27 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/acq/Lineitems.js b/Open-ILS/web/js/dojo/openils/acq/Lineitems.js index 729f744263..62dc8c5602 100644 --- a/Open-ILS/web/js/dojo/openils/acq/Lineitems.js +++ b/Open-ILS/web/js/dojo/openils/acq/Lineitems.js @@ -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(); } }; - - } diff --git a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js index 3b4ab939c2..cbbdcdddda 100644 --- a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js +++ b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/ui_js/oils/default/common/jubgrid.js @@ -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); + }, }; + diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/common/jubgrid.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/common/jubgrid.html index 79af8468ad..e0799711ca 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/common/jubgrid.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/common/jubgrid.html @@ -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"> -