copy buckets
[Evergreen.git] / Open-ILS / xul / staff_client / server / cat / copy_buckets.js
1 dump('entering cat.copy_buckets.js\n');
2
3 if (typeof cat == 'undefined') cat = {};
4 cat.copy_buckets = 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 cat.copy_buckets.prototype = {
13         'selection_list' : [],
14
15         'init' : function( params ) {
16
17                 var obj = this;
18
19                 obj.session = params['session'];
20                 obj.copy_ids = params['copy_ids'];
21
22                 JSAN.use('circ.util');
23                 var columns = circ.util.columns( 
24                         { 
25                                 'barcode' : { 'hidden' : false },
26                                 'title' : { 'hidden' : false },
27                                 'location' : { 'hidden' : false },
28                                 'call_number' : { 'hidden' : false },
29                                 'status' : { 'hidden' : false },
30                         } 
31                 );
32
33                 JSAN.use('util.list'); 
34
35                 obj.list1 = new util.list('pending_copies_list');
36                 obj.list1.init(
37                         {
38                                 'columns' : columns,
39                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
40                         }
41                 );
42                 for (var i = 0; i < obj.copy_ids.length; i++) {
43                         var item = obj.flesh_item_for_list( obj.copy_ids[i] );
44                         if (item) obj.list1.append( item );
45                 }
46                 
47                 obj.list2 = new util.list('copies_in_bucket_list');
48                 obj.list2.init(
49                         {
50                                 'columns' : columns,
51                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
52                                 'on_select' : function(ev) {
53                                         try {
54                                                 JSAN.use('util.functional');
55                                                 var sel = obj.list2.retrieve_selection();
56                                                 obj.selection_list = util.functional.map_list(
57                                                         sel,
58                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
59                                                 );
60                                                 obj.error.sdump('D_TRACE','circ/copy_buckets: selection list = ' + js2JSON(obj.selection_list) );
61                                                 if (obj.selection_list.length == 0) {
62                                                         obj.controller.view.copy_buckets_delete_item.disabled = true;
63                                                 } else {
64                                                         obj.controller.view.copy_buckets_delete_item.disabled = false;
65                                                 }
66                                         } catch(E) {
67                                                 alert('FIXME: ' + E);
68                                         }
69                                 },
70                         }
71                 );
72                 
73                 JSAN.use('util.controller'); obj.controller = new util.controller();
74                 obj.controller.init(
75                         {
76                                 'control_map' : {
77                                         'copy_buckets_menulist_placeholder' : [
78                                                 ['render'],
79                                                 function(e) {
80                                                         return function() {
81                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
82                                                                 var items = util.functional.map_list(
83                                                                         obj.network.simple_request(
84                                                                                 'BUCKET_RETRIEVE_VIA_USER',
85                                                                                 [ obj.session, obj.data.list.au[0].id() ]
86                                                                         ).copy,
87                                                                         function(o) {
88                                                                                 return [ o.name(), o.id() ];
89                                                                         }
90                                                                 );
91                                                                 g.error.sdump('D_TRACE','items = ' + js2JSON(items));
92                                                                 util.widgets.remove_children( e );
93                                                                 var ml = util.widgets.make_menulist(
94                                                                         items
95                                                                 );
96                                                                 e.appendChild( ml );
97                                                                 ml.setAttribute('id','bucket_menulist');
98                                                                 ml.setAttribute('accesskey','');
99                                                                 ml.addEventListener(
100                                                                         'command',
101                                                                         function(ev) {
102                                                                                 alert(ev.target.value)
103                                                                         }, false
104                                                                 );
105                                                                 obj.controller.view.bucket_menulist = ml;
106                                                         };
107                                                 },
108                                         ],
109
110                                         'copy_buckets_add' : [
111                                                 ['command'],
112                                                 function() {
113                                                         for (var i = 0; i < obj.copy_ids.length; i++) {
114                                                                 var item = obj.flesh_item_for_list( obj.copy_ids[i] );
115                                                                 if (item) obj.list2.append( item );
116                                                         }
117                                                 }
118                                         ],
119                                         'copy_buckets_delete_item' : [
120                                                 ['command'],
121                                                 function() {
122                                                         JSAN.use('circ.util');
123                                                         for (var i = 0; i < obj.selection_list.length; i++) {
124                                                                 var acp_id = obj.selection_list[i][0];
125                                                                 var barcode = obj.selection_list[i][1];
126                                                         }
127                                                 }
128                                         ],
129                                         'copy_buckets_delete_bucket' : [
130                                                 ['command'],
131                                                 function() {
132                                                 }
133                                         ],
134                                         'copy_buckets_new_bucket' : [
135                                                 ['command'],
136                                                 function() {
137                                                         try {
138                                                                 obj.data.new_bucket_value = ''; obj.data.stash('new_bucket_value');
139                                                                 JSAN.use('util.window'); var win = new util.window();
140                                                                 win.open(
141                                                                         obj.data.server + urls.XUL_BUCKET_NAME,
142                                                                         'new_bucket_win' + win.window_name_increment(),
143                                                                         'chrome,resizable,modal,center'
144                                                                 );
145
146                                                                 obj.data.stash_retrieve();
147                                                                 var name = obj.data.new_bucket_value;
148
149                                                                 if (name) {
150                                                                         var bucket = new ccb();
151                                                                         bucket.btype('staff_client');
152                                                                         bucket.owner( obj.data.list.au[0].id() );
153                                                                         bucket.name( name );
154
155                                                                         obj.network.simple_request('BUCKET_CREATE',[obj.session,'copy',bucket]);
156
157                                                                         obj.controller.render('copy_buckets_menulist_placeholder');
158                                                                 }
159                                                         } catch(E) {
160                                                                 alert('FIXME -- ' + E);
161                                                         }
162                                                 }
163                                         ],
164                                         'cmd_broken' : [
165                                                 ['command'],
166                                                 function() { alert('Not Yet Implemented'); }
167                                         ],
168                                         'cmd_copy_buckets_print' : [
169                                                 ['command'],
170                                                 function() {
171                                                         dump( js2JSON( obj.list2.dump() ) );
172                                                         alert( js2JSON( obj.list2.dump() ) );
173                                                 }
174                                         ],
175                                         'cmd_copy_buckets_reprint' : [
176                                                 ['command'],
177                                                 function() {
178                                                 }
179                                         ],
180                                         'cmd_copy_buckets_done' : [
181                                                 ['command'],
182                                                 function() {
183                                                         window.close();
184                                                 }
185                                         ],
186                                 }
187                         }
188                 );
189                 this.controller.render();
190
191         },
192
193         'flesh_item_for_list' : function(acp_id) {
194                 var obj = this;
195                 try {
196                         JSAN.use('circ.util');
197                         var copy = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ acp_id ]);
198                         if (copy == null) {
199                                 throw('COPY NOT FOUND');
200                         } else {
201                                 var item = {
202                                         'retrieve_id' : js2JSON( [ copy.id(), copy.barcode() ] ),
203                                         'row' : {
204                                                 'my' : {
205                                                         'mvr' : obj.network.simple_request('MODS_SLIM_RECORD_RETRIEVE_VIA_COPY', [ copy.id() ]),
206                                                         'acp' : copy,
207                                                 }
208                                         }
209                                 };
210                                 return item;
211                         }
212                 } catch(E) {
213                         alert('FIXME: need special alert and error handling\n' + js2JSON(E));
214                         return null;
215                 }
216
217         },
218         
219 }
220
221 dump('exiting cat.copy_buckets.js\n');