[open-ils-commits] r13009 - in trunk/Open-ILS/web: js/ui/default/acq/picklist templates/default/acq/picklist (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Apr 28 17:07:46 EDT 2009
Author: erickson
Date: 2009-04-28 17:07:41 -0400 (Tue, 28 Apr 2009)
New Revision: 13009
Modified:
trunk/Open-ILS/web/js/ui/default/acq/picklist/brief_record.js
trunk/Open-ILS/web/templates/default/acq/picklist/brief_record.tt2
Log:
added code to build the marc xml from the form, added option to select destination selection list for brief record. added stub for 'finish editing via marc editor' option
Modified: trunk/Open-ILS/web/js/ui/default/acq/picklist/brief_record.js
===================================================================
--- trunk/Open-ILS/web/js/ui/default/acq/picklist/brief_record.js 2009-04-28 03:15:38 UTC (rev 13008)
+++ trunk/Open-ILS/web/js/ui/default/acq/picklist/brief_record.js 2009-04-28 21:07:41 UTC (rev 13009)
@@ -3,16 +3,37 @@
dojo.require('dijit.form.TextBox');
dojo.require('dijit.form.DateTextBox');
dojo.require('dijit.form.Button');
+dojo.require('dijit.form.ComboBox');
dojo.require('openils.User');
dojo.require('openils.widget.AutoFieldWidget');
dojo.require('openils.MarcXPathParser');
+dojo.require('openils.acq.Picklist');
+var attrDefs = {};
+
function drawBriefRecordForm(fields) {
var tbody = dojo.byId('acq-brief-record-tbody');
var rowTmpl = dojo.byId('acq-brief-record-row');
fieldmapper.standardRequest(
+ ['open-ils.acq', 'open-ils.acq.picklist.user.retrieve.atomic'],
+ { async: true,
+ params: [openils.User.authtoken],
+ oncomplete : function(r) {
+ var list = openils.Util.readResponse(r);
+ plSelector.store =
+ new dojo.data.ItemFileReadStore({data:acqpl.toStoreData(list)});
+ }
+ }
+ );
+
+
+ marcEditButton.onClick = function(fields) {
+ saveBriefRecord(fields, true);
+ }
+
+ fieldmapper.standardRequest(
['open-ils.acq', 'open-ils.acq.lineitem_attr_definition.retrieve.all'],
{ async : true,
params : [openils.User.authtoken],
@@ -29,8 +50,10 @@
}
);
+ var xpathParser = new openils.MarcXPathParser();
dojo.forEach(attrs,
function(def) {
+ attrDefs[def.code()] = xpathParser.parse(def.xpath());
var row = rowTmpl.cloneNode(true);
dojo.query('[name=name]', row)[0].innerHTML = def.description();
new dijit.form.TextBox({name : def.code()}, dojo.query('[name=widget]', row)[0]);
@@ -43,9 +66,105 @@
);
}
-function compileBriefRecord(fields) {
- console.log(js2JSON(fields));
+function saveBriefRecord(fields, editMarc) {
+
+ // first, deal with the selection list
+ var picklist = plSelector.attr('value');
+
+ if(!picklist) {
+ compileBriefRecord(fields, editMarc);
+ return false;
+ }
+
+ // ComboBox value is the display string. find the actual picklist
+ // and create a new one if necessary
+ plSelector.store.fetch({
+ query : {name:picklist},
+
+ onComplete : function(items) {
+ if(items.length == 0) {
+
+ // create a new picklist for these items
+ openils.acq.Picklist.create(
+ {name:picklist, org_unit: openils.User.user.ws_ou()},
+ function(plId) {
+ dojo.mixin(fields, {picklist:plId});
+ compileBriefRecord(fields, editMarc);
+ }
+ );
+
+ } else {
+ var id = plSelector.store.getValue(items[0], 'id');
+ dojo.mixin(fields, {picklist:id});
+ compileBriefRecord(fields, editMarc);
+ }
+ }
+ });
+
return false;
}
+function compileBriefRecord(fields, editMarc) {
+
+ var baseString = '<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
+ 'xmlns="http://www.loc.gov/MARC21/slim" ' +
+ 'xmlns:marc="http://www.loc.gov/MARC21/slim" ' +
+ 'xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/ standards/marcxml/schema/MARC21slim.xsd">' +
+ '<leader/></record>';
+
+ var doc = new DOMParser().parseFromString(baseString, 'text/xml');
+
+ for(var f in fields) {
+
+ var def = attrDefs[f];
+ if(!def) continue;
+ var value = fields[f];
+ if(!value) continue;
+
+ var dfNode = doc.createElementNS('http://www.loc.gov/MARC21/slim', 'marc:datafield');
+ var sfNode = doc.createElementNS('http://www.loc.gov/MARC21/slim', 'marc:subfield');
+
+ // creates tags and fields in the document. If there are more than one
+ // option for the tag or code, use the first in the list
+ dfNode.setAttribute('tag', ''+def.tags[0]);
+ dfNode.setAttribute('ind1', ' ');
+ dfNode.setAttribute('ind2', ' ');
+ sfNode.setAttribute('code', ''+def.subfields[0]);
+ tNode = doc.createTextNode(value);
+
+ sfNode.appendChild(tNode);
+ dfNode.appendChild(sfNode);
+ doc.documentElement.appendChild(dfNode);
+ }
+
+
+ var xmlString = new XMLSerializer().serializeToString(doc);
+
+ var li = new fieldmapper.jub();
+ li.marc(xmlString);
+ li.picklist(fields.picklist);
+ li.selector(openils.User.user.id());
+ li.creator(openils.User.user.id());
+ li.editor(openils.User.user.id());
+
+ fieldmapper.standardRequest(
+ ['open-ils.acq', 'open-ils.acq.lineitem.create'],
+ { async : true,
+ params : [openils.User.authtoken, li],
+ oncomplete : function(r) {
+ var id = openils.Util.readResponse(r);
+ if(!id) return;
+ if(editMarc) {
+ // XXX load marc editor
+ } else {
+ if(fields.picklist)
+ location.href = location.href + '/../view/' + fields.picklist;
+ }
+ }
+ }
+ );
+
+ return false;
+}
+
openils.Util.addOnLoad(drawBriefRecordForm);
Modified: trunk/Open-ILS/web/templates/default/acq/picklist/brief_record.tt2
===================================================================
--- trunk/Open-ILS/web/templates/default/acq/picklist/brief_record.tt2 2009-04-28 03:15:38 UTC (rev 13008)
+++ trunk/Open-ILS/web/templates/default/acq/picklist/brief_record.tt2 2009-04-28 21:07:41 UTC (rev 13009)
@@ -4,10 +4,14 @@
<h1>New Brief Record</h1><br/>
<form dojoType='dijit.form.Form'>
<script type='dojo/method' event='onSubmit'>
- return compileBriefRecord(this.getValues());
+ return saveBriefRecord(this.getValues());
</script>
<table class='oils-generic-table'>
<tbody id='acq-brief-record-tbody'>
+ <tr>
+ <td>Add To Selection List</td>
+ <td><select dojoType='dijit.form.ComboBox' jsId='plSelector'/></td>
+ </tr>
<tr id='acq-brief-record-row'>
<td><div name='name'/></td>
<td><div name='widget'/></td>
@@ -15,9 +19,8 @@
</tbody>
<tbody>
<tr>
- <td colspan='2' style='text-align:center;'>
- <button dojoType='dijit.form.Button' type='submit'>Submit</button>
- </td>
+ <td><button dojoType='dijit.form.Button' type='submit'>Submit</button></td>
+ <td><button dojoType='dijit.form.Button' type='submit' jsId='marcEditButton'>Edit MARC</button></td>
</tr>
</tbody>
</table>
More information about the open-ils-commits
mailing list