Add basic authority browse/edit/delete interface
authordbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 19 Aug 2010 01:24:03 +0000 (01:24 +0000)
committerdbs <dbs@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 19 Aug 2010 01:24:03 +0000 (01:24 +0000)
http://localhost/eg/cat/authority/list should get you where you need to be

The paging is comical, the JS should probably be split out from the
declarative markup, the interface needs i18n, the UI needs to become
usable - but at least we have exposed some functionality for working
with authority records now.

Ideally this becomes a widget that we can just embed into other
interfaces to maintain context (which suggests using openils.cgi
to seed the initial values of the widget).

Note that the delete function works - it sets the deleted flag for
an are to "true" - but the underlying authorities browse interface
currently doesn't care about such niceties and always returns deleted
records along with undeleted records. So that might be the next stop.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@17255 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/fm_IDL.xml
Open-ILS/web/templates/default/cat/authority/list.tt2 [new file with mode: 0644]

index 2ca154a..902c10a 100644 (file)
@@ -1425,6 +1425,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <link field="bib_links" reltype="has_many" key="authority" map="" class="abl"/>
                        <link field="fixed_fields" reltype="might_have" key="record" map="" class="ard"/>
                </links>
+               <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+            <actions>
+                <create permission="CREATE_MARC IMPORT_MARC" global_required="true"/>
+                <retrieve/>
+                <update permission="UPDATE_MARC" global_required="true"/>
+                <delete permission="UPDATE_MARC" global_required="true"/>
+            </actions>
+        </permacrud>
+
        </class>
        <class id="ard" controller="open-ils.cstore" oils_obj:fieldmapper="authority::record_descriptor" oils_persist:tablename="authority.rec_descriptor" reporter:label="Authority Record Descriptor">
                <fields oils_persist:primary="id" oils_persist:sequence="authority.rec_descriptor_id_seq">
