Adds org unit selectors to Admin -> Server Admin -> Booking menu items, also modifies
authorJames Fournie <jfournie@sitka.bclibraries.ca>
Thu, 7 Jul 2011 02:07:50 +0000 (19:07 -0700)
committerMike Rylander <mrylander@gmail.com>
Tue, 23 Aug 2011 18:15:33 +0000 (14:15 -0400)
the IDL to give context-field based pcrud perms instead of 'require global'
This makes the booking module more org-unit scopable

Signed-off-by: James Fournie <jfournie@sitka.bclibraries.ca>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/examples/fm_IDL.xml
Open-ILS/web/templates/default/conify/global/booking/resource.tt2
Open-ILS/web/templates/default/conify/global/booking/resource_attr.tt2
Open-ILS/web/templates/default/conify/global/booking/resource_attr_map.tt2
Open-ILS/web/templates/default/conify/global/booking/resource_attr_value.tt2
Open-ILS/web/templates/default/conify/global/booking/resource_type.tt2

index 3604637..052631f 100644 (file)
@@ -3416,10 +3416,10 @@ SELECT  usr,
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <actions>
-                               <create permission="ADMIN_BOOKING_RESOURCE_TYPE" global_required='true'/>
-                               <retrieve />
-                               <update permission="ADMIN_BOOKING_RESOURCE_TYPE" global_required='true'/>
-                               <delete permission="ADMIN_BOOKING_RESOURCE_TYPE" global_required='true'/>
+                               <create permission="ADMIN_BOOKING_RESOURCE_TYPE" context_field='owner'/>
+                               <retrieve permission="ADMIN_BOOKING_RESOURCE_TYPE" context_field='owner'/>
+                               <update permission="ADMIN_BOOKING_RESOURCE_TYPE" context_field='owner'/>
+                               <delete permission="ADMIN_BOOKING_RESOURCE_TYPE" context_field='owner'/>
                        </actions>
                </permacrud>
        </class>
@@ -3448,10 +3448,10 @@ SELECT  usr,
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <actions>
-                               <create permission="ADMIN_BOOKING_RESOURCE" global_required='true'/>
-                               <retrieve />
-                               <update permission="ADMIN_BOOKING_RESOURCE" global_required='true'/>
-                               <delete permission="ADMIN_BOOKING_RESOURCE" global_required='true'/>
+                               <create permission="ADMIN_BOOKING_RESOURCE" context_field='owner'/>
+                               <retrieve permission="ADMIN_BOOKING_RESOURCE" context_field='owner'/>
+                               <update permission="ADMIN_BOOKING_RESOURCE" context_field='owner'/>
+                               <delete permission="ADMIN_BOOKING_RESOURCE" context_field='owner'/>
                        </actions>
                </permacrud>
        </class>
@@ -3474,10 +3474,10 @@ SELECT  usr,
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <actions>
-                               <create permission="ADMIN_BOOKING_RESOURCE_ATTR" global_required='true'/>
-                               <retrieve />
-                               <update permission="ADMIN_BOOKING_RESOURCE_ATTR" global_required='true'/>
-                               <delete permission="ADMIN_BOOKING_RESOURCE_ATTR" global_required='true'/>
+                               <create permission="ADMIN_BOOKING_RESOURCE_ATTR" context_field='owner'/>
+                               <retrieve permission="ADMIN_BOOKING_RESOURCE_ATTR" context_field='owner'/>
+                               <update permission="ADMIN_BOOKING_RESOURCE_ATTR" context_field='owner'/>
+                               <delete permission="ADMIN_BOOKING_RESOURCE_ATTR" context_field='owner'/>
                        </actions>
                </permacrud>
        </class>
@@ -3499,10 +3499,10 @@ SELECT  usr,
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <actions>
-                               <create permission="ADMIN_BOOKING_RESOURCE_ATTR_VALUE" global_required='true'/>
-                               <retrieve />
-                               <update permission="ADMIN_BOOKING_RESOURCE_ATTR_VALUE" global_required='true'/>
-                               <delete permission="ADMIN_BOOKING_RESOURCE_ATTR_VALUE" global_required='true'/>
+                               <create permission="ADMIN_BOOKING_RESOURCE_ATTR_VALUE" context_field='owner'/>
+                               <retrieve permission="ADMIN_BOOKING_RESOURCE_ATTR_VALUE" context_field='owner'/>
+                               <update permission="ADMIN_BOOKING_RESOURCE_ATTR_VALUE" context_field='owner'/>
+                               <delete permission="ADMIN_BOOKING_RESOURCE_ATTR_VALUE" context_field='owner'/>
                        </actions>
                </permacrud>
        </class>
