]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/po/view_po.js
Acq: complete improvements of receive/unreceive for lineitems and copies
[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 updatePoState(po_info) {
10     var data = po_info[PO.id()];
11     if (data) {
12         for (var key in data)
13             PO[key](data[key]);
14         renderPo();
15     }
16 }
17
18 function renderPo() {
19     dojo.byId("acq-po-view-id").innerHTML = PO.id();
20     dojo.byId("acq-po-view-name").innerHTML = PO.name();
21     dojo.byId("acq-po-view-total-li").innerHTML = PO.lineitem_count();
22     dojo.byId("acq-po-view-total-enc").innerHTML = PO.amount_encumbered();
23     dojo.byId("acq-po-view-total-spent").innerHTML = PO.amount_spent();
24     dojo.byId("acq-po-view-state").innerHTML = PO.state(); // TODO i18n
25
26     if(PO.state() == "pending") {
27         openils.Util.show("acq-po-activate");
28         if (PO.lineitem_count() > 1)
29             openils.Util.show("acq-po-split");
30     }
31 }
32
33 function init() {
34     liTable = new AcqLiTable();
35     liTable.reset();
36     liTable.isPO = poId;
37     liTable.poUpdateCallback = updatePoState;
38
39     fieldmapper.standardRequest(
40         ['open-ils.acq', 'open-ils.acq.purchase_order.retrieve'],
41         {   async: true,
42             params: [openils.User.authtoken, poId, {flesh_price_summary:true, flesh_lineitem_count:true}],
43             oncomplete: function(r) {
44                 PO = openils.Util.readResponse(r); /* save PO globally */
45                 renderPo();
46             }
47         }
48     );
49
50     fieldmapper.standardRequest(
51         ['open-ils.acq', 'open-ils.acq.lineitem.search'],
52         {   async: true,
53             params: [openils.User.authtoken, {purchase_order:poId}, {flesh_attrs:true, flesh_notes:true}],
54             onresponse: function(r) {
55                 liTable.show('list');
56                 liTable.addLineitem(openils.Util.readResponse(r));
57             }
58         }
59     );
60 }
61
62 function activatePo() {
63     progressDialog.show(true);
64     try {
65         fieldmapper.standardRequest(
66             ['open-ils.acq', 'open-ils.acq.purchase_order.activate'],
67             {   async: true,
68                 params: [openils.User.authtoken, PO.id()],
69                 oncomplete : function() {
70                     location.href = location.href;
71                 }
72             }
73         );
74     } catch(E) {
75         progressDialog.hide();
76     }
77 }
78
79 function splitPo() {
80     progressDialog.show(true);
81     try {
82         var list;
83         fieldmapper.standardRequest(
84             ['open-ils.acq', 'open-ils.acq.purchase_order.split_by_lineitems'],
85             {   async: true,
86                 params: [openils.User.authtoken, PO.id()],
87                 onresponse : function(r) {
88                     list = openils.Util.readResponse(r);
89                 },
90                 oncomplete : function() {
91                     progressDialog.hide();
92                     if (list) {
93                         location.href = oilsBasePath + '/eg/acq/po/search/' +
94                             list.join(",");
95                     }
96                 }
97             }
98         );
99     } catch(E) {
100         progressDialog.hide();
101         alert(E);
102     }
103 }
104
105 function updatePoName() {
106     var value = prompt('Enter new purchase order name:', PO.name()); // TODO i18n
107     if(!value || value == PO.name()) return;
108     PO.name(value);
109     var pcrud = new openils.PermaCrud();
110     pcrud.update(PO, {
111         oncomplete : function(r, cudResults) {
112             var stat = cudResults[0];
113             if(stat) 
114                 dojo.byId('acq-po-view-name').innerHTML = value;
115         }
116     });
117 }
118
119 openils.Util.addOnLoad(init);