1 dump('entering cat.copy_buckets.js\n');
3 if (typeof cat == 'undefined') cat = {};
4 cat.copy_buckets = function (params) {
6 JSAN.use('util.error'); this.error = new util.error();
7 JSAN.use('util.network'); this.network = new util.network();
9 JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
12 cat.copy_buckets.prototype = {
13 'selection_list1' : [],
14 'selection_list2' : [],
15 'bucket_id_name_map' : {},
17 'render_pending_copies' : function() {
20 for (var i = 0; i < obj.copy_ids.length; i++) {
21 var item = obj.flesh_item_for_list( obj.copy_ids[i] );
22 if (item) obj.list1.append( item );
26 'init' : function( params ) {
30 obj.session = params['session'];
31 obj.copy_ids = params['copy_ids'] || [];
33 JSAN.use('circ.util');
34 var columns = circ.util.columns(
36 'barcode' : { 'hidden' : false },
37 'title' : { 'hidden' : false },
38 'location' : { 'hidden' : false },
39 'call_number' : { 'hidden' : false },
40 'status' : { 'hidden' : false },
44 JSAN.use('util.list');
46 obj.list1 = new util.list('pending_copies_list');
50 'map_row_to_column' : circ.util.std_map_row_to_column(),
51 'on_select' : function(ev) {
53 JSAN.use('util.functional');
54 var sel = obj.list1.retrieve_selection();
55 obj.selection_list1 = util.functional.map_list(
57 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
59 obj.error.sdump('D_TRACE','circ/copy_buckets: selection list 1 = ' + js2JSON(obj.selection_list1) );
60 if (obj.selection_list1.length == 0) {
61 obj.controller.view.copy_buckets_sel_add.disabled = true;
63 obj.controller.view.copy_buckets_sel_add.disabled = false;
73 obj.render_pending_copies();
75 obj.list2 = new util.list('copies_in_bucket_list');
79 'map_row_to_column' : circ.util.std_map_row_to_column(),
80 'on_select' : function(ev) {
82 JSAN.use('util.functional');
83 var sel = obj.list2.retrieve_selection();
84 obj.selection_list2 = util.functional.map_list(
86 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
88 obj.error.sdump('D_TRACE','circ/copy_buckets: selection list 2 = ' + js2JSON(obj.selection_list2) );
89 if (obj.selection_list2.length == 0) {
90 obj.controller.view.copy_buckets_delete_item.disabled = true;
92 obj.controller.view.copy_buckets_delete_item.disabled = false;
101 JSAN.use('util.controller'); obj.controller = new util.controller();
105 'copy_buckets_menulist_placeholder' : [
109 JSAN.use('util.widgets'); JSAN.use('util.functional');
110 var items = util.functional.map_list(
111 obj.network.simple_request(
112 'BUCKET_RETRIEVE_VIA_USER',
113 [ obj.session, obj.data.list.au[0].id() ]
116 obj.bucket_id_name_map[ o.id() ] = o.name();
117 return [ o.name(), o.id() ];
120 g.error.sdump('D_TRACE','items = ' + js2JSON(items));
121 util.widgets.remove_children( e );
122 var ml = util.widgets.make_menulist(
126 ml.setAttribute('id','bucket_menulist');
127 ml.setAttribute('accesskey','');
129 function change_bucket(ev) {
130 var bucket_id = ev.target.value;
131 var bucket = obj.network.simple_request(
133 [ obj.session, 'copy', bucket_id ]
135 var items = bucket.items() || [];
137 for (var i = 0; i < items.length; i++) {
138 var item = obj.flesh_item_for_list(
139 items[i].target_copy(),
142 if (item) obj.list2.append( item );
146 ml.addEventListener( 'command', change_bucket , false);
147 obj.controller.view.bucket_menulist = ml;
150 'value' : ml.firstChild.firstChild.getAttribute('value')
154 JSAN.use('util.widgets'); util.widgets.dispatch('command',ml);
159 'copy_buckets_add' : [
162 var bucket_id = obj.controller.view.bucket_menulist.value;
163 if (!bucket_id) return;
164 for (var i = 0; i < obj.copy_ids.length; i++) {
165 var bucket_item = new ccbi();
166 bucket_item.isnew('1');
167 bucket_item.bucket(bucket_id);
168 bucket_item.target_copy( obj.copy_ids[i] );
170 var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
171 [ obj.session, 'copy', bucket_item ]);
173 if (typeof robj == 'object') throw robj;
175 var item = obj.flesh_item_for_list( obj.copy_ids[i], robj );
178 obj.list2.append( item );
185 'copy_buckets_sel_add' : [
188 var bucket_id = obj.controller.view.bucket_menulist.value;
189 if (!bucket_id) return;
190 for (var i = 0; i < obj.selection_list1.length; i++) {
191 var acp_id = obj.selection_list1[i][0];
192 //var barcode = obj.selection_list1[i][1];
193 var bucket_item = new ccbi();
194 bucket_item.isnew('1');
195 bucket_item.bucket(bucket_id);
196 bucket_item.target_copy( acp_id );
198 var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
199 [ obj.session, 'copy', bucket_item ]);
201 if (typeof robj == 'object') throw robj;
203 var item = obj.flesh_item_for_list( acp_id, robj );
206 obj.list2.append( item );
214 'copy_buckets_export' : [
217 for (var i = 0; i < obj.selection_list2.length; i++) {
218 var acp_id = obj.selection_list2[i][0];
219 //var barcode = obj.selection_list1[i][1];
220 //var bucket_item_id = obj.selection_list1[i][2];
221 var item = obj.flesh_item_for_list( acp_id );
223 obj.list1.append( item );
224 obj.copy_ids.push( acp_id );
230 'copy_buckets_delete_item' : [
233 for (var i = 0; i < obj.selection_list2.length; i++) {
235 //var acp_id = obj.selection_list2[i][0];
236 //var barcode = obj.selection_list2[i][1];
237 var bucket_item_id = obj.selection_list2[i][2];
238 var robj = obj.network.simple_request('BUCKET_ITEM_DELETE',
239 [ obj.session, 'copy', bucket_item_id ]);
240 if (typeof robj == 'object') throw robj;
241 obj.controller.render('copy_buckets_menulist_placeholder');
248 'copy_buckets_delete_bucket' : [
252 var bucket = obj.controller.view.bucket_menulist.value;
253 var name = obj.bucket_id_name_map[ bucket ];
254 var conf = prompt('To delete this bucket, re-type its name:','','Delete Bucket');
255 if (conf != name) return;
257 var robj = obj.network.simple_request('BUCKET_DELETE',[obj.session,'copy',bucket]);
258 if (typeof robj == 'object') throw robj;
259 obj.controller.render('copy_buckets_menulist_placeholder');
261 alert('FIXME -- ' + E);
265 'copy_buckets_new_bucket' : [
269 var name = prompt('What would you like to name the bucket?','','Bucket Creation');
272 var bucket = new ccb();
273 bucket.btype('staff_client');
274 bucket.owner( obj.data.list.au[0].id() );
277 var robj = obj.network.simple_request('BUCKET_CREATE',[obj.session,'copy',bucket]);
279 if (typeof robj == 'object') throw robj;
281 obj.controller.render('copy_buckets_menulist_placeholder');
288 'copy_buckets_batch_copy_edit' : [
292 JSAN.use('util.functional');
293 JSAN.use('util.window'); var win = new util.window();
296 + '?session=' + window.escape(obj.session)
297 + '©_ids=' + window.escape( js2JSON(
298 util.functional.map_list(
299 obj.list2.dump_retrieve_ids(),
301 return JSON2js(o)[0]; // acp_id
306 'batch_copy_editor_win_' + win.window_name_increment(),
307 'chrome,resizable,modal'
309 obj.controller.render('copy_buckets_menulist_placeholder');
310 obj.render_pending_copies(); // FIXME -- need a generic refresh for lists
318 function() { alert('Not Yet Implemented'); }
320 'cmd_copy_buckets_print' : [
323 dump( js2JSON( obj.list2.dump() ) );
324 alert( js2JSON( obj.list2.dump() ) );
327 'cmd_copy_buckets_reprint' : [
332 'cmd_copy_buckets_done' : [
341 this.controller.render();
345 'flesh_item_for_list' : function(acp_id,bucket_item_id) {
348 var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ acp_id ]);
350 throw('COPY NOT FOUND');
353 'retrieve_id' : js2JSON( [ copy.id(), copy.barcode(), bucket_item_id ] ),
356 'mvr' : obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]),
364 alert('FIXME: need special alert and error handling\n' + js2JSON(E));
372 dump('exiting cat.copy_buckets.js\n');