@@ -3521,10 +3521,18 @@ SELECT  usr,
                </links>
                <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
                        <actions>
-                               <create permission="ADMIN_BOOKING_RESOURCE_ATTR_MAP" global_required='true'/>
-                               <retrieve />
-                               <update permission="ADMIN_BOOKING_RESOURCE_ATTR_MAP" global_required='true'/>
-                               <delete permission="ADMIN_BOOKING_RESOURCE_ATTR_MAP" global_required='true'/>
+                               <create permission="ADMIN_BOOKING_RESOURCE_ATTR_MAP">
+                    <context link="resource" field="owner" />
+                </create>
+                               <retrieve permission="ADMIN_BOOKING_RESOURCE_ATTR_MAP">
+                    <context link="resource" field="owner" />
+                </retrieve>
+                               <update permission="ADMIN_BOOKING_RESOURCE_ATTR_MAP">
+                    <context link="resource" field="owner" />
+                </update>
+                               <delete permission="ADMIN_BOOKING_RESOURCE_ATTR_MAP">
+                    <context link="resource" field="owner" />
+                </delete>
                        </actions>
                </permacrud>
        </class>
index 380edad..4e3fe1f 100644 (file)
@@ -1,13 +1,21 @@
 [% WRAPPER default/base.tt2 %]
 [% ctx.page_title = 'Resources' %]
-<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
-    <div dojoType="dijit.layout.ContentPane" layoutAlign="top" class="oils-header-panel">
-        <div>Resources</div>
-        <div>
-            <button dojoType='dijit.form.Button' onClick='brsrcGrid.showCreateDialog()'>New Resource</button>
-            <button dojoType='dijit.form.Button' onClick='brsrcGrid.deleteSelected()'>Delete Selected</button>
-        </div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="top" class="oils-header-panel">
+    <div>Resources</div>
+    <div>
+        <button dojoType='dijit.form.Button' onClick='brsrcGrid.showCreateDialog()'>New Resource</button>
+        <button dojoType='dijit.form.Button' onClick='brsrcGrid.deleteSelected()'>Delete Selected</button>
     </div>
+</div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
+    <span>Context Org Unit</span>
+    <select dojoType="openils.widget.OrgUnitFilteringSelect"
+            jsId='contextOrgSelector'
+            searchAttr='shortname'
+            labelAttr='shortname'>
+    </select>
+</div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
     <table  jsId="brsrcGrid"
             dojoType="openils.widget.AutoGrid"
             fieldOrder="['owner', 'type', 'barcode',
             query="{id: '*'}"
             fmClass='brsrc'
             showPaginator='true'
+            autoHeight='true'
             editOnEnter='true'>
     </table>
 </div>
-
 <script type ="text/javascript">
     dojo.require('dijit.form.FilteringSelect');
     dojo.require('openils.widget.AutoGrid');
     dojo.require("openils.widget.PCrudAutocompleteBox");
