]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkin.js
cdac338c756afbcb6972d3e03f45c88aee02891d
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / checkin.js
1 dump('entering circ.checkin.js\n');
2
3 if (typeof patron == 'undefined') patron = {};
4 circ.checkin = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8         this.OpenILS = {}; JSAN.use('OpenILS.data'); this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
9 }
10
11 circ.checkin.prototype = {
12
13         'init' : function( params ) {
14
15                 var obj = this;
16
17                 obj.session = params['session'];
18
19                 JSAN.use('circ.util');
20                 var columns = circ.util.columns( 
21                         { 
22                                 'barcode' : { 'hidden' : false },
23                                 'title' : { 'hidden' : false },
24                                 'status' : { 'hidden' : false },
25                                 //'checkin_status' : { 'hidden' : false },
26                                 'checkin_route_to' : { 'hidden' : false },
27                                 'checkin_text' : { 'hidden' : false, 'flex' : 3 },
28                         } 
29                 );
30                 dump('columns = ' + js2JSON(columns) + '\n');
31
32                 JSAN.use('util.list'); obj.list = new util.list('checkin_list');
33                 obj.list.init(
34                         {
35                                 'columns' : columns,
36                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
37                         }
38                 );
39                 
40                 JSAN.use('util.controller'); obj.controller = new util.controller();
41                 obj.controller.init(
42                         {
43                                 'control_map' : {
44                                         'checkin_barcode_entry_textbox' : [
45                                                 ['keypress'],
46                                                 function(ev) {
47                                                         if (ev.keyCode && ev.keyCode == 13) {
48                                                                 obj.checkin();
49                                                         }
50                                                 }
51                                         ],
52                                         'cmd_broken' : [
53                                                 ['command'],
54                                                 function() { alert('Not Yet Implemented'); }
55                                         ],
56                                         'cmd_checkin_submit_barcode' : [
57                                                 ['command'],
58                                                 function() {
59                                                         obj.checkin();
60                                                 }
61                                         ],
62                                         'cmd_checkin_print' : [
63                                                 ['command'],
64                                                 function() {
65                                                 }
66                                         ],
67                                         'cmd_checkin_reprint' : [
68                                                 ['command'],
69                                                 function() {
70                                                 }
71                                         ],
72                                         'cmd_checkin_done' : [
73                                                 ['command'],
74                                                 function() {
75                                                 }
76                                         ],
77                                 }
78                         }
79                 );
80                 this.controller.view.checkin_barcode_entry_textbox.focus();
81
82         },
83
84         'checkin' : function() {
85                 var obj = this;
86                 try {
87                         var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
88                         var checkin = obj.network.request(
89                                 api.checkin_via_barcode.app,
90                                 api.checkin_via_barcode.method,
91                                 [ obj.session, barcode, obj.patron_id ]
92                         );
93                         obj.list.append(
94                                 {
95                                         'row' : {
96                                                 'my' : {
97                                                         'circ' : checkin.circ,
98                                                         'mvr' : checkin.record,
99                                                         'acp' : checkin.copy,
100                                                         'status' : checkin.status,
101                                                         'route_to' : checkin.route_to,
102                                                         'text' : checkin.text,
103                                                 }
104                                         }
105                                 //I could override map_row_to_column here
106                                 }
107                         );
108                         if (typeof obj.on_checkin == 'function') {
109                                 obj.on_checkin(checkin);
110                         }
111                         if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
112                                 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_checkin()\n');
113                                 window.xulG.on_checkin(checkin);
114                         } else {
115                                 obj.error.sdump('D_CIRC','circ.checkin: No external .on_checkin()\n');
116                         }
117
118                 } catch(E) {
119                         alert('FIXME: need special alert and error handling\n'
120                                 + js2JSON(E));
121                         if (typeof obj.on_failure == 'function') {
122                                 obj.on_failure(E);
123                         }
124                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
125                                 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_failure()\n');
126                                 window.xulG.on_failure(E);
127                         } else {
128                                 obj.error.sdump('D_CIRC','circ.checkin: No external .on_failure()\n');
129                         }
130                 }
131
132         },
133
134         'on_checkin' : function() {
135                 this.controller.view.checkin_barcode_entry_textbox.value = '';
136                 this.controller.view.checkin_barcode_entry_textbox.focus();
137         },
138
139         'on_failure' : function() {
140                 this.controller.view.checkin_barcode_entry_textbox.select();
141                 this.controller.view.checkin_barcode_entry_textbox.focus();
142         }
143 }
144
145 dump('exiting circ.checkin.js\n');