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