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 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
43 if (typeof JSAN == 'undefined') {
44 throw( $("commonStrings").getString('common.jsan.missing') );
46 JSAN.errorLevel = "die"; // none, warn, or die
47 JSAN.addRepository('/xul/server/');
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'});
54 g.error.sdump('D_TRACE','my_init() for notes.xul');
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});
61 var window_title = xul_param('title',{'modal_xulG':true});
63 try { document.title = window_title; } catch(E) {}
69 var err_msg = $("commonStrings").getFormattedString('common.exception', ['serial/notes.xul', js2JSON(E)]);
70 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
76 retrieve_notes(); render_notes();
79 function retrieve_notes() {
80 g.notes = g.network.simple_request('FM_'+g.function_type+'_RETRIEVE_ALL',[ { 'authtoken' : ses(), 'object_id' : g.object_id } ]).reverse();
83 function apply(node,field,value) {
88 case 'description' : n.appendChild( document.createTextNode( value ) ); break;
89 case 'label' : n.value = value; break;
90 default : n.value = value; break;
96 function render_notes() {
97 JSAN.use('util.widgets'); util.widgets.remove_children('notes_panel');
98 var np = $('notes_panel');
99 var hbox = document.createElement('hbox'); np.appendChild(hbox);
100 var btn = document.createElement('button'); hbox.appendChild(btn);
101 btn.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.render_notes.label'));
102 btn.setAttribute('accesskey', $('catStrings').getString('staff.cat.copy_notes.render_notes.accesskey'));
103 btn.setAttribute('oncommand','new_note()');
105 var hb; // keep button bar reference for adding close button
106 for (var i = 0; i < g.notes.length; i++) {
109 var node = $('note_template').cloneNode(true); np.appendChild(node); node.hidden = false;
110 apply(node,'create_date',g.notes[i].create_date().toString().substr(0,10));
111 util.widgets.apply(node,'name','create_date',
115 $('catStrings').getString('staff.cat.copy_notes.widgets_apply.note_id') + " "
116 + g.notes[i].id() + " "
117 + $('catStrings').getString('staff.cat.copy_notes.widgets_apply.creator_id') + " "
118 + g.notes[i].creator()
122 apply(node,'title',g.notes[i].title());
123 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'));
124 apply(node,'value',g.notes[i].value());
125 apply(node,'id',g.notes[i].id());
126 apply(node,'creator',g.notes[i].creator());
129 hb = document.createElement('hbox'); np.appendChild(hb);
130 var btn0 = document.createElement('button'); hb.appendChild(btn0);
131 btn0.setAttribute('label', $('serialStrings').getString('staff.serial.notes.do_edit_note.label'));
132 btn0.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
134 btn0.addEventListener(
136 function(index){ return function() { new_note(index) } }(i),
139 var btn1 = document.createElement('button'); hb.appendChild(btn1);
140 btn1.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.delete_note.label'));
141 btn1.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
143 btn1.addEventListener(
145 function(index){ return function() {
146 var r = g.error.yns_alert(
147 $('catStrings').getFormattedString('staff.cat.copy_notes.delete_note.prompt.msg', [g.notes[index].title(), g.notes[index].create_date().toString().substr(0,10)]),
148 $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.title'),
149 $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.yes'),
150 $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.no'),
152 $('commonStrings').getString('common.confirm')
155 g.network.simple_request('FM_'+g.function_type+'_DELETE',[ses(),g.notes[index].id()]);
156 setTimeout(function() {
157 alert($('catStrings').getString('staff.cat.copy_notes.delete_note.success'));
167 if (!hb) { // no notes yet, fill the space and add a bar
168 var spacer = document.createElement('spacer'); np.appendChild(spacer); spacer.flex = 1;
169 hb = document.createElement('hbox'); np.appendChild(hb);
171 var spacer = document.createElement('spacer');
172 hb.appendChild(spacer); spacer.flex = 1;
173 var btn2 = document.createElement('button'); hb.appendChild(btn2);
174 btn2.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.delete_note.close_window'));
175 btn2.setAttribute('oncommand','window.close();');
179 function xml_encode(str) {
180 return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''');
183 function new_note(index) {
187 var edit_mode; // for clarity
189 var button_accesskey;
191 if (typeof index != 'undefined') {
193 public = get_bool(g.notes[index].pub());
194 title = xml_encode(g.notes[index].title());
195 value = xml_encode(g.notes[index].value());
196 label_text = $('serialStrings').getString('staff.serial.notes.edit_note.label');
197 button_accesskey = $('serialStrings').getString('staff.serial.notes.edit_note.accesskey');
199 label_text = $('catStrings').getString('staff.cat.copy_notes.new_note.add_note.label');
200 button_accesskey = $('catStrings').getString('staff.cat.copy_notes.new_note.add_note.accesskey');
204 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite");
205 value = value.replace(/\n/g, " "); // preserve newlines
206 var xml = '<groupbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1"> \
207 <caption label="' + label_text + '"/> \
208 <grid flex="1"><columns><column/><column flex="1"/></columns> \
210 <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.public') + '"/><checkbox id="pub" name="fancy_data" checked="' + public + '"/></row> \
211 <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.title') + '"/><textbox id="title" name="fancy_data" context="clipboard" value="' + title + '"/></row> \
212 <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> \
213 <row><spacer/><hbox> \
214 <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') + '"/> \
215 <button label="' + label_text + '" accesskey="' + button_accesskey + '" name="fancy_submit"/></hbox></row> \
216 </rows></grid></groupbox>';
217 //g.data.init({'via':'stash'});
218 //g.data.temp_note_xml = xml; g.data.stash('temp_note_xml');
219 JSAN.use('util.window'); var win = new util.window();
220 var fancy_prompt_data = win.open(
221 urls.XUL_FANCY_PROMPT,
222 //+ '?xml_in_stash=temp_note_xml'
223 //+ '&focus=' + window.escape('title')
224 //+ '&title=' + window.escape('Add Note'),
225 'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
226 { 'xml' : xml, 'focus' : 'title', 'title' : label_text }
228 //g.data.init({'via':'stash'});
229 if (fancy_prompt_data.fancy_status == 'complete') {
230 //alert(js2JSON(g.data.fancy_prompt_data));
233 note = g.notes[index];
235 note = new g.constructor();
238 note.title( fancy_prompt_data.title );
239 note.value( fancy_prompt_data.note );
240 note.pub( get_bool( fancy_prompt_data.pub ) ? get_db_true() : get_db_false() );
241 note[g.object_type]( g.object_id );
242 var r = g.network.simple_request('FM_'+g.function_type+'_UPDATE',[ ses(), note ]);
243 if (typeof r.ilsevent != 'undefined') throw(r);
244 setTimeout(function() {
249 g.error.standard_unexpected_error_alert($('catStrings').getString('staff.cat.copy_notes.new_note.error'),E);
256 <messagecatalog id="catStrings" src="/xul/server/locale/<!--#echo var='locale'-->/cat.properties" />
257 <messagecatalog id="serialStrings" src="/xul/server/locale/<!--#echo var='locale'-->/serial.properties" />
259 <stack hidden="true" id="note_template" flex="1">
260 <vbox flex="1" style="background-color: black; margin:3px"/>
261 <vbox flex="1" style="background-color: #FFDE00; -moz-border-radius-topright: 35px; border: 2px groove ThreeDFace; margin:3px;" >
263 <description name="title" style="font-weight: bold"/>
265 <description name="create_date" style="font-weight: bold"/>
266 <description name="pub" style="font-weight: bold"/>
268 <description style="white-space: pre-wrap;" name="value"/>
272 <vbox flex="1" class="my_overflow" id="notes_panel">