]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkin.js
checkin skeleton
[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         JSAN.use('OpenILS.data'); this.OpenILS = {};
10         this.OpenILS.data = new OpenILS.data(); this.OpenILS.data.init({'via':'stash'});
11 }
12
13 circ.checkin.prototype = {
14
15         'init' : function( params ) {
16
17                 var obj = this;
18
19                 obj.session = params['session'];
20
21                 JSAN.use('circ.util');
22                 var columns = circ.util.columns( 
23                         { 
24                                 'barcode' : { 'hidden' : false },
25                                 'title' : { 'hidden' : false },
26                                 'status' : { 'hidden' : false },
27                         } 
28                 );
29
30                 JSAN.use('util.list'); obj.list = new util.list('checkin_list');
31                 obj.list.init(
32                         {
33                                 'columns' : columns,
34                                 'map_row_to_column' : function(row,col) {
35                                         // row contains { 'my' : { 'acp' : {}, 'circ' : {}, 'mvr' : {} } }
36                                         // col contains one of the objects listed above in columns
37                                         var my = row.my;
38                                         return eval( col.render );
39                                 },
40                         }
41                 );
42                 
43                 JSAN.use('util.controller'); obj.controller = new util.controller();
44                 obj.controller.init(
45                         {
46                                 'control_map' : {
47                                         'checkin_barcode_entry_textbox' : [
48                                                 ['keypress'],
49                                                 function(ev) {
50                                                         if (ev.keyCode && ev.keyCode == 13) {
51                                                                 obj.checkin();
52                                                         }
53                                                 }
54                                         ],
55                                         'cmd_broken' : [
56                                                 ['command'],
57                                                 function() { alert('Not Yet Implemented'); }
58                                         ],
59                                         'cmd_checkin_submit_barcode' : [
60                                                 ['command'],
61                                                 function() {
62                                                         obj.checkin();
63                                                 }
64                                         ],
65                                         'cmd_checkin_print' : [
66                                                 ['command'],
67                                                 function() {
68                                                 }
69                                         ],
70                                         'cmd_checkin_reprint' : [
71                                                 ['command'],
72                                                 function() {
73                                                 }
74                                         ],
75                                         'cmd_checkin_done' : [
76                                                 ['command'],
77                                                 function() {
78                                                 }
79                                         ],
80                                 }
81                         }
82                 );
83                 this.controller.view.checkin_barcode_entry_textbox.focus();
84
85         },
86
87         'checkin' : function() {
88                 var obj = this;
89                 try {
90                         var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
91                         var checkin = obj.network.request(
92                                 api.checkin_via_barcode.app,
93                                 api.checkin_via_barcode.method,
94                                 [ obj.session, barcode, obj.patron_id ]
95                         );
96                         obj.list.append(
97                                 {
98                                         'row' : {
99                                                 'my' : {
100                                                 'circ' : checkin.circ,
101                                                 'mvr' : checkin.record,
102                                                 'acp' : checkin.copy
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');