]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/copy_buckets_quick.xul
716d5e023f02c90f709710a00aa7b88153a6d378
[Evergreen.git] / Open-ILS / xul / staff_client / server / cat / copy_buckets_quick.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Patron Display -->
4
5 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
6 <!-- STYLESHEETS -->
7 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
8 <?xml-stylesheet href="chrome://open_ils_staff_client/skin/global.css" type="text/css"?>
9 <?xml-stylesheet href="/xul/server/skin/global.css" type="text/css"?>
10 <?xml-stylesheet href="/xul/server/skin/cat.css" type="text/css"?>
11
12 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
13 <!-- LOCALIZATION -->
14 <!DOCTYPE window PUBLIC "" ""[
15         <!--#include virtual="/opac/locale/en-US/lang.dtd"-->
16 ]>
17
18 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
19 <!-- OVERLAYS -->
20 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
21
22 <window id="copy_buckets_win" title="Add to Bucket"
23         onload="try { my_init(); font_helper(); } catch(E) { alert(E); }" persist="height,width"
24         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
25
26         <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
27         <!-- BEHAVIOR -->
28         <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};</script>
29         <scripts id="openils_util_scripts"/>
30
31         <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
32         <script>
33         <![CDATA[
34                 function $(id) { return document.getElementById(id); }
35                 function $c(n) { return document.createElement(n); }
36
37                 function my_init() {
38                         try {
39                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
40                                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
41                                 JSAN.errorLevel = "die"; // none, warn, or die
42                                 JSAN.addRepository('/xul/server/');
43                                 JSAN.use('util.error'); g.error = new util.error();
44                                 g.error.sdump('D_TRACE','my_init() for copy_buckets.xul');
45                                 JSAN.use('util.network'); g.network = new util.network();
46                                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
47
48                                 g.cgi = new CGI();
49                                 g.copy_ids = [];
50                                 if (g.cgi.param('copy_ids')) g.copy_ids = g.copy_ids.concat( JSON2js( g.cgi.param('copy_ids') ) );
51                                 if (typeof window.xuLG == 'object' && typeof window.xulG.copy_ids != 'undefined')
52                                         g.copy_ids = g.copy_ids.concat( window.xulG.copy_ids );
53                                 if (typeof g.data.cb_temp_copy_ids != 'undefined' && g.data.cb_temp_copy_ids != null) {
54                                         g.copy_ids = g.copy_ids.concat( JSON2js( g.data.cb_temp_copy_ids ) );
55                                         g.data.cb_temp_copy_ids = undefined; g.data.stash('cb_temp_copy_ids');
56                                 }
57
58                                 $('desc').appendChild( document.createTextNode( 
59                                         (g.copy_ids.length == 1 ?
60                                                 'Copy this 1 item into which bucket?' :
61                                                 'Copy these ' + g.copy_ids.length + ' items into which bucket?') 
62                                 ) );
63                                 var robj = g.network.simple_request('BUCKET_RETRIEVE_VIA_USER',[ ses(), g.data.list.au[0].id() ]);
64                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
65
66                                 for (var i = 0; i < robj.copy.length; i++) {
67                                         var listitem = $c('listitem');
68                                         listitem.setAttribute('label', robj.copy[i].name());
69                                         listitem.setAttribute('id', robj.copy[i].id());
70                                         $('bucket_list').appendChild(listitem);
71                                 }
72
73                                 try { $('bucket_list').selectedIndex = 0; } catch(E) { }
74
75                                 $('bucket_list').focus();
76
77                         } catch(E) {
78                                 try { 
79                                         g.error.standard_unexpected_error_alert('Trying to init copy_buckets_quick.xul',E); 
80                                 } catch(F) { 
81                                         alert(E); 
82                                 }
83                         }
84                 }
85
86                 g.new_bucket = function() {
87                         try {
88                                 var name = prompt('What would you like to name the bucket?','','Bucket Creation');
89                                 if (name) {
90                                         var bucket = new ccb();
91                                         bucket.btype('staff_client');
92                                         bucket.owner( g.data.list.au[0].id() );
93                                         bucket.name( name );
94
95                                         var bucket_id = g.network.simple_request('BUCKET_CREATE',[ses(),'copy',bucket]);
96                                         if (typeof bucket_id == 'object') throw bucket_id;
97
98                                         g.add_to_bucket(bucket_id);
99                                 }
100                         } catch(E) {
101                                 g.error.standard_unexpected_error_alert('Bucket creation failed.',E);
102                         }
103                 }
104
105                 g.add_to_bucket = function(b) {
106                         var bucket_id;
107                         if (b) {
108                                 bucket_id = b;
109                         } else {
110                                 try {
111                                         if ($('bucket_list').selectedItem) bucket_id = $('bucket_list').selectedItem.getAttribute('id');
112                                 } catch(E) {
113                                 }
114                         }
115                         if (!bucket_id) return;
116                         for (var i = 0; i < g.copy_ids.length; i++) {
117                                 var bucket_item = new ccbi();
118                                 bucket_item.isnew('1');
119                                 bucket_item.bucket(bucket_id);
120                                 bucket_item.target_copy( g.copy_ids[i] );
121                                 try {
122                                         var robj = g.network.simple_request('BUCKET_ITEM_CREATE', [ ses(), 'copy', bucket_item ]);
123                                         if (typeof robj == 'object') throw robj;
124
125                                 } catch(E) {
126                                         g.error.standard_unexpected_error_alert('Addition likely failed for bucket = ' + bucket_id + ' and copy id = ' + g.copy_ids[i],E);
127                                 }
128                         }
129                         window.close();
130                 }
131
132                 g.advanced = function() {
133                         JSAN.use('util.window'); var win = new util.window();
134                         g.data.cb_temp_copy_ids = js2JSON( g.copy_ids ); g.data.stash('cb_temp_copy_ids');
135                         win.open(urls.XUL_COPY_BUCKETS,'adv_copy_buckets','chrome,resizable,modal');
136                         window.close();
137                 }
138
139         ]]>
140         </script>
141
142         <vbox flex="1" style="overflow: auto">
143         <groupbox flex="1">
144                 <caption label="Item Buckets"/>
145                 <description id="desc"/>
146                 <listbox id="bucket_list" rows="5" flex="1" style="overflow: auto"/>
147                 <hbox>
148                         <button label="Add to Selected Bucket" accesskey="A" oncommand="g.add_to_bucket()"/>
149                         <button label="Add to New Bucket" accesskey="N" oncommand="g.new_bucket()"/>
150                 </hbox>
151                 <hbox>
152                         <!--
153                         <button label="Advanced" accesskey="v" oncommand="g.advanced()"/>
154                         -->
155                         <button label="Cancel" accesskey="C" oncommand="window.close()"/>
156                 </hbox>
157         </groupbox>
158         </vbox>
159
160 </window>
161