2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Serial Notes -->
8 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
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"?>
15 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
17 <!DOCTYPE window PUBLIC "" ""[
18 <!--#include virtual="/opac/locale/${locale}/lang.dtd"-->
21 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
23 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
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">
29 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
31 <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};</script>
32 <scripts id="openils_util_scripts"/>
34 <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
38 function $(id) { return document.getElementById(id); }
42 if (typeof JSAN == 'undefined') {
43 throw( $("commonStrings").getString('common.jsan.missing') );
45 JSAN.errorLevel = "die"; // none, warn, or die
46 JSAN.addRepository('/xul/server/');
48 JSAN.use('util.error'); g.error = new util.error();
49 JSAN.use('util.network'); g.network = new util.network();
50 JSAN.use('util.date'); JSAN.use('util.money');
51 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
53 g.error.sdump('D_TRACE','my_init() for notes.xul');
55 g.object_type = xul_param('object_type',{'modal_xulG':true});
56 g.object_id = xul_param('object_id',{'modal_xulG':true});
57 g.function_type = xul_param('function_type',{'modal_xulG':true});
58 g.constructor = xul_param('constructor',{'modal_xulG':true});
60 var window_title = xul_param('title',{'modal_xulG':true});
62 try { document.title = window_title; } catch(E) {}
68 var err_msg = $("commonStrings").getFormattedString('common.exception', ['serial/notes.xul', js2JSON(E)]);
69 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
75 retrieve_notes(); render_notes();
78 function retrieve_notes() {
79 g.notes = g.network.simple_request(
80 'FM_' + g.function_type + '_RETRIEVE_ALL', [
81 { 'authtoken' : ses(), 'object_id' : g.object_id }
86 function apply(node,field,value) {
91 case 'description' : n.appendChild( document.createTextNode( value ) ); break;
92 case 'label' : n.value = value; break;
93 default : n.value = value; break;
99 function render_notes() {
100 JSAN.use('util.widgets'); util.widgets.remove_children('notes_panel');
101 var np = $('notes_panel');
102 var hbox = document.createElement('hbox'); np.appendChild(hbox);
103 var btn = document.createElement('button'); hbox.appendChild(btn);
104 btn.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.render_notes.label'));
105 btn.setAttribute('accesskey', $('catStrings').getString('staff.cat.copy_notes.render_notes.accesskey'));
106 btn.setAttribute('oncommand','new_note()');
108 var hb; // keep button bar reference for adding close button
109 for (var i = 0; i < g.notes.length; i++) {
112 var node = $('note_template').cloneNode(true); np.appendChild(node); node.hidden = false;
113 apply(node,'create_date',g.notes[i].create_date().toString().substr(0,10));
114 util.widgets.apply(node,'name','create_date',
118 $('catStrings').getString('staff.cat.copy_notes.widgets_apply.note_id') + " "
119 + g.notes[i].id() + " "
120 + $('catStrings').getString('staff.cat.copy_notes.widgets_apply.creator_id') + " "
121 + g.notes[i].creator()
125 apply(node,'title',g.notes[i].title());
126 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'));
127 apply(node,'value',g.notes[i].value());
128 apply(node,'id',g.notes[i].id());
129 apply(node,'creator',g.notes[i].creator());
132 hb = document.createElement('hbox'); np.appendChild(hb);
133 var btn0 = document.createElement('button'); hb.appendChild(btn0);
134 btn0.setAttribute('label', $('serialStrings').getString('staff.serial.notes.do_edit_note.label'));
135 btn0.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
137 btn0.addEventListener(
139 function(index){ return function() { new_note(index) } }(i),
142 var btn1 = document.createElement('button'); hb.appendChild(btn1);
143 btn1.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.delete_note.label'));
144 btn1.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
146 btn1.addEventListener(
148 function(index){ return function() {
149 var r = g.error.yns_alert(
150 $('catStrings').getFormattedString('staff.cat.copy_notes.delete_note.prompt.msg', [g.notes[index].title(), g.notes[index].create_date().toString().substr(0,10)]),
151 $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.title'),
152 $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.yes'),
153 $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.no'),
155 $('commonStrings').getString('common.confirm')
158 g.network.simple_request('FM_'+g.function_type+'_DELETE',[ses(),g.notes[index].id()]);
159 setTimeout(function() {
160 alert($('catStrings').getString('staff.cat.copy_notes.delete_note.success'));
170 if (!hb) { // no notes yet, fill the space and add a bar
171 var spacer = document.createElement('spacer'); np.appendChild(spacer); spacer.flex = 1;
172 hb = document.createElement('hbox'); np.appendChild(hb);
174 var spacer = document.createElement('spacer');
175 hb.appendChild(spacer); spacer.flex = 1;
176 var btn2 = document.createElement('button'); hb.appendChild(btn2);
177 btn2.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.delete_note.close_window'));
178 btn2.setAttribute('oncommand','window.close();');
182 function xml_encode(str) {
183 return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
186 function new_note(index) {
190 var edit_mode; // for clarity
192 var button_accesskey;
194 if (typeof index != 'undefined') {
196 public = get_bool(g.notes[index].pub());
197 title = xml_encode(g.notes[index].title());
198 value = xml_encode(g.notes[index].value());
199 label_text = $('serialStrings').getString('staff.serial.notes.edit_note.label');
200 button_accesskey = $('serialStrings').getString('staff.serial.notes.edit_note.accesskey');
202 label_text = $('catStrings').getString('staff.cat.copy_notes.new_note.add_note.label');
203 button_accesskey = $('catStrings').getString('staff.cat.copy_notes.new_note.add_note.accesskey');
207 value = value.replace(/\n/g, " "); // preserve newlines
208 var xml = '<groupbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1"> \
209 <caption label="' + label_text + '"/> \
210 <grid flex="1"><columns><column/><column flex="1"/></columns> \
212 <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.public') + '"/><checkbox id="pub" name="fancy_data" checked="' + public + '"/></row> \
213 <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.title') + '"/><textbox id="title" name="fancy_data" context="clipboard" value="' + title + '"/></row> \
214 <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> \
215 <row><spacer/><hbox> \
216 <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') + '"/> \
217 <button label="' + label_text + '" accesskey="' + button_accesskey + '" name="fancy_submit"/></hbox></row> \
218 </rows></grid></groupbox>';
219 //g.data.init({'via':'stash'});
220 //g.data.temp_note_xml = xml; g.data.stash('temp_note_xml');
221 JSAN.use('util.window'); var win = new util.window();
222 var fancy_prompt_data = win.open(
223 urls.XUL_FANCY_PROMPT,
224 //+ '?xml_in_stash=temp_note_xml'
225 //+ '&focus=' + window.escape('title')
226 //+ '&title=' + window.escape('Add Note'),
227 'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
228 { 'xml' : xml, 'focus' : 'title', 'title' : label_text }
230 //g.data.init({'via':'stash'});
231 if (fancy_prompt_data.fancy_status == 'complete') {
232 //alert(js2JSON(g.data.fancy_prompt_data));
235 note = g.notes[index];
237 note = new g.constructor();
240 note.title( fancy_prompt_data.title );
241 note.value( fancy_prompt_data.note );
242 note.pub( get_bool( fancy_prompt_data.pub ) ? get_db_true() : get_db_false() );
243 note[g.object_type]( g.object_id );
244 var r = g.network.simple_request('FM_'+g.function_type+'_UPDATE',[ ses(), note ]);
245 if (typeof r.ilsevent != 'undefined') throw(r);
246 setTimeout(function() {
251 g.error.standard_unexpected_error_alert($('catStrings').getString('staff.cat.copy_notes.new_note.error'),E);
258 <messagecatalog id="catStrings" src="/xul/server/locale/<!--#echo var='locale'-->/cat.properties" />
259 <messagecatalog id="serialStrings" src="/xul/server/locale/<!--#echo var='locale'-->/serial.properties" />
261 <stack hidden="true" id="note_template" flex="1">
262 <vbox flex="1" style="background-color: black; margin:3px"/>
263 <vbox flex="1" style="background-color: #FFDE00; -moz-border-radius-topright: 35px; border: 2px groove ThreeDFace; margin:3px;" >
265 <description name="title" style="font-weight: bold"/>
267 <description name="create_date" style="font-weight: bold"/>
268 <description name="pub" style="font-weight: bold"/>
270 <description style="white-space: pre-wrap;" name="value"/>
274 <vbox flex="1" class="my_overflow" id="notes_panel">