From 1108cfc0b3978dc0fd80566a2b654edcf6b99d55 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 13 Mar 2012 12:17:23 -0400 Subject: [PATCH] Org unit sibling display sort order : admin UI Adds a new menu entry for Local Admin called "Library Sort Order", where staff can configure via drag-n-drop the sibling display order for org units in the opac. Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- .../src/templates/actor/org_unit/sibling_order.tt2 | 57 ++++++++++++ .../js/ui/default/actor/org_unit/sibling_order.js | 103 +++++++++++++++++++++ Open-ILS/web/opac/locale/en-US/lang.dtd | 1 + .../xul/staff_client/chrome/content/main/menu.js | 11 +++ .../chrome/content/main/menu_frame_menus.xul | 2 + .../chrome/locale/en-US/offline.properties | 1 + 6 files changed, 175 insertions(+) create mode 100644 Open-ILS/src/templates/actor/org_unit/sibling_order.tt2 create mode 100644 Open-ILS/web/js/ui/default/actor/org_unit/sibling_order.js diff --git a/Open-ILS/src/templates/actor/org_unit/sibling_order.tt2 b/Open-ILS/src/templates/actor/org_unit/sibling_order.tt2 new file mode 100644 index 0000000000..49050c3924 --- /dev/null +++ b/Open-ILS/src/templates/actor/org_unit/sibling_order.tt2 @@ -0,0 +1,57 @@ +[% WRAPPER base.tt2 %] +[% ctx.page_title = l('Org Unit Sibling Order') %] + + + +

[% l('Org Unit Sibling Order') %]

+
+ +
+
+
+ +
+ + + + + + + +
+ + + +
+
+
+
+
    +
  1. [% l('Select the org unit whose children you wish to sort.') %]
  2. +
  3. [% l('Drag the child org units up or down to change the position.') %]
  4. +
  5. [% l('After each drag operation, the changes are automatically saved.') %]
  6. +
  7. [% l('When finished, it will be necessary to restart/reload the web server (Apache) for the changes to take effect.') %]
  8. +
+
+
+
+ + +[% END %] diff --git a/Open-ILS/web/js/ui/default/actor/org_unit/sibling_order.js b/Open-ILS/web/js/ui/default/actor/org_unit/sibling_order.js new file mode 100644 index 0000000000..c06d98d3ee --- /dev/null +++ b/Open-ILS/web/js/ui/default/actor/org_unit/sibling_order.js @@ -0,0 +1,103 @@ +dojo.require("dijit.form.Button"); +dojo.require("dojo.dnd.Source"); +dojo.require("openils.User"); +dojo.require("openils.Util"); +dojo.require("openils.PermaCrud"); +dojo.require('openils.widget.OrgUnitFilteringSelect'); + +var user; +var pcrud; +var dndSource; + +function pageInit() { + user = new openils.User(); + pcrud = new openils.PermaCrud({authtoken : user.authtoken}); + fieldmapper.aou.slim_ok = false; // we need full orgs for updates + + user.buildPermOrgSelector( + ['UPDATE_ORG_UNIT', 'ADMIN_ORG_UNIT'], + contextOrgSelector, + null, + function() { + dojo.connect(contextOrgSelector, 'onChange', drawChildren) + // set the value to the root of the tree (instead of ws_ou). + contextOrgSelector.store.fetch({ + query : {id : '*'}, + onComplete : function(list) { + contextOrgSelector.attr('value', list[0].id); + } + }); + } + ); +} + +var tbody, rowTmpl; +function drawChildren() { + + if(!tbody) { + tbody = dojo.byId('child-tbody'); + rowTmpl = tbody.removeChild(dojo.byId('row-template')); + dndSource = new dojo.dnd.Source(tbody); + dojo.connect(dndSource, 'onDndDrop', updateSiblingOrder); + } + + dndSource.selectAll(); + dndSource.deleteSelectedNodes(); + dndSource.clearItems(); + + var org = fieldmapper.aou.findOrgUnit(contextOrgSelector.attr('value')); + if (!org.children()) return; + + // fetch the full child org units + org.children( + org.children().map( + function(c) { return fieldmapper.aou.findOrgUnit(c.id()) } + ) + ); + + // sort by sibling order, fall back to name + var children = org.children().sort( + function(a, b) { + if (a.sibling_order() < b.sibling_order()) { + return -1; + } else if (a.sibling_order() > b.sibling_order()) { + return 1; + } else if (a.name() < b.name()) { + return -1; + } + return 1; + } + ); + + dojo.forEach( + children, + function(child) { + var row = tbody.appendChild(rowTmpl.cloneNode(true)); + row.setAttribute('child', child.id()); + dojo.query('[name=name]', row)[0].innerHTML = child.name(); + dndSource.insertNodes(false, [row]); + } + ); +} + +function updateSiblingOrder() { + var pos = 0; + var toUpdate = []; + dojo.forEach( + dndSource.getAllNodes(), + function(node) { + childId = node.getAttribute('child'); + var child = fieldmapper.aou.findOrgUnit(childId); + if (child.sibling_order() != pos) { + child.sibling_order(pos); + toUpdate.push(child); + } + pos++; + } + ); + + if (toUpdate.length == 0) return; + pcrud.update(toUpdate); // run sync to prevent UI changes mid-update +} + +openils.Util.addOnLoad(pageInit); diff --git a/Open-ILS/web/opac/locale/en-US/lang.dtd b/Open-ILS/web/opac/locale/en-US/lang.dtd index 38b98661a8..e42c1a1039 100644 --- a/Open-ILS/web/opac/locale/en-US/lang.dtd +++ b/Open-ILS/web/opac/locale/en-US/lang.dtd @@ -2068,6 +2068,7 @@ + diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu.js b/Open-ILS/xul/staff_client/chrome/content/main/menu.js index 4ca96d828a..bc35694185 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu.js @@ -1106,6 +1106,17 @@ main.menu.prototype = { ); } ], + 'cmd_local_admin_lib_sort_order' : [ + ['oncommand'], + function(event) { + open_eg_web_page( + "/eg/actor/org_unit/sibling_order", + "menu.cmd_local_admin_lib_sort_order.tab", + event + ); + } + ], + 'cmd_reprint' : [ ['oncommand'], function() { diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul index bd98d4bb8d..67752f53e4 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu_frame_menus.xul @@ -124,6 +124,7 @@ /> + @@ -505,6 +506,7 @@ + diff --git a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties index 961ad06867..4f303139b1 100644 --- a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties +++ b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties @@ -252,6 +252,7 @@ menu.cmd_booking_resource.tab=Resources menu.cmd_booking_reservation.tab=Reservations menu.cmd_booking_reservation_pickup.tab=Reservation Pickup menu.cmd_booking_reservation_return.tab=Reservation Return +menu.cmd_local_admin_lib_sort_order.tab=Library Sort Order menu.cmd_booking_pull_list.tab=Booking Pull List menu.cmd_booking_capture.tab=Booking Capture menu.cmd_authority_manage.tab=Manage Authorities -- 2.11.0