Add bib field editor. Also make all the editors written so far...
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 22 Jun 2011 18:04:14 +0000 (14:04 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 11 Jul 2011 17:48:29 +0000 (13:48 -0400)
... for authority control sets-related objects do the right thing to
help users create/edit new child objects linked to the right parent
table without extra effort.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/web/js/dojo/openils/authority/nls/authority.js
Open-ILS/web/js/ui/default/cat/authority/common.js
Open-ILS/web/templates/default/cat/authority/control_set_authority_field.tt2
Open-ILS/web/templates/default/cat/authority/control_set_bib_field.tt2 [new file with mode: 0644]
Open-ILS/web/templates/default/cat/authority/thesaurus.tt2

index 9fef602..4c448c8 100644 (file)
@@ -18,5 +18,6 @@
     "MERGE_RESULT_SUCCESS": "Record merge is complete.",
     "THESAURI": "Thesauri (${0})",
     "AUTHORITY_FIELDS": "Authority Fields (${0})",
-    "CONTROL_SET_METADATA": "(${0}) ${1} / ${2}"
+    "CONTROL_SET_METADATA": "(${0}) ${1} / ${2}",
+    "AUTHORITY_FIELD_METADATA": "${3} (${1} ‡${2}) ${4}"
 }
index d8d8a37..bb30b48 100644 (file)
@@ -1,3 +1,4 @@
+/* To be used by interfaces for editing child tables of acs. */
 function render_control_set_metadata(control_set) {
     var anchor = dojo.byId("control-set-metadata");
     anchor.href = oilsBasePath + "/cat/authority/control_set?focus=" +
@@ -9,3 +10,27 @@ function render_control_set_metadata(control_set) {
     );
     openils.Util.show("control-set-metadata-holder");
 }
+
+/* To be used by interfaces for editing child tables of acsaf.  They not
+ * only want to know what acsaf they belong to, but for convenience they
+ * should also have handy the acs id to which their parent acsaf belongs,
+ * so they can provide the most helpful "back" link.
+ */
+function render_authority_field_metadata(authority_field, control_set_id) {
+    var anchor = dojo.byId("authority-field-metadata");
+    var href = oilsBasePath +
+        "/cat/authority/control_set_authority_field?focus=" +
+        authority_field.id();
+    if (control_set_id) href += "&acs=" + control_set_id;
+
+    anchor.href = href;
+    anchor.innerHTML = dojo.string.substitute(
+        localeStrings.AUTHORITY_FIELD_METADATA, [
+            "id", "tag", "sf_list", "name", "description"
+        ].map(function(k) {
+            var v = authority_field[k]();
+            return (v == null) ? "" : v;
+        })
+    );
+    openils.Util.show("authority-field-metadata-holder");
+}
index 6bf734e..740d408 100644 (file)
@@ -1,7 +1,4 @@
 [% WRAPPER default/base.tt2 %]
-<style type="text/css">
-    .control-set-metadata-holder { text-align: left }
-</style>
 [% ctx.page_title = "Configure Authority Authority Fields" %]
 <div dojoType="dijit.layout.ContentPane" layoutAlign="client">
     <div dojoType="dijit.layout.ContentPane" layoutAlign="top" class="oils-header-panel">
@@ -27,7 +24,7 @@
                 editOnEnter="true">
             <thead>
                 <tr>
-                    <th field="bib_fields" name="Controlled Bib Fields"></th>
+                    <th field="bib_fields" name="Controlled Bib Fields" get="get_just_id" formatter="format_bib_fields"></th>
                     <th field="axis_maps" name="Axes"></th>
                 </tr>
             </thead>
         );
     }
 
