]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkout.js
go back to Barcode after a non-cat checkout
[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.addEventListener(
62                                                                         'command',
63                                                                         function(ev) {
64                                                                                 var tb = obj.controller.view.checkout_barcode_entry_textbox;
65                                                                                 if (ev.target.value == 'barcode') {
66                                                                                         tb.disabled = false;
67                                                                                         tb.value = '';
68                                                                                         tb.focus();
69                                                                                 } else {
70                                                                                         tb.disabled = true;
71                                                                                         tb.value = 'Non-Cataloged';
72                                                                                 }
73                                                                         }, false
74                                                                 );
75                                                                 obj.controller.view.checkout_menu = ml;
76                                                         };
77                                                 },
78                                         ],
79                                         'checkout_barcode_entry_textbox' : [
80                                                 ['keypress'],
81                                                 function(ev) {
82                                                         if (ev.keyCode && ev.keyCode == 13) {
83                                                                 obj.checkout( { barcode: ev.target.value } );
84                                                         }
85                                                 }
86                                         ],
87                                         'cmd_broken' : [
88                                                 ['command'],
89                                                 function() { alert('Not Yet Implemented'); }
90                                         ],
91                                         'cmd_checkout_submit' : [
92                                                 ['command'],
93                                                 function() {
94                                                         var params = {};
95                                                         if (obj.controller.view.checkout_menu.value == 'barcode' ||
96                                                                 obj.controller.view.checkout_menu.value == '') {
97                                                                 params.barcode = obj.controller.view.checkout_barcode_entry_textbox.value;
98                                                         } else {
99                                                                 params.noncat = 1;
100                                                                 params.noncat_type = obj.controller.view.checkout_menu.value;
101                                                         }
102                                                         obj.checkout( params );
103                                                 }
104                                         ],
105                                         'cmd_checkout_print' : [
106                                                 ['command'],
107                                                 function() {
108                                                 }
109                                         ],
110                                         'cmd_checkout_reprint' : [
111                                                 ['command'],
112                                                 function() {
113                                                 }
114                                         ],
115                                         'cmd_checkout_done' : [
116                                                 ['command'],
117                                                 function() {
118                                                 }
119                                         ],
120                                 }
121                         }
122                 );
123                 this.controller.render();
124                 this.controller.view.checkout_barcode_entry_textbox.focus();
125
126         },
127
128         'checkout' : function(params) {
129                 if (!params) params = {};
130                 var obj = this;
131                 try {
132
133                         params.patron = obj.patron_id;
134
135                         var permit = obj.network.request(
136                                 api.CHECKOUT_PERMIT.app,
137                                 api.CHECKOUT_PERMIT.method,
138                                 [ obj.session, params ]
139                         );
140
141                         if (permit.ilsevent == 0) {
142
143                                 params.permit_key = permit.payload;
144
145                                 var checkout = obj.network.request(
146                                         api.CHECKOUT.app,
147                                         api.CHECKOUT.method,
148                                         [ obj.session, params ]
149                                 );
150                                 if (checkout.ilsevent == 0) {
151                                         if (!checkout.payload) checkout.payload = {};
152                                         if (!checkout.payload.circ) {
153                                                 checkout.payload.circ = new aoc();
154                                                 if (checkout.payload.noncat_circ) {
155                                                         checkout.payload.circ.circ_lib( checkout.payload.noncat_circ.circ_lib() );
156                                                         checkout.payload.circ.circ_staff( checkout.payload.noncat_circ.staff() );
157                                                         checkout.payload.circ.usr( checkout.payload.noncat_circ.patron() );
158                                                         
159                                                         JSAN.use('util.date');
160                                                         var c = checkout.payload.noncat_circ.circ_time();
161                                                         var d = c == "now" ? new Date() : util.date.db_date2Date( c );
162                                                         var t =obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ];
163                                                         var cd = t.circ_duration() || "14 days";
164                                                         var i = util.date.interval_to_seconds( cd ) * 1000;
165                                                         d.setTime( Date.parse(d) + i );
166                                                         checkout.payload.circ.due_date( util.date.formatted_date(d,'%F') );
167
168                                                 }
169                                         }
170                                         if (!checkout.payload.record) {
171                                                 checkout.payload.record = new mvr();
172                                                 if (checkout.payload.noncat_circ) {
173                                                         checkout.payload.record.title(
174                                                                 obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ].name()
175                                                         );
176                                                 }
177                                         }
178                                         if (!checkout.payload.copy) {
179                                                 checkout.payload.copy = new acp();
180                                                 checkout.payload.copy.barcode( 'special' );
181                                         }
182                                         obj.list.append(
183                                                 {
184                                                         'row' : {
185                                                                 'my' : {
186                                                                 'circ' : checkout.payload.circ,
187                                                                 'mvr' : checkout.payload.record,
188                                                                 'acp' : checkout.payload.copy
189                                                                 }
190                                                         }
191                                                 //I could override map_row_to_column here
192                                                 }
193                                         );
194                                         if (typeof obj.on_checkout == 'function') {
195                                                 obj.on_checkout(checkout.payload);
196                                         }
197                                         if (typeof window.xulG == 'object' && typeof window.xulG.on_checkout == 'function') {
198                                                 obj.error.sdump('D_CIRC','circ.checkout: Calling external .on_checkout()\n');
199                                                 window.xulG.on_checkout(checkout.payload);
200                                         } else {
201                                                 obj.error.sdump('D_CIRC','circ.checkout: No external .on_checkout()\n');
202                                         }
203                                 } else {
204                                         throw(checkout);
205                                 }
206
207                         } else {
208                                 throw(permit);
209                         }
210                 } catch(E) {
211                         alert('FIXME: need special alert and error handling\n'
212                                 + js2JSON(E));
213                         if (typeof obj.on_failure == 'function') {
214                                 obj.on_failure(E);
215                         }
216                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
217                                 obj.error.sdump('D_CIRC','circ.checkout: Calling external .on_failure()\n');
218                                 window.xulG.on_failure(E);
219                         } else {
220                                 obj.error.sdump('D_CIRC','circ.checkout: No external .on_failure()\n');
221                         }
222                 }
223
224         },
225
226         'on_checkout' : function() {
227                 this.controller.view.checkout_menu.selectedIndex = 0;
228                 this.controller.view.checkout_barcode_entry_textbox.disabled = false;
229                 this.controller.view.checkout_barcode_entry_textbox.value = '';
230                 this.controller.view.checkout_barcode_entry_textbox.focus();
231         },
232
233         'on_failure' : function() {
234                 this.controller.view.checkout_barcode_entry_textbox.select();
235                 this.controller.view.checkout_barcode_entry_textbox.focus();
236         }
237 }
238
239 dump('exiting circ.checkout.js\n');