+    dojo.require('openils.widget.OrgUnitFilteringSelect');
+
+    function filterGrid() {
+        brsrcGrid.resetStore();
+        var unit = contextOrgSelector.getValue();
+        var list = fieldmapper.aou.findOrgUnit(unit).orgNodeTrail().map( function (i) {return i.id() } );
+
+        if(unit){
+            brsrcGrid.loadAll({order_by:{brsrc : 'barcode'}}, { 'owner' : list });
+        } else {
+            brsrcGrid.loadAll({order_by:{brsrc : 'barcode'}});
+        }
+    }
 
     openils.Util.addOnLoad(
         function() {
-            var search = {"id": {"!=": null}};
+            var org_id = openils.User.user.ws_ou();
+            var list = fieldmapper.aou.findOrgUnit(org_id).orgNodeTrail().map( function (i) {return i.id() } );
+
+            new openils.User().buildPermOrgSelector('ADMIN_BOOKING_RESOURCE', contextOrgSelector, null, function() {
+                dojo.connect(contextOrgSelector, 'onChange', filterGrid);});
+
+            var search = {'owner':list};
+
             if (xulG && xulG.resultant_brsrc)
                 search = {id: xulG.resultant_brsrc};
 
index b917b8e..b9a3ece 100644 (file)
@@ -1,18 +1,27 @@
 [% WRAPPER default/base.tt2 %]
 [% ctx.page_title = 'Resource Attributes' %]
-<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
-    <div dojoType="dijit.layout.ContentPane" layoutAlign="top" class="oils-header-panel">
-        <div>Resource Attributes</div>
-        <div>
-            <button dojoType='dijit.form.Button' onClick='braGrid.showCreateDialog()'>New Resource Attribute</button>
-            <button dojoType='dijit.form.Button' onClick='braGrid.deleteSelected()'>Delete Selected</button>
-        </div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="top" class="oils-header-panel">
+    <div>Resource Attributes</div>
+    <div>
+        <button dojoType='dijit.form.Button' onClick='braGrid.showCreateDialog()'>New Resource Attribute</button>
+        <button dojoType='dijit.form.Button' onClick='braGrid.deleteSelected()'>Delete Selected</button>
     </div>
+</div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
+    <span>Context Org Unit</span>
+    <select dojoType="openils.widget.OrgUnitFilteringSelect"
+            jsId='contextOrgSelector'
+            searchAttr='shortname'
+            labelAttr='shortname'>
+    </select>
+</div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
     <table  jsId="braGrid"
             dojoType="openils.widget.AutoGrid"
             fieldOrder="['name', 'owner', 'resource_type', 'required']"
             query="{id: '*'}"
             fmClass='bra'
+            autoHeight='true'
             showPaginator='true'
             editOnEnter='true'>
     </table>
 <script type ="text/javascript">
     dojo.require("openils.widget.PCrudAutocompleteBox");
     dojo.require('openils.widget.AutoGrid');
+    dojo.require('openils.widget.OrgUnitFilteringSelect');
+
+    function filterGrid() {
+        braGrid.resetStore();
+        var unit = contextOrgSelector.getValue();
+        var list = fieldmapper.aou.findOrgUnit(unit).orgNodeTrail().map( function (i) {return i.id() } );
+
+        if(unit){
+            braGrid.loadAll({order_by:{bra : 'name'}}, { 'owner' : list });
+        } else {
+            braGrid.loadAll({order_by:{bra : 'name'}});
+        }
+    }
 
     openils.Util.addOnLoad(
         function() {
                     "fmclass": "brt", "searchAttr": "name"
                 });
             braGrid.overrideEditWidgets.resource_type.shove = {"create": ""};
-            braGrid.loadAll({order_by:{bra : 'name'}}, {"id": {"!=": null}});
+            var org_id = openils.User.user.ws_ou();
+            var list = fieldmapper.aou.findOrgUnit(org_id).orgNodeTrail().map( function (i) {return i.id() } );
+
+            new openils.User().buildPermOrgSelector('ADMIN_BOOKING_RESOURCE_ATTR', contextOrgSelector, null, function() {
+                dojo.connect(contextOrgSelector, 'onChange', filterGrid);});
+            braGrid.loadAll({order_by:{bra : 'name'}}, { 'owner' : list });
         }
     );
 </script>
index 5e35b11..a691fa3 100644 (file)
@@ -1,18 +1,27 @@
 [% WRAPPER default/base.tt2 %]
 [% ctx.page_title = 'Resource Attribute Maps' %]
-<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
-    <div dojoType="dijit.layout.ContentPane" layoutAlign="top" class='oils-header-panel'>
-        <div>Resource Attribute Maps</div>
-        <div>
-            <button dojoType='dijit.form.Button' onClick='bramGrid.showCreateDialog()'>New Resource Attribute Map</button>
-            <button dojoType='dijit.form.Button' onClick='bramGrid.deleteSelected()'>Delete Selected</button>
-        </div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="top" class='oils-header-panel'>
+    <div>Resource Attribute Maps</div>
+    <div>
+        <button dojoType='dijit.form.Button' onClick='bramGrid.showCreateDialog()'>New Resource Attribute Map</button>
+        <button dojoType='dijit.form.Button' onClick='bramGrid.deleteSelected()'>Delete Selected</button>
     </div>
