]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/picklist/from_bib.js
Acq: back/next result paging through unified search interfaces
[Evergreen.git] / Open-ILS / web / js / ui / default / acq / picklist / from_bib.js
1 dojo.require("dijit.form.Button");
2 dojo.require("openils.widget.XULTermLoader");
3
4 var termLoader = null;
5 var liTable = null;
6 var pager = null;
7 var usingPl = null;
8
9 function fetchRecords() {
10     var data = termLoader.attr("value");
11     var result_count = 0;
12     pager.total = data.length;
13
14     progressDialog.show(true);
15     fieldmapper.standardRequest(
16         ["open-ils.acq", "open-ils.acq.biblio.create_by_id"], {
17             "params": [
18                 openils.User.authtoken,
19                 data.slice(
20                     pager.displayOffset,
21                     pager.displayOffset + pager.displayLimit
22                 ), {
23                     "flesh_attrs": true,
24                     "flesh_cancel_reason": true,
25                     "flesh_notes": true,
26                     "reuse_picklist": usingPl
27                 }
28             ],
29             "onresponse": function(r) {
30                 if (r = openils.Util.readResponse(r)) {
31                     if (typeof(r) != "object") {
32                         usingPl = r;
33                     } else if (r.classname && r.classname == "jub") {
34                         result_count++;
35                         liTable.addLineitem(r);
36                     }
37                     /* The ML method is buggy and sometimes responds with
38                      * more objects that we don't want, hence the specific
39                      * conditionals above that don't necesarily consume all
40                      * responses. */
41                 }
42             }
43         }
44     );
45     pager.batch_length = result_count;
46     progressDialog.hide();
47 }
48
49 function beginSearch() {
50     var data = termLoader.attr("value");
51     if (!data || !data.length) {
52         alert(localeStrings.LOAD_TERMS_FIRST);
53         return;
54     }
55
56     pager.go(0);
57     openils.Util.hide("acq-frombib-upload-box");
58     openils.Util.show("acq-frombib-reload-box");
59 }
60
61 function init() {
62     new openils.widget.XULTermLoader(
63         {"parentNode": "acq-frombib-upload"}
64     ).build(function(w) { termLoader = w; });
65     liTable = new AcqLiTable();
66     pager = new LiTablePager(fetchRecords, liTable);
67
68     openils.Util.show("acq-frombib-begin-holder");
69 }
70
71 openils.Util.addOnLoad(init);