68bc6776a5abf0f5b0068f4bbc0831da1a3dcc7b
[Evergreen.git] / Open-ILS / xul / staff_client / server / circ / copy_status.js
1 dump('entering circ.copy_status.js\n');
2
3 if (typeof circ == 'undefined') circ = {};
4 circ.copy_status = 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('util.date');
9         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
10 }
11
12 circ.copy_status.prototype = {
13         'selection_list' : [],
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                                 'location' : { 'hidden' : false },
27                                 'call_number' : { 'hidden' : false },
28                                 'status' : { 'hidden' : false },
29                         } 
30                 );
31
32                 JSAN.use('util.list'); obj.list = new util.list('copy_status_list');
33                 obj.list.init(
34                         {
35                                 'columns' : columns,
36                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
37                                 'on_select' : function(ev) {
38                                         try {
39                                                 JSAN.use('util.functional');
40                                                 var sel = obj.list.retrieve_selection();
41                                                 obj.selection_list = util.functional.map_list(
42                                                         sel,
43                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
44                                                 );
45                                                 obj.error.sdump('D_TRACE','circ/copy_status: selection list = ' + js2JSON(obj.selection_list) );
46                                                 if (obj.selection_list.length == 0) {
47                                                         obj.controller.view.sel_checkin.disabled = true;
48                                                         obj.controller.view.sel_edit.disabled = true;
49                                                         obj.controller.view.sel_opac.disabled = true;
50                                                         obj.controller.view.sel_patron.disabled = true;
51                                                         obj.controller.view.sel_bucket.disabled = true;
52                                                 } else {
53                                                         obj.controller.view.sel_checkin.disabled = false;
54                                                         obj.controller.view.sel_edit.disabled = false;
55                                                         obj.controller.view.sel_opac.disabled = false;
56                                                         obj.controller.view.sel_patron.disabled = false;
57                                                         obj.controller.view.sel_bucket.disabled = false;
58                                                 }
59                                         } catch(E) {
60                                                 alert('FIXME: ' + E);
61                                         }
62                                 },
63                         }
64                 );
65                 
66                 JSAN.use('util.controller'); obj.controller = new util.controller();
67                 obj.controller.init(
68                         {
69                                 'control_map' : {
70                                         'sel_checkin' : [
71                                                 ['command'],
72                                                 function() {
73                                                         JSAN.use('circ.util');
74                                                         for (var i = 0; i < obj.selection_list.length; i++) {
75                                                                 var barcode = obj.selection_list[i][1];
76                                                                 var checkin = circ.util.checkin_via_barcode(
77                                                                         obj.session, barcode
78                                                                 );
79                                                         }
80                                                 }
81                                         ],
82                                         'sel_edit' : [
83                                                 ['command'],
84                                                 function() {
85                                                         try {
86                                                                 obj.spawn_copy_editor();
87                                                         } catch(E) {
88                                                                 alert(E);
89                                                         }
90                                                 }
91                                         ],
92                                         'sel_opac' : [
93                                                 ['command'],
94                                                 function() {
95                                                         alert('Not Yet Implemented');
96                                                 }
97                                         ],
98                                         'sel_patron' : [
99                                                 ['command'],
100                                                 function() {
101                                                         alert('Not Yet Implemented');
102                                                 }
103                                         ],
104                                         'sel_bucket' : [
105                                                 ['command'],
106                                                 function() {
107                                                         alert('Not Yet Implemented');
108                                                 }
109                                         ],
110                                         'copy_status_barcode_entry_textbox' : [
111                                                 ['keypress'],
112                                                 function(ev) {
113                                                         if (ev.keyCode && ev.keyCode == 13) {
114                                                                 obj.copy_status();
115                                                         }
116                                                 }
117                                         ],
118                                         'cmd_broken' : [
119                                                 ['command'],
120                                                 function() { alert('Not Yet Implemented'); }
121                                         ],
122                                         'cmd_copy_status_submit_barcode' : [
123                                                 ['command'],
124                                                 function() {
125                                                         obj.copy_status();
126                                                 }
127                                         ],
128                                         'cmd_copy_status_print' : [
129                                                 ['command'],
130                                                 function() {
131                                                         dump( js2JSON( obj.list.dump() ) );
132                                                         alert( js2JSON( obj.list.dump() ) );
133                                                 }
134                                         ],
135                                         'cmd_copy_status_reprint' : [
136                                                 ['command'],
137                                                 function() {
138                                                 }
139                                         ],
140                                         'cmd_copy_status_done' : [
141                                                 ['command'],
142                                                 function() {
143                                                 }
144                                         ],
145                                 }
146                         }
147                 );
148                 this.controller.render();
149                 this.controller.view.copy_status_barcode_entry_textbox.focus();
150
151         },
152
153         'copy_status' : function() {
154                 var obj = this;
155                 try {
156                         var barcode = obj.controller.view.copy_status_barcode_entry_textbox.value;
157                         JSAN.use('circ.util');
158                         var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE_VIA_BARCODE', [ barcode ]);
159                         if (copy == null) {
160                                 throw('COPY NOT FOUND');
161                         } else {
162                                 obj.list.append(
163                                         {
164                                                 'retrieve_id' : js2JSON( [ copy.id(), barcode ] ),
165                                                 'row' : {
166                                                         'my' : {
167                                                                 'mvr' : obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]),
168                                                                 'acp' : copy,
169                                                         }
170                                                 }
171                                         }
172                                 );
173                         }
174                         obj.controller.view.copy_status_barcode_entry_textbox.value = '';
175                         obj.controller.view.copy_status_barcode_entry_textbox.focus();
176                 } catch(E) {
177                         alert('FIXME: need special alert and error handling\n'
178                                 + js2JSON(E));
179                         obj.controller.view.copy_status_barcode_entry_textbox.select();
180                         obj.controller.view.copy_status_barcode_entry_textbox.focus();
181                 }
182
183         },
184         
185         'spawn_copy_editor' : function() {
186
187                 /* FIXME -  a lot of redundant calls here */
188
189                 var obj = this;
190
191                 JSAN.use('util.widgets'); JSAN.use('util.functional');
192
193                 var list = obj.selection_list;
194
195                 list = util.functional.map_list(
196                         list,
197                         function (obj) {
198                                 return obj[0];
199                         }
200                 );
201
202                 var copies = util.functional.map_list(
203                         list,
204                         function (acp_id) {
205                                 return obj.network.simple_request('FM_ACP_RETRIEVE',[acp_id]);
206                         }
207                 );
208
209                 var edit = 0;
210                 try {
211                         edit = obj.network.request(
212                                 api.PERM_MULTI_ORG_CHECK.app,
213                                 api.PERM_MULTI_ORG_CHECK.method,
214                                 [ 
215                                         obj.session, 
216                                         obj.data.list.au[0].id(), 
217                                         util.functional.map_list(
218                                                 copies,
219                                                 function (obj) {
220                                                         return obj.network.simple_request('FM_ACN_RETRIEVE',[obj.call_number()]).owning_lib();
221                                                 }
222                                         ),
223                                         [ 'UPDATE_COPY', 'UPDATE_BATCH_COPY' ]
224                                 ]
225                         ).length == 0 ? 1 : 0;
226                 } catch(E) {
227                         obj.error.sdump('batch permission check: ' + E);
228                 }
229
230                 var title = list.length == 1 ? 'Copy' : 'Copies';
231
232                 JSAN.use('util.window'); var win = new util.window();
233                 obj.data.temp = '';
234                 obj.data.stash('temp');
235                 var w = win.open(
236                         window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
237                                 +'?session='+window.escape(obj.session)
238                                 +'&copy_ids='+window.escape(js2JSON(list))
239                                 +'&edit='+edit,
240                         title,
241                         'chrome,modal,resizable'
242                 );
243                 /* FIXME -- need to unique the temp space, and not rely on modalness of window */
244                 obj.data.stash_retrieve();
245                 copies = JSON2js( obj.data.temp );
246                 obj.error.sdump('D_CAT','in circ/copy_status, copy editor, copies =\n<<' + copies + '>>');
247                 if (edit=='1' && copies!='' && typeof copies != 'undefined') {
248                         try {
249                                 var r = obj.network.request(
250                                         api.FM_ACP_FLESHED_BATCH_UPDATE.app,
251                                         api.FM_ACP_FLESHED_BATCH_UPDATE.method,
252                                         [ obj.session, copies ]
253                                 );
254                                 /* FIXME -- revisit the return value here */
255                         } catch(E) {
256                                 alert('copy update error: ' + js2JSON(E));
257                         }
258                 }
259         },
260
261 }
262
263 dump('exiting circ.copy_status.js\n');