]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/serial/notes.xul
Serial alert notes missing commit
[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                                 if (typeof JSAN == 'undefined') { 
43                                         throw( $("commonStrings").getString('common.jsan.missing') );
44                                 }
45                                 JSAN.errorLevel = "die"; // none, warn, or die
46                                 JSAN.addRepository('/xul/server/');
47
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'});
52
53                                 g.error.sdump('D_TRACE','my_init() for notes.xul');
54
55                                 g.notes = xul_param('notes');
56                                 g.disable_create = xul_param('disable_create');
57                                 // in the code below, by default, function_type and
58                                 // fm_type (aka classname) are assumed the same other
59                                 // than case
60                                 if (g.notes) { // we have the notes passed in
61                                         g.function_type_map = xul_param('function_type_map');
62                                         if (!g.function_type_map) { // didn't get one, build one
63                                                 g.function_type_map = {};
64                                                 for (i = 0; i < g.notes.length; i++) {
65                                                         g.function_type_map[g.notes[i].classname] = g.notes[i].classname.toUpperCase();
66                                                 }
67                                         }
68                                         g.section_titles = xul_param('section_titles');
69                                         g.section_id_names = xul_param('section_id_names');
70                                 } else { // we need to retreieve the notes
71                                         g.object_type = xul_param('object_type');
72                                         g.object_id = xul_param('object_id');
73                                         function_type = xul_param('function_type');
74                                         g.fm_type = xul_param('fm_type');
75                                         if (!g.fm_type) {
76                                                 g.fm_type = function_type.toLowerCase();
77                                         }
78                                         g.function_type = function_type;
79                                         g.function_type_map = {};
80                                         g.function_type_map[g.fm_type] = function_type;
81                                         g.constructor = xul_param('constructor');
82                                 }
83
84                                 var window_title = xul_param('title',{'modal_xulG':true});
85                                 if (window_title) {
86                                         try { document.title = window_title; } catch(E) {}
87                                 }
88
89                                 refresh();
90
91                         } catch(E) {
92                                 var err_msg = $("commonStrings").getFormattedString('common.exception', ['serial/notes.xul', js2JSON(E)]);
93                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
94                                 alert(err_msg);
95                         }
96                 }
97
98                 function refresh() {
99                         retrieve_notes(); render_notes();
100                 }
101
102                 function retrieve_notes() {
103                         if (g.notes) return;
104                         g.notes = g.network.simple_request(
105                                 'FM_' + g.function_type_map[g.fm_type] + '_RETRIEVE_ALL', [
106                                         { 'authtoken' : ses(), 'object_id' : g.object_id }
107                                 ]
108                         );
109                 }
110
111                 function apply(node,field,value) {
112                         util.widgets.apply(
113                                 node,'name',field,
114                                 function(n) {
115                                         switch(n.nodeName) {
116                                                 case 'description' : n.appendChild( document.createTextNode( value ) ); break;
117                                                 case 'image' : n.src = value; break;
118                                                 default : n.value = value; break;
119                                         }
120                                 }
121                         );
122                 }
123
124                 function render_notes() {
125                         JSAN.use('util.widgets'); util.widgets.remove_children('notes_panel');
126                         var np = $('notes_panel');
127                         if (!g.disable_create) {
128                                 var hbox = document.createElement('hbox'); np.appendChild(hbox);
129                                         var btn = document.createElement('button'); hbox.appendChild(btn);
130                                                 btn.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.render_notes.label'));
131                                                 btn.setAttribute('accesskey', $('catStrings').getString('staff.cat.copy_notes.render_notes.accesskey'));
132                                                 btn.setAttribute('oncommand','new_note()');
133                         }
134
135                         var hb; // keep button bar reference for adding close button
136                         var section_type;
137                         var section_id;
138                         var section_indices = {};
139                         for (var i = 0; i < g.notes.length; i++) {
140                                 var note = g.notes[i];
141
142                                 if (g.section_titles) {
143                                         if (note.classname != section_type || note[g.section_id_names[note.classname]]() != section_id) {
144                                                 section_type = note.classname;
145                                                 if (!(section_type in section_indices)) {
146                                                         section_indices[section_type] = 0;
147                                                 } else {
148                                                         section_indices[section_type]++;
149                                                 }
150                                                 var section_title = g.section_titles[section_type][section_indices[section_type]];
151                                                 section_id = note[g.section_id_names[section_type]]();
152
153                                                 // add the title to the window
154                                                 var hbox = document.createElement('hbox');
155                                                 np.appendChild(hbox);
156                                                 var desc = document.createElement('description');
157                                                 desc.appendChild(document.createTextNode(section_title));
158                                                 hbox.appendChild(desc);
159                                         }
160                                 }
161
162                                 /* template */
163                                 var node = $('note_template').cloneNode(true); np.appendChild(node); node.hidden = false;
164                                 apply(node,'create_date',note.create_date().toString().substr(0,10));
165                                 util.widgets.apply(node,'name','create_date',
166                                         function(n) {
167                                                 n.setAttribute(
168                                                         "tooltiptext",
169                                                         $('catStrings').getString('staff.cat.copy_notes.widgets_apply.note_id') + " "
170                                                         + note.id() + " "
171                                                         + $('catStrings').getString('staff.cat.copy_notes.widgets_apply.creator_id') + " "
172                                                         + note.creator()
173                                                 );
174                                         }
175                                 );
176                                 apply(node,'title',note.title());
177                                 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'));
178                                 apply(node,'alert',get_bool( g.notes[i].alert() ) ? '/xul/server/skin/media/images/bell.png' : '');
179                                 apply(node,'value',g.notes[i].value());
180                                 apply(node,'id',g.notes[i].id());
181                                 apply(node,'creator',g.notes[i].creator());
182
183                                 /* button bar */
184                                 hb = document.createElement('hbox'); np.appendChild(hb);
185                                         var btn0 = document.createElement('button'); hb.appendChild(btn0);
186                                                 btn0.setAttribute('label', $('serialStrings').getString('staff.serial.notes.do_edit_note.label'));
187                                                 btn0.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
188
189                                                 btn0.addEventListener(
190                                                         'command',
191                                                         function(index){ return function() { new_note(index) } }(i),
192                                                         false
193                                                 );
194                                         var btn1 = document.createElement('button'); hb.appendChild(btn1);
195                                                 btn1.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.delete_note.label'));
196                                                 btn1.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
197
198                                                 btn1.addEventListener(
199                                                         'command',
200                                                         function(index){ return function() { 
201                                                                 var r = g.error.yns_alert(
202                                                                         $('catStrings').getFormattedString('staff.cat.copy_notes.delete_note.prompt.msg', [g.notes[index].title(), g.notes[index].create_date().toString().substr(0,10)]),
203                                                                         $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.title'),
204                                                                         $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.yes'),
205                                                                         $('catStrings').getString('staff.cat.copy_notes.delete_note.prompt.no'),
206                                                                         null,
207                                                                         $('commonStrings').getString('common.confirm')
208                                                                 ); 
209                                                                 if (r == 0) {
210                                                                         g.network.simple_request('FM_'+g.function_type_map[g.notes[index].classname]+'_DELETE',[ses(),g.notes[index].id()]);
211                                                                         g.notes.splice(index, 1);
212                                                                         setTimeout(function() { 
213                                                                                 alert($('catStrings').getString('staff.cat.copy_notes.delete_note.success'));
214                                                                                 refresh(); },0
215                                                                         );
216                                                                         if(!xulG.notes_updated) xulG.notes_updated = {};
217                                                                         xulG.notes_updated[g.notes[index].classname] = 1;
218                                                                 }
219                                                         } }(i),
220                                                         false
221                                                 );
222                         }
223
224                         // add close button
225                         if (!hb) { // no notes yet, fill the space and add a bar
226                                 var spacer = document.createElement('spacer'); np.appendChild(spacer); spacer.flex = 1;
227                                 hb = document.createElement('hbox'); np.appendChild(hb);
228                         }
229                         var spacer = document.createElement('spacer');
230                         hb.appendChild(spacer); spacer.flex = 1;
231                         var btn2 = document.createElement('button'); hb.appendChild(btn2);
232                         btn2.setAttribute('label', $('catStrings').getString('staff.cat.copy_notes.delete_note.close_window'));
233                         btn2.setAttribute('oncommand','window.close();');
234
235                 }
236                 
237                 function xml_encode(str) {
238                         return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
239                 }
240
241                 function new_note(index) {
242                         var public = false;
243                         var alert = false;
244                         var title = '';
245                         var value = '';
246                         var edit_mode; // for clarity
247                         var label_text;
248                         var button_accesskey;
249                         var note_fm_type;
250
251                         if (typeof index != 'undefined') {
252                                 edit_mode = true;
253                                 public = get_bool(g.notes[index].pub());
254                                 alert = get_bool(g.notes[index].alert());
255                                 title = xml_encode(g.notes[index].title());
256                                 value = xml_encode(g.notes[index].value());
257                                 note_fm_type = g.notes[index].classname;
258                                 label_text = $('serialStrings').getString('staff.serial.notes.edit_note.label');
259                                 button_accesskey = $('serialStrings').getString('staff.serial.notes.edit_note.accesskey');
260                         } else {
261                                 note_fm_type = g.fm_type;
262                                 label_text = $('catStrings').getString('staff.cat.copy_notes.new_note.add_note.label');
263                                 button_accesskey = $('catStrings').getString('staff.cat.copy_notes.new_note.add_note.accesskey');
264                         }
265
266                         try {
267                                 value = value.replace(/\n/g, "&#10;"); // preserve newlines
268                                 var xml = '<groupbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1"> \
269                                         <caption label="' + label_text + '"/> \
270                                         <grid flex="1"><columns><column/><column flex="1"/></columns> \
271                                                 <rows> \
272                                                         <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.public') + '"/><checkbox id="pub" name="fancy_data" checked="' + public + '"/></row> \
273                                                         <row><label value="' + fieldmapper.IDL.fmclasses[note_fm_type].field_map.alert.label + '"/><checkbox id="alert" name="fancy_data" checked="' + alert + '"/></row> \
274                                                         <row><label value="' + $('catStrings').getString('staff.cat.copy_notes.new_note.title') + '"/><textbox id="title" name="fancy_data" context="clipboard" value="' + title + '"/></row> \
275                                                         <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> \
276                                                         <row><spacer/><hbox> \
277                                                                 <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') + '"/> \
278                                                                 <button label="' + label_text + '" accesskey="' + button_accesskey + '" name="fancy_submit"/></hbox></row> \
279                                                 </rows></grid></groupbox>';
280                                 JSAN.use('util.window'); var win = new util.window();
281                                 var fancy_prompt_data = win.open(
282                                         urls.XUL_FANCY_PROMPT,
283                                         'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
284                                         { 'xml' : xml, 'focus' : 'title', 'title' : label_text }
285                                 );
286                                 if (fancy_prompt_data.fancy_status == 'complete') {
287                                         var note;
288                                         if (edit_mode) {
289                                                 note = g.notes[index];
290                                         } else {
291                                                 note = new g.constructor();
292                                                 note.isnew(1);
293                                                 note[g.object_type]( g.object_id );
294                                         }
295                                         note.title( fancy_prompt_data.title );
296                                         note.value( fancy_prompt_data.note );
297                                         note.pub( get_bool( fancy_prompt_data.pub ) ? get_db_true() : get_db_false() );
298                                         note.alert( get_bool( fancy_prompt_data.alert ) ? get_db_true() : get_db_false() );
299                                         var r = g.network.simple_request('FM_'+g.function_type_map[note.classname]+'_UPDATE',[ ses(), note ]);
300                                         if (typeof r.ilsevent != 'undefined') throw(r);
301                                         // not every note type support pcrud, so we can't do this
302                                         // for now, if they pass in a pile of notes (g.notes mode),
303                                         // they simply won't be able to add notes
304                                         // One alternative would be to teach the UPDATE functions
305                                         // to send back the updated note objects
306                                         /*
307                                         if (!edit_mode) { // fetch new note and add to pile
308                                                 note = g.network.request(
309                                                         'open-ils.pcrud',
310                                                         'open-ils.pcrud.retrieve.' + note.classname,
311                                                         [ ses(), r ]
312                                                 );
313                                                 g.notes.push(note);
314                                         }
315                                         */
316                                         if (!edit_mode) { // force re-fetch of notes
317                                                 g.notes = undefined;
318                                         }
319                                         if(!xulG.notes_updated) xulG.notes_updated = {};
320                                         xulG.notes_updated[note.classname] = 1;
321                                         setTimeout(function() {
322                                                 refresh();},0
323                                         );
324                                 }
325                         } catch(E) {
326                                 g.error.standard_unexpected_error_alert($('catStrings').getString('staff.cat.copy_notes.new_note.error'),E);
327                         }
328                 }
329
330         ]]>
331         </script>
332
333         <messagecatalog id="catStrings" src="/xul/server/locale/<!--#echo var='locale'-->/cat.properties" />
334         <messagecatalog id="serialStrings" src="/xul/server/locale/<!--#echo var='locale'-->/serial.properties" />
335
336         <stack hidden="true" id="note_template" flex="1">
337                 <vbox flex="1" style="background-color: black; margin:3px"/>
338                 <vbox flex="1" style="background-color: #FFDE00; -moz-border-radius-topright: 35px; border: 2px groove ThreeDFace; margin:3px;" >
339                         <hbox align="start">
340                                 <description name="title" style="font-weight: bold"/>
341                                 <spacer flex="1"/>
342                                 <description name="create_date" style="font-weight: bold"/>
343                                 <description name="pub" style="font-weight: bold"/>
344                                 <image name="alert" src=""/>
345                         </hbox>
346                         <description style="white-space: pre-wrap;" name="value"/>
347                 </vbox>
348         </stack>
349
350         <vbox flex="1" class="my_overflow" id="notes_panel">
351         </vbox>
352
353
354 </window>
355