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 'init' : function( params ) {
21 obj.session = params['session'];
22 obj.copy_ids = params['copy_ids'];
24 JSAN.use('circ.util');
25 var columns = circ.util.columns(
27 'barcode' : { 'hidden' : false },
28 'title' : { 'hidden' : false },
29 'location' : { 'hidden' : false },
30 'call_number' : { 'hidden' : false },
31 'status' : { 'hidden' : false },
35 JSAN.use('util.list');
37 obj.list1 = new util.list('pending_copies_list');
41 'map_row_to_column' : circ.util.std_map_row_to_column(),
42 'on_select' : function(ev) {
44 JSAN.use('util.functional');
45 var sel = obj.list1.retrieve_selection();
46 obj.selection_list1 = util.functional.map_list(
48 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
50 obj.error.sdump('D_TRACE','circ/copy_buckets: selection list 1 = ' + js2JSON(obj.selection_list1) );
51 if (obj.selection_list1.length == 0) {
52 obj.controller.view.copy_buckets_sel_add.disabled = true;
54 obj.controller.view.copy_buckets_sel_add.disabled = false;
63 for (var i = 0; i < obj.copy_ids.length; i++) {
64 var item = obj.flesh_item_for_list( obj.copy_ids[i] );
65 if (item) obj.list1.append( item );
68 obj.list2 = new util.list('copies_in_bucket_list');
72 'map_row_to_column' : circ.util.std_map_row_to_column(),
73 'on_select' : function(ev) {
75 JSAN.use('util.functional');
76 var sel = obj.list2.retrieve_selection();
77 obj.selection_list2 = util.functional.map_list(
79 function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
81 obj.error.sdump('D_TRACE','circ/copy_buckets: selection list 2 = ' + js2JSON(obj.selection_list2) );
82 if (obj.selection_list2.length == 0) {
83 obj.controller.view.copy_buckets_delete_item.disabled = true;
85 obj.controller.view.copy_buckets_delete_item.disabled = false;
94 JSAN.use('util.controller'); obj.controller = new util.controller();
98 'copy_buckets_menulist_placeholder' : [
102 JSAN.use('util.widgets'); JSAN.use('util.functional');
103 var items = util.functional.map_list(
104 obj.network.simple_request(
105 'BUCKET_RETRIEVE_VIA_USER',
106 [ obj.session, obj.data.list.au[0].id() ]
109 obj.bucket_id_name_map[ o.id() ] = o.name();
110 return [ o.name(), o.id() ];
113 g.error.sdump('D_TRACE','items = ' + js2JSON(items));
114 util.widgets.remove_children( e );
115 var ml = util.widgets.make_menulist(
119 ml.setAttribute('id','bucket_menulist');
120 ml.setAttribute('accesskey','');
122 function change_bucket(ev) {
123 var bucket_id = ev.target.value;
124 var bucket = obj.network.simple_request(
126 [ obj.session, 'copy', bucket_id ]
128 var items = bucket.items() || [];
130 for (var i = 0; i < items.length; i++) {
131 var item = obj.flesh_item_for_list(
132 items[i].target_copy(),
135 if (item) obj.list2.append( item );
139 ml.addEventListener( 'command', change_bucket , false);
140 obj.controller.view.bucket_menulist = ml;
143 'value' : ml.firstChild.firstChild.getAttribute('value')
147 JSAN.use('util.widgets'); util.widgets.dispatch('command',ml);
152 'copy_buckets_add' : [
155 var bucket_id = obj.controller.view.bucket_menulist.value;
156 if (!bucket_id) return;
157 for (var i = 0; i < obj.copy_ids.length; i++) {
158 var bucket_item = new ccbi();
159 bucket_item.isnew('1');
160 bucket_item.bucket(bucket_id);
161 bucket_item.target_copy( obj.copy_ids[i] );
163 var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
164 [ obj.session, 'copy', bucket_item ]);
166 if (typeof robj == 'object') throw robj;
168 var item = obj.flesh_item_for_list( obj.copy_ids[i], robj );
171 obj.list2.append( item );
178 'copy_buckets_sel_add' : [
181 var bucket_id = obj.controller.view.bucket_menulist.value;
182 if (!bucket_id) return;
183 for (var i = 0; i < obj.selection_list1.length; i++) {
184 var acp_id = obj.selection_list1[i][0];
185 //var barcode = obj.selection_list1[i][1];
186 var bucket_item = new ccbi();
187 bucket_item.isnew('1');
188 bucket_item.bucket(bucket_id);
189 bucket_item.target_copy( acp_id );
191 var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
192 [ obj.session, 'copy', bucket_item ]);
194 if (typeof robj == 'object') throw robj;
196 var item = obj.flesh_item_for_list( acp_id, robj );
199 obj.list2.append( item );
207 'copy_buckets_export' : [
210 for (var i = 0; i < obj.selection_list2.length; i++) {
211 var acp_id = obj.selection_list2[i][0];
212 //var barcode = obj.selection_list1[i][1];
213 //var bucket_item_id = obj.selection_list1[i][2];
214 var item = obj.flesh_item_for_list( acp_id );
215 if (item) obj.list1.append( item );
221 'copy_buckets_delete_item' : [
224 for (var i = 0; i < obj.selection_list2.length; i++) {
226 //var acp_id = obj.selection_list2[i][0];
227 //var barcode = obj.selection_list2[i][1];
228 var bucket_item_id = obj.selection_list2[i][2];
229 var robj = obj.network.simple_request('BUCKET_ITEM_DELETE',
230 [ obj.session, 'copy', bucket_item_id ]);
231 if (typeof robj == 'object') throw robj;
232 obj.controller.render('copy_buckets_menulist_placeholder');
239 'copy_buckets_delete_bucket' : [
243 var bucket = obj.controller.view.bucket_menulist.value;
244 var name = obj.bucket_id_name_map[ bucket ];
245 var conf = prompt('To delete this bucket, re-type its name:','','Delete Bucket');
246 if (conf != name) return;
248 var robj = obj.network.simple_request('BUCKET_DELETE',[obj.session,'copy',bucket]);
249 if (typeof robj == 'object') throw robj;
250 obj.controller.render('copy_buckets_menulist_placeholder');
252 alert('FIXME -- ' + E);
256 'copy_buckets_new_bucket' : [
260 var name = prompt('What would you like to name the bucket?','','Bucket Creation');
263 var bucket = new ccb();
264 bucket.btype('staff_client');
265 bucket.owner( obj.data.list.au[0].id() );
268 var robj = obj.network.simple_request('BUCKET_CREATE',[obj.session,'copy',bucket]);
270 if (typeof robj == 'object') throw robj;
272 obj.controller.render('copy_buckets_menulist_placeholder');
281 function() { alert('Not Yet Implemented'); }
283 'cmd_copy_buckets_print' : [
286 dump( js2JSON( obj.list2.dump() ) );
287 alert( js2JSON( obj.list2.dump() ) );
290 'cmd_copy_buckets_reprint' : [
295 'cmd_copy_buckets_done' : [
304 this.controller.render();
308 'flesh_item_for_list' : function(acp_id,bucket_item_id) {
311 var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ acp_id ]);
313 throw('COPY NOT FOUND');
316 'retrieve_id' : js2JSON( [ copy.id(), copy.barcode(), bucket_item_id ] ),
319 'mvr' : obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]),
327 alert('FIXME: need special alert and error handling\n' + js2JSON(E));
335 dump('exiting cat.copy_buckets.js\n');