]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/holds.js
when clicking on 'cancel' on the login deck on MYOPAC, the user is
[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                 holdsHandleStaff();
42                 return;
43         }
44
45         if( holdRecipient == null ) holdRecipient = G.user;
46         if( holdRequestor == null ) holdRequestor = G.user;
47
48         if(!(holdRequestor && holdRequestor.session)) {
49
50                 detachAllEvt('common','locationChanged');
51                 attachEvt('common','loggedIn', holdsDrawWindow)
52                 initLogin();
53                 return;
54         }
55         swapCanvas($('holds_box'));
56
57         var rec = findRecord( recid, type );
58         currentHoldsRecordObj = rec;
59
60         if(!holdsOrgSelectorBuilt) {
61                 holdsBuildOrgSelector(null,0);
62                 holdsOrgSelectorBuilt = true;
63         }
64
65         appendClear($('holds_recipient'), text(
66                 holdRecipient.family_name() + ', ' +  
67                         holdRecipient.first_given_name()));
68         appendClear($('holds_title'), text(rec.title()));
69         appendClear($('holds_author'), text(rec.author()));
70
71         //removeChildren($('holds_format'));
72         for( var i in rec.types_of_resource() ) {
73                 var res = rec.types_of_resource()[i];
74                 var img = elem("img");
75                 setResourcePic(img, res);
76                 $('holds_format').appendChild(text(' '+res+' '));
77                 $('holds_format').appendChild(img);
78                 $('holds_format').appendChild(text(' '));
79         }
80
81         appendClear( $('holds_phone'), text(holdRecipient.day_phone()));
82         appendClear( $('holds_email'), text(holdRecipient.email()));
83         $('holds_cancel').onclick = showCanvas;
84         $('holds_submit').onclick = holdsPlaceHold; 
85 }
86
87
88 function holdsBuildOrgSelector(node, depth) {
89
90         if(!node) {
91                 node = globalOrgTree;
92                 depth = 0;
93         }
94
95         var selector = $('holds_org_selector');
96         var index = selector.options.length;
97
98         if(IE) {
99                 var pre = elem("pre");
100                 for(var x=2; x <= findOrgType(node.ou_type()).depth(); x++) {
101                         pre.appendChild(text("    "));
102                 }
103                 pre.appendChild(text(node.name()));
104                 var select = new Option("", node.id());
105                 selector.options[index] = select;
106                 select.appendChild(pre);
107         
108         } else {
109                 var pad = (findOrgType(node.ou_type()).depth() - 1) * 12;
110                 if(pad < 0) pad = 0;
111                 var select = new Option(node.name(), node.id());
112                 select.setAttribute("style", "padding-left: "+pad+'px;');
113                 selector.options[index] = select;
114         }       
115
116         if( node.id() == holdRecipient.home_ou() ) {
117                 selector.selectedIndex = index;
118                 selector.options[index].selected = true;        
119         }
120
121         for( var i in node.children() ) {
122                 var child = node.children()[i];
123                 if(child) {
124                         holdsBuildOrgSelector(child, depth+1);
125                 }
126         }
127 }
128
129 function holdsPlaceHold() {
130
131         var org = $('holds_org_selector').options[
132                 $('holds_org_selector').selectedIndex].value;
133
134         var hold = new ahr();
135         hold.pickup_lib(org); 
136         hold.request_lib(org); 
137         hold.requestor(holdRequestor.id());
138         hold.usr(holdRecipient.id());
139         hold.hold_type('T');
140         hold.email_notify(holdRecipient.email());
141         hold.phone_notify(holdRecipient.day_phone());
142         hold.target(currentHoldRecord);
143         
144         var req = new Request( CREATE_HOLD, holdRequestor.session, hold );
145         req.send(true);
146         var res = req.result();
147
148         if( res == '1' ) alert($('holds_success').innerHTML);
149         else alert($('holds_failure').innerHTML);
150         
151         showCanvas();
152         holdRecipient = null;
153         holdRequestor = null;
154 }
155
156 function holdsCancel(holdid, user) {
157         if(!user) user = G.user;
158         var req = new Request(CANCEL_HOLD, user.session, holdid);
159         req.send(true);
160         return req.result();
161 }
162
163