[open-ils-commits] r11674 - in trunk/Open-ILS/web: js/ui/default/conify/global/config templates/default/conify/global/config
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Dec 23 16:38:30 EST 2008
Author: erickson
Date: 2008-12-23 16:38:26 -0500 (Tue, 23 Dec 2008)
New Revision: 11674
Modified:
trunk/Open-ILS/web/js/ui/default/conify/global/config/standing_penalty.js
trunk/Open-ILS/web/templates/default/conify/global/config/standing_penalty.tt2
Log:
implemented delete and update
Modified: trunk/Open-ILS/web/js/ui/default/conify/global/config/standing_penalty.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/conify/global/config/standing_penalty.js 2008-12-23 21:33:40 UTC (rev 11673)
+++ trunk/Open-ILS/web/js/ui/default/conify/global/config/standing_penalty.js 2008-12-23 21:38:26 UTC (rev 11674)
@@ -2,19 +2,25 @@
dojo.require('dojo.data.ItemFileWriteStore');
dojo.require('dojox.form.CheckedMultiSelect');
dojo.require('dijit.form.TextBox');
+dojo.require('dojox.grid.cells.dijit');
+ var spCache = {};
+
function spBuildGrid() {
- var store = new dojo.data.ItemFileWriteStore({data:csp.toStoreData([])});
+ var store = new dojo.data.ItemFileWriteStore({data:csp.initStoreData()});
spGrid.setStore(store);
spGrid.render();
+ dojo.connect(store, 'onSet', spGridChanged);
+
fieldmapper.standardRequest(
['open-ils.pcrud', 'open-ils.pcrud.search.csp'],
{ async: true,
params: [openils.User.authtoken, {id:{'!=':null}}, {order_by:{csp:'id'}}],
onresponse: function(r) {
if(sp = openils.Util.readResponse(r))
- store.newItem(csp.toStoreData([sp]).items[0]);
- },
+ store.newItem(csp.itemToStoreData(sp));
+ spCache[sp.id()] = sp;
+ }
}
);
}
@@ -25,25 +31,106 @@
var penalty = new csp();
penalty.name(args.name);
penalty.label(args.label);
+ penalty.block_list(formatBlockList(args.block_list));
+ fieldmapper.standardRequest(
+ ['open-ils.permacrud', 'open-ils.permacrud.create.csp'],
+ { async: true,
+ params: [openils.User.authtoken, penalty],
+ oncomplete: function(r) {
+ if(obj = openils.Util.readResponse(r))
+ spGrid.store.newItem(csp.itemToStoreData(obj));
+ }
+ }
+ );
+}
+
+function formatBlockList(list) {
var str = '';
- for(var idx in args.block_list)
- str += args.block_list[idx] + '|';
- str = str.replace(/\|$/, '');
- penalty.block_list(str || null);
+ for(var idx in list)
+ str += list[idx] + '|';
+ return str.replace(/\|$/, '');
+}
+function spGridChanged(item, attr, oldVal, newVal) {
+ var sp = spCache[spGrid.store.getValue(item, 'id')];
+ console.log("changing cm " + sp.id() + " object: " + attr + " = " + newVal);
+ if(attr == 'block_list') {
+ sp[attr](formatBlockList(newVal));
+ } else {
+ sp[attr](newVal);
+ }
+ sp.ischanged(true);
+ spSaveButton.setDisabled(false);
+}
+function saveChanges() {
+ spGrid.doclick(0);
+ var changedObjects = [];
+ for(var i in spCache){
+ var sp = spCache[i];
+ if(sp.ischanged())
+ changedObjects.push(sp);
+ }
+ _saveChanges(changedObjects, 0);
+}
+function _saveChanges(changedObjects, idx) {
+
+ if(idx >= changedObjects.length) {
+ // we've made it through the list
+ spSaveButton.setDisabled(true);
+ return;
+ }
+
+ var item = changedObjects[idx];
+
fieldmapper.standardRequest(
- ['open-ils.permacrud', 'open-ils.permacrud.create.csp'],
+ ['open-ils.permacrud', 'open-ils.permacrud.update.csp'],
{ async: true,
- params: [openils.User.authtoken, penalty],
+ params: [openils.User.authtoken, item],
oncomplete: function(r) {
- if(new String(openils.Util.readResponse(r)) != '0')
- spBuildGrid();
+ if(stat = openils.Util.readResponse(r)) {
+ _saveChanges(changedObjects, ++idx);
+ }
}
}
);
}
+function formatId(inDatum) {
+ if(inDatum < 100){
+ return "<span style='color:red;'>"+ inDatum +"</span>";
+ }
+ return inDatum;
+
+}
+function deleteFromGrid() {
+ _deleteFromGrid(spGrid.selection.getSelected(), 0);
+}
+
+function _deleteFromGrid(list, idx) {
+ if(idx >= list.length) // we've made it through the list
+ return;
+
+ var item = list[idx];
+ var id = spGrid.store.getValue(item, 'id');
+ if(id > 100){
+ _deleteFromGrid(list, ++idx);
+ return;
+ }
+ fieldmapper.standardRequest(
+ ['open-ils.permacrud', 'open-ils.permacrud.delete.csp'],
+ { async: true,
+ params: [openils.User.authtoken, id],
+ oncomplete: function(r) {
+ if(obj = openils.Util.readResponse(r)) {
+ spGrid.store.deleteItem(item);
+ }
+ _deleteFromGrid(list, ++idx);
+ }
+ }
+ );
+}
+
openils.Util.addOnLoad(spBuildGrid);
Modified: trunk/Open-ILS/web/templates/default/conify/global/config/standing_penalty.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/conify/global/config/standing_penalty.tt2 2008-12-23 21:33:40 UTC (rev 11673)
+++ trunk/Open-ILS/web/templates/default/conify/global/config/standing_penalty.tt2 2008-12-23 21:38:26 UTC (rev 11674)
@@ -5,6 +5,26 @@
</style>
<h1>Standing Penalty Types</h1><br/>
+<script>
+ if(!dojo._hasResource['openils.widget.StandingPenaltyBlockedSelector']) {
+ dojo.provide('openils.widget.StandingPenaltyBlockedSelector');
+ dojo.require('dojox.form.CheckedMultiSelect');
+ dojo.require('dojo.data.ItemFileReadStore');
+ dojo.declare(
+ 'openils.widget.StandingPenaltyBlockedSelector',
+ [dojox.form.CheckedMultiSelect],
+ {
+ postCreate : function() {
+ this._multiValue = true;
+ this.addOption({value:'CIRC', label:'CIRC'});
+ this.addOption({value:'RENEW', label:'RENEW'});
+ this.addOption({value:'HOLD', label:'HOLD'});
+ }
+ }
+ );
+ }
+</script>
+
<div dojoType="dijit.form.DropDownButton">
<span>New Standing Penalty</span>
<div dojoType="dijit.TooltipDialog" execute="spCreate(arguments[0]);">
@@ -20,11 +40,7 @@
<tr>
<td><label for="block_list">Blocked Actions: </label></td>
<td>
- <select style='overflow-y:auto;' multiple='true' dojoType="dojox.form.CheckedMultiSelect" name="block_list">
- <option value='CIRC'>CIRC</option>
- <option value='RENEW'>RENEW</option>
- <option value='HOLD'>HOLD</option>
- </select>
+ <select style='overflow-y:auto;' multiple='true' dojoType="openils.widget.StandingPenaltyBlockedSelector" name="block_list">
</td>
</tr>
<tr>
@@ -35,16 +51,22 @@
</table>
</div>
</div>
-
+
+ <button dojoType='dijit.form.Button' onClick="deleteFromGrid();">Delete Selected</button>
+ <button dojoType='dijit.form.Button' onclick='saveChanges();' disabled='disabled' jsId='spSaveButton'>Save Changes</button>
<div dojoType="dijit.layout.ContentPane" layoutAlign="top">
<div dojoType="dijit.layout.ContentPane" layoutAlign="client" style='height:600px;'>
<table jsId="spGrid" dojoType="dojox.grid.DataGrid" query="{id: '*'}" rowSelector='20px'>
<thead>
<tr>
- <th field="id">ID</th>
- <th field="name" width='auto'>Name</th>
- <th field="label" width='auto'>Label</th>
- <th field="block_list" width='auto'>Block List</th>
+ <th field="id" width='auto' formatter='formatId'>ID</th>
+ <th field="name" width='auto' editable='true'
+ cellType='dojox.grid.cells._Widget' widgetClass='dijit.form.TextBox'>Name</th>
+ <th field="label" width='auto' editable='true'
+ cellType='dojox.grid.cells._Widget' widgetClass='dijit.form.TextBox'>Label</th>
+ <th field="block_list" width='auto' editable='true'
+ cellType='dojox.grid.cells._Widget'
+ widgetClass='openils.widget.StandingPenaltyBlockedSelector' jsId='formatBlockList'>Block List</th>
</tr>
</thead>
</table>
More information about the open-ils-commits
mailing list