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