]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/acq/picklist/from_bib.js
Acq: several interface improvements
[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 = openils.Util.uniqueElements(termLoader.attr("value"));
11     var result_count = 0;
12     // Don't show a total for now... This total is the total number of
13     // search terms, but a user would take it to mean the total number of
14     // results, which we don't have a straightfoward way of getting without
15     // doing the search more that once.
16
17     // pager.total = data.length;
18
19     progressDialog.show(true);
20     fieldmapper.standardRequest(
21         ["open-ils.acq", "open-ils.acq.biblio.create_by_id"], {
22             "params": [
23                 openils.User.authtoken,
24                 data.slice(
25                     pager.displayOffset,
26                     pager.displayOffset + pager.displayLimit
27                 ), {
28                     "flesh_attrs": true,
29                     "flesh_cancel_reason": true,
30                     "flesh_notes": true,
31                     "reuse_picklist": usingPl
32                 }
33             ],
34             "onresponse": function(r) {
35                 if (r = openils.Util.readResponse(r)) {
36                     if (typeof(r) != "object") {
37                         usingPl = r;
38                     } else if (r.classname && r.classname == "jub") {
39                         result_count++;
40                         liTable.addLineitem(r);
41                     }
42                     /* The ML method is buggy and sometimes responds with
43                      * more objects that we don't want, hence the specific
44                      * conditionals above that don't necesarily consume all
45                      * responses. */
46                 }
47             }
48         }
49     );
50     pager.batch_length = result_count;
51     progressDialog.hide();
52 }
53
54 function beginSearch() {
55     var data = termLoader.attr("value");
56     if (!data || !data.length) {
57         alert(localeStrings.LOAD_TERMS_FIRST);
58         return;
59     }
60
61     pager.go(0);
62     openils.Util.hide("acq-frombib-upload-box");
63     openils.Util.show("acq-frombib-reload-box");
64 }
65
66 function init() {
67     new openils.widget.XULTermLoader(
68         {"parentNode": "acq-frombib-upload", "parseCSV": true}
69     ).build(function(w) { termLoader = w; });
70
71     liTable = new AcqLiTable();
72     liTable.enableActionsDropdownOptions("vp");
73
74     pager = new LiTablePager(fetchRecords, liTable);
75
76     openils.Util.show("acq-frombib-begin-holder");
77 }
78
79 openils.Util.addOnLoad(init);