[open-ils-commits] r14650 - in trunk/Open-ILS/web: js/ui/default/conify/global/asset templates/default/conify/global/asset (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Oct 28 11:59:17 EDT 2009
Author: erickson
Date: 2009-10-28 11:59:14 -0400 (Wed, 28 Oct 2009)
New Revision: 14650
Modified:
trunk/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_order.js
trunk/Open-ILS/web/templates/default/conify/global/asset/copy_location_order.tt2
Log:
plugged in load time ordering and apply changes operation to delete old order entries and create new ones
Modified: trunk/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_order.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_order.js 2009-10-28 13:52:36 UTC (rev 14649)
+++ trunk/Open-ILS/web/js/ui/default/conify/global/asset/copy_location_order.js 2009-10-28 15:59:14 UTC (rev 14650)
@@ -7,9 +7,9 @@
dojo.require('openils.Util');
dojo.require('openils.widget.AutoGrid');
dojo.require('openils.PermaCrud');
+dojo.require('openils.widget.ProgressDialog');
var user;
-var pcrud;
var orders;
var locations;
var source;
@@ -17,7 +17,6 @@
function init() {
user = new openils.User();
- pcrud = new openils.PermaCrud({authtoken : user.authtoken});
source = new dojo.dnd.Source('acl-ol');
user.buildPermOrgSelector(
@@ -33,20 +32,101 @@
}
function filterGrid(org) {
+
+ // fetch the locations and order entries
+ var pcrud = new openils.PermaCrud({authtoken : user.authtoken});
orders = pcrud.search('acplo', {org : org}, {order_by : {acplo : 'position'}});
- locations = pcrud.search('acpl', {owning_lib : org}); //TODO
+ locations = pcrud.search('acpl', {owning_lib : org}, {order_by : {acpl : 'name'}}); // TODO
+
+ // init the DnD environment
source.selectAll();
source.deleteSelectedNodes();
source.clearItems();
+ var locs = [];
+
+ // sort and append by existing order settings
+ dojo.forEach(orders,
+ function(order) {
+ locs.push(
+ locations.filter(function(l) {return l.id() == order.location()})[0]
+ );
+ }
+ );
+
+ // append any non-sorted locations
dojo.forEach(locations,
+ function(l) {
+ if(!locs.filter(function(ll) { return ll.id() == l.id() })[0])
+ locs.push(l);
+ }
+ );
+
+ // shove them into the DnD environment
+ dojo.forEach(locs,
function(loc) {
- source.insertNodes(false, [
- loc.name() + ' (' + fieldmapper.aou.findOrgUnit(loc.owning_lib()).shortname()+')'
+ var node = source.insertNodes(false, [
+ {
+ data : loc.name() + ' (' + fieldmapper.aou.findOrgUnit(loc.owning_lib()).shortname()+')',
+ type : [loc.id()+''] // use the type field to store the ID
+ }
]);
}
);
}
+function applyChanges() {
+ progressDialog.show(true);
+ if(orders.length)
+ deleteOrders(createOrders);
+ else
+ createOrders();
+}
+
+function deleteOrders(onload) {
+ // delete the existing order entries in preparation for new ones
+ var pcrud = new openils.PermaCrud({authtoken : user.authtoken});
+ pcrud.delete(
+ orders,
+ {
+ async : true,
+ oncomplete : function() {
+ if(onload) onload();
+ }
+ }
+ );
+}
+
+function createOrders() {
+
+ var newOrders = [];
+
+ // pull the locations out of the DnD environment and create order entries for them
+ dojo.forEach(
+ source.getAllNodes(),
+ function(node) {
+ var item = source.getItem(node.id);
+ var o = new fieldmapper.acplo();
+ o.position(newOrders.length + 1);
+ o.location(item.type[0]); // location.id() is stored in DnD item type
+ o.org(contextOrgSelector.attr('value'));
+ newOrders.push(o);
+ }
+ );
+
+ // send the order entries off to the server
+ var pcrud = new openils.PermaCrud({authtoken : user.authtoken});
+ pcrud.create(
+ newOrders,
+ {
+ async : true,
+ oncomplete : function(r) {
+ progressDialog.hide();
+ filterGrid(contextOrgSelector.attr('value'));
+ }
+ }
+ );
+}
+
openils.Util.addOnLoad(init);
Modified: trunk/Open-ILS/web/templates/default/conify/global/asset/copy_location_order.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/conify/global/asset/copy_location_order.tt2 2009-10-28 13:52:36 UTC (rev 14649)
+++ trunk/Open-ILS/web/templates/default/conify/global/asset/copy_location_order.tt2 2009-10-28 15:59:14 UTC (rev 14650)
@@ -5,8 +5,7 @@
<div dojoType="dijit.layout.ContentPane" layoutAlign="client" class='oils-header-panel'>
<div>Copy Location Order</div>
- <div>
- </div>
+ <div></div>
</div>
<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
@@ -17,10 +16,15 @@
labelAttr='shortname'>
</select>
<button dojoType='dijit.form.Button' onClick='applyChanges()'>Apply Changes</button>
+ <span>To move an item, drag it up or down with the mouse.</span>
</div>
<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
<ol id='acl-ol'></ol>
</div>
+<div class='hidden'>
+ <div dojoType='openils.widget.ProgressDialog' jsId='progressDialog'/>
+</div>
+
[% END %]
More information about the open-ils-commits
mailing list