Copy Location Circ Limit Sets Admin UI
authorBill Erickson <berick@esilibrary.com>
Fri, 13 Apr 2012 20:19:03 +0000 (16:19 -0400)
committerMike Rylander <mrylander@gmail.com>
Tue, 24 Jul 2012 12:07:40 +0000 (08:07 -0400)
Changes are applied to the existing Admin -> Local Administration ->
Circ Limit Sets interface to support copy location limit groups.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Copy Location Circ Limit Sets : UI 2

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/templates/conify/global/config/circ_limit_set.tt2
Open-ILS/web/js/ui/default/conify/global/config/circ_limit_set.js

index 9f9b90f..7541673 100644 (file)
                 </tr>
             </tbody>
         </table>
+        <h3>[% l('Linked Copy Locations') %]</h3>
+        <table class='oils-generic-table'>
+            <tbody>
+                <tr>
+                    <th>[% l('Name') %]</th>
+                    <th>[% l('Remove') %]</th>
+                </tr>
+            </tbody>
+            <tbody name='copy-loc-entry-tbody'>
+                <tr name='copy-loc-entry-row'>
+                    <td name='copy-loc'></td>
+                    <td><a name='remove-copy-loc' href='javascript:void(0);'>[% l('Remove') %]</a></td>
+                </tr>
+            </tbody>
+            <tbody name='copy-loc-entry-new'>
+                <tr>
+                    <td><div name='copy-loc-selector'></div></td>
+                    <td><a href='javascript:void(0);' name='add-copy-loc'>[% l('Add') %]</a></td>
+                </tr>
+            </tbody>
+        </table>
         <h3>Linked Limit Groups</h3>
         <table class='oils-generic-table'>
             <tbody>
index 49d6aa8..eca7c98 100644 (file)
@@ -4,11 +4,14 @@ dojo.require('openils.widget.AutoGrid');
 dojo.require('openils.widget.AutoFieldWidget');
 dojo.require('openils.PermaCrud');
 dojo.require('openils.widget.ProgressDialog');
+dojo.require('openils.User');
 
 var linkedEditor = null;
 var circModEntryCache = [];
+var copyLocEntryCache = [];
 var limitGroupEntryCache = [];
 var circModCache = {};
+var copyLocCache = {};
 var limitGroupCache = {};
 var curLinkedEditor;
 