+    function get_just_id(row_index, item) {
+        if (item) return this.grid.store.getValue(item, "id");
+    }
+
+    function format_bib_fields(id) {
+        if (id) {
+            var text = acsaf_cache[id].bib_fields().map(
+                function(f) { return f.tag(); }
+            ).sort().join(", ");
+            var href = "control_set_bib_field?";
+            if (control_set)
+                href += "acs=" + control_set.id() + "&amp;";
+            href += "acsaf=" + id;
+            return "<a href='" + href + "'>"  + text + "</a>";
+        }
+    }
 
     function my_init() {
         cgi = new openils.CGI();
         if (control_set) {
             control_set = pcrud.retrieve("acs", control_set);
             render_control_set_metadata(control_set);
-            /* XXX TODO
-               when browsing by control_set, make it impossible to
-               create/edit acsaf objects with any other control_set.
-               */
+
+            acsaf_grid.overrideEditWidgets.control_set =
+                new dijit.form.TextBox({"disabled": true});
+            acsaf_grid.overrideEditWidgets.control_set.shove =
+                {"create": control_set.id()};
         }
 
         acsaf_grid.onPostCreate = function(o) { acsaf_cache[o.id()] = o; };
diff --git a/Open-ILS/web/templates/default/cat/authority/control_set_bib_field.tt2 b/Open-ILS/web/templates/default/cat/authority/control_set_bib_field.tt2
new file mode 100644 (file)
index 0000000..6cca21b
--- /dev/null
@@ -0,0 +1,71 @@
+[% WRAPPER default/base.tt2 %]
+[% ctx.page_title = "Configure Authority Control Set Bib Fields" %]
+<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
+    <div dojoType="dijit.layout.ContentPane" layoutAlign="top" class="oils-header-panel">
+        <div>Control Set Bib Fields</div>
+        <div>
+            <button dojoType="dijit.form.Button" onClick="acsbf_grid.showCreateDialog()">New Control Set Bib Field</button>
+            <button dojoType="dijit.form.Button" onClick="acsbf_grid.deleteSelected()">Delete Selected</button>
+        </div>
+    </div>
+    <div id="authority-field-metadata-holder" class="hidden">
+        Showing only control set bib fields linked to authority field:
+        <a id="authority-field-metadata"></a>
+    </div>
+    <div>
+        <table  jsId="acsbf_grid"
+                dojoType="openils.widget.AutoGrid"
+                autoHeight="true"
+                defaultCellWidth="'auto'"
+                suppressEditFields="['id']"
+                fieldOrder="['tag','authority_field']"
+                query="{id: '*'}"
+                fmClass="acsbf"
+                editOnEnter="true">
+        </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");
+    dojo.require("openils.PermaCrud");
+
+    dojo.requireLocalization("openils.authority", "authority");
+    var localeStrings =
+        dojo.i18n.getLocalization("openils.authority", "authority");
+
+    var cgi, pcrud;
+
+    function my_init() {
+        var authority_field, control_set_id;
+        var where = {"id": {"!=": null}};
+
+        cgi = new openils.CGI();
+        pcrud = new openils.PermaCrud();
+
+        authority_field = cgi.param("acsaf");
+        control_set_id = cgi.param("acs");
+
+        if (authority_field) {
+            /* This block not only limits the scope of our search for acsbf
+               objects, but makes sure that we create/update only acsbf's
+               that link back to the authority field (acsaf) we're interested
+               in.  */
+            authority_field = pcrud.retrieve("acsaf", authority_field);
+            where.authority_field = authority_field.id();
+            render_authority_field_metadata(authority_field, control_set_id);
+
+            acsbf_grid.overrideEditWidgets.authority_field =
+                new dijit.form.TextBox({"disabled": true});
+            acsbf_grid.overrideEditWidgets.authority_field.shove =
+                {"create": authority_field.id()};
+        }
+
+        acsbf_grid.loadAll({"order_by": {"acsbf": "tag"}}, where);
+    }
+
+    openils.Util.addOnLoad(my_init);
+</script>
+[% END %]
index 7f41066..5e4c2bd 100644 (file)
@@ -1,7 +1,4 @@
 [% WRAPPER default/base.tt2 %]
-<style type="text/css">
-    .control-set-metadata-holder { text-align: left }
-</style>
 [% ctx.page_title = "Configure Authority Thesauri" %]
 <div dojoType="dijit.layout.ContentPane" layoutAlign="client">
     <div dojoType="dijit.layout.ContentPane" layoutAlign="top" class="oils-header-panel">
             control_set = pcrud.retrieve("acs", control_set);
             where.control_set = control_set.id();
             render_control_set_metadata(control_set);
+
+            at_grid.overrideEditWidgets.control_set =
+                new dijit.form.TextBox({"disabled": true});
+            at_grid.overrideEditWidgets.control_set.shove =
+                {"create": control_set.id()};
         }
 
         at_grid.loadAll({"order_by": {"at": "code"}}, where);