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