Ability to return to specific authority.control_set or
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 22 Jun 2011 14:50:06 +0000 (10:50 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 11 Jul 2011 17:48:29 +0000 (13:48 -0400)
to specific authority.control_set_authority_field from a child table.
Other improvements heading toward finishing authority control set config UI

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Cat/Authority.pm
Open-ILS/web/js/ui/default/cat/authority/common.js [new file with mode: 0644]
Open-ILS/web/templates/default/cat/authority/control_set.tt2
Open-ILS/web/templates/default/cat/authority/control_set_authority_field.tt2
Open-ILS/web/templates/default/cat/authority/thesaurus.tt2

index 937aee7..696a446 100644 (file)
@@ -238,7 +238,7 @@ __PACKAGE__->register_method(
         "params" => [
             {"name" => "limit",  "desc" => "limit (optional; default 15)", "type" => "number"},
             {"name" => "offset",  "desc" => "offset doptional; default 0)", "type" => "number"},
-            {"name" => "id",  "desc" => "acs id (optional; default all)", "type" => "number"}
+            {"name" => "focus",  "desc" => "optionally make sure the acs object with ID matching this value comes at the top of the result set (only works with offset 0)", "type" => "number"}
         ]
     }
 );
@@ -248,19 +248,32 @@ sub retrieve_acs {
     my $self = shift;
     my $client = shift;
 
-    my ($limit, $offset, $id) = map int, @_;
+    my ($limit, $offset, $focus) = map int, @_;
 
     $limit ||= 15;
     $offset ||= 0;
-    $id ||= undef;
+    $focus ||= undef;
 
     my $e = new_editor;
-    my $where = {"id" => ($id ? $id : {"!=" => undef})};
+    my $order_by = [
+        {"class" => "acs", "field" => "name"}
+    ];
+
+    # Here is the magic that let's us say that a given acsaf
+    # will be our first result.
+    unshift @$order_by, {
+        "class" => "acs", "field" => "id",
+        "transform" => "numeric_eq", "params" => [$focus],
+        "direction" => "desc"
+    } if $focus;
+
     my $sets = $e->search_authority_control_set([
-        $where, {
+        {"id" => {"!=" => undef}}, {
             "flesh" => 1,
             "flesh_fields" => {"acs" => [qw/thesauri authority_fields/]},
-            "order_by" => {"acs" => "name"}
+            "order_by" => $order_by,
+            "limit" => $limit,
+            "offset" => $offset
         }
     ]) or return $e->die_event;
 
@@ -270,4 +283,67 @@ sub retrieve_acs {
     return undef;
 }
 
+__PACKAGE__->register_method(
+    "method" => "retrieve_acsaf",
+    "api_name" => "open-ils.cat.authority.control_set_authority_field.retrieve",
+    "api_level" => 1,
+    "stream" => 1,
+    "argc" => 2,
+    "signature" => {
+        "desc" => q/Retrieve authority.control_set_authority_field objects with
+        fleshed bib_fields and axes/,
+        "params" => [
+            {"name" => "limit",  "desc" => "limit (optional; default 15)", "type" => "number"},
+            {"name" => "offset",  "desc" => "offset (optional; default 0)", "type" => "number"},
+            {"name" => "control_set",  "desc" => "optionally constrain by value of acsaf.control_set field", "type" => "number"},
+            {"name" => "focus", "desc" => "optionally make sure the acsaf object with ID matching this value comes at the top of the result set (only works with offset 0)"}
+        ]
+    }
+);
+
+sub retrieve_acsaf {
+    my $self = shift;
+    my $client = shift;
+
+    my ($limit, $offset, $control_set, $focus) = map int, @_;
+
+    $limit ||= 15;
+    $offset ||= 0;
+    $control_set ||= undef;
+    $focus ||= undef;
+
+    my $e = new_editor;
+    my $where = {
+        "control_set" => ($control_set ? $control_set : {"!=" => undef})
+    };
+    my $order_by = [
+        {"class" => "acsaf", "field" => "main_entry", "direction" => "desc"},
+        {"class" => "acsaf", "field" => "id"}
+    ];
+
+    unshift @$order_by, {
+        "class" => "acsaf", "field" => "id",
+        "transform" => "numeric_eq", "params" => [$focus],
+        "direction" => "desc"
+    } if $focus;
+
+    my $fields = $e->search_authority_control_set_authority_field([
+        $where, {
+            "flesh" => 2,
+            "flesh_fields" => {
+                "acsaf" => ["bib_fields", "axis_maps"],
+                "abaafm" => ["axis"]
+            },
+            "order_by" => $order_by,
+            "limit" => $limit,
+            "offset" => $offset
+        }
+    ]) or return $e->die_event;
+
+    $e->disconnect;
+
+    $client->respond($_) foreach @$fields;
+    return undef;
+}
+
 1;
diff --git a/Open-ILS/web/js/ui/default/cat/authority/common.js b/Open-ILS/web/js/ui/default/cat/authority/common.js
new file mode 100644 (file)
index 0000000..d8d8a37
--- /dev/null
@@ -0,0 +1,11 @@
+function render_control_set_metadata(control_set) {
+    var anchor = dojo.byId("control-set-metadata");
+    anchor.href = oilsBasePath + "/cat/authority/control_set?focus=" +
+        control_set.id();
+    anchor.innerHTML = dojo.string.substitute(
+        localeStrings.CONTROL_SET_METADATA, [
+            control_set.id(), control_set.name(), control_set.description()
+        ]
+    );
+    openils.Util.show("control-set-metadata-holder");
+}
index d763b61..4d1e97d 100644 (file)
 
 <script type="text/javascript">
     dojo.require("openils.widget.AutoGrid");
+    dojo.require("openils.CGI");
     dojo.requireLocalization("openils.authority", "authority");
     var localeStrings =
         dojo.i18n.getLocalization("openils.authority", "authority");
     var acs_cache = {};
+    var cgi;
 
     function format_acs_id(id) {
         if (id) {
@@ -59,7 +61,7 @@
         fieldmapper.standardRequest(
             ["open-ils.cat", "open-ils.cat.authority.control_set.retrieve"], {
                 "async": true,
-                "params": [acs_grid.displayLimit, acs_grid.displayOffset],
+                "params": [acs_grid.displayLimit, acs_grid.displayOffset, cgi.param("focus")],
                 "onresponse": function(r) {
                     if (r = openils.Util.readResponse(r)) {
                         acs_cache[r.id()] = r;
@@ -75,6 +77,8 @@
 
     openils.Util.addOnLoad(
         function() {
+            cgi = new openils.CGI();
+
             acs_grid.onPostCreate = function(obj) {acs_cache[obj.id()] = obj;};
             acs_grid.dataLoader = acs_grid_loader;
             acs_grid_loader();
index 17e70cf..6bf734e 100644 (file)
@@ -7,29 +7,35 @@
     <div dojoType="dijit.layout.ContentPane" layoutAlign="top" class="oils-header-panel">
         <div>Authority Fields</div>
         <div>
-            <button dojoType="dijit.form.Button" onClick="acsaf_grid.showCreateDialog()">New Authority Fields</button>
+            <button dojoType="dijit.form.Button" onClick="acsaf_grid.showCreateDialog()">New Authority Field</button>
             <button dojoType="dijit.form.Button" onClick="acsaf_grid.deleteSelected()">Delete Selected</button>
         </div>
     </div>
     <div id="control-set-metadata-holder" class="hidden">
-        Showing only authority fields linked to
-        <a href="control_set">control set</a>:
-        <span id="control-set-metadata"></span>
+        Showing only authority fields linked to control set:
+        <a id="control-set-metadata"></a>
     </div>
     <div>
         <table  jsId="acsaf_grid"
                 dojoType="openils.widget.AutoGrid"
                 autoHeight="true"
-                defaultCellWidth="'auto'"
-                fieldOrder="['id','name','description','main_entry','control_set','tag','sf_list']"
+                defaultCellWidth="'12%'"
+                fieldOrder="['id','name','description','main_entry','control_set','tag','sf_list','bib_fields','axis_maps']"
                 suppressEditFields="['id']"
                 query="{id: '*'}"
                 fmClass="acsaf"
                 editOnEnter="true">
+            <thead>
+                <tr>
+                    <th field="bib_fields" name="Controlled Bib Fields"></th>
+                    <th field="axis_maps" name="Axes"></th>
+                </tr>
+            </thead>
         </table>
     </div>
 </div>
-
+<script type="text/javascript"
+    src="[% ctx.media_prefix %]/js/ui/default/cat/authority/common.js"></script>
 <script type="text/javascript">
     dojo.require("openils.widget.AutoGrid");
     dojo.require("openils.CGI");
     var localeStrings =
         dojo.i18n.getLocalization("openils.authority", "authority");
 
-    var cgi, pcrud;
+    var cgi, pcrud, control_set;
+    var acsaf_cache = {};
 
-    function render_control_set_metadata(control_set) {
-        var span = dojo.byId("control-set-metadata");
-        span.innerHTML = dojo.string.substitute(
-            localeStrings.CONTROL_SET_METADATA, [
-                control_set.id(), control_set.name(), control_set.description()
-            ]
+    function acsaf_grid_loader() {
+        acsaf_cache = {};
+        acsaf_grid.resetStore();
+        acsaf_grid.showLoadProgressIndicator();
+        fieldmapper.standardRequest(
+            ["open-ils.cat",
+                "open-ils.cat.authority.control_set_authority_field.retrieve"],{
+                "async": true,
+                "params": [
+                    acsaf_grid.displayLimit, acsaf_grid.displayOffset,
+                    control_set.id(), cgi.param("focus")
+                ],
+                "onresponse": function(r) {
+                    if (r = openils.Util.readResponse(r)) {
+                        acsaf_cache[r.id()] = r;
+                        acsaf_grid.store.newItem(r.toStoreItem());
+                    }
+                },
+                "oncomplete": function() {
+                    acsaf_grid.hideLoadProgressIndicator();
+                }
+            }
         );
-        openils.Util.show("control-set-metadata-holder");
     }
 
-    function my_init() {
-        var control_set;
-        var where = {"id": {"!=": null}};
 
+    function my_init() {
         cgi = new openils.CGI();
         pcrud = new openils.PermaCrud();
 
         control_set = cgi.param("acs");
         if (control_set) {
             control_set = pcrud.retrieve("acs", control_set);
-            where.control_set = control_set.id();
             render_control_set_metadata(control_set);
             /* XXX TODO
-               1) put render_control_set_metadata() somewhere that it doesn't
-               have to be repeated.
-               2) when browsing by control_set, make it impossible to
+               when browsing by control_set, make it impossible to
                create/edit acsaf objects with any other control_set.
                */
         }
 
-        acsaf_grid.loadAll(
-            {"order_by": {"acsaf": ["main_entry DESC", "id"]}},
-            where
-        );
+        acsaf_grid.onPostCreate = function(o) { acsaf_cache[o.id()] = o; };
+        acsaf_grid.dataLoader = acsaf_grid_loader;
+        acsaf_grid_loader();
     }
 
     openils.Util.addOnLoad(my_init);
index 0c62dab..7f41066 100644 (file)
@@ -12,8 +12,8 @@
         </div>
     </div>
     <div id="control-set-metadata-holder" class="hidden">
-        Showing only thesauri linked to <a href="control_set">control set</a>:
-        <span id="control-set-metadata"></span>
+        Showing only thesauri linked to control set:
+        <a id="control-set-metadata"></a>
     </div>
     <div>
         <table  jsId="at_grid"
@@ -28,7 +28,8 @@
         </table>
     </div>
 </div>
-
+<script type="text/javascript"
+    src="[% ctx.media_prefix %]/js/ui/default/cat/authority/common.js"></script>
 <script type="text/javascript">
     dojo.require("openils.widget.AutoGrid");
     dojo.require("openils.CGI");
 
     var cgi, pcrud;
 
-    function render_control_set_metadata(control_set) {
-        var span = dojo.byId("control-set-metadata");
-        span.innerHTML = dojo.string.substitute(
-            localeStrings.CONTROL_SET_METADATA, [
-                control_set.id(), control_set.name(), control_set.description()
-            ]
-        );
-        openils.Util.show("control-set-metadata-holder");
-    }
-
     function my_init() {
         var control_set;
         var where = {"code": {"!=": null}};