added copy_ids argument to spawn_batch_copy_editor
[Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / cat / copy_edit.js
1 var cn_list;
2
3 function copy_edit_init() {
4         mw.sdump('D_CAT','entering my_init for copy_edit.js\n');
5         mw.sdump('D_CAT','TESTING: copy_edit.js: ' + mw.G['main_test_variable'] + '\n');
6         mw.sdump('D_CAT','Gathering copies to put in the acn object...\n');
7         var id_mapped_list = [];
8         if (params.tree) {
9                 var list = get_list_from_tree_selection( params.tree );
10                 mw.sdump('D_CAT','list.length = ' + list.length + '\n');
11                 var filtered_list = filter_list(
12                         list,
13                         function (obj) {
14                                 return (obj.getAttribute('object_type') == 'copy');
15                         }
16                 );
17                 mw.sdump('D_CAT','filtered_list.length = ' + filtered_list.length + '\n');
18                 id_mapped_list.concat(
19                         map_list(
20                                 filtered_list,
21                                 function (obj) {
22                                         return obj.getAttribute('copy_id');
23                                 }
24                         )
25                 );
26                 mw.sdump('D_CAT','id_mapped_list.length = ' + id_mapped_list.length + '\n');
27         }
28         if (params.copy_ids) {
29                 id_mapped_list = id_mapped_list.concat( copy_ids );
30         }
31         var result = [];
32         try {
33                 result = user_request(
34                         'open-ils.search',
35                         'open-ils.search.asset.copy.fleshed.batch.retrieve', 
36                         [ id_mapped_list ]
37                 )[0];
38         } catch(E) {
39                 handle_error(E);
40         }
41         mw.sdump('D_CAT','result.length = ' + result.length + '\n');
42         cn_list = new Array();
43         for (var i in result) {
44                 cn_list[i] = new acn();
45                 cn_list[i].label( filtered_list[i].getAttribute('callnumber') );
46                 cn_list[i].owning_lib( filtered_list[i].getAttribute('ou_id') );
47                 cn_list[i].copies( [ result[i] ] );
48         }
49         mw.sdump('D_CAT','cn_list = ' + js2JSON(cn_list) + '\n');
50         spawn_legacy_copy_editor();
51 }
52
53 function spawn_legacy_copy_editor() {
54         mw.sdump('D_CAT','trying to spawn_copy_editor()\n');
55         var params = { 'select_all' : true };
56         var chrome = 'chrome://evergreen/content/cat/copy.xul';
57         var frame = document.getElementById('copy_edit_frame');
58         frame.setAttribute('src',chrome);
59         frame.setAttribute('flex','1');
60         frame.contentWindow.cn_list = cn_list;
61         frame.contentWindow.mw = mw;
62         frame.contentWindow.real_parentWindow = this;
63         frame.contentWindow.parentWindow = window.app_shell;
64         frame.contentWindow.params = params;
65 }
66
67 function save_edited_copies() {
68         //mw.sdump('D_CAT','trying to save ====================================================================================\n\n\n');
69         //mw.sdump('D_CAT','cn_list = ' + js2JSON(cn_list) + '\n\n');
70         var copies = [];
71         for (var i = 0; i < cn_list.length; i++) {
72                 var cn_copies = cn_list[i].copies();
73                 for (var j = 0; j < cn_copies.length; j++) {
74                         copies.push( cn_copies[j] );
75                 }
76         }
77         //mw.sdump('D_CAT','copies = ' + js2JSON(copies) + '\n\n');
78         try {
79                 var result = user_request(
80                         'open-ils.cat',
81                         'open-ils.cat.asset.copy.fleshed.batch.update',
82                         [ mw.G.auth_ses[0], copies ]
83                 )[0];
84                 if (result == '1') {
85                         alert('Successfully updated these copies.\n');
86                 } else {
87                         throw('There was an error updating the copies.\n');
88                 }
89                 mw.sdump('D_CAT','Result = ' + js2JSON(result) + '\n');
90                 refresh_spawning_browse_list();
91         } catch(E) {
92                 handle_error(E);
93         }
94 }
95
96 function refresh_spawning_browse_list() {
97         try {
98                 params.refresh_func();
99         } catch(E) {
100                 mw.sdump('D_CAT','refresh_spawning_browse_list error: ' + js2JSON(E) + '\n');
101         }
102 }