]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/info_notes.xul
Switch to .authoritative version of some methods
[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.patron_id = xul_param('patron_id');
52
53                                 g.new_note = false;
54
55                                 refresh();
56
57                         } catch(E) {
58                                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
59                                         "system administrator or software developer the following:\npatron_info.xul\n" + E + '\n';
60                                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
61                                 alert(err_msg);
62                         }
63                 }
64
65                 function refresh() {
66                         retrieve_notes(); render_notes();
67                 }
68
69                 function retrieve_notes() {
70                         if (g.new_note) {
71                                 g.notes = g.network.simple_request('FM_AUN_RETRIEVE_ALL.authoritative',[ ses(), { 'patronid' : g.patron_id } ]).reverse();
72                                 g.new_note = false;
73                         } else {
74                                 g.notes = g.network.simple_request('FM_AUN_RETRIEVE_ALL.authoritative',[ ses(), { 'patronid' : g.patron_id } ]).reverse();
75                         }
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','Add New Note');
97                                                 btn.setAttribute('accesskey','A');
98                                                 btn.setAttribute('oncommand','new_note()');
99
100                         for (var i = 0; i < g.notes.length; i++) {
101
102                                 /* template */
103                                 var node = $('note_template').cloneNode(true); np.appendChild(node); node.hidden = false;
104                                 apply(node,'create_date',g.notes[i].create_date().toString().substr(0,10));
105                                 util.widgets.apply(node,'name','create_date',
106                                         function(n){n.setAttribute("tooltiptext","Note ID: " + g.notes[i].id() + " Creator ID: " + g.notes[i].creator());}
107                                 );
108                                 apply(node,'title',g.notes[i].title());
109                                 apply(node,'pub',get_bool(g.notes[i].pub()) ? "Patron Visible" : "Staff Only");
110                                 apply(node,'value',g.notes[i].value());
111                                 apply(node,'id',g.notes[i].id());
112                                 apply(node,'creator',g.notes[i].creator());
113
114                                 /* button bar */
115                                 var hb = document.createElement('hbox'); np.appendChild(hb);
116                                         var btn1 = document.createElement('button'); hb.appendChild(btn1);
117                                                 btn1.setAttribute('label','Delete This Note');
118                                                 btn1.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
119
120                                                 btn1.addEventListener(
121                                                         'command',
122                                                         function(id){ return function() { 
123                                                                 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'); 
124                                                                 if (r == 0) {
125                                                                         g.network.simple_request('FM_AUN_DELETE',[ses(),g.notes[id].id()]);
126                                                                         setTimeout(function(){ g.new_note = true; alert('Note deleted.'); refresh();},0);
127                                                                 }
128                                                         } }(i),
129                                                         false
130                                                 );
131                                         var btn2 = document.createElement('button'); hb.appendChild(btn2);
132                                                 btn2.setAttribute('label','Print');
133                                                 btn2.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
134
135                                                 btn2.addEventListener(
136                                                         'command',
137                                                         function(id){ return function() { 
138                                                                 try {
139                                                                         JSAN.use('patron.util'); 
140                                                                         var patron_obj = patron.util.retrieve_fleshed_au_via_id(ses(),g.patron_id);
141                                                                         var staff_obj = patron.util.retrieve_name_via_id( ses(), g.notes[id].creator() );
142                                                                         JSAN.use('util.print'); var p = new util.print();
143                                                                         p.simple(
144                                                                                 '<hr/>'
145                                                                                 + '<p>Pertaining to ' + 
146                                                                                         ( patron_obj.prefix() ? patron_obj.prefix() + ' ' : '') + 
147                                                                                         patron_obj.family_name() + ', ' + 
148                                                                                         patron_obj.first_given_name() + ' ' +
149                                                                                         ( patron_obj.second_given_name() ? patron_obj.second_given_name() + ' ' : '' ) +
150                                                                                         ( patron_obj.suffix() ? patron_obj.suffix() : '')
151                                                                                         + ' : ' 
152                                                                                 + patron_obj.card().barcode() + '</p>'
153                                                                                 + '<p><b>"' 
154                                                                                 + g.notes[id].title() + '"</b> created on ' + g.notes[id].create_date().toString().substr(0,10) 
155                                                                                 + ' by ' + staff_obj[0] + ' @ ' + g.data.hash.aou[ staff_obj[3] ].shortname()
156                                                                                 + '</p><p>'
157                                                                                 + g.notes[id].value()
158                                                                                 + '</p><hr/>'
159                                                                         );
160                                                                 } catch(E) {
161                                                                         g.error.standard_unexpected_error_alert('printing note #' + g.notes[id].id(), E);
162                                                                 }
163                                                         } }(i),
164                                                         false
165                                                 );
166                         }
167
168                 }
169                 
170                 function new_note() {
171                         try {
172                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect UniversalBrowserWrite");
173                                 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>';
174                                 //g.data.init({'via':'stash'});
175                                 //g.data.temp_note_xml = xml; g.data.stash('temp_note_xml');
176                                 JSAN.use('util.window'); var win = new util.window();
177                                 var fancy_prompt_data = win.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                                         { 'xml' : xml, 'focus' : 'title', 'title' : 'Add Note' }
184                                 );
185                                 if (fancy_prompt_data.fancy_status == 'complete') {
186                                         //alert(js2JSON(g.data.fancy_prompt_data));
187                                         var note = new aun();
188                                         note.isnew(1);
189                                         note.title( fancy_prompt_data.title );
190                                         note.value( fancy_prompt_data.note );
191                                         note.pub( get_bool( 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