[open-ils-commits] r12916 - in trunk/Open-ILS/web: js/ui/default/acq/picklist templates/default/acq/picklist (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Apr 20 12:28:07 EDT 2009
Author: erickson
Date: 2009-04-20 12:28:02 -0400 (Mon, 20 Apr 2009)
New Revision: 12916
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 list clone and merge
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 2009-04-20 15:32:41 UTC (rev 12915)
+++ trunk/Open-ILS/web/js/ui/default/acq/picklist/view_list.js 2009-04-20 16:28:02 UTC (rev 12916)
@@ -3,15 +3,20 @@
dojo.require('dijit.Dialog');
dojo.require('dijit.form.Button');
dojo.require('dijit.form.TextBox');
+dojo.require('dijit.form.FilteringSelect');
dojo.require('dijit.form.Button');
dojo.require('dojox.grid.cells.dijit');
dojo.require('openils.acq.Picklist');
dojo.require('openils.Util');
+dojo.require('openils.widget.ProgressDialog');
var listAll = false;
var plCache = {};
function loadGrid() {
+
+ dojo.connect(plMergeDialog, 'onOpen', function(){loadLeadPlSelector();});
+
var method = 'open-ils.acq.picklist.user.retrieve';
if(listAll)
method = method.replace(/user/, 'user.all');
@@ -19,7 +24,6 @@
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],
@@ -33,7 +37,7 @@
plCache[pl.id()] = pl;
store.newItem(acqpl.toStoreItem(pl));
}
- }
+ },
}
);
}
@@ -66,48 +70,7 @@
}
);
}
-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);
@@ -125,6 +88,90 @@
openils.acq.Picklist.deleteList(list);
}
+function cloneSelectedPl(fields) {
+
+ var selected = plListGrid.selection.getSelected();
+ if(selected.length == 0 || !(fields.name)) return;
+
+ var item = selected[0]; // clone the first selected
+ progressDialog.show();
+ progressDialog.update({maximum:item.entry_count, progress:0});
+
+ fieldmapper.standardRequest(
+ ['open-ils.acq', 'open-ils.acq.picklist.clone'],
+ { async: true,
+ params: [openils.User.authtoken, item.id, fields.name],
+ onresponse : function(r) {
+ var resp = openils.Util.readResponse(r);
+ if(!resp) return;
+ progressDialog.update({progress:resp.li});
+ if(resp.complete) {
+ progressDialog.hide();
+ var pl = resp.picklist;
+ plCache[pl.id()] = pl;
+ pl.owner(openils.User.user);
+ plListGrid.store.newItem(fieldmapper.acqpl.toStoreItem(pl));
+ }
+ }
+ }
+ );
+}
+
+function loadLeadPlSelector() {
+ var store = new dojo.data.ItemFileWriteStore({data:acqpl.initStoreData()});
+ var selected = plListGrid.selection.getSelected();
+ dojo.forEach(selected, function(item) {
+ var pl = plCache[plListGrid.store.getValue(item, 'id')];
+ store.newItem(fieldmapper.acqpl.toStoreItem(pl));
+ });
+ plMergeLeadSelector.store = store;
+ plMergeLeadSelector.startup();
+}
+
+function mergeSelectedPl(fields) {
+ if(!fields.lead) return;
+
+ var ids = [];
+ var totalLi = 0;
+ var selected = plListGrid.selection.getSelected();
+ var leadPl = plCache[fields.lead];
+
+ dojo.forEach(selected, function(item) {
+ var id = plListGrid.store.getValue(item, 'id');
+ if(id == fields.lead) return;
+ totalLi += new Number(plListGrid.store.getValue(item, 'entry_count'));
+ ids.push(id);
+ });
+
+ progressDialog.show();
+ progressDialog.update({maximum:totalLi, progress:0});
+
+ fieldmapper.standardRequest(
+ ['open-ils.acq', 'open-ils.acq.picklist.merge'],
+ { async: true,
+ params: [openils.User.authtoken, fields.lead, ids],
+ onresponse : function(r) {
+ var resp = openils.Util.readResponse(r);
+ if(!resp) return;
+ progressDialog.update({progress:resp.li});
+
+ if(resp.complete) {
+ progressDialog.hide();
+ leadPl.entry_count( leadPl.entry_count() + totalLi );
+
+ // remove the deleted lists from the grid
+ dojo.forEach(selected, function(item) {
+ var id = plListGrid.store.getValue(item, 'id');
+ if(id != fields.lead)
+ plListGrid.store.deleteItem(item);
+ });
+ }
+ }
+ }
+ );
+
+}
+
openils.Util.addOnLoad(loadGrid);
Modified: trunk/Open-ILS/web/templates/default/acq/picklist/list.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/acq/picklist/list.tt2 2009-04-20 15:32:41 UTC (rev 12915)
+++ trunk/Open-ILS/web/templates/default/acq/picklist/list.tt2 2009-04-20 16:28:02 UTC (rev 12916)
@@ -32,13 +32,14 @@
}
</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'>
@@ -48,10 +49,43 @@
</table>
</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>
+
+ <button dojoType="dijit.form.Button" onclick="deleteFromGrid();">Delete Selected</button>
+
+ <div dojoType="dijit.form.DropDownButton">
+ <span>Clone Selected</span>
+ <div dojoType="dijit.TooltipDialog" execute="cloneSelectedPl(arguments[0]);">
+ <table class='dijitTooltipTable'>
+ <tr>
+ <td><label for="name">New Name:</label></td>
+ <td><input dojoType="dijit.form.TextBox" name="name"/></td>
+ </tr>
+ <tr>
+ <td colspan='2' align='center'>
+ <button dojoType='dijit.form.Button' type="submit">Clone</button>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </div>
+
+ <div dojoType="dijit.form.DropDownButton">
+ <span>Merge Selected</span>
+ <div dojoType="dijit.TooltipDialog" execute="mergeSelectedPl(arguments[0]);" jsId='plMergeDialog'>
+ <table class='dijitTooltipTable'>
+ <tr>
+ <td><label for="name">Choose the Lead Selection List:</label></td>
+ <td><input jsId='plMergeLeadSelector' dojoType="dijit.form.FilteringSelect" name="lead"/></td>
+ </tr>
+ <tr>
+ <td colspan='2' align='center'>
+ <button dojoType='dijit.form.Button' type="submit">Merge</button>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </div>
+
</div>
<div dojoType="dijit.layout.ContentPane" layoutAlign="top">
@@ -73,4 +107,6 @@
</div>
</div>
+<div class='hidden'><div jsId='progressDialog' dojoType='openils.widget.ProgressDialog'/></div>
+
[% END %]
More information about the open-ils-commits
mailing list