@@ -25,6 +28,17 @@ function load(){
     dojo.forEach(temp, function(g) { circModCache[g.code()] = g; } );
     temp = pcrud.retrieveAll('cclg');
     dojo.forEach(temp, function(g) { limitGroupCache[g.id()] = g; } );
+
+    // Avoid fetching all copy locations because there can be many 
+    // thousands.  Limit to those within permission range of the user.
+    new openils.User().getPermOrgList(
+        'ADMIN_CIRC_MATRIX_MATCHPOINT',
+        function (orgList) {
+            temp = pcrud.search('acpl', {owning_lib : orgList});
+            dojo.forEach(temp, function(g) { copyLocCache[g.id()] = g; } );
+        }, 
+        true, true 
+    );
 }
 
 function byName(name, ctxt) {
@@ -34,6 +48,7 @@ function byName(name, ctxt) {
 function buildEditPaneAdditions(editPane) {
     circModEntryCache = [];
     limitGroupEntryCache = [];
+    copyLocEntryCache = [];
     var tr = document.createElement('tr');
     var td = document.createElement('td');
     td.setAttribute('colspan','2');
@@ -46,6 +61,7 @@ function buildEditPaneAdditions(editPane) {
     curLinkedEditor = linkedEditor.cloneNode(true);
     td.appendChild(curLinkedEditor);
     var circModTmpl = byName('circ-mod-entry-tbody', curLinkedEditor).removeChild(byName('circ-mod-entry-row', curLinkedEditor));
+    var copyLocTmpl = byName('copy-loc-entry-tbody', curLinkedEditor).removeChild(byName('copy-loc-entry-row', curLinkedEditor));
     var limitGroupTmpl = byName('limit-group-entry-tbody', curLinkedEditor).removeChild(byName('limit-group-entry-row', curLinkedEditor));
 
     var cm_selector = new openils.widget.AutoFieldWidget({
@@ -55,6 +71,13 @@ function buildEditPaneAdditions(editPane) {
     });
     cm_selector.build();
 
+    var cl_selector = new openils.widget.AutoFieldWidget({
+        fmClass : 'cclsacpl',
+        fmField : 'copy_loc',
+        parentNode : byName('copy-loc-selector', curLinkedEditor)
+    });
+    cl_selector.build();
+
     var lg_selector = new openils.widget.AutoFieldWidget({
         fmClass : 'cclsgm',
         fmField : 'limit_group',
@@ -72,6 +95,19 @@ function buildEditPaneAdditions(editPane) {
         byName('circ-mod-entry-tbody', editPane.domNode).appendChild(row);
     }
 
+    function addLoc(id) {
+        var row = copyLocTmpl.cloneNode(true);
+        row.setAttribute('loc_id', id);
+        var copyloc = copyLocCache[id];
+        byName('copy-loc', row).innerHTML = 
+            fieldmapper.aou.findOrgUnit(copyloc.owning_lib()).shortname() +
+            ' : ' + copyloc.name();
+        byName('remove-copy-loc', row).onclick = function() {
+            byName('copy-loc-entry-tbody', clsGrid.editPane.domNode).removeChild(row);
+        }
+        byName('copy-loc-entry-tbody', editPane.domNode).appendChild(row);
+    }
+
     function addGroup(group) {
         var row = limitGroupTmpl.cloneNode(true);
         row.setAttribute('limit_group', group);
@@ -86,6 +122,10 @@ function buildEditPaneAdditions(editPane) {
         addMod(cm_selector.widget.attr('value'));
     }
 
+    byName('add-copy-loc', editPane.domNode).onclick = function() {
+        addLoc(cl_selector.widget.attr('value'));
+    }
+
     byName('add-limit-group', editPane.domNode).onclick = function() {
         addGroup(lg_selector.widget.attr('value'));
     }
@@ -98,8 +138,10 @@ function buildEditPaneAdditions(editPane) {
     if(editPane.mode == 'update') {
         var pcrud = new openils.PermaCrud();
         circModEntryCache = pcrud.search('cclscmm', {limit_set: limitSet});
+        copyLocEntryCache = pcrud.search('cclsacpl', {limit_set: limitSet});
         limitGroupEntryCache = pcrud.search('cclsgm', {limit_set: limitSet});
         dojo.forEach(circModEntryCache, function(g) { addCircMod(circModTmpl, g); } );
+        dojo.forEach(copyLocEntryCache, function(g) { addCopyLoc(copyLocTmpl, g); } );
         dojo.forEach(limitGroupEntryCache, function(g) { addLimitGroup(limitGroupTmpl, g); } );
     } 
 }
@@ -115,6 +157,20 @@ function addCircMod(tmpl, circ_mod_entry) {
     byName('circ-mod-entry-tbody', clsGrid.editPane.domNode).appendChild(row);
 }
 
+function addCopyLoc(tmpl, copy_loc_entry) {
+    var row = tmpl.cloneNode(true);
+    var id = copy_loc_entry.copy_loc();
+    var copyloc = copyLocCache[id];
+    row.setAttribute('loc_id', id);
+    byName('copy-loc', row).innerHTML = 
+        fieldmapper.aou.findOrgUnit(copyloc.owning_lib()).shortname() +
+        ' : ' + copyloc.name();
+    byName('remove-copy-loc', row).onclick = function() {
+        byName('copy-loc-entry-tbody', clsGrid.editPane.domNode).removeChild(row);
+    }
+    byName('copy-loc-entry-tbody', clsGrid.editPane.domNode).appendChild(row);
+}
+
 function addLimitGroup(tmpl, limit_group_entry) {
     var row = tmpl.cloneNode(true);
     var group = limit_group_entry.limit_group();
@@ -170,6 +226,30 @@ function updateLinked(fmObject, rowindex) {
         }
     );
 
+    // Next, copy locations
+    var copy_locs = [];
+    dojo.query('[name=copy-loc-entry-row]', this.editPane.domNode).forEach(
+        function(row) {
+            var loc_id = row.getAttribute('loc_id');
+            copy_locs.push(loc_id);
+            if(!copyLocEntryCache.filter(function(i) { return (i.copy_loc() == loc_id); })[0]) {
+                var entry = new fieldmapper.cclsacpl();
+                entry.isnew(true);
+                entry.limit_set(id);
+                entry.copy_loc(loc_id);
+                add.push(entry);
+            }
+        }
+    );
+    dojo.forEach(copyLocEntryCache, function(eLoc) {
+            if(!copy_locs.filter(function(i) { return (i == eLoc.copy_loc()); })[0]) {
+                eLoc.isdeleted(true);
+                remove.push(eLoc);
+            }
+        }
+    );
+
+
     // Next, limit groups
     var limit_groups = [];
     dojo.query('[name=limit-group-entry-row]', this.editPane.domNode).forEach(