]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/serial/notes.xul
895b91368dec4e1c19391b77c0ab8f58ebe90e34
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / serial / notes.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Serial Notes -->
4 <!--
5  vim:noet:sw=4:ts=4
6 -->
7
8 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
9 <!-- STYLESHEETS -->
10 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
11 <?xml-stylesheet href="chrome://open_ils_staff_client/skin/global.css" type="text/css"?>
12 <?xml-stylesheet href="/xul/server/skin/global.css" type="text/css"?>
13 <?xml-stylesheet href="/xul/server/skin/patron_display.css" type="text/css"?>
14
15 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
16 <!-- LOCALIZATION -->
17 <!DOCTYPE window PUBLIC "" ""[
18         <!--#include virtual="/opac/locale/${locale}/lang.dtd"-->
19 ]>
20
21 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
22 <!-- OVERLAYS -->
23 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
24
25 <window id="notes_win" width="700" height="550" oils_persist="height width sizemode"
26         onload="try{ my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
27         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
28
29         <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
30         <!-- BEHAVIOR -->
31         <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};</script>
32         <scripts id="openils_util_scripts"/>
33
34         <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
35         <script>
36         <![CDATA[
37
38                 function $(id) { return document.getElementById(id); }
39
40                 function my_init() {
41                         try {
42                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
43                                 if (typeof JSAN == 'undefined') { 
44                                         throw( $("commonStrings").getString('common.jsan.missing') );
45                                 }
46                                 JSAN.errorLevel = "die"; // none, warn, or die
47                                 JSAN.addRepository('/xul/server/');
48
49                                 JSAN.use('util.error'); g.error = new util.error();
50                                 JSAN.use('util.network'); g.network = new util.network();
51                                 JSAN.use('util.date'); JSAN.use('util.money'); 
52                                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
53
54                                 g.error.sdump('D_TRACE','my_init() for notes.xul');
55
56                                 g.object_type = xul_param('object_type',{'modal_xulG':true});
57                                 g.object_id = xul_param('object_id',{'modal_xulG':true});
58                                 g.function_type = xul_param('function_type',{'modal_xulG':true});
59                                 g.constructor = xul_param('constructor',{'modal_xulG':true});
60
61                                 refresh();
62
63                         } catch(E) {
64                                 var err_msg = $("commonStrings").getFormattedString('common.exception', ['serial/notes.xul', js2JSON(E)]);
65                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
66                                 alert(err_msg);
67                         }
68                 }
69
70                 function refresh() {
71                         retrieve_notes(); render_notes();
72                 }
73
74                 function retrieve_notes() {
75                         g.notes = g.network.simple_request('FM_'+g.function_type+'_RETRIEVE_ALL',[ { 'authtoken' : ses(), 'object_id' : g.object_id } ]).reverse();
76                 }
77
78                 function apply(node,field,value) {
79                         util.widgets.apply(
80                                 node,'name',field,
81                                 function(n) {
82                                         switch(n.nodeName) {
83                                                 case 'description' : n.appendChild( document.createTextNode( value ) ); break;
84                                                 case 'label' : n.value = value; break;
85                                                 default : n.value = value; break;
86                                         }
87                                 }
88                         );
89                 }
90
91                 function render_notes() {
92                         JSAN.use('util.widgets'); util.widgets.remove_children('notes_panel');
93                         var np = $('notes_panel');
94                                 var hbox = document.createElement('hbox'); np.appendChild(hbox);
95                                         var btn = document.createElement('button'); hbox.appendChild(btn);
96                                                 btn.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.render_notes.label'));
97                                                 btn.setAttribute('accesskey', $('catStrings').getString('staff.cat.copy_notes.render_notes.accesskey'));
98                                                 btn.setAttribute('oncommand','new_note()');
99
100                         var hb; // keep button bar reference for adding close button
101                         for (var i = 0; i < g.notes.length; i++) {
102
103                                 /* template */
104                                 var node = $('note_template').cloneNode(true); np.appendChild(node); node.hidden = false;
105                                 apply(node,'create_date',g.notes[i].create_date().toString().substr(0,10));
106                                 util.widgets.apply(node,'name','create_date',
107                                         function(n) {
108                                                 n.setAttribute(
109                                                         "tooltiptext",
110                                                         $('catStrings').getString('staff.cat.copy_notes.widgets_apply.note_id') + " "
111                                                         + g.notes[i].id() + " " 
112                                                         + $('catStrings').getString('staff.cat.copy_notes.widgets_apply.creator_id') + " "
113                                                         + g.notes[i].creator()
114                                                 );
115                                         }
116                                 );
117                                 apply(node,'title',g.notes[i].title());
118                                 apply(node,'pub',get_bool( g.notes[i].pub() ) ? $('catStrings').getString('staff.cat.copy_notes.widgets.public') : $('catStrings').getString('staff.cat.copy_notes.widgets.private'));
119                                 apply(node,'value',g.notes[i].value());
120                                 apply(node,'id',g.notes[i].id());
121                                 apply(node,'creator',g.notes[i].creator());
122
123                                 /* button bar */
124                                 hb = document.createElement('hbox'); np.appendChild(hb);
125                                         var btn0 = document.createElement('button'); hb.appendChild(btn0);
126                                                 btn0.setAttribute('label', $('serialStrings').getString('staff.serial.notes.do_edit_note.label'));
127                                                 btn0.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
128
129                                                 btn0.addEventListener(
130                                                         'command',
131                                                         function(index){ return function() { new_note(index) } }(i),
132                                                         false
133                                                 );
134                                         var btn1 = document.createElement('button'); hb.appendChild(btn1);
135                                                 btn1.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.delete_note.label'));
136                                                 btn1.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
137
138                                                 btn1.addEventListener(
139                                                         'command',
140                                                         function(index){ return function() { 
141                                                                 var r = g.error.yns_alert(
142                                                                         $('catStrings').getFormattedString('staff.cat.copy_notes.delete_note.prompt.msg', [g.notes[index].title(), g.notes[index].create_date().toString().substr(0,10)]),
143                                                                         $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.title'),
144                                                                         $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.yes'),
145                                                                         $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.no'),
146                                                                         null,
147                                                                         $('commonStrings').getString('common.confirm')
148                                                                 ); 
149                                                                 if (r == 0) {
150                                                                         g.network.simple_request('FM_'+g.function_type+'_DELETE',[ses(),g.notes[index].id()]);
151                                                                         setTimeout(function() { 
152                                                                                 alert($('catStrings').getString('staff.cat.copy_notes.delete_note.success'));
153                                                                                 refresh(); },0
154                                                                         );
155                                                                 }
156                                                         } }(i),
157                                                         false
158                                                 );
159                         }
160
161                         // add close button
162                         if (!hb) { // no notes yet, fill the space and add a bar
163                                 var spacer = document.createElement('spacer'); np.appendChild(spacer); spacer.flex = 1;
164                                 hb = document.createElement('hbox'); np.appendChild(hb);
165                         }
166                         var spacer = document.createElement('spacer');
167                         hb.appendChild(spacer); spacer.flex = 1;
168                         var btn2 = document.createElement('button'); hb.appendChild(btn2);
169                         btn2.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.delete_note.close_window'));
170                         btn2.setAttribute('oncommand','window.close();');
171
172                 }
173                 
174                 function new_note(index) {
175                         var public = false;
176                         var title = '';
177                         var value = '';
178                         var edit_mode; // for clarity
179                         var label_text;
180                         var button_accesskey;
181
182                         if (typeof index != 'undefined') {
183                                 edit_mode = true;
184                                 public = get_bool(g.notes[index].pub());
185                                 title = g.notes[index].title();
186                                 value = g.notes[index].value();
187                                 label_text = $('serialStrings').getString('staff.serial.notes.edit_note.label');
188                                 button_accesskey = $('serialStrings').getString('staff.serial.notes.edit_note.accesskey');
189                         } else {
190                                 label_text = $('catStrings').getString('staff.cat.copy_notes.new_note.add_note.label');
191                                 button_accesskey = $('catStrings').getString('staff.cat.copy_notes.new_note.add_note.accesskey');
192                         }
193
194                         try {
195                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite");
196                                 var xml = '<groupbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1"> \
197                                         <caption label="' + label_text + '"/> \
198                                         <grid flex="1"><columns><column/><column flex="1"/></columns> \
199                                                 <rows> \
200                                                         <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.public') + '"/><checkbox id="pub" name="fancy_data" checked="' + public + '"/></row> \
201                                                         <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.title') + '"/><textbox id="title" name="fancy_data" context="clipboard" value="' + title + '"/></row> \
202                                                         <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.note') + '"/><textbox multiline="true" id="note" name="fancy_data" context="clipboard" value="' + value + '"/></row> \
203                                                         <row><spacer/><hbox> \
204                                                                 <button label="' + $('catStrings').getString('staff.cat.copy_notes.new_note.cancel.label') + '" name="fancy_cancel" accesskey="' + $('catStrings').getString('staff.cat.copy_notes.new_note.cancel.accesskey') + '"/> \
205                                                                 <button label="' + label_text + '" accesskey="' + button_accesskey + '" name="fancy_submit"/></hbox></row> \
206                                                 </rows></grid></groupbox>';
207                                 //g.data.init({'via':'stash'});
208                                 //g.data.temp_note_xml = xml; g.data.stash('temp_note_xml');
209                                 JSAN.use('util.window'); var win = new util.window();
210                                 var fancy_prompt_data = win.open(
211                                         urls.XUL_FANCY_PROMPT,
212                                         //+ '?xml_in_stash=temp_note_xml'
213                                         //+ '&focus=' + window.escape('title')
214                                         //+ '&title=' + window.escape('Add Note'),
215                                         'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
216                                         { 'xml' : xml, 'focus' : 'title', 'title' : label_text }
217                                 );
218                                 //g.data.init({'via':'stash'});
219                                 if (fancy_prompt_data.fancy_status == 'complete') {
220                                         //alert(js2JSON(g.data.fancy_prompt_data));
221                                         var note;
222                                         if (edit_mode) {
223                                                 note = g.notes[index];
224                                         } else {
225                                                 note = new g.constructor();
226                                                 note.isnew(1);
227                                         }
228                                         note.title( fancy_prompt_data.title );
229                                         note.value( fancy_prompt_data.note );
230                                         note.pub( get_bool( fancy_prompt_data.pub ) ? get_db_true() : get_db_false() );
231                                         note[g.object_type]( g.object_id );
232                                         var r = g.network.simple_request('FM_'+g.function_type+'_UPDATE',[ ses(), note ]);
233                                         if (typeof r.ilsevent != 'undefined') throw(r);
234                                         setTimeout(function() {
235                                                 refresh();},0
236                                         );
237                                 }
238                         } catch(E) {
239                                 g.error.standard_unexpected_error_alert($('catStrings').getString('staff.cat.copy_notes.new_note.error'),E);
240                         }
241                 }
242
243         ]]>
244         </script>
245
246         <messagecatalog id="catStrings" src="/xul/server/locale/<!--#echo var='locale'-->/cat.properties" />
247         <messagecatalog id="serialStrings" src="/xul/server/locale/<!--#echo var='locale'-->/serial.properties" />
248
249         <stack hidden="true" id="note_template" flex="1">
250                 <groupbox flex="1" style="background-color: black;"/>
251                 <groupbox flex="1" style="background-color: #FFDE00; -moz-border-radius-topright: 35px;" >
252                         <hbox>
253                                 <description name="title" style="font-weight: bold"/>
254                                 <spacer flex="1"/>
255                                 <description name="create_date" style="font-weight: bold"/>
256                                 <description name="pub" style="font-weight: bold"/>
257                         </hbox>
258                         <description name="value"/>
259                 </groupbox>
260         </stack>
261
262         <vbox flex="1" class="my_overflow" id="notes_panel">
263         </vbox>
264
265
266 </window>
267