]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/circ/checkin.js
refactor
[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                         } 
26                 );
27                 dump('columns = ' + js2JSON(columns) + '\n');
28
29                 JSAN.use('util.list'); obj.list = new util.list('checkin_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                                         'checkin_barcode_entry_textbox' : [
42                                                 ['keypress'],
43                                                 function(ev) {
44                                                         if (ev.keyCode && ev.keyCode == 13) {
45                                                                 obj.checkin();
46                                                         }
47                                                 }
48                                         ],
49                                         'cmd_broken' : [
50                                                 ['command'],
51                                                 function() { alert('Not Yet Implemented'); }
52                                         ],
53                                         'cmd_checkin_submit_barcode' : [
54                                                 ['command'],
55                                                 function() {
56                                                         obj.checkin();
57                                                 }
58                                         ],
59                                         'cmd_checkin_print' : [
60                                                 ['command'],
61                                                 function() {
62                                                 }
63                                         ],
64                                         'cmd_checkin_reprint' : [
65                                                 ['command'],
66                                                 function() {
67                                                 }
68                                         ],
69                                         'cmd_checkin_done' : [
70                                                 ['command'],
71                                                 function() {
72                                                 }
73                                         ],
74                                 }
75                         }
76                 );
77                 this.controller.view.checkin_barcode_entry_textbox.focus();
78
79         },
80
81         'checkin' : function() {
82                 var obj = this;
83                 try {
84                         var barcode = obj.controller.view.checkin_barcode_entry_textbox.value;
85                         var checkin = obj.network.request(
86                                 api.checkin_via_barcode.app,
87                                 api.checkin_via_barcode.method,
88                                 [ obj.session, barcode, obj.patron_id ]
89                         );
90                         obj.list.append(
91                                 {
92                                         'row' : {
93                                                 'my' : {
94                                                 'circ' : checkin.circ,
95                                                 'mvr' : checkin.record,
96                                                 'acp' : checkin.copy
97                                                 }
98                                         }
99                                 //I could override map_row_to_column here
100                                 }
101                         );
102                         if (typeof obj.on_checkin == 'function') {
103                                 obj.on_checkin(checkin);
104                         }
105                         if (typeof window.xulG == 'object' && typeof window.xulG.on_checkin == 'function') {
106                                 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_checkin()\n');
107                                 window.xulG.on_checkin(checkin);
108                         } else {
109                                 obj.error.sdump('D_CIRC','circ.checkin: No external .on_checkin()\n');
110                         }
111
112                 } catch(E) {
113                         alert('FIXME: need special alert and error handling\n'
114                                 + js2JSON(E));
115                         if (typeof obj.on_failure == 'function') {
116                                 obj.on_failure(E);
117                         }
118                         if (typeof window.xulG == 'object' && typeof window.xulG.on_failure == 'function') {
119                                 obj.error.sdump('D_CIRC','circ.checkin: Calling external .on_failure()\n');
120                                 window.xulG.on_failure(E);
121                         } else {
122                                 obj.error.sdump('D_CIRC','circ.checkin: No external .on_failure()\n');
123                         }
124                 }
125
126         },
127
128         'on_checkin' : function() {
129                 this.controller.view.checkin_barcode_entry_textbox.value = '';
130                 this.controller.view.checkin_barcode_entry_textbox.focus();
131         },
132
133         'on_failure' : function() {
134                 this.controller.view.checkin_barcode_entry_textbox.select();
135                 this.controller.view.checkin_barcode_entry_textbox.focus();
136         }
137 }
138
139 dump('exiting circ.checkin.js\n');