]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/info_notes.xul
to cache or not to cache... don't cache if you just changed data
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / info_notes.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/patron_display.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="patron_info_win" width="700" height="550"
23         onload="try{ my_init(); font_helper(); } catch(E) { alert(E); }"
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
35                 function $(id) { return document.getElementById(id); }
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
44                                 JSAN.use('util.error'); g.error = new util.error();
45                                 JSAN.use('util.network'); g.network = new util.network();
46                                 JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('patron.util');
47                                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
48
49                                 g.error.sdump('D_TRACE','my_init() for patron_info.xul');
50
51                                 g.cgi = new CGI();
52                                 g.patron_id = g.cgi.param('patron_id');
53
54                                 g.new_note = false;
55
56                                 refresh();
57
58                         } catch(E) {
59                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
60                                         "system administrator or software developer the following:\npatron_info.xul\n" + E + '\n';
61                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
62                                 alert(err_msg);
63                         }
64                 }
65
66                 function refresh() {
67                         retrieve_notes(); render_notes();
68                 }
69
70                 function retrieve_notes() {
71                         if (g.new_note) {
72                                 g.notes = g.network.simple_request('FM_AUN_RETRIEVE_ALL',[ ses(), { 'patronid' : g.patron_id } ]).reverse();
73                                 g.new_note = false;
74                         } else {
75                                 g.notes = g.network.cached_request('FM_AUN_RETRIEVE_ALL',[ ses(), { 'patronid' : g.patron_id } ]).reverse();
76                         }
77                 }
78
79                 function apply(node,field,value) {
80                         util.widgets.apply(
81                                 node,'name',field,
82                                 function(n) {
83                                         switch(n.nodeName) {
84                                                 case 'description' : n.appendChild( document.createTextNode( value ) ); break;
85                                                 case 'label' : n.value = value; break;
86                                                 default : n.value = value; break;
87                                         }
88                                 }
89                         );
90                 }
91
92                 function render_notes() {
93                         JSAN.use('util.widgets'); util.widgets.remove_children('notes_panel');
94                         var np = $('notes_panel');
95                                 var hbox = document.createElement('hbox'); np.appendChild(hbox);
96                                         var btn = document.createElement('button'); hbox.appendChild(btn);
97                                                 btn.setAttribute('label','Add New Note');
98                                                 btn.setAttribute('accesskey','A');
99                                                 btn.setAttribute('oncommand','new_note()');
100
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){n.setAttribute("tooltiptext","Note ID: " + g.notes[i].id() + " Creator ID: " + g.notes[i].creator());}
108                                 );
109                                 apply(node,'title',g.notes[i].title());
110                                 apply(node,'pub',get_bool(g.notes[i].pub()) ? "Patron Visible" : "Staff Only");
111                                 apply(node,'value',g.notes[i].value());
112                                 apply(node,'id',g.notes[i].id());
113                                 apply(node,'creator',g.notes[i].creator());
114
115                                 /* button bar */
116                                 var hb = document.createElement('hbox'); np.appendChild(hb);
117                                         var btn1 = document.createElement('button'); hb.appendChild(btn1);
118                                                 btn1.setAttribute('label','Delete This Note');
119                                                 btn1.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
120
121                                                 btn1.addEventListener(
122                                                         'command',
123                                                         function(id){ return function() { 
124                                                                 var r = g.error.yns_alert('Delete the note titled "' + g.notes[id].title() + '" created on ' + g.notes[id].create_date().toString().substr(0,10) + '?','Delete Note','Yes','No',null,'Check here to confirm this action'); 
125                                                                 if (r == 0) {
126                                                                         g.network.simple_request('FM_AUN_DELETE',[ses(),g.notes[id].id()]);
127                                                                         setTimeout(function(){ g.new_note = true; alert('Note deleted.'); refresh();},0);
128                                                                 }
129                                                         } }(i),
130                                                         false
131                                                 );
132                                         var btn2 = document.createElement('button'); hb.appendChild(btn2);
133                                                 btn2.setAttribute('label','Print');
134                                                 btn2.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
135
136                                                 btn2.addEventListener(
137                                                         'command',
138                                                         function(id){ return function() { 
139                                                                 try {
140                                                                         JSAN.use('patron.util'); 
141                                                                         var patron_obj = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id);
142                                                                         var staff_obj = patron.util.retrieve_name_via_id( ses(), g.notes[id].creator() );
143                                                                         JSAN.use('util.print'); var p = new util.print();
144                                                                         p.simple(
145                                                                                 '<hr/>'
146                                                                                 + '<p>Pertaining to ' + 
147                                                                                         ( patron_obj.prefix() ? patron_obj.prefix() + ' ' : '') + 
148                                                                                         patron_obj.family_name() + ', ' + 
149                                                                                         patron_obj.first_given_name() + ' ' +
150                                                                                         ( patron_obj.second_given_name() ? patron_obj.second_given_name() + ' ' : '' ) +
151                                                                                         ( patron_obj.suffix() ? patron_obj.suffix() : '')
152                                                                                         + ' : ' 
153                                                                                 + patron_obj.card().barcode() + '</p>'
154                                                                                 + '<p><b>"' 
155                                                                                 + g.notes[id].title() + '"</b> created on ' + g.notes[id].create_date().toString().substr(0,10) 
156                                                                                 + ' by ' + staff_obj[0] + ' @ ' + g.data.hash.aou[ staff_obj[3] ].shortname()
157                                                                                 + '</p><p>'
158                                                                                 + g.notes[id].value()
159                                                                                 + '</p><hr/>'
160                                                                         );
161                                                                 } catch(E) {
162                                                                         g.error.standard_unexpected_error_alert('printing note #' + g.notes[id].id(), E);
163                                                                 }
164                                                         } }(i),
165                                                         false
166                                                 );
167                         }
168
169                 }
170                 
171                 function new_note() {
172                         try {
173                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite");
174                                 var xml = '<groupbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1"><caption label="New Note"/><grid flex="1"><columns><column/><column flex="1"/></columns><rows><row><label value="Patron Visible?"/><checkbox id="pub" name="fancy_data"/></row><row><label value="Title"/><textbox id="title" name="fancy_data"/></row><row><label value="Note"/><textbox multiline="true" id="note" name="fancy_data"/></row><row><spacer/><hbox><button label="Cancel" name="fancy_cancel" accesskey="C"/><button label="Add Note" accesskey="A" name="fancy_submit"/></hbox></row></rows></grid></groupbox>';
175                                 g.data.init({'via':'stash'});
176                                 g.data.temp_note_xml = xml; g.data.stash('temp_note_xml');
177                                 window.open(
178                                         urls.XUL_FANCY_PROMPT
179                                         + '?xml_in_stash=temp_note_xml'
180                                         + '&focus=' + window.escape('title')
181                                         + '&title=' + window.escape('Add Note'),
182                                         'fancy_prompt', 'chrome,resizable,modal,width=700,height=500'
183                                 );
184                                 g.data.init({'via':'stash'});
185                                 if (g.data.fancy_prompt_data != '') {
186                                         //alert(js2JSON(g.data.fancy_prompt_data));
187                                         var note = new aun();
188                                         note.isnew(1);
189                                         note.title( g.data.fancy_prompt_data.title );
190                                         note.value( g.data.fancy_prompt_data.note );
191                                         note.pub( get_bool( g.data.fancy_prompt_data.pub ) ? get_db_true() : get_db_false() );
192                                         note.usr( g.patron_id );
193                                         var r = g.network.simple_request('FM_AUN_CREATE',[ ses(), note ]);
194                                         if (typeof r.ilsevent != 'undefined') throw(r);
195                                         setTimeout(function(){ g.new_note = true; alert('Note added.'); refresh();},0);
196                                 }
197                         } catch(E) {
198                                 g.error.standard_unexpected_error_alert('The note was not likely created.',E);
199                         }
200                 }
201
202         ]]>
203         </script>
204
205         <stack hidden="true" id="note_template" flex="1">
206                 <groupbox flex="1" style="background-color: black;"/>
207                 <groupbox flex="1" style="background-color: #FFDE00; -moz-border-radius-topright: 35px;" >
208                         <hbox>
209                                 <description name="title" style="font-weight: bold"/>
210                                 <spacer flex="1"/>
211                                 <description name="create_date" style="font-weight: bold"/>
212                                 <description name="pub" style="font-weight: bold"/>
213                         </hbox>
214                         <description name="value"/>
215                 </groupbox>
216         </stack>
217
218         <vbox flex="1" class="my_overflow" id="notes_panel">
219         </vbox>
220
221
222 </window>
223