+</div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
+    <span>Context Org Unit</span>
+    <select dojoType="openils.widget.OrgUnitFilteringSelect"
+            jsId='contextOrgSelector'
+            searchAttr='shortname'
+            labelAttr='shortname'>
+    </select>
+</div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
     <table  jsId="bramGrid"
             dojoType="openils.widget.AutoGrid"
             fieldOrder="['resource', 'resource_attr', 'value']"
             query="{id: '*'}"
             fmClass='bram'
+            autoHeight='true'
             showPaginator='true'
             editOnEnter='true'>
     </table>
 <script type ="text/javascript">
     dojo.require("openils.widget.PCrudAutocompleteBox");
     dojo.require('openils.widget.AutoGrid');
+    dojo.require('openils.widget.OrgUnitFilteringSelect');
 
+    function filterGrid() {
+        bramGrid.resetStore();
+        var unit = contextOrgSelector.getValue();
+        var list = fieldmapper.aou.findOrgUnit(unit).orgNodeTrail().map( function (i) {return i.id() } );
+
+        if(unit){
+            bramGrid.loadAll({"order_by":"resource_attr"}, {"resource_attr":{"in":{"select":{"bra":["id"]},"from":"bra","where":{"+bra":{"owner": list } } } } } );
+        } else {
+            bramGrid.loadAll({order_by:{bram : 'resource_attr'}});
+        }
+    }
     openils.Util.addOnLoad(
         function() {
+            var org_id = openils.User.user.ws_ou();
+            var list = fieldmapper.aou.findOrgUnit(org_id).orgNodeTrail().map( function (i) {return i.id() } );
+
+            new openils.User().buildPermOrgSelector('ADMIN_BOOKING_RESOURCE_TYPE', contextOrgSelector, null, function() {
+                dojo.connect(contextOrgSelector, 'onChange', filterGrid);});
+
             bramGrid.overrideEditWidgets.resource =
                 new openils.widget.PCrudAutocompleteBox({
                     "fmclass": "brsrc", "searchAttr": "barcode"
                 });
             bramGrid.overrideEditWidgets.resource.shove = {"create": ""};
-            bramGrid.loadAll({"order_by": {"bram": "resource_attr"}});
+            bramGrid.loadAll({"order_by":"resource_attr"}, {"resource_attr":{"in":{"select":{"bra":["id"]},"from":"bra","where":{"+bra":{"owner": list } } } } } );
         }
     );
 </script>
index af1c5a7..3593db9 100644 (file)
@@ -1,18 +1,27 @@
 [% WRAPPER default/base.tt2 %]
 [% ctx.page_title = 'Resource Attribute Values' %]
-<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
-    <div dojoType="dijit.layout.ContentPane" layoutAlign="top" class='oils-header-panel'>
-        <div>Resource Attribute Values</div>
-        <div>
-            <button dojoType='dijit.form.Button' onClick='bravGrid.showCreateDialog()'>New Resource Attribute Value</button>
-            <button dojoType='dijit.form.Button' onClick='bravGrid.deleteSelected()'>Delete Selected</button>
-        </div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="top" class='oils-header-panel'>
+    <div>Resource Attribute Values</div>
+    <div>
+        <button dojoType='dijit.form.Button' onClick='bravGrid.showCreateDialog()'>New Resource Attribute Value</button>
+        <button dojoType='dijit.form.Button' onClick='bravGrid.deleteSelected()'>Delete Selected</button>
     </div>
+</div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
+    <span>Context Org Unit</span>
+    <select dojoType="openils.widget.OrgUnitFilteringSelect"
+            jsId='contextOrgSelector'
+            searchAttr='shortname'
+            labelAttr='shortname'>
+    </select>
+</div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
     <table  jsId="bravGrid"
             dojoType="openils.widget.AutoGrid"
             fieldOrder="['owner', 'attr', 'valid_value']"
             query="{id: '*'}"
             fmClass='brav'
