]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/util.js
new copy editor
[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         win.open( 
61                 xulG.url_prefix(urls.XUL_COPY_BUCKETS) 
62                 + '?copy_ids=' + js2JSON(
63                         util.functional.map_list(
64                                 selection_list,
65                                 function (o) {
66                                         return o.copy_id;
67                                 }
68                         )
69                 ),
70                 'sel_bucket_win' + win.window_name_increment(),
71                 'chrome,resizable,modal,center'
72         );
73 }
74
75 cat.util.spawn_copy_editor = function(list,edit) {
76         try {
77         var obj = {};
78         JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
79         JSAN.use('util.network'); obj.network = new util.network();
80         JSAN.use('util.error'); obj.error = new util.error();
81
82         var title = list.length == 1 ? '' : 'Batch '; 
83         title += edit == 1 ? 'Edit' : 'View';
84         title += ' Copy Attributes';
85
86         JSAN.use('util.window'); var win = new util.window();
87         obj.data.temp = '';
88         obj.data.stash('temp');
89         var w = win.open(
90                 window.xulG.url_prefix(urls.XUL_COPY_EDITOR)
91                         +'?copy_ids='+window.escape(js2JSON(list))
92                         +'&edit='+edit,
93                 title,
94                 'chrome,modal,resizable'
95         );
96         /* FIXME -- need to unique the temp space, and not rely on modalness of window */
97         obj.data.stash_retrieve();
98         var copies = JSON2js( obj.data.temp_copies );
99         obj.error.sdump('D_CAT','in cat/copy_status, copy editor, copies =\n<<' + copies + '>>');
100         if (edit=='1' && copies!='' && typeof copies != 'undefined') {
101                 try {
102                         var r = obj.network.request(
103                                 api.FM_ACP_FLESHED_BATCH_UPDATE.app,
104                                 api.FM_ACP_FLESHED_BATCH_UPDATE.method,
105                                 [ ses(), copies ]
106                         );
107                         /* FIXME -- revisit the return value here */
108                 } catch(E) {
109                         obj.error.standard_unexpected_error_alert('copy update error',E);
110                 }
111         } else {
112                 //alert('not updating');
113         }
114         } catch(E) {
115                 alert(E);
116         }
117 }
118
119 dump('exiting cat/util.js\n');