From 3d7a658a0a130649853958764c20837f8808c0f0 Mon Sep 17 00:00:00 2001 From: senator Date: Tue, 4 May 2010 21:24:30 +0000 Subject: [PATCH] Acq: PO items i'face (acq.po_item is a peer of acq.lineitem for non-bib stuff) git-svn-id: svn://svn.open-ils.org/ILS/trunk@16388 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/css/skin/default/acq.css | 6 + Open-ILS/web/js/ui/default/acq/po/item_table.js | 175 +++++++++++++++++++++ Open-ILS/web/js/ui/default/acq/po/view_po.js | 17 +- .../web/templates/default/acq/po/item_table.tt2 | 34 ++++ Open-ILS/web/templates/default/acq/po/view.tt2 | 2 + 5 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/web/js/ui/default/acq/po/item_table.js create mode 100644 Open-ILS/web/templates/default/acq/po/item_table.tt2 diff --git a/Open-ILS/web/css/skin/default/acq.css b/Open-ILS/web/css/skin/default/acq.css index f55da5643..01c5c5782 100644 --- a/Open-ILS/web/css/skin/default/acq.css +++ b/Open-ILS/web/css/skin/default/acq.css @@ -236,3 +236,9 @@ option[disabled="disabled"] { font-style: italic; } #acq-eligible-li-table th { background-color: #ccc; border: 1px #333 inset; font-weight: bold; padding: 6px; } #acq-eligible-li-table td { padding: 2px 6px; border: 1px #333 inset; } #acq-eligible-li-table div[name="lid_link_holder"] { margin-left: 10px; } + +#acq-po-item-table th { font-weight: bold; padding: 2px 6px; } +#acq-po-item-table-items tr td { padding: 2px 6px; } +#acq-po-item-table-items tr td button[name="delete"] { color: #c00; } +#acq-po-item-table-items tr { margin: 6px 0; } +#acq-po-item-table-controls { margin-top: 8px; } diff --git a/Open-ILS/web/js/ui/default/acq/po/item_table.js b/Open-ILS/web/js/ui/default/acq/po/item_table.js new file mode 100644 index 000000000..3c1f9a55c --- /dev/null +++ b/Open-ILS/web/js/ui/default/acq/po/item_table.js @@ -0,0 +1,175 @@ +function PoItemTable() { + var self = this; + + this.init = function(po, pcrud) { + this.po = po; + this.pcrud = pcrud || new openils.PermaCrud(); + + this.tHead = dojo.byId("acq-po-item-table-headings"); + this.tBody = dojo.byId("acq-po-item-table-items"); + this.template = this.tBody.removeChild(dojo.query("tr", this.tBody)[0]); + dojo.byId("acq-po-item-table-new-charge").onclick = function() { + self.addItem(); + }; + dojo.byId("acq-po-item-table-save-new").onclick = function() { + self.saveNew(); + }; + + this.fundAWArgs = { + "searchFilter": {"active": "t"}, + "searchFormat": ["${0} (${1})", "code", "year"], + "labelFormat": [ + "${1} (${2})", + "id", "code", "year" + ], + "dijitArgs": {"labelType": "html"}, + "noCache": true + }; + + this.reset(); + }; + + this.empty = function(which) { + if (this._empty == which) return; /* nothing to do */ + + openils.Util[which ? "show" : "hide"]("acq-po-item-table-i-am-empty"); + openils.Util[which ? "hide" : "show"](this.tHead, "table-header-group"); + this._empty = which; + }; + + this.reset = function() { + this.rowId = -1; + this.rows = {}; + this.realItems = {}; + dojo.empty(this.tBody); + this.empty(true); + + this.disableSave(); + }; + + this.hide = function() { openils.Util.hide("acq-po-item-table"); }; + + this.show = function() { openils.Util.show("acq-po-item-table"); }; + + this.disableSave = function() { + dojo.byId("acq-po-item-table-save-new").disabled = true; + }; + + this.rowIndices = function() { + return openils.Util.objectProperties(this.rows); + }; + + this.newRowIndices = function() { + return this.rowIndices().filter(function(o) { return o < 0; }); + }; + + this.saveNew = function() { + var virtIds = this.newRowIndices(); + var po_items = virtIds.map( + function(k) { + var widgets = self.rows[k]; + var po_item = new acqpoi(); + for (var field in widgets) + po_item[field](widgets[field].attr("value")); + po_item.purchase_order(self.po.id()); + return po_item; + } + ); + + progressDialog.show(true); + + pcrud.create( + po_items, { + "oncomplete": function(r, objs) { + progressDialog.hide(); + r = openils.Util.readResponse(r); /* may not use */ + + virtIds.forEach(function(k) { self.deleteRow(k); }); + objs.forEach(function(o) { self.addItem(o); }); + } + } + ); + }; + + this._deleteRow = function(id) { + dojo.destroy(dojo.query("[rowId='" + id + "']")[0]); + delete this.rows[id]; + delete this.realItems[id]; + + if (!this.rowIndices().length) this.reset(); + else if (!this.newRowIndices().length) this.disableSave(); + }; + + this.deleteRow = function(id) { + if (id > 0) { + progressDialog.show(true); + pcrud.eliminate( + this.realItems[id], { + "oncomplete": function(r) { + progressDialog.hide(); + r = openils.Util.readResponse(r); /* may not use */ + + self._deleteRow(id); + } + } + ); + } else { + this._deleteRow(id); + } + }; + + this._addItemRow = function(item) { + var ourId = item ? item.id() : this.rowId--; + + if (item) + this.realItems[ourId] = item; + + this.rows[ourId] = {}; + var row = dojo.clone(this.template); + dojo.attr(row, "rowId", ourId); + + nodeByName("delete", row).onclick = function() { + self.deleteRow(ourId); + }; + + return {"id": ourId, "node": row}; + }; + + /* add a row with widgets for the user to enter new data */ + this.addItem = function(item) { + var row = this._addItemRow(item); + + dojo.query("td[name]", row.node).forEach( + function(element) { + var field = dojo.attr(element, "name"); + var em = dojo.attr(element, "em"); + var awArgs = dojo.mixin( + { + "fmField": field, + "parentNode": dojo.create( + "div", {"style": "width: " + + String(Number(em) + 1) + "em"}, + element, "only" + ), + "orgLimitPerms": ["CREATE_PURCHASE_ORDER"], + "dijitArgs": {"style": "width: " + em + "em"}, + "readOnly": Boolean(item) + }, + (field == "fund" ? self.fundAWArgs : {}), + (item ? {"fmObject": item} : {"fmClass": "acqpoi"}) + ); + new openils.widget.AutoFieldWidget(awArgs).build( + function(w) { self.rows[row.id][field] = w; } + ); + } + ); + + this.empty(false); + + dojo.place(row.node, this.tBody, "last"); + if (!item) + dojo.byId("acq-po-item-table-save-new").disabled = false; + }; + + this.init.apply(this, arguments); +} diff --git a/Open-ILS/web/js/ui/default/acq/po/view_po.js b/Open-ILS/web/js/ui/default/acq/po/view_po.js index c68f1c636..cc3c2a746 100644 --- a/Open-ILS/web/js/ui/default/acq/po/view_po.js +++ b/Open-ILS/web/js/ui/default/acq/po/view_po.js @@ -5,6 +5,7 @@ dojo.require('openils.PermaCrud'); var pcrud = new openils.PermaCrud(); var PO = null; var liTable; +var poItemTable; var poNoteTable; var invoiceLinkDialogManager; @@ -145,10 +146,12 @@ function AcqPoNoteTable() { this.hide = function() { openils.Util.hide("acq-po-notes-div"); liTable.show("list"); + poItemTable.show(); }; this.show = function() { liTable.hide(); + poItemTable.hide(); self.drawPoNotes(); openils.Util.show("acq-po-notes-div"); }; @@ -325,6 +328,13 @@ function renderPo() { openils.Util.show("acq-po-split"); } + // XXX we probably don't *always* need to do this... + poItemTable.reset(); + PO.po_items().forEach( + function(po_item) { poItemTable.addItem(po_item); } + ); + poItemTable.show(); + prepareInvoiceFeatures(); } @@ -347,10 +357,15 @@ function init() { "flesh_provider": true, "flesh_price_summary": true, "flesh_lineitem_count": true, - "flesh_notes": true + "flesh_notes": true, + "flesh_po_items": true }], oncomplete: function(r) { PO = openils.Util.readResponse(r); /* save PO globally */ + + /* po item table */ + poItemTable = new PoItemTable(PO, pcrud); + renderPo(); } } diff --git a/Open-ILS/web/templates/default/acq/po/item_table.tt2 b/Open-ILS/web/templates/default/acq/po/item_table.tt2 new file mode 100644 index 000000000..1948b6d35 --- /dev/null +++ b/Open-ILS/web/templates/default/acq/po/item_table.tt2 @@ -0,0 +1,34 @@ + diff --git a/Open-ILS/web/templates/default/acq/po/view.tt2 b/Open-ILS/web/templates/default/acq/po/view.tt2 index 24d3e50a9..5e1c56dd4 100644 --- a/Open-ILS/web/templates/default/acq/po/view.tt2 +++ b/Open-ILS/web/templates/default/acq/po/view.tt2 @@ -1,6 +1,7 @@ [% WRAPPER 'default/base.tt2' %] +
@@ -87,5 +88,6 @@ [% INCLUDE 'default/acq/common/li_table.tt2' %] [% INCLUDE "default/acq/common/notes.tt2" which = "Po" %] + [% INCLUDE "default/acq/po/item_table.tt2" %]
[% END %] -- 2.11.0