+            autoHeight='true'
             showPaginator='true'
             editOnEnter='true'>
     </table>
 <script type ="text/javascript">
     dojo.require('dijit.form.FilteringSelect');
     dojo.require('openils.widget.AutoGrid');
+    dojo.require('openils.widget.OrgUnitFilteringSelect');
+
+    function filterGrid() {
+        bravGrid.resetStore();
+        var unit = contextOrgSelector.getValue();
+        var list = fieldmapper.aou.findOrgUnit(unit).orgNodeTrail().map( function (i) {return i.id() } );
+
+        if(unit){
+            bravGrid.loadAll({order_by:{brav : 'attr'}}, { 'owner' : list });
+        } else {
+            bravGrid.loadAll({order_by:{brav : 'attr'}});
+        }
+    }
 
     openils.Util.addOnLoad(
         function() {
-            bravGrid.loadAll({order_by:{brav : 'attr'}}, {"id": {"!=": null}});
+            var org_id = openils.User.user.ws_ou();
+            var list = fieldmapper.aou.findOrgUnit(org_id).orgNodeTrail().map( function (i) {return i.id() } );
+
+            new openils.User().buildPermOrgSelector('ADMIN_BOOKING_RESOURCE_ATTR_VALUE', contextOrgSelector, null, function() {
+                dojo.connect(contextOrgSelector, 'onChange', filterGrid);});
+
+            bravGrid.loadAll({order_by:{brav : 'attr'}}, { 'owner' : list });
         }
     );
 </script>
index 36afba7..ac4c3a4 100644 (file)
@@ -1,6 +1,5 @@
 [% WRAPPER default/base.tt2 %]
 [% ctx.page_title = 'Resource Types' %]
-<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
     <div dojoType="dijit.layout.ContentPane" layoutAlign="top" class="oils-header-panel">
         <div>Resource Types</div>
         <div>
@@ -8,6 +7,15 @@
             <button dojoType='dijit.form.Button' onClick='brtGrid.deleteSelected()'>Delete Selected</button>
         </div>
     </div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
+    <span>Context Org Unit</span>
+    <select dojoType="openils.widget.OrgUnitFilteringSelect"
+            jsId='contextOrgSelector'
+            searchAttr='shortname'
+            labelAttr='shortname'>
+    </select>
+</div>
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
     <table  jsId="brtGrid"
             dojoType="openils.widget.AutoGrid"
             fieldOrder="['name', 'fine_interval', 'fine_amount',
@@ -17,6 +25,7 @@
             query="{id: '*'}"
             fmClass='brt'
             showPaginator='true'
+            autoHeight='true'
             editOnEnter='true'>
     </table>
 </div>
 <script type ="text/javascript">
     dojo.require('dijit.form.FilteringSelect');
     dojo.require('openils.widget.AutoGrid');
+    dojo.require('openils.widget.OrgUnitFilteringSelect');
 
+    function filterGrid() {
+        brtGrid.resetStore();
+        var unit = contextOrgSelector.getValue();
+        var list = fieldmapper.aou.findOrgUnit(unit).orgNodeTrail().map( function (i) {return i.id() } );
+
+        if(unit){
+            brtGrid.loadAll({order_by:{brt : 'name'}}, { 'owner' : list });
+        } else {
+            brtGrid.loadAll({order_by:{brt : 'name'}});
+        }
+    }
     openils.Util.addOnLoad(
         function() {
-            brtGrid.loadAll({"order_by": {"brt": "name"}}, {"id": {"!=": null}});
+            var org_id = openils.User.user.ws_ou();
+            var list = fieldmapper.aou.findOrgUnit(org_id).orgNodeTrail().map( function (i) {return i.id() } );
+
+            new openils.User().buildPermOrgSelector('ADMIN_BOOKING_RESOURCE_TYPE', contextOrgSelector, null, function() {
+                dojo.connect(contextOrgSelector, 'onChange', filterGrid);});
+
+            brtGrid.loadAll({"order_by": {"brt": "name"}}, { 'owner' : list });
         }
     );
 </script>