dojo.require("openils.acq.Lineitem");
dojo.require("openils.Util");
dojo.require("openils.XUL");
+dojo.require("openils.CGI");
+dojo.require("openils.PermaCrud");
+dojo.require('openils.BibTemplate');
+dojo.require('fieldmapper.OrgUtils');
var liTable;
-
-function attrDefByName(attr) {
- return openils.acq.Lineitem.attrDefs[
- attr.attr_type().replace(/lineitem_(.*)_attr_definition/, "$1")
- ].filter(
- function(o) { return (o.code() == attr.attr_name()); }
- ).pop();
-}
-
-function drawLiInfo(li) {
- var infoTbody = dojo.byId("acq-related-info-tbody");
- var infoRow = infoTbody.removeChild(dojo.byId("acq-related-info-row"));
-
- li.attributes().forEach(
- function(attr) {
- var row = dojo.clone(infoRow);
-
- nodeByName("label", row).innerHTML =
- attrDefByName(attr).description();
- nodeByName("value", row).innerHTML = attr.attr_value();
-
- infoTbody.appendChild(row);
-
- if (["title", "author"].indexOf(attr.attr_name()) != -1) {
- nodeByName(
- attr.attr_name(), dojo.byId("acq-related-mini-display")
- ).innerHTML = attr.attr_value();
- }
- }
- );
-}
+var identTarget;
+var bibRecord;
+var paramPL;
+var paramPO;
function fetchLi() {
fieldmapper.standardRequest(
["open-ils.acq", "open-ils.acq.lineitem.retrieve"], {
"async": true,
- "params": [openils.User.authtoken, liId, {
+ "params": [openils.User.authtoken, targetId, {
"flesh_attrs": true,
"flesh_li_details": true,
"flesh_fund_debit": true,
"flesh_cancel_reason": true
}],
"oncomplete": function(r) {
+ fetchBib();
drawLiInfo(openils.Util.readResponse(r));
}
}
);
}
-function hideDetails() {
- openils.Util.show("acq-related-mini");
- openils.Util.hide("acq-related-info-div");
-}
-
-function showDetails() {
- openils.Util.show("acq-related-info-div");
- openils.Util.hide("acq-related-mini");
-}
function fetchRelated() {
+ var method = 'open-ils.acq.lineitems_for_bib.by_lineitem_id';
+ if(identTarget == 'bib')
+ var method = 'open-ils.acq.lineitems_for_bib.by_bib_id';
+
fieldmapper.standardRequest(
- ["open-ils.acq", "open-ils.acq.lineitems_for_bib.by_lineitem_id"], {
+ ["open-ils.acq", method], {
"async": true,
- "params": [openils.User.authtoken, liId, {
+ "params": [openils.User.authtoken, targetId, {
"flesh_attrs": true,
"flesh_notes": true,
"flesh_cancel_reason": true
}
);
}
+
+function fetchBib() {
+ new openils.BibTemplate({
+ record : targetId,
+ org_unit : fieldmapper.aou.findOrgUnit(openils.User.user.ws_ou()).shortname()
+ }).render();
+
+ new openils.PermaCrud().retrieve('bre', targetId, {
+ oncomplete : function(r) {
+ bibRecord = openils.Util.readResponse(r);
+ // render bib details
+ // perhaps we just pull these from the beating heart of bibtemplate
+ }
+ })
+}
+
+function addLi(fields) {
+
+ var li = new fieldmapper.jub();
+ li.marc(bibRecord.marc());
+ li.eg_bib_id(bibRecord.id());
+ if(fields.picklist) li.picklist(fields.picklist);
+ if(fields.po) li.po(fields.po);
+ 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(fields.picklist)
+ location.href = oilsBasePath + '/acq/picklist/view/' + fields.picklist;
+ else
+ location.href = oilsBasePath + '/acq/po/view/' + fields.po;
+ }
+ }
+ );
+}
+
+function loadPl() {
+
+ if(paramPL) {
+
+ fieldmapper.standardRequest(
+ ['open-ils.acq', 'open-ils.acq.picklist.retrieve'],
+ { async: true,
+ params: [openils.User.authtoken, paramPL],
+ oncomplete : function(r) {
+ var pl = openils.Util.readResponse(r);
+ plSelector.store =
+ new dojo.data.ItemFileReadStore({data:fieldmapper.acqpl.toStoreData([pl])});
+ plSelector.attr('value', pl.name());
+ plSelector.attr('disabled', true);
+ }
+ }
+ );
+
+ } else {
+
+ 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:fieldmapper.acqpl.toStoreData(list)});
+ }
+ }
+ );
+ }
+}
+
+
function load() {
- openils.acq.Lineitem.fetchAttrDefs(fetchLi);
- dojo.byId("acq-related-info-back-button").onclick = hideDetails;
- dojo.byId("acq-related-info-show-button").onclick = showDetails;
+ var cgi = new openils.CGI();
+
+ identTarget = cgi.param('target');
+ paramPL = cgi.param('pl');
+ paramPO = cgi.param('po');
+
+ loadPl();
+
+ if(identTarget == 'bib') {
+ fetchBib();
+ } else {
+ fetchLi();
+ }
liTable = new AcqLiTable();
liTable.reset();
[% WRAPPER "default/base.tt2" %]
[% ctx.page_title = "Related Lineitems" %]
<script src="[% ctx.media_prefix %]/js/ui/default/acq/lineitem/related.js"></script>
-<script type="text/javascript">var liId = "[% ctx.page_args.0 %]";</script>
+<script type="text/javascript">var targetId = "[% ctx.page_args.0 %]";</script>
<h1>Related Lineitems</h1>
<div id="acq-related-mini">
+ <script>
+ function iterateSubfields(item) {
+ var out = '';
+ var list = dojo.query('subfield', item);
+ for (var i = 0; i < list.length; i++) {
+ out += dojox.data.dom.textContent(list[i]) + ' ';
+ }
+ return out;
+ }
+ </script>
<ul id="acq-related-mini-display">
- <li name="title"></li>
- <li name="author"></li>
+ <li>
+ <div type='opac/slot-data' query='datafield[tag=245]'>
+ <script type='opac/slot-format'>return iterateSubfields(item)</script>
+ </div>
+ </li>
+ <li>
+ <div type='opac/slot-data' query='datafield[tag=100] subfield[code=a]'/>
+ </li>
+ <li>
+ <div type='opac/slot-data' query='datafield[tag=020]'>
+ <script type='opac/slot-format'>return iterateSubfields(item)</script>
+ </div>
+ <div type='opac/slot-data' query='datafield[tag=024]'>
+ <script type='opac/slot-format'>return iterateSubfields(item)</script>
+ </div>
+ <div type='opac/slot-data' query='datafield[tag=022]'>
+ <script type='opac/slot-format'>return iterateSubfields(item)</script>
+ </div>
+ </li>
+ <li>
+ <div type='opac/slot-data' query='datafield[tag=260] subfield[code=c]'/>
+ </li>
</ul>
- <div dojoType="dijit.form.Button" id="acq-related-info-show-button">
- Show details
+ <div dojoType="dijit.form.DropDownButton">
+ <span>Create New Lineitem For This Record</span>
+ <div dojoType="dijit.TooltipDialog" execute="addLi(arguments[0]);">
+ <table>
+ <tbody>
+ <tr>
+ <td>Add To Selection List</td>
+ <td style='padding-left:10px;'><div name='picklist' jsId='plSelector' dojoType='dijit.form.FilteringSelect'/></td>
+ </tr>
+ <tr>
+ <td colspan='2' style='align:center'>
+ <button dojoType="dijit.form.Button" type="submit">Create</button>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
</div>
+
</div>
[% INCLUDE "default/acq/common/info.tt2" which = "Related" %]
[% INCLUDE "default/acq/common/li_table.tt2" %]