]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkout.js
ec660004aa2b1b8a8191dcf357f15ffb9eeacf8c
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / checkout.js
1 dump('entering circ.checkout.js\n');
2
3 if (typeof circ == 'undefined') circ = {};
4 circ.checkout = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
9 }
10
11 circ.checkout.prototype = {
12
13         'init' : function( params ) {
14
15                 var obj = this;
16
17                 obj.session = params['session'];
18                 obj.patron_id = params['patron_id'];
19
20                 JSAN.use('circ.util');
21                 var columns = circ.util.columns( 
22                         { 
23                                 'barcode' : { 'hidden' : false },
24                                 'title' : { 'hidden' : false },
25                                 'due_date' : { 'hidden' : false },
26                         } 
27                 );
28
29                 JSAN.use('util.list'); obj.list = new util.list('checkout_list');
30                 obj.list.init(
31                         {
32                                 'columns' : columns,
33                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
34                         }
35                 );
36                 
37                 JSAN.use('util.controller'); obj.controller = new util.controller();
38                 obj.controller.init(
39                         {
40                                 'control_map' : {
41                                         'checkout_menu_placeholder' : [
42                                                 ['render'],
43                                                 function(e) {
44                                                         return function() {
45                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
46                                                                 var items = [ [ 'Barcode:' , 'barcode' ] ].concat(
47                                                                         util.functional.map_list(
48                                                                                 obj.data.list.cnct,
49                                                                                 function(o) {
50                                                                                         return [ o.name(), o.id() ];
51                                                                                 }
52                                                                         )
53                                                                 );
54                                                                 g.error.sdump('D_TRACE','items = ' + js2JSON(items));
55                                                                 util.widgets.remove_children( e );
56                                                                 var ml = util.widgets.make_menulist(
57                                                                         items
58                                                                 );
59                                                                 e.appendChild( ml );
60                                                                 ml.setAttribute('id','checkout_menulist');
61                                                                 ml.setAttribute('accesskey','');
62                                                                 ml.addEventListener(
63                                                                         'command',
64                                                                         function(ev) {
65                                                                                 var tb = obj.controller.view.checkout_barcode_entry_textbox;
66                                                                                 if (ev.target.value == 'barcode') {
67                                                                                         tb.disabled = false;
68                                                                                         tb.value = '';
69                                                                                         tb.focus();
70                                                                                 } else {
71                                                                                         tb.disabled = true;
72                                                                                         tb.value = 'Non-Cataloged';
73                                                                                 }
74                                                                         }, false
75                                                                 );
76                                                                 obj.controller.view.checkout_menu = ml;
77                                                         };
78                                                 },
79                                         ],
80                                         'checkout_barcode_entry_textbox' : [
81                                                 ['keypress'],
82                                                 function(ev) {
83                                                         if (ev.keyCode && ev.keyCode == 13) {
84                                                                 obj.checkout( { barcode: ev.target.value } );
85                                                         }
86                                                 }
87                                         ],
88                                         'cmd_broken' : [
89                                                 ['command'],
90                                                 function() { alert('Not Yet Implemented'); }
91                                         ],
92                                         'cmd_checkout_submit' : [
93                                                 ['command'],
94                                                 function() {
95                                                         var params = {};
96                                                         if (obj.controller.view.checkout_menu.value == 'barcode' ||
97                                                                 obj.controller.view.checkout_menu.value == '') {
98                                                                 params.barcode = obj.controller.view.checkout_barcode_entry_textbox.value;
99                                                         } else {
100                                                                 params.noncat = 1;
101                                                                 params.noncat_type = obj.controller.view.checkout_menu.value;
102                                                         }
103                                                         obj.checkout( params );
104                                                 }
105                                         ],
106                                         'cmd_checkout_print' : [
107                                                 ['command'],
108                                                 function() {
109                                                 }
110                                         ],
111                                         'cmd_checkout_reprint' : [
112                                                 ['command'],
113                                                 function() {
114                                                 }
115                                         ],
116                                         'cmd_checkout_done' : [
117                                                 ['command'],
118                                                 function() {
119                                                 }
120                                         ],
121                                 }
122                         }
123                 );
124                 this.controller.render();
125                 this.controller.view.checkout_barcode_entry_textbox.focus();
126
127         },
128
129         'checkout' : function(params) {
130                 if (!params) params = {};
131                 var obj = this;
132                 try {
133
134                         params.patron = obj.patron_id;
135
136                         var permit = obj.network.request(
137                                 api.CHECKOUT_PERMIT.app,
138                                 api.CHECKOUT_PERMIT.method,
139                                 [ obj.session, params ]
140                         );
141
142                         if (permit.ilsevent == 0) {
143
144                                 params.permit_key = permit.payload;
145
146                                 var checkout = obj.network.request(
147                                         api.CHECKOUT.app,
148                                         api.CHECKOUT.method,
149                                         [ obj.session, params ]
150                                 );
151                                 if (checkout.ilsevent == 0) {
152                                         if (!checkout.payload) checkout.payload = {};
153                                         if (!checkout.payload.circ) {
154                                                 checkout.payload.circ = new aoc();
155                                                 if (checkout.payload.noncat_circ) {
156                                                         checkout.payload.circ.circ_lib( checkout.payload.noncat_circ.circ_lib() );
157                                                         checkout.payload.circ.circ_staff( checkout.payload.noncat_circ.staff() );
158                                                         checkout.payload.circ.usr( checkout.payload.noncat_circ.patron() );
159                                                         
160                                                         JSAN.use('util.date');
161                                                         var c = checkout.payload.noncat_circ.circ_time();
162                                                         var d = c == "now" ? new Date() : util.date.db_date2Date( c );
163                                                         var t =obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ];
164                                                         var cd = t.circ_duration() || "14 days";
165                                                         var i = util.date.interval_to_seconds( cd ) * 1000;
166                                                         d.setTime( Date.parse(d) + i );
167                                                         checkout.payload.circ.due_date( util.date.formatted_date(d,'%F') );
168
169                                                 }
170                                         }
171                                         if (!checkout.payload.record) {
172                                                 checkout.payload.record = new mvr();
173                                                 if (checkout.payload.noncat_circ) {
174                                                         checkout.payload.record.title(
175                                                                 obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ].name()
176                                                         );
177                                                 }
178                                         }
179                                         if (!checkout.payload.copy) {
180                                                 checkout.payload.copy = new acp();
181                                                 checkout.payload.copy.barcode( 'special' );
182                                         }
183                                         obj.list.append(
184                                                 {
185                                                         'row' : {
186                                                                 'my' : {
187                                                                 'circ' : checkout.payload.circ,
188                                                                 'mvr' : checkout.payload.record,
189                                                                 'acp' : checkout.payload.copy
190                                                                 }
191                                                         }
192                                                 //I could override map_row_to_column here
193                                                 }
194                                         );
195                                         if (typeof obj.on_checkout == 'function') {
196                                                 obj.on_checkout(checkout.payload);
197                                         }
198                                         if (typeof window.xulG == 'object' && typeof window.xulG.on_checkout == 'function') {
199                                                 obj.error.sdump('D_CIRC','circ.checkout: Calling external .on_checkout()\n');
200                                                 window.xulG.on_checkout(checkout.payload);
201                                         } else {
202                                                 obj.error.sdump('D_CIRC','circ.checkout: No external .on_checkout()\n');
203                                         }
204                                 } else {
205                                         throw(checkout);
206                                 }
207
208                         } else {
209                                 throw(permit);
210                         }
211                 } catch(E) {
212                         alert('FIXME: need special alert and error handling\n'
213                                 + js2JSON(E));
214                         if (typeof obj.on_failure == 'function') {
215                                 obj.on_failure(E);
216                         }
217                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
218                                 obj.error.sdump('D_CIRC','circ.checkout: Calling external .on_failure()\n');
219                                 window.xulG.on_failure(E);
220                         } else {
221                                 obj.error.sdump('D_CIRC','circ.checkout: No external .on_failure()\n');
222                         }
223                 }
224
225         },
226
227         'on_checkout' : function() {
228                 this.controller.view.checkout_menu.selectedIndex = 0;
229                 this.controller.view.checkout_barcode_entry_textbox.disabled = false;
230                 this.controller.view.checkout_barcode_entry_textbox.value = '';
231                 this.controller.view.checkout_barcode_entry_textbox.focus();
232         },
233
234         'on_failure' : function() {
235                 this.controller.view.checkout_barcode_entry_textbox.select();
236                 this.controller.view.checkout_barcode_entry_textbox.focus();
237         }
238 }
239
240 dump('exiting circ.checkout.js\n');