Initial dev repository
[kcls-web.git] / js / ui / default / acq / po / create.js
1 dojo.require("openils.widget.EditDialog");
2 dojo.require("openils.widget.EditPane");
3
4 var editDialog;
5
6 function toPoListing() {
7     location.href = oilsBasePath + "/acq/search/unified?ca=po";
8 }
9
10 function toOnePo(id) {
11     location.href = oilsBasePath + "/acq/po/view/" + id;
12 }
13
14 openils.Util.addOnLoad(
15     function() {
16         editDialog = new openils.widget.EditDialog({
17             "editPane": new openils.widget.EditPane({
18                 "fmObject": new acqpo(),
19                 /* After realizing how many fields should be excluded from this
20                  * interface because users shouldn't set them arbitrarily,
21                  * it hardly seems like using these Edit widgets gives much
22                  * much advantage over a hardcoded interface. */
23                 "suppressFields": [
24                     "create_time", "edit_time", "editor", "order_date",
25                     "owner", "cancel_reason", "creator", "state", "name"
26                 ],
27                 "fieldOrder": ["ordering_agency", "provider"],
28                 "mode": "create",
29                 overrideWidgetArgs : {
30                     provider : { dijitArgs : { store_options : { base_filter : { active :"t" } } } }
31                 },
32                 "onSubmit": function(po) {
33                     fieldmapper.standardRequest(
34                         ["open-ils.acq", "open-ils.acq.purchase_order.create"],{
35                             "async": false,
36                             "params": [openils.User.authtoken, po],
37                             "onresponse": function(r) {
38                                 toOnePo(
39                                     openils.Util.readResponse(r).
40                                     purchase_order.id()
41                                 );
42                             }
43                         }
44                     );
45                 },
46                 "onCancel": function() {
47                     editDialog.hide();
48                     toPoListing();
49                     /* I'd rather do window.close() or xulG.close_tab(),
50                      * but neither of those seem to work here. */
51                 }
52             })
53         });
54         editDialog.startup();
55         editDialog.show();
56     }
57 );