]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/picklist/view.js
ACQ : lineitem recovers focus from various interfaces
[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     if (cgi.param('focus_li')) {
33         dojo.forEach(
34             ['search', 'invoice'], // perhaps a wee bit too loose
35             function(source) {
36                 if (document.referrer.match(new RegExp(source))) {
37                     openils.Util.show('acq-pl-return-to-' + source);
38                     var newCgi = new openils.CGI({url : document.referrer});
39                     newCgi.param('focus_li', cgi.param('focus_li'));
40                     dojo.byId('acq-pl-return-to-' + source + '-button').onclick = function() {
41                         location.href = newCgi.url();
42                     }
43                 }
44             }
45         );
46     }
47 }
48
49 function drawPl() {
50
51     dojo.byId("oils-acq-picklist-name").innerHTML = plist.name();
52     dojo.byId("oils-acq-picklist-attr-owner").innerHTML = plist.owner().usrname();
53     dojo.byId("oils-acq-picklist-attr-count").innerHTML = plist.entry_count();
54
55     dojo.byId("oils-acq-picklist-attr-cdate").innerHTML =
56          dojo.date.locale.format(
57             dojo.date.stamp.fromISOString(plist.create_time()), 
58             {selector:'date'}
59         );
60
61     dojo.byId("oils-acq-picklist-attr-edate").innerHTML = 
62          dojo.date.locale.format(
63             dojo.date.stamp.fromISOString(plist.edit_time()), 
64             {selector:'date'}
65         );
66
67     loadLIs();
68 }
69
70 function loadLIs() {
71     liTable.reset();
72
73     if(plist.entry_count() > (plOffset + plLimit)) {
74         liTable.setNext(
75             function() { 
76                 plOffset += plLimit;
77                 loadLIs();
78             }
79         );
80     } else {
81         liTable.setNext(null);
82     }
83
84     if(plOffset > 0) {
85         liTable.setPrev(
86             function() { 
87                 plOffset -= plLimit;
88                 loadLIs();
89             }
90         );
91     } else {
92         liTable.setPrev(null);
93     }
94
95
96     fieldmapper.standardRequest(
97         ['open-ils.acq', 'open-ils.acq.lineitem.picklist.retrieve'],
98         {   async: true,
99             params: [openils.User.authtoken, plId, 
100                 {flesh_notes:true, flesh_cancel_reason:true, flesh_attrs:true, clear_marc:true, offset:plOffset, limit:plLimit}],
101             onresponse: function(r) {
102                 var li = openils.Util.readResponse(r);
103                 if (li) { /* Not every response is an LI (for some reason) */
104                     liTable.addLineitem(li);
105                     liTable.show('list');
106                 }
107             }
108         }
109     );
110 }
111
112 openils.Util.addOnLoad(load);
113
114