]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/po/view_po.js
Acq: Give users a way to split one PO into many (one PO per lineitem).
[working/Evergreen.git] / Open-ILS / web / js / ui / default / acq / po / view_po.js
1 dojo.require('dijit.layout.ContentPane');
2 dojo.require('openils.User');
3 dojo.require('openils.Util');
4 dojo.require('openils.PermaCrud');
5
6 var PO = null;
7 var liTable;
8
9 function init() {
10     liTable = new AcqLiTable();
11     liTable.reset();
12     liTable.isPO = poId;
13
14     fieldmapper.standardRequest(
15         ['open-ils.acq', 'open-ils.acq.purchase_order.retrieve'],
16         {   async: true,
17             params: [openils.User.authtoken, poId, {flesh_price_summary:true, flesh_lineitem_count:true}],
18             oncomplete: function(r) {
19                 PO = openils.Util.readResponse(r);
20                 dojo.byId('acq-po-view-id').innerHTML = PO.id();
21                 dojo.byId('acq-po-view-name').innerHTML = PO.name();
22                 dojo.byId('acq-po-view-total-li').innerHTML = PO.lineitem_count();
23                 dojo.byId('acq-po-view-total-enc').innerHTML = PO.amount_encumbered();
24                 dojo.byId('acq-po-view-total-spent').innerHTML = PO.amount_spent();
25                 dojo.byId('acq-po-view-state').innerHTML = PO.state(); // TODO i18n
26
27                 if(PO.state() == 'pending') {
28                     openils.Util.show('acq-po-activate');
29                     if (PO.lineitem_count() > 1) {
30                         openils.Util.show('acq-po-split');
31                     }
32                 }
33             }
34         }
35     );
36
37     fieldmapper.standardRequest(
38         ['open-ils.acq', 'open-ils.acq.lineitem.search'],
39         {   async: true,
40             params: [openils.User.authtoken, {purchase_order:poId}, {flesh_attrs:true, flesh_notes:true}],
41             onresponse: function(r) {
42                 liTable.show('list');
43                 liTable.addLineitem(openils.Util.readResponse(r));
44             }
45         }
46     );
47 }
48
49 function activatePo() {
50     progressDialog.show(true);
51     try {
52         fieldmapper.standardRequest(
53             ['open-ils.acq', 'open-ils.acq.purchase_order.activate'],
54             {   async: true,
55                 params: [openils.User.authtoken, PO.id()],
56                 oncomplete : function() {
57                     location.href = location.href;
58                 }
59             }
60         );
61     } catch(E) {
62         progressDialog.hide();
63     }
64 }
65
66 function splitPo() {
67     progressDialog.show(true);
68     try {
69         var list;
70         fieldmapper.standardRequest(
71             ['open-ils.acq', 'open-ils.acq.purchase_order.split_by_lineitems'],
72             {   async: true,
73                 params: [openils.User.authtoken, PO.id()],
74                 onresponse : function(r) {
75                     list = openils.Util.readResponse(r);
76                 },
77                 oncomplete : function() {
78                     progressDialog.hide();
79                     if (list) {
80                         location.href = oilsBasePath + '/eg/acq/po/search/' +
81                             list.join(",");
82                     }
83                 }
84             }
85         );
86     } catch(E) {
87         progressDialog.hide();
88         alert(E);
89     }
90 }
91
92 function updatePoName() {
93     var value = prompt('Enter new purchase order name:', PO.name()); // TODO i18n
94     if(!value || value == PO.name()) return;
95     PO.name(value);
96     var pcrud = new openils.PermaCrud();
97     pcrud.update(PO, {
98         oncomplete : function(r, cudResults) {
99             var stat = cudResults[0];
100             if(stat) 
101                 dojo.byId('acq-po-view-name').innerHTML = value;
102         }
103     });
104 }
105
106 openils.Util.addOnLoad(init);