]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/util.js
quick copy bucket add
[Evergreen.git] / Open-ILS / xul / staff_client / server / cat / util.js
1 dump('entering cat/util.js\n');
2
3 if (typeof cat == 'undefined') var cat = {};
4 cat.util = {};
5
6 cat.util.EXPORT_OK      = [ 
7         'spawn_copy_editor', 'add_copies_to_bucket', 'show_in_opac', 'spawn_spine_editor',
8 ];
9 cat.util.EXPORT_TAGS    = { ':all' : cat.util.EXPORT_OK };
10
11 cat.util.spawn_spine_editor = function(selection_list) {
12         JSAN.use('util.error'); var error = new util.error();
13         try {
14                 JSAN.use('util.functional');
15                 xulG.new_tab(
16                         xulG.url_prefix( urls.XUL_SPINE_LABEL ) + '?barcodes=' 
17                         + js2JSON( util.functional.map_list(selection_list,function(o){return o.barcode;}) ),
18                         { 'tab_name' : 'Spine Labels' },
19                         {}
20                 );
21         } catch(E) {
22                 error.standard_unexpected_error_alert('Spine Labels',E);
23         }
24 }
25
26 cat.util.show_in_opac = function(selection_list) {
27         JSAN.use('util.error'); var error = new util.error();
28         var doc_id; var seen = {};
29         try {
30                 for (var i = 0; i < selection_list.length; i++) {
31                         doc_id = selection_list[i].doc_id;
32                         if (!doc_id) {
33                                 alert(selection_list[i].barcode + ' is not cataloged');
34                                 continue;
35                         }
36                         if (typeof seen[doc_id] != 'undefined') {
37                                 continue;
38                         }
39                         seen[doc_id] = true;
40                         var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
41                         var content_params = { 
42                                 'session' : ses(),
43                                 'authtime' : ses('authtime'),
44                                 'opac_url' : opac_url,
45                         };
46                         xulG.new_tab(
47                                 xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
48                                 {'tab_name':'Retrieving title...'}, 
49                                 content_params
50                         );
51                 }
52         } catch(E) {
53                 error.standard_unexpected_error_alert('Error opening catalog for document id = ' + doc_id,E);
54         }
55 }
56
57 cat.util.add_copies_to_bucket = function(selection_list) {
58         JSAN.use('util.functional');
59         JSAN.use('util.window'); var win = new util.window();
60         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
61         data.temp_copy_ids = js2JSON(
62                 util.functional.map_list(
63                         selection_list,
64                         function (o) {
65                                 return o.copy_id;
66                         }
67                 )
68         );
69         data.stash('temp_copy_ids');
70         win.open( 
71                 xulG.url_prefix(urls.XUL_COPY_BUCKETS_QUICK),
72                 'sel_bucket_win' + win.window_name_increment(),
73                 'chrome,resizable,modal,center'
74         );
75 }
76
77 cat.util.spawn_copy_editor = function(list,edit) {
78         try {
79         var obj = {};
80         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
81         JSAN.use('util.network'); obj.network = new util.network();
82         JSAN.use('util.error'); obj.error = new util.error();
83
84         var title = list.length == 1 ? '' : 'Batch '; 
85         title += edit == 1 ? 'Edit' : 'View';
86         title += ' Copy Attributes';
87
88         JSAN.use('util.window'); var win = new util.window();
89         obj.data.temp = '';
90         obj.data.stash('temp');
91         obj.data.temp_copy_ids = js2JSON(list);
92         obj.data.stash('temp_copy_ids');
93         var w = win.open(
94                 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
95                         +'?edit='+edit,
96                 title,
97                 'chrome,modal,resizable'
98         );
99         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
100         obj.data.stash_retrieve();
101         if (!obj.data.temp_copies) return;
102         var copies = JSON2js( obj.data.temp_copies );
103         obj.data.temp_copies = null; obj.data.stash('temp_copies');
104         obj.data.temp_callnumbers = null; obj.data.stash('temp_callnumbers');
105         obj.data.temp_copy_ids = null; obj.data.stash('temp_copy_ids');
106         obj.error.sdump('D_CAT','in cat/copy_status, copy editor, copies =\n<<' + copies + '>>');
107         if (edit=='1' && copies!='' && typeof copies != 'undefined') {
108                 try {
109                         var r = obj.network.request(
110                                 api.FM_ACP_FLESHED_BATCH_UPDATE.app,
111                                 api.FM_ACP_FLESHED_BATCH_UPDATE.method,
112                                 [ ses(), copies ]
113                         );
114                         /* FIXME -- revisit the return value here */
115                 } catch(E) {
116                         obj.error.standard_unexpected_error_alert('copy update error',E);
117                 }
118         } else {
119                 //alert('not updating');
120         }
121         } catch(E) {
122                 alert(E);
123         }
124 }
125
126 dump('exiting cat/util.js\n');