diff --git a/Open-ILS/web/templates/default/cat/authority/list.tt2 b/Open-ILS/web/templates/default/cat/authority/list.tt2
new file mode 100644 (file)
index 0000000..428f884
--- /dev/null
@@ -0,0 +1,131 @@
+[% ctx.page_title = 'Authority record list' %]
+[% WRAPPER default/base.tt2 %]
+
+<script>
+dojo.require('dijit.form.Button');
+dojo.require('dijit.form.DropDownButton');
+dojo.require('dijit.form.FilteringSelect');
+dojo.require('dijit.form.Form');
+dojo.require('dijit.form.NumberSpinner');
+dojo.require('dijit.form.TextBox');
+dojo.require("dijit.Menu");
+dojo.require("dijit.MenuItem");
+dojo.require('dojox.xml.parser');
+dojo.require('openils.PermaCrud');
+dojo.require('openils.XUL');
+dojo.require('openils.widget.OrgUnitFilteringSelect');
+
+/*
+// OrgUnits do not currently affect the retrieval of authority records,
+// but this is how to display them if they become OrgUnit-aware
+function authOUListInit() {
+    new openils.User().buildPermOrgSelector(
+        "STAFF_LOGIN", // anywhere you can log in
+        dijit.byId("authOU"),
+        null, // pre-selected org
+        null
+    );
+}
+dojo.addOnLoad(authOUListInit);
+*/
+function displayAuthorities(data) { 
+    // Grab each record from the returned authority records
+    dojo.query("record", data).forEach(function(node) {
+        authText = '';
+        authId = 0;
+
+        // Grab each authority record field from the authority record
+        dojo.query("datafield[tag^='1']", node).forEach(function(dfNode) {
+            authText += dojox.xml.parser.textContent(dfNode); 
+        });
+        // Grab the ID of the authority record
+        dojo.query("datafield[tag='901'] subfield[code='c']", node).forEach(function(dfNode) {
+            authId = dojox.xml.parser.textContent(dfNode); 
+        });
+
+        // Create the authority record listing entry
+        dojo.place('<div class="authEntry" id="auth' + authId + '">' + authText + '</div>', "authlist-div", "last");
+        // Add the menu of new/edit/delete/mark-for-merge options
+        var auth_menu = new dijit.Menu({});
+        new dijit.MenuItem({"onClick": function(){
+            pcrud = new openils.PermaCrud();
+            var auth_rec = pcrud.retrieve("are", authId);
+            if (auth_rec) {
+                loadMarcEditor(pcrud, auth_rec);
+            }
+        }, "label":"Edit"}).placeAt(auth_menu, "first");
+        new dijit.MenuItem({"onClick":function(){
+            pcrud = new openils.PermaCrud();
+            var auth_rec = pcrud.retrieve("are", authId);
+            if (auth_rec) {
+                pcrud.eliminate(auth_rec);
+                alert("Deleted authority record # " + authId);
+            }
+        }, "label":"Delete"}).placeAt(auth_menu, "last");
+        var auth_mb = new dijit.form.DropDownButton({dropDown: auth_menu, label:"Actions"});
+        auth_mb.placeAt("auth" + authId, "first");
+        auth_menu.startup();
+    });
+}
+
+function loadMarcEditor(pcrud, rec) {
+    /*
+       To run in Firefox directly, must set signed.applets.codebase_principal_support
+       to true in about:config
+     */
+    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+    win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
+
+    win.xulG = {
+        "record": {"marc": rec.marc()},
+        "save": {
+            "label": "Save",
+            "func": function(xmlString) {
+                rec.marc(xmlString);
+                rec.ischanged(true);
+                pcrud.update(rec);
+                alert("Record was saved");
+                win.close();
+            }
+        }
+    };
+}
+</script>
+
+<div dojoType="dijit.form.Form" id="myForm" jsId="myForm" encType="multipart/form-data" action="" method="">
+    <label for="authTerm">Search term: </label><input type="text" name="authTerm" value="" dojoType="dijit.form.TextBox" trim="true" id="authTerm" propercase="false"/>
+    <label for="authAxis">Authority type: </label><select type="text" name="authAxis" value="" dojoType="dijit.form.FilteringSelect" trim="true" id="authAxis" propercase="false">
+        <option value="authority.author">Author</option>
+        <option value="authority.subject">Subject</option>
+        <option value="authority.title">Title</option>
+        <option value="authority.topic">Topic</option>
+    </select>
+<!-- Not currently useful - see authOUListInit() above -->
+<!--    <label for="authOU">Library: </label><select dojoType="openils.widget.OrgUnitFilteringSelect" id="authOU" name="authOU" searchAttr="shortname" labelAttr="shortname"></select> -->
+    <label for="authPage">Page: </label><input dojoType="dijit.form.NumberSpinner" value="0" constraints="{min:-100,max:100,places:0}" smallDelta="1" id="authPage" name="authPage"/>
+    <div dojoType="dijit.form.Button" type="button" value="Submit">Submit
+        <script type="dojo/method" event="onClick" args="evt">
+            /* Protect against null input */
+            if (!dijit.byId('authTerm').attr('value')) {
+                return;
+            }
+
+            /* Clear out the current contents of the page */
+            dojo.query("#authlist-div div").orphan();
+
+            url = '/opac/extras/startwith/marcxml/'
+                + dijit.byId('authAxis').attr('value')
+                // + '/' + dijit.byId('authOU').attr('value')
+                + '/1' // replace with preceding line if OUs gain some meaning
+                + '/' + dijit.byId('authTerm').attr('value')
+                + '/' + dijit.byId('authPage').attr('value')
+            ;
+            dojo.xhrGet({"url":url, "handleAs":"xml", "content":{"format":"marcxml"}, "load":displayAuthorities });
+        </script>
+    </div>
+</div>
+
+<div id='authlist-div'></div>
+
+[% END %]
+