1 dojo.require('dijit.layout.ContentPane');
2 dojo.require("dojo.dnd.Container");
3 dojo.require("dojo.dnd.Source");
4 dojo.require('openils.widget.OrgUnitFilteringSelect');
5 dojo.require('fieldmapper.OrgUtils');
6 dojo.require('openils.User');
7 dojo.require('openils.Util');
8 dojo.require('openils.widget.AutoGrid');
9 dojo.require('openils.PermaCrud');
10 dojo.require('openils.widget.ProgressDialog');
19 user = new openils.User();
20 source = new dojo.dnd.Source('acl-ol');
22 user.buildPermOrgSelector(
23 'ADMIN_COPY_LOCATION_ORDER',
27 dojo.connect(contextOrgSelector, 'onChange', filterGrid);
31 filterGrid(user.user.ws_ou());
34 function filterGrid(org) {
36 // fetch the locations and order entries
38 var pcrud = new openils.PermaCrud({authtoken : user.authtoken});
39 orders = pcrud.search('acplo', {org : org}, {order_by : {acplo : 'position'}});
40 locations = pcrud.search('acpl',
41 {owning_lib : fieldmapper.aou.orgNodeTrail(fieldmapper.aou.findOrgUnit(org), true), deleted : 'f'},
42 {order_by : {acpl : 'name'}}
46 // init the DnD environment
48 source.deleteSelectedNodes();
53 // sort and append by existing order settings
59 function(l) { return l.id() == order.location(); }
65 // append any non-sorted locations
66 dojo.forEach(locations,
68 if(!locs.filter(function(ll) { return ll.id() == l.id() })[0])
73 // shove them into the DnD environment
77 var node = source.insertNodes(false, [
79 data : loc.name() + ' (' + fieldmapper.aou.findOrgUnit(loc.owning_lib()).shortname()+')',
80 type : [loc.id()+''] // use the type field to store the ID
87 function applyChanges() {
88 progressDialog.show();
91 var contextOrg = contextOrgSelector.attr('value');
93 // pull the locations out of the DnD environment and create order entries for them
97 var item = source.getItem(node.id);
98 var o = new fieldmapper.acplo();
99 o.position(newOrders.length + 1);
100 o.location(item.type[0]); // location.id() is stored in DnD item type
106 fieldmapper.standardRequest(
107 ['open-ils.circ', 'open-ils.circ.copy_location_order.update'],
110 params : [openils.User.authtoken, newOrders],
111 onresponse : function(r) {
112 if(r = openils.Util.readResponse(r)) {
115 progressDialog.hide();
116 filterGrid(contextOrg);
119 progressDialog.update(r);
126 openils.Util.addOnLoad(init);