ACQ return-to-[search/invoice] buttons repair
[working/Evergreen.git] / Open-ILS / web / js / ui / default / acq / picklist / view.js
1 dojo.require('dojo.date.stamp');
2 dojo.require('dojo.date.locale');
3 dojo.require('openils.User');
4 dojo.require('openils.Util');
5 dojo.require('openils.CGI');
6 dojo.require('dijit.layout.ContentPane');
7
8 var plist;
9 var plOffset = 0;
10 var plLimit = 20;
11 var liTable;
12
13
14 function load() {
15     liTable = new AcqLiTable();
16     liTable.isPL = plId;
17     fieldmapper.standardRequest(
18         ['open-ils.acq', 'open-ils.acq.picklist.retrieve.authoritative'],
19         {   async: true,
20             params: [openils.User.authtoken, plId, 
21                 {flesh_lineitem_count:true, flesh_owner:true}],
22             oncomplete: function(r) {
23                 plist = openils.Util.readResponse(r);
24                 drawPl(plist);
25             }
26         }
27     );
28
29     /* if we got here from the search/invoice page with a focused LI,
30      * return to the previous page with the same LI focused */
31     var cgi = new openils.CGI();
32     var source = cgi.param('source');
33     var focus_li = cgi.param('focus_li');
34     if (source && focus_li) {
35         dojo.forEach(
36             ['search', 'invoice'], // perhaps a wee bit too loose
37             function(srcType) {
38                 if (source.match(new RegExp(srcType))) {
39                     openils.Util.show('acq-pl-return-to-' + srcType);
40                     var newCgi = new openils.CGI({url : source});
41                     newCgi.param('focus_li', cgi.param('focus_li'));
42                     dojo.byId('acq-pl-return-to-' + srcType + '-button').onclick = function() {
43                         location.href = newCgi.url();
44                     }
45                 }
46             }
47         );
48     }
49 }
50
51 function drawPl() {
52
53     dojo.byId("oils-acq-picklist-name").innerHTML = plist.name();
54     dojo.byId("oils-acq-picklist-attr-owner").innerHTML = plist.owner().usrname();
55     dojo.byId("oils-acq-picklist-attr-count").innerHTML = plist.entry_count();
56
57     dojo.byId("oils-acq-picklist-attr-cdate").innerHTML =
58          dojo.date.locale.format(
59             dojo.date.stamp.fromISOString(plist.create_time()), 
60             {selector:'date'}
61         );
62
63     dojo.byId("oils-acq-picklist-attr-edate").innerHTML = 
64          dojo.date.locale.format(
65             dojo.date.stamp.fromISOString(plist.edit_time()), 
66             {selector:'date'}
67         );
68
69     loadLIs();
70 }
71
72 function loadLIs() {
73     liTable.reset();
74
75     if(plist.entry_count() > (plOffset + plLimit)) {
76         liTable.setNext(
77             function() { 
78                 plOffset += plLimit;
79                 loadLIs();
80             }
81         );
82     } else {
83         liTable.setNext(null);
84     }
85
86     if(plOffset > 0) {
87         liTable.setPrev(
88             function() { 
89                 plOffset -= plLimit;
90                 loadLIs();
91             }
92         );
93     } else {
94         liTable.setPrev(null);
95     }
96
97
98     fieldmapper.standardRequest(
99         ['open-ils.acq', 'open-ils.acq.lineitem.picklist.retrieve'],
100         {   async: true,
101             params: [openils.User.authtoken, plId, 
102                 {flesh_notes:true, flesh_cancel_reason:true, flesh_attrs:true, clear_marc:true, offset:plOffset, limit:plLimit}],
103             onresponse: function(r) {
104                 var li = openils.Util.readResponse(r);
105                 if (li) { /* Not every response is an LI (for some reason) */
106                     liTable.addLineitem(li);
107                     liTable.show('list');
108                 }
109             }
110         }
111     );
112 }
113
114 openils.Util.addOnLoad(load);
115
116