]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/holds.js
XUL based holds work. Need to test from within the staff client.
[working/Evergreen.git] / Open-ILS / web / opac / skin / default / js / holds.js
1
2 var currentHoldRecord;
3 var currentHoldRecordObj;
4 var holdsOrgSelectorBuilt = false;
5 var holdRecipient;
6 var holdRequestor
7 var holdEmail;
8 var holdPhone;
9
10
11 function holdsHandleStaff() {
12         swapCanvas($('xulholds_box'));
13         $('xul_recipient_barcode').focus();
14         $('xul_recipient_barcode').onkeypress = function(evt) 
15                 {if(userPressedEnter(evt)) { _holdsHandleStaff(); } };
16         $('xul_recipient_barcode_submit').onclick = _holdsHandleStaff;
17 }
18
19 function _holdsHandleStaff() {
20         var barcode = $('xul_recipient_barcode').value;
21         var user = grabUserByBarcode( G.user.session, barcode );
22         var code = checkILSEvent(user);
23         if(code || !user) {
24                 alertILSEvent(code, barcode);
25                 showCanvas();
26                 return;
27         }
28         holdRecipient = user;
29         holdsDrawWindow( currentHoldRecord, null );
30 }
31
32 function holdsDrawWindow(recid, type) {
33
34         if(recid == null) {
35                 recid = currentHoldRecord;
36                 if(recid == null) return;
37         }       
38         currentHoldRecord = recid;
39         
40         if(isXUL() && holdRecipient == null ) { 
41         //if(holdRecipient == null ) { 
42                 holdsHandleStaff();
43                 return;
44         }
45
46         if( holdRecipient == null ) holdRecipient = G.user;
47         if( holdRequestor == null ) holdRequestor = G.user;
48
49         if(!(holdRequestor && holdRequestor.session)) {
50
51                 detachAllEvt('common','locationChanged');
52                 attachEvt('common','loggedIn', holdsDrawWindow)
53                 initLogin();
54                 return;
55         }
56         swapCanvas($('holds_box'));
57
58         var rec = findRecord( recid, type );
59         currentHoldsRecordObj = rec;
60
61         if(!holdsOrgSelectorBuilt) {
62                 holdsBuildOrgSelector(null,0);
63                 holdsOrgSelectorBuilt = true;
64         }
65
66         appendClear($('holds_recipient'), text(
67                 holdRecipient.family_name() + ', ' +  
68                         holdRecipient.first_given_name()));
69         appendClear($('holds_title'), text(rec.title()));
70         appendClear($('holds_author'), text(rec.author()));
71
72         //removeChildren($('holds_format'));
73         for( var i in rec.types_of_resource() ) {
74                 var res = rec.types_of_resource()[i];
75                 var img = elem("img");
76                 setResourcePic(img, res);
77                 $('holds_format').appendChild(text(' '+res+' '));
78                 $('holds_format').appendChild(img);
79                 $('holds_format').appendChild(text(' '));
80         }
81
82         appendClear( $('holds_phone'), text(holdRecipient.day_phone()));
83         appendClear( $('holds_email'), text(holdRecipient.email()));
84         $('holds_cancel').onclick = showCanvas;
85         $('holds_submit').onclick = holdsPlaceHold; 
86 }
87
88
89 function holdsBuildOrgSelector(node, depth) {
90
91         if(!node) {
92                 node = globalOrgTree;
93                 depth = 0;
94         }
95
96         var selector = $('holds_org_selector');
97         var index = selector.options.length;
98
99         if(IE) {
100                 var pre = elem("pre");
101                 for(var x=2; x <= findOrgType(node.ou_type()).depth(); x++) {
102                         pre.appendChild(text("    "));
103                 }
104                 pre.appendChild(text(node.name()));
105                 var select = new Option("", node.id());
106                 selector.options[index] = select;
107                 select.appendChild(pre);
108         
109         } else {
110                 var pad = (findOrgType(node.ou_type()).depth() - 1) * 12;
111                 if(pad < 0) pad = 0;
112                 var select = new Option(node.name(), node.id());
113                 select.setAttribute("style", "padding-left: "+pad+'px;');
114                 selector.options[index] = select;
115         }       
116
117         if( node.id() == holdRecipient.home_ou() ) {
118                 selector.selectedIndex = index;
119                 selector.options[index].selected = true;        
120         }
121
122         for( var i in node.children() ) {
123                 var child = node.children()[i];
124                 if(child) {
125                         holdsBuildOrgSelector(child, depth+1);
126                 }
127         }
128 }
129
130 function holdsPlaceHold() {
131
132         var org = $('holds_org_selector').options[
133                 $('holds_org_selector').selectedIndex].value;
134
135         var hold = new ahr();
136         hold.pickup_lib(org); 
137         hold.request_lib(org); 
138         hold.requestor(holdRequestor.id());
139         hold.usr(holdRecipient.id());
140         hold.hold_type('T');
141         hold.email_notify(holdRecipient.email());
142         hold.phone_notify(holdRecipient.day_phone());
143         hold.target(currentHoldRecord);
144         
145         var req = new Request( CREATE_HOLD, holdRequestor.session, hold );
146         req.send(true);
147         var res = req.result();
148
149         if( res == '1' ) alert($('holds_success').innerHTML);
150         else alert($('holds_failure').innerHTML);
151         
152         showCanvas();
153         holdRecipient = null;
154         holdRequestor = null;
155 }
156
157 function holdsCancel(holdid, user) {
158         if(!user) user = G.user;
159         var req = new Request(CANCEL_HOLD, user.session, holdid);
160         req.send(true);
161         return req.result();
162 }
163
164