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